Skip to main content
Open In Colab Open on GitHub AutoGen offers conversable agents powered by LLM, tool, or human, which can be used to perform tasks collectively via automated chat. This framework allows tool use and human participation through multi-agent conversation. Please find documentation about this feature here. In this notebook, we demonstrate how to use AssistantAgent and UserProxyAgent to make function calls with the new feature of OpenAI models (in model version 0613). A specified prompt and function configs must be passed to AssistantAgent to initialize the agent. The corresponding functions must be passed to UserProxyAgent, which will execute any function calls made by AssistantAgent. Besides this requirement of matching descriptions with functions, we recommend checking the system message in the AssistantAgent to ensure the instructions align with the function call descriptions.
Install ag2:
For more information, please refer to the installation guide.
Learn more about configuring LLMs for agents here.

Making Async and Sync Function Calls

In this example, we demonstrate function call execution with AssistantAgent and UserProxyAgent. With the default system prompt of AssistantAgent, we allow the LLM assistant to perform tasks with code, and the UserProxyAgent would extract code blocks from the LLM response and execute them. With the new “function_call” feature, we define functions and specify the description of the function in the OpenAI config for the AssistantAgent. Then we register the functions in UserProxyAgent.
Start the conversation. await is used to pause and resume code execution for async IO operations. Without await, an async function returns a coroutine object but doesn’t execute the function. With await, the async function is executed and the current function is paused until the awaited function returns a result.

Async Function Call with Group Chat

Sync and async can be used in topologies beyond two agents. Below, we show this feature for a group chat.
Finally, we initialize the chat that would use the functions defined above: