diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py index 4fb8d3c43c7d..9450d4512e38 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py @@ -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, @@ -15,6 +14,7 @@ SystemMessage, UserMessage, ) +from autogen_core.tools import FunctionTool, Tool from typing_extensions import deprecated from .. import EVENT_LOGGER_NAME diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_tool_use_assistant_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_tool_use_assistant_agent.py index 6142b63ebba2..1ebe1f22662b 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_tool_use_assistant_agent.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_tool_use_assistant_agent.py @@ -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 diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_handoff.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_handoff.py index 3ab859a08e86..33efc5677708 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_handoff.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_handoff.py @@ -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 diff --git a/python/packages/autogen-agentchat/tests/test_assistant_agent.py b/python/packages/autogen-agentchat/tests/test_assistant_agent.py index 5041871c15c1..d5673b0a942e 100644 --- a/python/packages/autogen-agentchat/tests/test_assistant_agent.py +++ b/python/packages/autogen-agentchat/tests/test_assistant_agent.py @@ -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 diff --git a/python/packages/autogen-agentchat/tests/test_group_chat.py b/python/packages/autogen-agentchat/tests/test_group_chat.py index 9ab26363ba2b..c94ef3191b2a 100644 --- a/python/packages/autogen-agentchat/tests/test_group_chat.py +++ b/python/packages/autogen-agentchat/tests/test_group_chat.py @@ -33,7 +33,7 @@ from autogen_agentchat.teams._group_chat._swarm_group_chat import SwarmGroupChatManager from autogen_agentchat.ui import Console from autogen_core import AgentId, CancellationToken -from autogen_core.components.tools import FunctionTool +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 diff --git a/python/packages/autogen-core/docs/src/reference/index.md b/python/packages/autogen-core/docs/src/reference/index.md index 5e81a2cb151c..6441e86ef4ec 100644 --- a/python/packages/autogen-core/docs/src/reference/index.md +++ b/python/packages/autogen-core/docs/src/reference/index.md @@ -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 ``` diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.components.tool_agent.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.tool_agent.rst similarity index 51% rename from python/packages/autogen-core/docs/src/reference/python/autogen_core.components.tool_agent.rst rename to python/packages/autogen-core/docs/src/reference/python/autogen_core.tool_agent.rst index b18b93d8a394..18e8e8a7df5b 100644 --- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.components.tool_agent.rst +++ b/python/packages/autogen-core/docs/src/reference/python/autogen_core.tool_agent.rst @@ -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: diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.components.tools.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.tools.rst similarity index 53% rename from python/packages/autogen-core/docs/src/reference/python/autogen_core.components.tools.rst rename to python/packages/autogen-core/docs/src/reference/python/autogen_core.tools.rst index 9895f97b5a9b..d4cba212476b 100644 --- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.components.tools.rst +++ b/python/packages/autogen-core/docs/src/reference/python/autogen_core.tools.rst @@ -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: diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/company-research.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/company-research.ipynb index 45f4be3075ee..44d1b089a5ab 100644 --- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/company-research.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/company-research.ipynb @@ -26,7 +26,7 @@ "from autogen_agentchat.conditions import TextMentionTermination\n", "from autogen_agentchat.teams import RoundRobinGroupChat\n", "from autogen_agentchat.ui import Console\n", - "from autogen_core.components.tools import FunctionTool\n", + "from autogen_core.tools import FunctionTool\n", "from autogen_ext.models import OpenAIChatCompletionClient" ] }, diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/literature-review.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/literature-review.ipynb index 0d34e239076e..4613b6dc20ab 100644 --- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/literature-review.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/literature-review.ipynb @@ -26,7 +26,7 @@ "from autogen_agentchat.conditions import TextMentionTermination\n", "from autogen_agentchat.teams import RoundRobinGroupChat\n", "from autogen_agentchat.ui import Console\n", - "from autogen_core.components.tools import FunctionTool\n", + "from autogen_core.tools import FunctionTool\n", "from autogen_ext.models import OpenAIChatCompletionClient" ] }, diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb index 9fcf6933f547..c4f78fc05a57 100644 --- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb @@ -21,7 +21,7 @@ "## Assistant Agent\n", "\n", "{py:class}`~autogen_agentchat.agents.AssistantAgent` is a built-in agent that\n", - "uses a language model with ability to use tools." + "uses a language model and has the ability to use tools." ] }, { @@ -59,8 +59,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can call the {py:meth}`~autogen_agentchat.agents.AssistantAgent.on_messages` \n", - "method to get the agent to respond to a message." + "\n", + "## Getting Responses\n", + "\n", + "We can use the {py:meth}`~autogen_agentchat.agents.AssistantAgent.on_messages` method to get the agent response to a given message.\n" ] }, { @@ -134,7 +136,7 @@ "source": [ "The User Proxy agent is ideally used for on-demand human-in-the-loop interactions for scenarios such as Just In Time approvals, human feedback, alerts, etc. For slower user interactions, consider terminating the session using a termination condition and start another one from run or run_stream with another message.\n", "\n", - "### Stream Messages\n", + "## Streaming Messages\n", "\n", "We can also stream each message as it is generated by the agent by using the\n", "{py:meth}`~autogen_agentchat.agents.AssistantAgent.on_messages_stream` method,\n", @@ -172,7 +174,7 @@ "\n", "\n", "async def assistant_run_stream() -> None:\n", - " # Option 1: read each message from the stream.\n", + " # Option 1: read each message from the stream (as shown in the previous example).\n", " # async for message in agent.on_messages_stream(\n", " # [TextMessage(content=\"Find information on AutoGen\", source=\"user\")],\n", " # cancellation_token=CancellationToken(),\n", @@ -198,12 +200,12 @@ "source": [ "The {py:meth}`~autogen_agentchat.agents.AssistantAgent.on_messages_stream` method\n", "returns an asynchronous generator that yields each inner message generated by the agent,\n", - "and the last item is the final response message in the {py:attr}`~autogen_agentchat.base.Response.chat_message` attribute.\n", + "with the final item being the response message in the {py:attr}`~autogen_agentchat.base.Response.chat_message` attribute.\n", "\n", - "From the messages, you can see the assistant agent used the `web_search` tool to\n", - "search for information and responded using the search results.\n", + "From the messages, you can observe that the assistant agent utilized the `web_search` tool to\n", + "gather information and responded based on the search results.\n", "\n", - "### Understanding Tool Calling\n", + "## Understanding Tool Calling\n", "\n", "Large Language Models (LLMs) are typically limited to generating text or code responses. However, many complex tasks benefit from the ability to use external tools that perform specific actions, such as fetching data from APIs or databases.\n", "\n", @@ -233,8 +235,7 @@ "source": [ "## Next Step\n", "\n", - "Now we have discussed how to use the {py:class}`~autogen_agentchat.agents.AssistantAgent`,\n", - "we can move on to the next section to learn how to use the teams feature of AgentChat." + "Having explored the usage of the {py:class}`~autogen_agentchat.agents.AssistantAgent`, we can now proceed to the next section to learn about the teams feature in AgentChat.\n" ] }, { diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb index a5599965f569..97d09cda2d56 100644 --- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb @@ -6,48 +6,22 @@ "source": [ "# Teams\n", "\n", - "```{include} ../warning.md\n", - "```\n", - "\n", - "In AgentChat, teams define how groups of agents collaborate to address tasks.\n", - "A team is composed of one or more agents, and interacts with your application\n", - "by receiving task and returning task result.\n", - "It is stateful and maintains context across multiple tasks.\n", - "A team uses a stateful termination condition to determine when to stop processing the\n", - "current task.\n", - "\n", - "The diagram below shows the relationship between team and your application.\n", - "\n", - "![AgentChat Teams](./agentchat-team.svg)\n", + "In this section you'll learn how to create a _multi-agent team_ (or simply team) using AutoGen. A team is a group of agents that work together to achieve a common goal.\n", "\n", - "AgentChat provides several preset teams that implements one or more [multi-agent design patterns](../../core-user-guide/design-patterns/index.md) to simplify development. Here is a list of the preset teams:\n", + "We'll first show you hot create and run a team. We'll then explain how to observe the team's behavior, which is crucial for debugging and understanding the team's performance, and common operations to control the team's behavior.\n", "\n", - "- {py:class}`~autogen_agentchat.teams.RoundRobinGroupChat`: All participants share context and takes turn to respond in a round-robin fashion. We will cover this team in this section.\n", - "- {py:class}`~autogen_agentchat.teams.SelectorGroupChat`: All participants share context and use a model-based selector (with custom override) to select the next agent to respond. See [Selector Group Chat](./selector-group-chat.ipynb) for more details.\n", - "- {py:class}`~autogen_agentchat.teams.Swarm`: All participants share context and use {py:class}`~autogen_agentchat.messages.HandoffMessage`to pass control to the next agent. See [Swarm](./swarm.ipynb) for more details.\n", - "\n", - "At a high-level, a team API consists of the following methods:\n", - "\n", - "- {py:meth}`~autogen_agentchat.base.TaskRunner.run`: Process a task, which can be a {py:class}`str`, {py:class}`~autogen_agentchat.messages.TextMessage`, {py:class}`~autogen_agentchat.messages.MultiModalMessage`, or {py:class}`~autogen_agentchat.messages.HandoffMessage`, and returns {py:class}`~autogen_agentchat.base.TaskResult`. The task can also be `None` to resume processing the previous task if the team has not been reset.\n", - "- {py:meth}`~autogen_agentchat.base.TaskRunner.run_stream`: Similar to {py:meth}`~autogen_agentchat.base.TaskRunner.run`, but it returns an async generator of messages and the final task result.\n", - "- {py:meth}`~autogen_agentchat.base.Team.reset`: To reset the team state if the next task is not related to the previous task. Otherwise, the team can utilize the context from the previous task to process the next one.\n", - "\n", - "In this section, we will be using the\n", - "{py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` team to introduce the AgentChat team API." + "We'll start by focusing on a simple team with consisting of a single agent (the baseline case) and use a round robin strategy to select the agent to act. We'll then show how to create a team with multiple agents and how to implement a more sophisticated strategy to select the agent to act." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Round-Robin Group Chat\n", + "## Creating a Team\n", "\n", - "{py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` is a simple team that allows all agents to share context and take turns to respond in a round-robin fashion.\n", - "On its turn, each agent broadcasts its response to all other agents in the team, so all agents have the same context.\n", + "{py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` is a simple yet effective team configuration where all agents share the same context and take turns responding in a round-robin fashion. Each agent, during its turn, broadcasts its response to all other agents, ensuring that the entire team maintains a consistent context.\n", "\n", - "We will start by creating a team with a single {py:class}`~autogen_agentchat.agents.AssistantAgent` agent\n", - "and {py:class}`~autogen_agentchat.conditions.TextMentionTermination`\n", - "termination condition that stops the team when a word is detected." + "We will begin by creating a team with a single {py:class}`~autogen_agentchat.agents.AssistantAgent` and a {py:class}`~autogen_agentchat.conditions.TextMentionTermination` condition that stops the team when a specific word is detected in the agent's response.\n" ] }, { @@ -93,7 +67,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Running Team\n", + "## Running a Team\n", "\n", "Let's calls the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run` method\n", "to start the team with a task." @@ -136,45 +110,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Reseting Team\n", + "## Observability\n", "\n", - "You can reset the team by calling the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.reset` method.\n", - "It will clear the team's state including all of its agents'." + "Similar to the agent's {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream` method, you can stream the team's messages by calling the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run_stream` method. This method returns a generator that yields messages produced by the agents in the team as they are generated, with the final item being the task result.\n" ] }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "await single_agent_team.reset() # Reset the team for the next run." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "It is usually a good idea to reset the team if the next task is not related to the previous task.\n", - "However, if the next task is related to the previous task, you don't need to reset.\n", - "See [Resuming Team](#resuming-team) below." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Streaming Team Messages\n", - "\n", - "Similar to agent's {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream` method,\n", - "you can stream the team's messages by calling the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run_stream` method.\n", - "It will return a generator that yields the messages produced by the agents in the team as they are generated,\n", - "and the last item will be the task result." - ] - }, - { - "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -210,10 +153,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As the above example shows, you can obtain the reason why the team stopped by checking the {py:attr}`~autogen_agentchat.base.TaskResult.stop_reason` attribute.\n", + "As demonstrated in the example above, you can determine the reason why the team stopped by checking the {py:attr}`~autogen_agentchat.base.TaskResult.stop_reason` attribute.\n", "\n", - "There is a covenient method {py:meth}`~autogen_agentchat.ui.Console` that prints the messages to the console\n", - "with proper formatting." + "The {py:meth}`~autogen_agentchat.ui.Console` method provides a convenient way to print messages to the console with proper formatting.\n" ] }, { @@ -258,23 +200,54 @@ ") # Stream the messages to the console." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Controlling a Team\n", + "\n", + "You can reset the team by calling the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.reset` method. This method will clear the team's state, including all agents." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "await single_agent_team.reset() # Reset the team for the next run." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is usually a good idea to reset the team if the next task is not related to the previous task.\n", + "However, if the next task is related to the previous task, you don't need to reset and you can instead resume. We will cover this in the next section." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "## Team Usage Guide\n", + "\n", + "We will now implement a slightly more complex team with multiple agents and learn how to resume the team after stopping it and even involve the user in the conversation.\n", + "\n" + ] + }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reflection Pattern\n", "\n", - "Now we will create a team with two agents that implements the\n", - "Reflection pattern, which is a multi-agent design pattern that uses\n", - "a critic agent to evaluate the responses of a primary agent.\n", + "We will now create a team with two agents that implement the _reflection_ pattern, a multi-agent design pattern where a critic agent evaluates the responses of a primary agent.\n", "\n", - "See how the reflection pattern works using the [Core API](../../core-user-guide/design-patterns/reflection.ipynb).\n", + "Learn more about the reflection pattern using the [Core API](../../core-user-guide/design-patterns/reflection.ipynb).\n", "\n", - "In this example, we will use the {py:class}`~autogen_agentchat.agents.AssistantAgent` agent class\n", - "for both the primary and critic agents.\n", - "We will use both the {py:class}`~autogen_agentchat.conditions.TextMentionTermination`\n", - "and {py:class}`~autogen_agentchat.conditions.MaxMessageTermination` termination conditions\n", - "together to stop the team." + "In this example, we will use the {py:class}`~autogen_agentchat.agents.AssistantAgent` class for both the primary and critic agents. We will combine the {py:class}`~autogen_agentchat.conditions.TextMentionTermination` and {py:class}`~autogen_agentchat.conditions.MaxMessageTermination` conditions to stop the team.\n" ] }, { @@ -418,7 +391,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Resuming Team\n", + "### Resuming a Team\n", "\n", "Let's run the team again with a new task while keeping the context about the previous task." ] @@ -552,7 +525,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Resuming A Previous Task\n", + "### Resuming a Previous Task\n", "\n", "We can call {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run` or {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run_stream` methods\n", "without setting the `task` again to resume the previous task. The team will continue from where it left off." @@ -600,29 +573,25 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Pause for User Input\n", + "### Pausing for User Input\n", "\n", - "Often times, team needs additional input from the application (i.e., user)\n", - "to continue processing the task. We will show two possible ways to do it:\n", + "Sometimes, teams may require additional input from the application (e.g., the user) to continue making meaningful progress on a task. Here are two ways to achieve this:\n", "\n", - "- Set the maximum number of turns such that the team stops after the specified number of turns.\n", + "- Set the maximum number of turns so that the team stops after the specified number of turns.\n", "- Use the {py:class}`~autogen_agentchat.conditions.HandoffTermination` termination condition.\n", "\n", - "You can also use custom termination conditions, see [Termination Conditions](./termination.ipynb)." + "You can also create custom termination conditions. For more details, see [Termination Conditions](./termination.ipynb).\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "#### Maximum Number of Turns\n", + "#### Via Max Turns\n", "\n", - "This is the simplest way to pause the team for user input. For example,\n", - "you can set the maximum number of turns to 1 such that the team stops right\n", - "after the first agent responds. This is useful when you want the user\n", - "to constantly engage with the team, such as in a chatbot scenario.\n", + "This method allows you to pause the team for user input by setting a maximum number of turns. For instance, you can configure the team to stop after the first agent responds by setting `max_turns` to 1. This is particularly useful in scenarios where continuous user engagement is required, such as in a chatbot.\n", "\n", - "Simply set the `max_turns` parameter in the {py:meth}`~autogen_agentchat.teams.RoundRobinGroupChat` constructor.\n", + "To implement this, set the `max_turns` parameter in the {py:meth}`~autogen_agentchat.teams.RoundRobinGroupChat` constructor.\n", "\n", "```python\n", "team = RoundRobinGroupChat([...], max_turns=1)\n", @@ -640,7 +609,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Using Handoff to Pause Team\n", + "#### Via Handoff\n", "\n", "You can use the {py:class}`~autogen_agentchat.conditions.HandoffTermination` termination condition\n", "to stop the team when an agent sends a {py:class}`~autogen_agentchat.messages.HandoffMessage` message.\n", @@ -649,7 +618,7 @@ "with a handoff setting.\n", "\n", "```{note}\n", - "The model used with {py:class}`~autogen_agentchat.agents.AssistantAgent`must support tool call\n", + "The model used with {py:class}`~autogen_agentchat.agents.AssistantAgent` must support tool call\n", "to use the handoff feature.\n", "```" ] @@ -792,4 +761,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/warning.md b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/warning.md deleted file mode 100644 index 102d9282ce2e..000000000000 --- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/warning.md +++ /dev/null @@ -1,5 +0,0 @@ -```{warning} - -AgentChat is Work in Progress. APIs may change in future releases. - -``` diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb index 9ef2f26d4937..4a8d8d4943f2 100644 --- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb @@ -29,7 +29,6 @@ " 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", @@ -37,6 +36,7 @@ " 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" ] @@ -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`." ] }, { @@ -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." ] }, diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/group-chat.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/group-chat.ipynb index a5e51d85adc1..6e8169881c7d 100644 --- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/group-chat.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/group-chat.ipynb @@ -83,7 +83,6 @@ " TypeSubscription,\n", " message_handler,\n", ")\n", - "from autogen_core.components.tools import FunctionTool\n", "from autogen_core.models import (\n", " AssistantMessage,\n", " ChatCompletionClient,\n", @@ -91,6 +90,7 @@ " 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", @@ -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." ] }, diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/handoffs.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/handoffs.ipynb index 6c86ed5d95cb..b40443cee509 100644 --- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/handoffs.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/handoffs.ipynb @@ -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", @@ -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" ] @@ -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." ] }, { diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/message-and-communication.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/message-and-communication.ipynb index a775c0f5963a..b9a8f423a7e2 100644 --- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/message-and-communication.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/message-and-communication.ipynb @@ -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." ] }, diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb index d8e318bd9149..26f140302c09 100644 --- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb @@ -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." ] }, @@ -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." @@ -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", @@ -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." @@ -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", @@ -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", @@ -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." ] }, @@ -163,7 +163,6 @@ " 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", @@ -171,6 +170,7 @@ " 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", @@ -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", @@ -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", diff --git a/python/packages/autogen-core/samples/chess_game.py b/python/packages/autogen-core/samples/chess_game.py index b2a50f5140c3..b359772aa460 100644 --- a/python/packages/autogen-core/samples/chess_game.py +++ b/python/packages/autogen-core/samples/chess_game.py @@ -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 diff --git a/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.py b/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.py index c0e50d9d2c01..246861cb6da8 100644 --- a/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.py +++ b/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.py @@ -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, @@ -21,6 +20,7 @@ SystemMessage, UserMessage, ) +from autogen_core.tools import Tool from ..types import ( FunctionCallMessage, diff --git a/python/packages/autogen-core/samples/slow_human_in_loop.py b/python/packages/autogen-core/samples/slow_human_in_loop.py index df8530b1aa04..9c4476d06b5c 100644 --- a/python/packages/autogen-core/samples/slow_human_in_loop.py +++ b/python/packages/autogen-core/samples/slow_human_in_loop.py @@ -42,7 +42,6 @@ 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, @@ -50,6 +49,7 @@ 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 diff --git a/python/packages/autogen-core/src/autogen_core/components/tool_agent/__init__.py b/python/packages/autogen-core/src/autogen_core/components/tool_agent/__init__.py index e072efdd7cd2..ff03136668e2 100644 --- a/python/packages/autogen-core/src/autogen_core/components/tool_agent/__init__.py +++ b/python/packages/autogen-core/src/autogen_core/components/tool_agent/__init__.py @@ -1,11 +1,23 @@ -from ._caller_loop import tool_agent_caller_loop -from ._tool_agent import ( - InvalidToolArgumentsException, - ToolAgent, - ToolException, - ToolExecutionException, - ToolNotFoundException, +from typing import Any + +from typing_extensions import deprecated + +from ...tool_agent import ( + InvalidToolArgumentsException as InvalidToolArgumentsExceptionAlias, +) +from ...tool_agent import ( + ToolAgent as ToolAgentAlias, +) +from ...tool_agent import ( + ToolException as ToolExceptionAlias, +) +from ...tool_agent import ( + ToolExecutionException as ToolExecutionExceptionAlias, +) +from ...tool_agent import ( + ToolNotFoundException as ToolNotFoundExceptionAlias, ) +from ...tool_agent import tool_agent_caller_loop as tool_agent_caller_loop_alias __all__ = [ "ToolAgent", @@ -15,3 +27,45 @@ "ToolExecutionException", "tool_agent_caller_loop", ] + + +@deprecated( + "autogen_core.tool_agent.ToolAgentAlias moved to autogen_core.tool_agent.ToolAgentAlias. This alias will be removed in 0.4.0." +) +class ToolAgent(ToolAgentAlias): + pass + + +@deprecated( + "autogen_core.tool_agent.ToolExceptionAlias moved to autogen_core.tool_agent.ToolExceptionAlias. This alias will be removed in 0.4.0." +) +class ToolException(ToolExceptionAlias): + pass + + +@deprecated( + "autogen_core.tool_agent.ToolNotFoundExceptionAlias moved to autogen_core.tool_agent.ToolNotFoundExceptionAlias. This alias will be removed in 0.4.0." +) +class ToolNotFoundException(ToolNotFoundExceptionAlias): + pass + + +@deprecated( + "autogen_core.tool_agent.InvalidToolArgumentsExceptionAlias moved to autogen_core.tool_agent.InvalidToolArgumentsExceptionAlias. This alias will be removed in 0.4.0." +) +class InvalidToolArgumentsException(InvalidToolArgumentsExceptionAlias): + pass + + +@deprecated( + "autogen_core.tool_agent.ToolExecutionExceptionAlias moved to autogen_core.tool_agent.ToolExecutionExceptionAlias. This alias will be removed in 0.4.0." +) +class ToolExecutionException(ToolExecutionExceptionAlias): + pass + + +@deprecated( + "autogen_core.tool_agent.tool_agent_caller_loop moved to autogen_core.tool_agent.tool_agent_caller_loop. This alias will be removed in 0.4.0." +) +def tool_agent_caller_loop(*args: Any, **kwargs: Any) -> Any: + return tool_agent_caller_loop_alias(*args, **kwargs) # type: ignore diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py b/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py index dcfb1759a91d..e3c480fee302 100644 --- a/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py +++ b/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py @@ -1,6 +1,33 @@ -from ._base import BaseTool, BaseToolWithState, ParametersSchema, Tool, ToolSchema -from ._code_execution import CodeExecutionInput, CodeExecutionResult, PythonCodeExecutionTool -from ._function_tool import FunctionTool +from typing import TypeVar + +from pydantic import BaseModel +from typing_extensions import deprecated + +from ...tools import ( + BaseTool as BaseToolAlias, +) +from ...tools import ( + BaseToolWithState as BaseToolWithStateAlias, +) +from ...tools import ( + CodeExecutionInput as CodeExecutionInputAlias, +) +from ...tools import ( + CodeExecutionResult as CodeExecutionResultAlias, +) +from ...tools import FunctionTool as FunctionToolAlias +from ...tools import ( + ParametersSchema as ParametersSchemaAlias, +) +from ...tools import ( + PythonCodeExecutionTool as PythonCodeExecutionToolAlias, +) +from ...tools import ( + Tool as ToolAlias, +) +from ...tools import ( + ToolSchema as ToolSchemaAlias, +) __all__ = [ "Tool", @@ -13,3 +40,69 @@ "CodeExecutionResult", "FunctionTool", ] + + +ArgsT = TypeVar("ArgsT", bound=BaseModel, contravariant=True) +ReturnT = TypeVar("ReturnT", bound=BaseModel, covariant=True) +StateT = TypeVar("StateT", bound=BaseModel) + + +@deprecated( + "autogen_core.tools.BaseToolAlias moved to autogen_core.tools.BaseToolAlias. This alias will be removed in 0.4.0." +) +class BaseTool(BaseToolAlias[ArgsT, ReturnT]): + pass + + +@deprecated("autogen_core.tools.ToolAlias moved to autogen_core.tools.ToolAlias. This alias will be removed in 0.4.0.") +class Tool(ToolAlias): + pass + + +@deprecated( + "autogen_core.tools.ToolSchemaAlias moved to autogen_core.tools.ToolSchemaAlias. This alias will be removed in 0.4.0." +) +class ToolSchema(ToolSchemaAlias): + pass + + +@deprecated( + "autogen_core.tools.ParametersSchemaAlias moved to autogen_core.tools.ParametersSchemaAlias. This alias will be removed in 0.4.0." +) +class ParametersSchema(ParametersSchemaAlias): + pass + + +@deprecated( + "autogen_core.tools.BaseToolWithStateAlias moved to autogen_core.tools.BaseToolWithStateAlias. This alias will be removed in 0.4.0." +) +class BaseToolWithState(BaseToolWithStateAlias[ArgsT, ReturnT, StateT]): + pass + + +@deprecated( + "autogen_core.tools.PythonCodeExecutionToolAlias moved to autogen_core.tools.PythonCodeExecutionToolAlias. This alias will be removed in 0.4.0." +) +class PythonCodeExecutionTool(PythonCodeExecutionToolAlias): + pass + + +@deprecated( + "autogen_core.tools.CodeExecutionInputAlias moved to autogen_core.tools.CodeExecutionInputAlias. This alias will be removed in 0.4.0." +) +class CodeExecutionInput(CodeExecutionInputAlias): + pass + + +@deprecated( + "autogen_core.tools.CodeExecutionResultAlias moved to autogen_core.tools.CodeExecutionResultAlias. This alias will be removed in 0.4.0." +) +class CodeExecutionResult(CodeExecutionResultAlias): + pass + + +@deprecated( + "autogen_core.tools.FunctionToolAlias moved to autogen_core.tools.FunctionToolAlias. This alias will be removed in 0.4.0." +) +class FunctionTool(FunctionToolAlias): + pass diff --git a/python/packages/autogen-core/src/autogen_core/models/_model_client.py b/python/packages/autogen-core/src/autogen_core/models/_model_client.py index fef42da5d8ee..c141c480dd78 100644 --- a/python/packages/autogen-core/src/autogen_core/models/_model_client.py +++ b/python/packages/autogen-core/src/autogen_core/models/_model_client.py @@ -12,7 +12,7 @@ ) from .. import CancellationToken -from ..components.tools import Tool, ToolSchema +from ..tools import Tool, ToolSchema from ._types import CreateResult, LLMMessage, RequestUsage diff --git a/python/packages/autogen-core/src/autogen_core/tool_agent/__init__.py b/python/packages/autogen-core/src/autogen_core/tool_agent/__init__.py new file mode 100644 index 000000000000..e072efdd7cd2 --- /dev/null +++ b/python/packages/autogen-core/src/autogen_core/tool_agent/__init__.py @@ -0,0 +1,17 @@ +from ._caller_loop import tool_agent_caller_loop +from ._tool_agent import ( + InvalidToolArgumentsException, + ToolAgent, + ToolException, + ToolExecutionException, + ToolNotFoundException, +) + +__all__ = [ + "ToolAgent", + "ToolException", + "ToolNotFoundException", + "InvalidToolArgumentsException", + "ToolExecutionException", + "tool_agent_caller_loop", +] diff --git a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_caller_loop.py b/python/packages/autogen-core/src/autogen_core/tool_agent/_caller_loop.py similarity index 96% rename from python/packages/autogen-core/src/autogen_core/components/tool_agent/_caller_loop.py rename to python/packages/autogen-core/src/autogen_core/tool_agent/_caller_loop.py index 9a26fe015534..2353ca184f86 100644 --- a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_caller_loop.py +++ b/python/packages/autogen-core/src/autogen_core/tool_agent/_caller_loop.py @@ -1,8 +1,8 @@ import asyncio from typing import List -from ... import AgentId, AgentRuntime, BaseAgent, CancellationToken, FunctionCall -from ...models import ( +from .. import AgentId, AgentRuntime, BaseAgent, CancellationToken, FunctionCall +from ..models import ( AssistantMessage, ChatCompletionClient, FunctionExecutionResult, diff --git a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_tool_agent.py b/python/packages/autogen-core/src/autogen_core/tool_agent/_tool_agent.py similarity index 95% rename from python/packages/autogen-core/src/autogen_core/components/tool_agent/_tool_agent.py rename to python/packages/autogen-core/src/autogen_core/tool_agent/_tool_agent.py index a2e5b9ca0a32..08d8f4b25376 100644 --- a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_tool_agent.py +++ b/python/packages/autogen-core/src/autogen_core/tool_agent/_tool_agent.py @@ -2,8 +2,8 @@ from dataclasses import dataclass from typing import List -from ... import FunctionCall, MessageContext, RoutedAgent, message_handler -from ...models import FunctionExecutionResult +from .. import FunctionCall, MessageContext, RoutedAgent, message_handler +from ..models import FunctionExecutionResult from ..tools import Tool __all__ = [ diff --git a/python/packages/autogen-core/src/autogen_core/tools/__init__.py b/python/packages/autogen-core/src/autogen_core/tools/__init__.py new file mode 100644 index 000000000000..dcfb1759a91d --- /dev/null +++ b/python/packages/autogen-core/src/autogen_core/tools/__init__.py @@ -0,0 +1,15 @@ +from ._base import BaseTool, BaseToolWithState, ParametersSchema, Tool, ToolSchema +from ._code_execution import CodeExecutionInput, CodeExecutionResult, PythonCodeExecutionTool +from ._function_tool import FunctionTool + +__all__ = [ + "Tool", + "ToolSchema", + "ParametersSchema", + "BaseTool", + "BaseToolWithState", + "PythonCodeExecutionTool", + "CodeExecutionInput", + "CodeExecutionResult", + "FunctionTool", +] diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_base.py b/python/packages/autogen-core/src/autogen_core/tools/_base.py similarity index 98% rename from python/packages/autogen-core/src/autogen_core/components/tools/_base.py rename to python/packages/autogen-core/src/autogen_core/tools/_base.py index b41d747d65b2..7c4042e9afd6 100644 --- a/python/packages/autogen-core/src/autogen_core/components/tools/_base.py +++ b/python/packages/autogen-core/src/autogen_core/tools/_base.py @@ -7,8 +7,8 @@ from pydantic import BaseModel from typing_extensions import NotRequired -from ... import CancellationToken -from ..._function_utils import normalize_annotated_type +from .. import CancellationToken +from .._function_utils import normalize_annotated_type T = TypeVar("T", bound=BaseModel, contravariant=True) diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_code_execution.py b/python/packages/autogen-core/src/autogen_core/tools/_code_execution.py similarity index 92% rename from python/packages/autogen-core/src/autogen_core/components/tools/_code_execution.py rename to python/packages/autogen-core/src/autogen_core/tools/_code_execution.py index eb792a32fef6..f3f2b072e6fd 100644 --- a/python/packages/autogen-core/src/autogen_core/components/tools/_code_execution.py +++ b/python/packages/autogen-core/src/autogen_core/tools/_code_execution.py @@ -1,7 +1,7 @@ from pydantic import BaseModel, Field, model_serializer -from ... import CancellationToken -from ...code_executor import CodeBlock, CodeExecutor +from .. import CancellationToken +from ..code_executor import CodeBlock, CodeExecutor from ._base import BaseTool diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py b/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py similarity index 96% rename from python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py rename to python/packages/autogen-core/src/autogen_core/tools/_function_tool.py index 45041121caeb..026fc845e9c2 100644 --- a/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py +++ b/python/packages/autogen-core/src/autogen_core/tools/_function_tool.py @@ -4,8 +4,8 @@ from pydantic import BaseModel -from ... import CancellationToken -from ..._function_utils import ( +from .. import CancellationToken +from .._function_utils import ( args_base_model_from_signature, get_typed_signature, ) @@ -39,7 +39,7 @@ class FunctionTool(BaseTool[BaseModel, BaseModel]): import random from autogen_core import CancellationToken - from autogen_core.components.tools import FunctionTool + from autogen_core.tools import FunctionTool from typing_extensions import Annotated import asyncio diff --git a/python/packages/autogen-core/tests/test_tool_agent.py b/python/packages/autogen-core/tests/test_tool_agent.py index f17ce64242ab..d0d6dec8915b 100644 --- a/python/packages/autogen-core/tests/test_tool_agent.py +++ b/python/packages/autogen-core/tests/test_tool_agent.py @@ -4,14 +4,6 @@ import pytest from autogen_core import AgentId, CancellationToken, FunctionCall, SingleThreadedAgentRuntime -from autogen_core.components.tool_agent import ( - InvalidToolArgumentsException, - ToolAgent, - ToolExecutionException, - ToolNotFoundException, - tool_agent_caller_loop, -) -from autogen_core.components.tools import FunctionTool, Tool, ToolSchema from autogen_core.models import ( AssistantMessage, ChatCompletionClient, @@ -23,6 +15,14 @@ RequestUsage, UserMessage, ) +from autogen_core.tool_agent import ( + InvalidToolArgumentsException, + ToolAgent, + ToolExecutionException, + ToolNotFoundException, + tool_agent_caller_loop, +) +from autogen_core.tools import FunctionTool, Tool, ToolSchema def _pass_function(input: str) -> str: diff --git a/python/packages/autogen-core/tests/test_tools.py b/python/packages/autogen-core/tests/test_tools.py index b35986423dbe..64d97e11519d 100644 --- a/python/packages/autogen-core/tests/test_tools.py +++ b/python/packages/autogen-core/tests/test_tools.py @@ -4,8 +4,8 @@ import pytest from autogen_core import CancellationToken from autogen_core._function_utils import get_typed_signature -from autogen_core.components.tools import BaseTool, FunctionTool -from autogen_core.components.tools._base import ToolSchema +from autogen_core.tools import BaseTool, FunctionTool +from autogen_core.tools._base import ToolSchema from pydantic import BaseModel, Field, model_serializer from pydantic_core import PydanticUndefined diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_tool_definitions.py b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_tool_definitions.py index b4c8ad9011a2..462061d14428 100644 --- a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_tool_definitions.py +++ b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_tool_definitions.py @@ -1,4 +1,4 @@ -from autogen_core.components.tools import ParametersSchema, ToolSchema +from autogen_core.tools import ParametersSchema, ToolSchema TOOL_OPEN_PATH = ToolSchema( name="open_path", diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py b/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py index 8a4b31975bad..4e16d7001d6c 100644 --- a/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py +++ b/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py @@ -33,8 +33,8 @@ ToolCallResultMessage, ) from autogen_core import CancellationToken, FunctionCall -from autogen_core.components.tools import FunctionTool, Tool from autogen_core.models._types import FunctionExecutionResult +from autogen_core.tools import FunctionTool, Tool _has_openai_dependencies: bool = True try: diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/_video_surfer.py b/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/_video_surfer.py index d74161df17e5..21146c3c72b0 100644 --- a/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/_video_surfer.py +++ b/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/_video_surfer.py @@ -1,8 +1,8 @@ from typing import Any, Awaitable, Callable, List, Optional from autogen_agentchat.agents import AssistantAgent -from autogen_core.components.tools import Tool from autogen_core.models import ChatCompletionClient +from autogen_core.tools import Tool from .tools import ( extract_audio, diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_tool_definitions.py b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_tool_definitions.py index 5d54d5ff1238..fd2928248596 100644 --- a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_tool_definitions.py +++ b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_tool_definitions.py @@ -1,6 +1,6 @@ from typing import Any, Dict -from autogen_core.components.tools._base import ParametersSchema, ToolSchema +from autogen_core.tools._base import ParametersSchema, ToolSchema def _load_tool(tooldef: Dict[str, Any]) -> ToolSchema: diff --git a/python/packages/autogen-ext/src/autogen_ext/models/_openai/_openai_client.py b/python/packages/autogen-ext/src/autogen_ext/models/_openai/_openai_client.py index 154c0a68b4e9..56bd96708ad7 100644 --- a/python/packages/autogen-ext/src/autogen_ext/models/_openai/_openai_client.py +++ b/python/packages/autogen-ext/src/autogen_ext/models/_openai/_openai_client.py @@ -28,7 +28,6 @@ FunctionCall, Image, ) -from autogen_core.components.tools import Tool, ToolSchema from autogen_core.logging import LLMCallEvent from autogen_core.models import ( AssistantMessage, @@ -43,6 +42,7 @@ TopLogprob, UserMessage, ) +from autogen_core.tools import Tool, ToolSchema from openai import AsyncAzureOpenAI, AsyncOpenAI from openai.types.chat import ( ChatCompletion, diff --git a/python/packages/autogen-ext/src/autogen_ext/models/_reply_chat_completion_client.py b/python/packages/autogen-ext/src/autogen_ext/models/_reply_chat_completion_client.py index 42f9e89e2fac..e3e0ff35a803 100644 --- a/python/packages/autogen-ext/src/autogen_ext/models/_reply_chat_completion_client.py +++ b/python/packages/autogen-ext/src/autogen_ext/models/_reply_chat_completion_client.py @@ -4,7 +4,6 @@ from typing import Any, AsyncGenerator, List, Mapping, Optional, Sequence, Union from autogen_core import EVENT_LOGGER_NAME, CancellationToken -from autogen_core.components.tools import Tool, ToolSchema from autogen_core.models import ( ChatCompletionClient, CreateResult, @@ -12,6 +11,7 @@ ModelCapabilities, RequestUsage, ) +from autogen_core.tools import Tool, ToolSchema logger = logging.getLogger(EVENT_LOGGER_NAME) diff --git a/python/packages/autogen-ext/src/autogen_ext/tools/_langchain_adapter.py b/python/packages/autogen-ext/src/autogen_ext/tools/_langchain_adapter.py index cb6e82aa8298..ea657691d942 100644 --- a/python/packages/autogen-ext/src/autogen_ext/tools/_langchain_adapter.py +++ b/python/packages/autogen-ext/src/autogen_ext/tools/_langchain_adapter.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any, Callable, Dict, Type, cast from autogen_core import CancellationToken -from autogen_core.components.tools import BaseTool +from autogen_core.tools import BaseTool from pydantic import BaseModel, Field, create_model if TYPE_CHECKING: diff --git a/python/packages/autogen-ext/tests/models/test_openai_model_client.py b/python/packages/autogen-ext/tests/models/test_openai_model_client.py index 8cf302450081..76b481aa22bc 100644 --- a/python/packages/autogen-ext/tests/models/test_openai_model_client.py +++ b/python/packages/autogen-ext/tests/models/test_openai_model_client.py @@ -4,7 +4,6 @@ import pytest from autogen_core import CancellationToken, Image -from autogen_core.components.tools import BaseTool, FunctionTool from autogen_core.models import ( AssistantMessage, CreateResult, @@ -15,6 +14,7 @@ SystemMessage, UserMessage, ) +from autogen_core.tools import BaseTool, FunctionTool from autogen_ext.models import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient from autogen_ext.models._openai._model_info import resolve_model from autogen_ext.models._openai._openai_client import calculate_vision_tokens, convert_tools diff --git a/python/packages/autogen-ext/tests/test_openai_assistant_agent.py b/python/packages/autogen-ext/tests/test_openai_assistant_agent.py index 0166f17dbf89..da55d860c674 100644 --- a/python/packages/autogen-ext/tests/test_openai_assistant_agent.py +++ b/python/packages/autogen-ext/tests/test_openai_assistant_agent.py @@ -5,7 +5,7 @@ import pytest from autogen_agentchat.messages import TextMessage from autogen_core import CancellationToken -from autogen_core.components.tools._base import BaseTool, Tool +from autogen_core.tools._base import BaseTool, Tool from autogen_ext.agents.openai import OpenAIAssistantAgent from azure.identity import DefaultAzureCredential, get_bearer_token_provider from openai import AsyncAzureOpenAI diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/_tools.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/_tools.py index 740ea1c73f02..a49c2d8b785e 100644 --- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/_tools.py +++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/_tools.py @@ -1,4 +1,4 @@ -from autogen_core.components.tools import ParametersSchema, ToolSchema +from autogen_core.tools import ParametersSchema, ToolSchema TOOL_OPEN_LOCAL_FILE = ToolSchema( name="open_local_file", diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/tool_definitions.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/tool_definitions.py index b662f4101d8a..06832e98909a 100644 --- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/tool_definitions.py +++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/tool_definitions.py @@ -1,7 +1,7 @@ from typing import Any, Dict -# TODO Why does pylance fail if I import from autogen_core.components.tools instead? -from autogen_core.components.tools._base import ParametersSchema, ToolSchema +# TODO Why does pylance fail if I import from autogen_core.tools instead? +from autogen_core.tools._base import ParametersSchema, ToolSchema def _load_tool(tooldef: Dict[str, Any]) -> ToolSchema: diff --git a/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.py b/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.py index 2afe7757968e..b9a7d4ceeb41 100644 --- a/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.py +++ b/python/packages/autogen-magentic-one/tests/headless_web_surfer/test_web_surfer.py @@ -9,10 +9,10 @@ import pytest from autogen_core import AgentId, AgentProxy, FunctionCall, SingleThreadedAgentRuntime -from autogen_core.components.tools._base import ToolSchema from autogen_core.models import ( UserMessage, ) +from autogen_core.tools._base import ToolSchema from autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurfer from autogen_magentic_one.agents.multimodal_web_surfer.tool_definitions import ( TOOL_PAGE_DOWN, diff --git a/python/packages/autogen-studio/autogenstudio/database/component_factory.py b/python/packages/autogen-studio/autogenstudio/database/component_factory.py index 3b9082554a34..140112ede2fe 100644 --- a/python/packages/autogen-studio/autogenstudio/database/component_factory.py +++ b/python/packages/autogen-studio/autogenstudio/database/component_factory.py @@ -9,7 +9,7 @@ from autogen_agentchat.agents import AssistantAgent, UserProxyAgent from autogen_agentchat.conditions import MaxMessageTermination, StopMessageTermination, TextMentionTermination from autogen_agentchat.teams import MagenticOneGroupChat, RoundRobinGroupChat, SelectorGroupChat -from autogen_core.components.tools import FunctionTool +from autogen_core.tools import FunctionTool from autogen_ext.agents.file_surfer import FileSurfer from autogen_ext.agents.magentic_one import MagenticOneCoderAgent from autogen_ext.agents.web_surfer import MultimodalWebSurfer diff --git a/python/packages/autogen-studio/tests/test_component_factory.py b/python/packages/autogen-studio/tests/test_component_factory.py index 8d2b8cbb84c1..57c0e38192c0 100644 --- a/python/packages/autogen-studio/tests/test_component_factory.py +++ b/python/packages/autogen-studio/tests/test_component_factory.py @@ -4,7 +4,7 @@ from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat, MagenticOneGroupChat from autogen_agentchat.conditions import MaxMessageTermination, StopMessageTermination, TextMentionTermination -from autogen_core.components.tools import FunctionTool +from autogen_core.tools import FunctionTool from autogenstudio.datamodel.types import ( AgentConfig,