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
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:
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:
Save the Configuration:
Step 4: Creating a Test Workflow
3. Add Skill to Workflow:
Step 5: Testing the Agent
2. Monitor Execution:
3. Review the Output:
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 !
Helping Enterprises deploy #GenerativeAI in their workflows !
8 个月Local model exploration sparks curiosity. Custom skill creation unlocks potential. Nedved Yang