Skip to content

Commit

Permalink
Migrate remaining components (microsoft#4626)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits authored Dec 10, 2024
1 parent 51d4a10 commit 218e84f
Show file tree
Hide file tree
Showing 44 changed files with 262 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any, AsyncGenerator, Awaitable, Callable, Dict, List, Mapping, Sequence

from autogen_core import CancellationToken, FunctionCall
from autogen_core.components.tools import FunctionTool, Tool
from autogen_core.models import (
AssistantMessage,
ChatCompletionClient,
Expand All @@ -15,6 +14,7 @@
SystemMessage,
UserMessage,
)
from autogen_core.tools import FunctionTool, Tool
from typing_extensions import deprecated

from .. import EVENT_LOGGER_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import warnings
from typing import Any, Awaitable, Callable, List

from autogen_core.components.tools import Tool
from autogen_core.models import (
ChatCompletionClient,
)
from autogen_core.tools import Tool

from .. import EVENT_LOGGER_NAME
from ._assistant_agent import AssistantAgent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import Any, Dict

from autogen_core.components.tools import FunctionTool, Tool
from autogen_core.tools import FunctionTool, Tool
from pydantic import BaseModel, Field, model_validator

from .. import EVENT_LOGGER_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ToolCallResultMessage,
)
from autogen_core import Image
from autogen_core.components.tools import FunctionTool
from autogen_core.tools import FunctionTool
from autogen_ext.models import OpenAIChatCompletionClient
from openai.resources.chat.completions import AsyncCompletions
from openai.types.chat.chat_completion import ChatCompletion, Choice
Expand Down
2 changes: 1 addition & 1 deletion python/packages/autogen-agentchat/tests/test_group_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
from autogen_agentchat.teams._group_chat._swarm_group_chat import SwarmGroupChatManager
from autogen_agentchat.ui import Console
from autogen_core import AgentId, CancellationToken, FunctionCall
from autogen_core.components.tools import FunctionTool
from autogen_core.models import FunctionExecutionResult
from autogen_core.tools import FunctionTool
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
from autogen_ext.models import OpenAIChatCompletionClient, ReplayChatCompletionClient
from openai.resources.chat.completions import AsyncCompletions
Expand Down
4 changes: 2 additions & 2 deletions python/packages/autogen-core/docs/src/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ python/autogen_core
python/autogen_core.code_executor
python/autogen_core.models
python/autogen_core.model_context
python/autogen_core.components.tools
python/autogen_core.components.tool_agent
python/autogen_core.tools
python/autogen_core.tool_agent
python/autogen_core.exceptions
python/autogen_core.logging
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
autogen\_core.components.tool\_agent
autogen\_core.tool\_agent
====================================


.. automodule:: autogen_core.components.tool_agent
.. automodule:: autogen_core.tool_agent
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
autogen\_core.components.tools
autogen\_core.tools
==============================


.. automodule:: autogen_core.components.tools
.. automodule:: autogen_core.tools
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent\n",
"from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_core.components.tools import FunctionTool\n",
"from autogen_core.tools import FunctionTool\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent\n",
"from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_core.components.tools import FunctionTool\n",
"from autogen_core.tools import FunctionTool\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
" message_handler,\n",
")\n",
"from autogen_core.base.intervention import DefaultInterventionHandler, DropMessage\n",
"from autogen_core.components.tools import PythonCodeExecutionTool, ToolSchema\n",
"from autogen_core.models import (\n",
" ChatCompletionClient,\n",
" LLMMessage,\n",
" SystemMessage,\n",
" UserMessage,\n",
")\n",
"from autogen_core.tool_agent import ToolAgent, ToolException, tool_agent_caller_loop\n",
"from autogen_core.tools import PythonCodeExecutionTool, ToolSchema\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
]
Expand Down Expand Up @@ -64,7 +64,7 @@
"metadata": {},
"source": [
"Let's create a simple tool use agent that is capable of using tools through a\n",
"{py:class}`~autogen_core.components.tool_agent.ToolAgent`."
"{py:class}`~autogen_core.tool_agent.ToolAgent`."
]
},
{
Expand Down Expand Up @@ -165,7 +165,7 @@
"First, we create a Docker-based command-line code executor\n",
"using {py:class}`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`,\n",
"and then use it to instantiate a built-in Python code execution tool\n",
"{py:class}`~autogen_core.components.tools.PythonCodeExecutionTool`\n",
"{py:class}`~autogen_core.tools.PythonCodeExecutionTool`\n",
"that runs code in a Docker container."
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
" TypeSubscription,\n",
" message_handler,\n",
")\n",
"from autogen_core.components.tools import FunctionTool\n",
"from autogen_core.models import (\n",
" AssistantMessage,\n",
" ChatCompletionClient,\n",
" LLMMessage,\n",
" SystemMessage,\n",
" UserMessage,\n",
")\n",
"from autogen_core.tools import FunctionTool\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from IPython.display import display # type: ignore\n",
"from pydantic import BaseModel\n",
Expand Down Expand Up @@ -233,7 +233,7 @@
"\n",
"Now let's define the `IllustratorAgent` which uses a DALL-E model to generate\n",
"an illustration based on the description provided.\n",
"We set up the image generator as a tool using {py:class}`~autogen_core.components.tools.FunctionTool`\n",
"We set up the image generator as a tool using {py:class}`~autogen_core.tools.FunctionTool`\n",
"wrapper, and use a model client to make the tool call."
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
" TypeSubscription,\n",
" message_handler,\n",
")\n",
"from autogen_core.components.tools import FunctionTool, Tool\n",
"from autogen_core.models import (\n",
" AssistantMessage,\n",
" ChatCompletionClient,\n",
Expand All @@ -75,6 +74,7 @@
" SystemMessage,\n",
" UserMessage,\n",
")\n",
"from autogen_core.tools import FunctionTool, Tool\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from pydantic import BaseModel"
]
Expand Down Expand Up @@ -339,7 +339,7 @@
"\n",
"The AI agents can use regular tools to complete tasks if they don't need to hand off the task to other agents.\n",
"We define the tools using simple functions and create the tools using the\n",
"{py:class}`~autogen_core.components.tools.FunctionTool` wrapper."
"{py:class}`~autogen_core.tools.FunctionTool` wrapper."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
"recipient are tightly coupled -- they are created together and the sender\n",
"is linked to a specific instance of the recipient.\n",
"For example, an agent executes tool calls by sending direct messages to\n",
"an instance of {py:class}`~autogen_core.components.tool_agent.ToolAgent`,\n",
"an instance of {py:class}`~autogen_core.tool_agent.ToolAgent`,\n",
"and uses the responses to form an action-observation loop."
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"In the context of AI agents, tools are designed to be executed by agents in\n",
"response to model-generated function calls.\n",
"\n",
"AutoGen provides the {py:mod}`autogen_core.components.tools` module with a suite of built-in\n",
"AutoGen provides the {py:mod}`autogen_core.tools` module with a suite of built-in\n",
"tools and utilities for creating and running custom tools."
]
},
Expand All @@ -22,7 +22,7 @@
"source": [
"## Built-in Tools\n",
"\n",
"One of the built-in tools is the {py:class}`~autogen_core.components.tools.PythonCodeExecutionTool`,\n",
"One of the built-in tools is the {py:class}`~autogen_core.tools.PythonCodeExecutionTool`,\n",
"which allows agents to execute Python code snippets.\n",
"\n",
"Here is how you create the tool and use it."
Expand All @@ -44,7 +44,7 @@
],
"source": [
"from autogen_core import CancellationToken\n",
"from autogen_core.components.tools import PythonCodeExecutionTool\n",
"from autogen_core.tools import PythonCodeExecutionTool\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"\n",
"# Create the tool.\n",
Expand Down Expand Up @@ -73,7 +73,7 @@
"The {py:class}`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`\n",
"class is a built-in code executor that runs Python code snippets in a subprocess\n",
"in the command line environment of a docker container.\n",
"The {py:class}`~autogen_core.components.tools.PythonCodeExecutionTool` class wraps the code executor\n",
"The {py:class}`~autogen_core.tools.PythonCodeExecutionTool` class wraps the code executor\n",
"and provides a simple interface to execute Python code snippets.\n",
"\n",
"Other built-in tools will be added in the future."
Expand All @@ -87,9 +87,9 @@
"\n",
"A tool can also be a simple Python function that performs a specific action.\n",
"To create a custom function tool, you just need to create a Python function\n",
"and use the {py:class}`~autogen_core.components.tools.FunctionTool` class to wrap it.\n",
"and use the {py:class}`~autogen_core.tools.FunctionTool` class to wrap it.\n",
"\n",
"The {py:class}`~autogen_core.components.tools.FunctionTool` class uses descriptions and type annotations\n",
"The {py:class}`~autogen_core.tools.FunctionTool` class uses descriptions and type annotations\n",
"to inform the LLM when and how to use a given function. The description provides context\n",
"about the function’s purpose and intended use cases, while type annotations inform the LLM about\n",
"the expected parameters and return type.\n",
Expand All @@ -114,7 +114,7 @@
"import random\n",
"\n",
"from autogen_core import CancellationToken\n",
"from autogen_core.components.tools import FunctionTool\n",
"from autogen_core.tools import FunctionTool\n",
"from typing_extensions import Annotated\n",
"\n",
"\n",
Expand All @@ -140,9 +140,9 @@
"source": [
"## Tool-Equipped Agent\n",
"\n",
"To use tools with an agent, you can use {py:class}`~autogen_core.components.tool_agent.ToolAgent`,\n",
"To use tools with an agent, you can use {py:class}`~autogen_core.tool_agent.ToolAgent`,\n",
"by using it in a composition pattern.\n",
"Here is an example tool-use agent that uses {py:class}`~autogen_core.components.tool_agent.ToolAgent`\n",
"Here is an example tool-use agent that uses {py:class}`~autogen_core.tool_agent.ToolAgent`\n",
"as an inner agent for executing tools."
]
},
Expand All @@ -163,14 +163,14 @@
" SingleThreadedAgentRuntime,\n",
" message_handler,\n",
")\n",
"from autogen_core.components.tools import FunctionTool, Tool, ToolSchema\n",
"from autogen_core.models import (\n",
" ChatCompletionClient,\n",
" LLMMessage,\n",
" SystemMessage,\n",
" UserMessage,\n",
")\n",
"from autogen_core.tool_agent import ToolAgent, tool_agent_caller_loop\n",
"from autogen_core.tools import FunctionTool, Tool, ToolSchema\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"\n",
"\n",
Expand Down Expand Up @@ -209,7 +209,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The `ToolUseAgent` class uses a convenience function {py:meth}`~autogen_core.components.tool_agent.tool_agent_caller_loop`, \n",
"The `ToolUseAgent` class uses a convenience function {py:meth}`~autogen_core.tool_agent.tool_agent_caller_loop`, \n",
"to handle the interaction between the model and the tool agent.\n",
"The core idea can be described using a simple control flow graph:\n",
"\n",
Expand All @@ -218,7 +218,7 @@
"The `ToolUseAgent`'s `handle_user_message` handler handles messages from the user,\n",
"and determines whether the model has generated a tool call.\n",
"If the model has generated tool calls, then the handler sends a function call\n",
"message to the {py:class}`~autogen_core.components.tool_agent.ToolAgent` agent\n",
"message to the {py:class}`~autogen_core.tool_agent.ToolAgent` agent\n",
"to execute the tools,\n",
"and then queries the model again with the results of the tool calls.\n",
"This process continues until the model stops generating tool calls,\n",
Expand Down
2 changes: 1 addition & 1 deletion python/packages/autogen-core/samples/chess_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
DefaultTopicId,
SingleThreadedAgentRuntime,
)
from autogen_core.components.tools import FunctionTool
from autogen_core.model_context import BufferedChatCompletionContext
from autogen_core.models import SystemMessage
from autogen_core.tools import FunctionTool
from chess import BLACK, SQUARE_NAMES, WHITE, Board, Move
from chess import piece_name as get_piece_name
from common.agents._chat_completion_agent import ChatCompletionAgent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
RoutedAgent,
message_handler,
)
from autogen_core.components.tools import Tool
from autogen_core.model_context import ChatCompletionContext
from autogen_core.models import (
AssistantMessage,
Expand All @@ -21,6 +20,7 @@
SystemMessage,
UserMessage,
)
from autogen_core.tools import Tool

from ..types import (
FunctionCallMessage,
Expand Down
2 changes: 1 addition & 1 deletion python/packages/autogen-core/samples/slow_human_in_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
type_subscription,
)
from autogen_core.base.intervention import DefaultInterventionHandler
from autogen_core.components.tools import BaseTool
from autogen_core.model_context import BufferedChatCompletionContext
from autogen_core.models import (
AssistantMessage,
ChatCompletionClient,
SystemMessage,
UserMessage,
)
from autogen_core.tools import BaseTool
from common.types import TextMessage
from common.utils import get_chat_completion_client_from_envs
from pydantic import BaseModel, Field
Expand Down
Loading

0 comments on commit 218e84f

Please sign in to comment.