Geek out time: Creating an Agent with Customized Skill in AutoGen Builder

Geek out time: Creating an Agent with Customized Skill in AutoGen Builder

((Also on Constellar tech blog: https://medium.com/the-constellar-digital-technology-blog/geek-out-time-creating-an-agent-with-customized-skill-in-autogen-builder-f775bd9c00d9 ))

I have tried using the local LLM/SLM through Autogen Builder at “https://www.dhirubhai.net/pulse/geek-out-time-creating-local-ai-agent-my-mac-using-autogen-yang-tu0rc/?trackingId=bGOJuSFhSC2drvNO5G2jXQ%3D%3D”, as the follow-up, the next step is to explore how to create a custom skill in AutoGen Builder and assign it to an agent. I pick the skill of fetching HTML pages from a given URL.

Step 1: Setting Up Your Environment

Please visit “https://www.dhirubhai.net/pulse/geek-out-time-creating-local-ai-agent-my-mac-using-autogen-yang-tu0rc/?trackingId=bGOJuSFhSC2drvNO5G2jXQ%3D%3D” for how to run the autogen builder.

Step 2: Creating a New Skill

  1. Log in to AutoGen Builder: Open AutoGen Builder in your web browser and log in with your credentials.
  2. Navigate to Skills Section: Go to the section where you can create new skills.
  3. Create a New Skill:

  • Click on the “Create New Skill” button
  • Name the skill GetHTMLPage.
  • Provide a description such as Get Html Page

4. Add the Python Code:

In the code editor or input field provided by AutoGen Builder, paste the following Python code:

import requests

def fetch_html_page(url: str) -> str:
    """
    Function to fetch the HTML content of a given URL.

    :param url: The URL of the webpage to fetch.
    :return: The HTML content of the webpage.
    """
    try:
        response = requests.get(url)
        response.raise_for_status()  # Raise an HTTPError for bad responses (4xx and 5xx)
        return response.text
    except requests.RequestException as e:
        print(f"Error fetching the URL {url}: {e}")
        return ""

# Main skill function
def main(url: str) -> str:
    return fetch_html_page(url)

# Example usage (for local testing)
if __name__ == "__main__":
    url = "https://www.example.com"
    html_content = main(url)
    print(html_content)        

5. Save the Skill:

  • Click on the “Save” button to save your new skill.

Step 3: Configuring the System Message

The “System Message” provides instructions for the agent on how to handle the task. Here’s an example of what to include:

Instructions:
1. Receive a URL as input from the user.
2. Execute the pre-configured Python code to fetch the HTML content of the given URL.
3. Return the fetched HTML content as the output.
Handle the task step-by-step:
- If a URL is provided, proceed to fetch its HTML content using the code.
- If any errors occur, capture and return the error message.
Your primary objective is to provide the HTML content of the provided URL or an error message if the fetching fails.
Reply "TERMINATE" at the end when everything is done.        

Create or Edit the Agent:

Go to the section in AutoGen Builder where you can create or edit the agent.

Under the “Models”, I am using the GPT, where you need to go to OpenAI site to generate the API key to put in here. (https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)

Finally, link the custom skill created to the agent.

System Message:

  • Paste the above “System Message” into the “System Message” field of the agent configuration.

Save the Configuration:

  • Save the agent configuration with the new system message.

Step 4: Creating a Test Workflow

  1. Navigate to Workflows Section: Go to the section where you can create or manage workflows.
  2. Create a New Workflow:

  • Click on the “Create New Workflow” button.
  • Name the workflow appropriately, for example, GetHtmlPage.

3. Add Skill to Workflow:

  • Add the “GetHtmlPage” agent to the workflow as the “Receiver”

Step 5: Testing the Agent

  1. Run the Workflow:

  • Click on the “Run” button to execute the workflow with the provided input.

2. Monitor Execution:

  • Watch the execution logs to see if the skill runs successfully.

3. Review the Output:

  • Verify that the output contains the HTML content of the provided URL.

Conclusion

Following these steps, we’ve successfully created a custom agent in AutoGen Builder that fetches HTML content from a URL. The guide provided a comprehensive process, from setting up the environment to testing the agent. If you encounter any issues or need further assistance, feel free to ping me. It will be interesting to try a few complicated custom skills with group chat. Stay tuned.

Have fun !

Raghav Sehgal

Helping Enterprises deploy #GenerativeAI in their workflows !

8 个月

Local model exploration sparks curiosity. Custom skill creation unlocks potential. Nedved Yang

要查看或添加评论,请登录

Nedved Yang的更多文章

社区洞察

其他会员也浏览了