mirror of
https://github.com/microsoft/autogen.git
synced 2026-05-13 03:00:55 -04:00
Tool use in agentchat (#664)
* Tool use in agentchat * Update link * doc string
This commit is contained in:
@@ -311,7 +311,7 @@
|
||||
],
|
||||
"source": [
|
||||
"from autogen_agentchat.agents import CodeExecutorAgent, CodingAssistantAgent\n",
|
||||
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
|
||||
"from autogen_agentchat.teams.group_chat import RoundRobinGroupChat\n",
|
||||
"from autogen_core.components.code_executor import DockerCommandLineCodeExecutor\n",
|
||||
"from autogen_core.components.models import OpenAIChatCompletionClient\n",
|
||||
"\n",
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Tool Use\n",
|
||||
"\n",
|
||||
":::{note}\n",
|
||||
"See [here](pkg-info-autogen-agentchat) for installation instructions.\n",
|
||||
":::\n",
|
||||
"\n",
|
||||
":::{warning}\n",
|
||||
"🚧 Under construction 🚧\n",
|
||||
":::"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from autogen_agentchat.agents import ToolUseAssistantAgent\n",
|
||||
"from autogen_agentchat.teams.group_chat import RoundRobinGroupChat\n",
|
||||
"from autogen_core.components.models import OpenAIChatCompletionClient\n",
|
||||
"from autogen_core.components.tools import FunctionTool"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"async def get_weather(city: str) -> str:\n",
|
||||
" return \"Sunny\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"get_weather_tool = FunctionTool(get_weather, description=\"Get the weather for a city\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"user:\n",
|
||||
"What's the weather in New York?\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"Weather_Assistant:\n",
|
||||
"[FunctionCall(id='call_I8mFF4D73eoC3hhO81ldmIG3', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"tool_agent:\n",
|
||||
"[FunctionExecutionResult(content='Sunny', call_id='call_I8mFF4D73eoC3hhO81ldmIG3')]\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"Weather_Assistant:\n",
|
||||
"The weather in New York is sunny. \n",
|
||||
"\n",
|
||||
"TERMINATE\n",
|
||||
"TeamRunResult(result='The weather in New York is sunny. \\n\\nTERMINATE')\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"assistant = ToolUseAssistantAgent(\n",
|
||||
" \"Weather_Assistant\",\n",
|
||||
" model_client=OpenAIChatCompletionClient(model=\"gpt-4o-mini\"),\n",
|
||||
" tool_schema=[get_weather_tool.schema],\n",
|
||||
")\n",
|
||||
"team = RoundRobinGroupChat([assistant], tools=[get_weather_tool])\n",
|
||||
"result = await team.run(\"What's the weather in New York?\")\n",
|
||||
"print(result)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -17,4 +17,5 @@ myst:
|
||||
:hidden:
|
||||
|
||||
guides/quickstart
|
||||
guides/tool_use
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user