Add AG2 framework integration guide#887
Conversation
Adds documentation for using Arcade tools with AG2 (formerly AutoGen), an open-source multi-agent framework. Includes quick start example with AssistantAgent + ConversableAgent pattern and register_for_llm/register_for_execution tool registration.
|
@faridun-ag2 is attempting to deploy a commit to the Arcade AI Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey @torresmateo 👋 We're from the AG2 team — AG2 (formerly AutoGen) is an open-source framework for building multi-agent AI systems. We've been working on an integration with Arcade and put together this guide showing how to use Arcade tools with AG2 agents. The guide covers:
We also have more examples in our build-with-ag2 repo. Would love your feedback on the guide — happy to adjust anything to match your docs standards! |
| AG2 registers tools as typed Python functions. Define a wrapper for each Arcade tool you want the agent to use. Each function calls the `call_arcade_tool` helper with the appropriate tool name and inputs. | ||
|
|
||
| ```python filename="main.py" | ||
| def list_emails(max_results: int = 10, is_unread: bool = False) -> dict: | ||
| """List emails from Gmail inbox. | ||
| - max_results: maximum number of emails to return (default 10) | ||
| - is_unread: if True, return only unread emails | ||
| """ | ||
| return call_arcade_tool( | ||
| "Gmail.ListEmails", | ||
| {"max_results": max_results, "is_unread": is_unread}, | ||
| ) | ||
|
|
||
|
|
||
| def send_email(to: str, subject: str, body: str) -> dict: | ||
| """Send a new email. | ||
| - to: recipient email address | ||
| - subject: email subject line | ||
| - body: plain-text email body | ||
| """ | ||
| return call_arcade_tool( | ||
| "Gmail.SendEmail", | ||
| {"recipient": to, "subject": subject, "body": body}, | ||
| ) | ||
|
|
||
|
|
||
| def reply_to_email(email_id: str, body: str) -> dict: | ||
| """Reply to an email by message ID. | ||
| - email_id: ID of the message to reply to | ||
| - body: plain-text reply body | ||
| """ | ||
| return call_arcade_tool( | ||
| "Gmail.ReplyToEmail", | ||
| {"reply_to_message_id": email_id, "body": body, "reply_to_whom": "ONLY_THE_SENDER"}, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Create the agents and register the tools | ||
|
|
||
| Create the `AssistantAgent` and `ConversableAgent`, then register each tool function using the `register_for_llm` and `register_for_execution` pattern. This tells the assistant which tools it can call and the user proxy how to execute them. | ||
|
|
||
| ```python filename="main.py" | ||
| assistant = AssistantAgent( | ||
| name="GmailAssistant", | ||
| llm_config=llm_config, | ||
| system_message="You are a helpful Gmail assistant. Use the provided tools to help the user manage their email.", | ||
| ) | ||
|
|
||
| user_proxy = ConversableAgent( | ||
| name="User", | ||
| human_input_mode="ALWAYS", | ||
| is_termination_msg=lambda msg: "TERMINATE" in (msg.get("content") or ""), | ||
| ) | ||
|
|
||
| # Register tools: each function is registered for both LLM (caller) and execution (executor) | ||
| for func, description in [ | ||
| (list_emails, "List emails from Gmail inbox. Filter by unread status and max results."), | ||
| (send_email, "Send a new email to a recipient with subject and body."), | ||
| (reply_to_email, "Reply to an email by message ID with a body."), | ||
| ]: | ||
| user_proxy.register_for_execution()(func) | ||
| assistant.register_for_llm(description=description)(func) | ||
| ``` |
There was a problem hiding this comment.
I see how this may work, but I don't want to encourage "masking" of Arcade's own tool definitions in a "get started" tutorial. I like the overall pattern though, and I think it's very easy to turn this into a dynamic function builder. I think a better pattern is:
- defining which tools will be retrieved from Arcade
- get the tool definitions
- use the tool definitions to generate compatible callables for the framework
In this case, it seems that we need simple python functions, so the structure of the "generator" could be to programmatically assemble the callable based on the tool definition.
Summary
AssistantAgent+ConversableAgentpattern andregister_for_llm/register_for_executiontool registrationChanges
app/en/get-started/agent-frameworks/ag2/— new guide with_meta.tsxanduse-arcade-tools/page.mdxapp/_components/agent-framework-tabs.tsx— AG2 card in Python tabapp/en/get-started/agent-frameworks/_meta.tsx— AG2 nav entryapp/en/home/landing-page.tsx— AG2 in frameworks list and "Power Your Agent" cardpublic/images/icons/ag2.svg— AG2 logo iconTest plan
/en/get-started/agent-frameworks/ag2/use-arcade-tools