A programming framework for agentic AI
Remove autogen_agentchat.tasks, create autogen_agentchat.ui and autogen_agentchat.conditions (#4512)
Eric Zhu32aa452af861
diff --git a/README.md b/README.mdindex a876fa19e..b29719347 100644--- a/README.md+++ b/README.md@@ -115,7 +115,8 @@ To use Azure OpenAI models, follow the instruction```pythonimport asynciofrom autogen_agentchat.agents import AssistantAgent-from autogen_agentchat.task import Console, TextMentionTermination+from autogen_agentchat.ui import Console+from autogen_agentchat.conditions import TextMentionTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_ext.models import OpenAIChatCompletionClientdiff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.pyindex 051f85ffe..e2bb8fd71 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@@ -106,7 +106,7 @@ class AssistantAgent(BaseChatAgent):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.messages import TextMessage- from autogen_agentchat.task import Console+ from autogen_agentchat.ui import Consolefrom autogen_core.base import CancellationTokendiff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.pyindex 9a8cdffaa..6ed878bc2 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_society_of_mind_agent.py@@ -43,7 +43,7 @@ class SocietyOfMindAgent(BaseChatAgent):from autogen_agentchat.agents import AssistantAgent, SocietyOfMindAgentfrom autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.teams import RoundRobinGroupChat- from autogen_agentchat.task import MaxMessageTermination+ from autogen_agentchat.conditions import MaxMessageTerminationasync def main() -> None:diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.pyindex 5de17f706..5997816d1 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py@@ -33,7 +33,7 @@ class UserProxyAgent(BaseChatAgent):For typical use cases that involveslow human responses, it is recommended to use termination conditions- such as :class:`~autogen_agentchat.task.HandoffTermination` or :class:`~autogen_agentchat.task.SourceMatchTermination`+ such as :class:`~autogen_agentchat.conditions.HandoffTermination` or :class:`~autogen_agentchat.conditions.SourceMatchTermination`to stop the running team and return the control to the application.You can run the team again with the user input. This way, the state of the teamcan be saved and restored when the user responds.diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_termination.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_termination.pyindex c923e8ced..211b912c1 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_termination.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_termination.py@@ -23,7 +23,7 @@ class TerminationCondition(ABC):.. code-block:: pythonimport asyncio- from autogen_agentchat.task import MaxMessageTermination, TextMentionTermination+ from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTerminationasync def main() -> None:diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/conditions/__init__.py b/python/packages/autogen-agentchat/src/autogen_agentchat/conditions/__init__.pynew file mode 100644index 000000000..cc8e5e831--- /dev/null+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/conditions/__init__.py@@ -0,0 +1,21 @@+from ._terminations import (+ ExternalTermination,+ HandoffTermination,+ MaxMessageTermination,+ SourceMatchTermination,+ StopMessageTermination,+ TextMentionTermination,+ TimeoutTermination,+ TokenUsageTermination,+)++__all__ = [+ "MaxMessageTermination",+ "TextMentionTermination",+ "StopMessageTermination",+ "TokenUsageTermination",+ "HandoffTermination",+ "TimeoutTermination",+ "ExternalTermination",+ "SourceMatchTermination",+]diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/task/_terminations.py b/python/packages/autogen-agentchat/src/autogen_agentchat/conditions/_terminations.pysimilarity index 99%rename from python/packages/autogen-agentchat/src/autogen_agentchat/task/_terminations.pyrename to python/packages/autogen-agentchat/src/autogen_agentchat/conditions/_terminations.pyindex 9db5b584a..bab3e03ff 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/task/_terminations.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/conditions/_terminations.py@@ -218,7 +218,7 @@ class ExternalTermination(TerminationCondition):.. code-block:: python- from autogen_agentchat.task import ExternalTermination+ from autogen_agentchat.conditions import ExternalTerminationtermination = ExternalTermination()diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/task/__init__.py b/python/packages/autogen-agentchat/src/autogen_agentchat/task/__init__.pyindex d863c87cd..6ff207788 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/task/__init__.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/task/__init__.py@@ -1,14 +1,79 @@-from ._console import Console-from ._terminations import (- ExternalTermination,- HandoffTermination,- MaxMessageTermination,- SourceMatchTermination,- StopMessageTermination,- TextMentionTermination,- TimeoutTermination,- TokenUsageTermination,+from typing import AsyncGenerator, TypeVar++from typing_extensions import deprecated++from ..base import Response, TaskResult+from ..conditions import (+ ExternalTermination as ExternalTerminationAlias,+)+from ..conditions import (+ HandoffTermination as HandoffTerminationAlias,+)+from ..conditions import (+ MaxMessageTermination as MaxMessageTerminationAlias,+)+from ..conditions import (+ SourceMatchTermination as SourceMatchTerminationAlias,+)+from ..conditions import (+ StopMessageTermination as StopMessageTerminationAlias,+)+from ..conditions import (+ TextMentionTermination as TextMentionTerminationAlias,+)+from ..conditions import (+ TimeoutTermination as TimeoutTerminationAlias,)+from ..conditions import (+ TokenUsageTermination as TokenUsageTerminationAlias,+)+from ..messages import AgentMessage+from ..ui import Console as ConsoleAlias+++@deprecated("Moved to autogen_agentchat.terminations.ExternalTermination. Will remove this in 0.4.0.", stacklevel=2)+class ExternalTermination(ExternalTerminationAlias): ...+++@deprecated("Moved to autogen_agentchat.terminations.HandoffTermination. Will remove this in 0.4.0.", stacklevel=2)+class HandoffTermination(HandoffTerminationAlias): ...+++@deprecated("Moved to autogen_agentchat.terminations.MaxMessageTermination. Will remove this in 0.4.0.", stacklevel=2)+class MaxMessageTermination(MaxMessageTerminationAlias): ...+++@deprecated("Moved to autogen_agentchat.terminations.SourceMatchTermination. Will remove this in 0.4.0.", stacklevel=2)+class SourceMatchTermination(SourceMatchTerminationAlias): ...+++@deprecated("Moved to autogen_agentchat.terminations.StopMessageTermination. Will remove this in 0.4.0.", stacklevel=2)+class StopMessageTermination(StopMessageTerminationAlias): ...+++@deprecated("Moved to autogen_agentchat.terminations.TextMentionTermination. Will remove this in 0.4.0.", stacklevel=2)+class TextMentionTermination(TextMentionTerminationAlias): ...+++@deprecated("Moved to autogen_agentchat.terminations.TimeoutTermination. Will remove this in 0.4.0.", stacklevel=2)+class TimeoutTermination(TimeoutTerminationAlias): ...+++@deprecated("Moved to autogen_agentchat.terminations.TokenUsageTermination. Will remove this in 0.4.0.", stacklevel=2)+class TokenUsageTermination(TokenUsageTerminationAlias): ...+++T = TypeVar("T", bound=TaskResult | Response)+++@deprecated("Moved to autogen_agentchat.ui.Console. Will remove this in 0.4.0.", stacklevel=2)+async def Console(+ stream: AsyncGenerator[AgentMessage | T, None],+ *,+ no_inline_images: bool = False,+) -> T:+ return await ConsoleAlias(stream, no_inline_images=no_inline_images)+__all__ = ["MaxMessageTermination",diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.pyindex 0990ddc66..371e58014 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py@@ -175,7 +175,7 @@ class BaseGroupChat(Team, ABC):cancellation_token (CancellationToken | None): The cancellation token to kill the task immediately.Setting the cancellation token potentially put the team in an inconsistent state,and it may not reset the termination condition.- To gracefully stop the team, use :class:`~autogen_agentchat.task.ExternalTermination` instead.+ To gracefully stop the team, use :class:`~autogen_agentchat.conditions.ExternalTermination` instead.Example using the :class:`~autogen_agentchat.teams.RoundRobinGroupChat` team:@@ -184,7 +184,7 @@ class BaseGroupChat(Team, ABC):import asynciofrom autogen_agentchat.agents import AssistantAgent- from autogen_agentchat.task import MaxMessageTermination+ from autogen_agentchat.conditions import MaxMessageTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_ext.models import OpenAIChatCompletionClient@@ -214,7 +214,7 @@ class BaseGroupChat(Team, ABC):import asynciofrom autogen_agentchat.agents import AssistantAgent- from autogen_agentchat.task import MaxMessageTermination+ from autogen_agentchat.conditions import MaxMessageTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_core.base import CancellationTokenfrom autogen_ext.models import OpenAIChatCompletionClient@@ -274,7 +274,7 @@ class BaseGroupChat(Team, ABC):cancellation_token (CancellationToken | None): The cancellation token to kill the task immediately.Setting the cancellation token potentially put the team in an inconsistent state,and it may not reset the termination condition.- To gracefully stop the team, use :class:`~autogen_agentchat.task.ExternalTermination` instead.+ To gracefully stop the team, use :class:`~autogen_agentchat.conditions.ExternalTermination` instead.Example using the :class:`~autogen_agentchat.teams.RoundRobinGroupChat` team:@@ -282,7 +282,7 @@ class BaseGroupChat(Team, ABC):import asynciofrom autogen_agentchat.agents import AssistantAgent- from autogen_agentchat.task import MaxMessageTermination+ from autogen_agentchat.conditions import MaxMessageTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_ext.models import OpenAIChatCompletionClient@@ -314,7 +314,8 @@ class BaseGroupChat(Team, ABC):import asynciofrom autogen_agentchat.agents import AssistantAgent- from autogen_agentchat.task import MaxMessageTermination, Console+ from autogen_agentchat.conditions import MaxMessageTermination+ from autogen_agentchat.ui import Consolefrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_core.base import CancellationTokenfrom autogen_ext.models import OpenAIChatCompletionClient@@ -432,7 +433,7 @@ class BaseGroupChat(Team, ABC):import asynciofrom autogen_agentchat.agents import AssistantAgent- from autogen_agentchat.task import MaxMessageTermination+ from autogen_agentchat.conditions import MaxMessageTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_ext.models import OpenAIChatCompletionClientdiff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_group_chat.pyindex e8d83176f..2a4ea7a28 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_group_chat.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_group_chat.py@@ -41,7 +41,7 @@ class MagenticOneGroupChat(BaseGroupChat):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import MagenticOneGroupChat- from autogen_agentchat.task import Console+ from autogen_agentchat.ui import Consoleasync def main() -> None:diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.pyindex f5c128a6c..4566bf8fe 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.py@@ -71,7 +71,8 @@ class RoundRobinGroupChat(BaseGroupChat):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import RoundRobinGroupChat- from autogen_agentchat.task import TextMentionTermination, Console+ from autogen_agentchat.conditions import TextMentionTermination+ from autogen_agentchat.ui import Consoleasync def main() -> None:@@ -100,7 +101,8 @@ class RoundRobinGroupChat(BaseGroupChat):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import RoundRobinGroupChat- from autogen_agentchat.task import TextMentionTermination, Console+ from autogen_agentchat.conditions import TextMentionTermination+ from autogen_agentchat.ui import Consoleasync def main() -> None:diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.pyindex cfcebd378..76d9108c0 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.py@@ -208,7 +208,8 @@ class SelectorGroupChat(BaseGroupChat):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import SelectorGroupChat- from autogen_agentchat.task import TextMentionTermination, Console+ from autogen_agentchat.conditions import TextMentionTermination+ from autogen_agentchat.ui import Consoleasync def main() -> None:@@ -261,7 +262,8 @@ class SelectorGroupChat(BaseGroupChat):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import SelectorGroupChat- from autogen_agentchat.task import TextMentionTermination, Console+ from autogen_agentchat.conditions import TextMentionTermination+ from autogen_agentchat.ui import Consolefrom autogen_agentchat.messages import AgentMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.pyindex 0e658ab75..7feaf3736 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py@@ -100,7 +100,7 @@ class Swarm(BaseGroupChat):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import Swarm- from autogen_agentchat.task import MaxMessageTermination+ from autogen_agentchat.conditions import MaxMessageTerminationasync def main() -> None:@@ -127,7 +127,7 @@ class Swarm(BaseGroupChat):asyncio.run(main())- Using the :class:`~autogen_agentchat.task.HandoffTermination` for human-in-the-loop handoff:+ Using the :class:`~autogen_agentchat.conditions.HandoffTermination` for human-in-the-loop handoff:.. code-block:: python@@ -135,7 +135,8 @@ class Swarm(BaseGroupChat):from autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import Swarm- from autogen_agentchat.task import HandoffTermination, Console, MaxMessageTermination+ from autogen_agentchat.conditions import HandoffTermination, MaxMessageTermination+ from autogen_agentchat.ui import Consolefrom autogen_agentchat.messages import HandoffMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/ui/__init__.py b/python/packages/autogen-agentchat/src/autogen_agentchat/ui/__init__.pynew file mode 100644index 000000000..d668e02c5--- /dev/null+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/ui/__init__.py@@ -0,0 +1,3 @@+from ._console import Console++__all__ = ["Console"]diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/task/_console.py b/python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.pysimilarity index 100%rename from python/packages/autogen-agentchat/src/autogen_agentchat/task/_console.pyrename to python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.pydiff --git a/python/packages/autogen-agentchat/tests/test_group_chat.py b/python/packages/autogen-agentchat/tests/test_group_chat.pyindex bd901d45b..207b87882 100644--- a/python/packages/autogen-agentchat/tests/test_group_chat.py+++ b/python/packages/autogen-agentchat/tests/test_group_chat.py@@ -12,6 +12,7 @@ from autogen_agentchat.agents import (CodeExecutorAgent,)from autogen_agentchat.base import Handoff, Response, TaskResult+from autogen_agentchat.conditions import HandoffTermination, MaxMessageTermination, TextMentionTerminationfrom autogen_agentchat.messages import (AgentMessage,ChatMessage,@@ -22,12 +23,12 @@ from autogen_agentchat.messages import (ToolCallMessage,ToolCallResultMessage,)-from autogen_agentchat.task import Console, HandoffTermination, MaxMessageTermination, TextMentionTerminationfrom autogen_agentchat.teams import (RoundRobinGroupChat,SelectorGroupChat,Swarm,)+from autogen_agentchat.ui import Consolefrom autogen_core.base import CancellationTokenfrom autogen_core.components import FunctionCallfrom autogen_core.components.code_executor import LocalCommandLineCodeExecutordiff --git a/python/packages/autogen-agentchat/tests/test_society_of_mind_agent.py b/python/packages/autogen-agentchat/tests/test_society_of_mind_agent.pyindex 0b9f635ac..a62d6c1db 100644--- a/python/packages/autogen-agentchat/tests/test_society_of_mind_agent.py+++ b/python/packages/autogen-agentchat/tests/test_society_of_mind_agent.py@@ -3,7 +3,7 @@ from typing import Any, AsyncGenerator, Listimport pytestfrom autogen_agentchat.agents import AssistantAgent, SocietyOfMindAgent-from autogen_agentchat.task import MaxMessageTermination+from autogen_agentchat.conditions import MaxMessageTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_ext.models import OpenAIChatCompletionClientfrom openai.resources.chat.completions import AsyncCompletionsdiff --git a/python/packages/autogen-agentchat/tests/test_termination_condition.py b/python/packages/autogen-agentchat/tests/test_termination_condition.pyindex ec6ff43e0..c8df96f42 100644--- a/python/packages/autogen-agentchat/tests/test_termination_condition.py+++ b/python/packages/autogen-agentchat/tests/test_termination_condition.py@@ -2,8 +2,7 @@ import asyncioimport pytestfrom autogen_agentchat.base import TerminatedException-from autogen_agentchat.messages import HandoffMessage, StopMessage, TextMessage-from autogen_agentchat.task import (+from autogen_agentchat.conditions import (ExternalTermination,HandoffTermination,MaxMessageTermination,@@ -13,6 +12,7 @@ from autogen_agentchat.task import (TimeoutTermination,TokenUsageTermination,)+from autogen_agentchat.messages import HandoffMessage, StopMessage, TextMessagefrom autogen_core.components.models import RequestUsagediff --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.ipynbindex 21d10aadc..3cc8bcbee 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@@ -23,7 +23,7 @@"outputs": [],"source": ["from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent\n",- "from autogen_agentchat.task import TextMentionTermination\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_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.ipynbindex 94f08abdb..e769a84b1 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@@ -23,7 +23,7 @@"outputs": [],"source": ["from autogen_agentchat.agents import CodingAssistantAgent, ToolUseAssistantAgent\n",- "from autogen_agentchat.task import TextMentionTermination\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_ext.models import OpenAIChatCompletionClient"diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/travel-planning.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/travel-planning.ipynbindex fbcce8f53..b3d16b2fe 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/travel-planning.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/examples/travel-planning.ipynb@@ -18,7 +18,7 @@"outputs": [],"source": ["from autogen_agentchat.agents import CodingAssistantAgent\n",- "from autogen_agentchat.task import TextMentionTermination\n",+ "from autogen_agentchat.conditions import TextMentionTermination\n","from autogen_agentchat.teams import RoundRobinGroupChat\n","from autogen_ext.models import OpenAIChatCompletionClient"]diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynbindex 2c45f19a2..378e05e22 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb@@ -1,160 +1,161 @@{- "cells": [- {- "cell_type": "markdown",- "metadata": {},- "source": [- "# Quickstart"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "```{include} warning.md\n",- "\n",- "```\n",- "\n",- ":::{note}\n",- "For installation instructions, please refer to the [installation guide](./installation).\n",- ":::\n",- "\n",- "In AutoGen AgentChat, you can build applications quickly using preset agents.\n",- "To illustrate this, we will begin with creating a team of a single agent\n",- "that can use tools and respond to messages.\n",- "\n",- "The following code uses the OpenAI model. If you haven't already, you need to\n",- "install the following package and extension:"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {- "vscode": {- "languageId": "shellscript"- }- },- "outputs": [],- "source": [- "pip install 'autogen-agentchat==0.4.0.dev8' 'autogen-ext[openai]==0.4.0.dev8'"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "To use Azure OpenAI models and AAD authentication,\n",- "you can follow the instructions [here](./tutorial/models.ipynb#azure-openai)."- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [- {- "name": "stdout",- "output_type": "stream",- "text": [- "---------- user ----------\n",- "What is the weather in New York?\n",- "---------- weather_agent ----------\n",- "[FunctionCall(id='call_AhTZ2q3TNL8x0qs00e3wIZ7y', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",- "[Prompt tokens: 79, Completion tokens: 15]\n",- "---------- weather_agent ----------\n",- "[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_AhTZ2q3TNL8x0qs00e3wIZ7y')]\n",- "---------- weather_agent ----------\n",- "The weather in New York is currently 73 degrees and sunny.\n",- "[Prompt tokens: 90, Completion tokens: 14]\n",- "---------- weather_agent ----------\n",- "TERMINATE\n",- "[Prompt tokens: 137, Completion tokens: 4]\n",- "---------- Summary ----------\n",- "Number of messages: 5\n",- "Finish reason: Text 'TERMINATE' mentioned\n",- "Total prompt tokens: 306\n",- "Total completion tokens: 33\n",- "Duration: 1.43 seconds\n"- ]- }- ],- "source": [- "from autogen_agentchat.agents import AssistantAgent\n",- "from autogen_agentchat.task import Console, TextMentionTermination\n",- "from autogen_agentchat.teams import RoundRobinGroupChat\n",- "from autogen_ext.models import OpenAIChatCompletionClient\n",- "\n",- "\n",- "# Define a tool\n",- "async def get_weather(city: str) -> str:\n",- " return f\"The weather in {city} is 73 degrees and Sunny.\"\n",- "\n",- "\n",- "async def main() -> None:\n",- " # Define an agent\n",- " weather_agent = AssistantAgent(\n",- " name=\"weather_agent\",\n",- " model_client=OpenAIChatCompletionClient(\n",- " model=\"gpt-4o-2024-08-06\",\n",- " # api_key=\"YOUR_API_KEY\",\n",- " ),\n",- " tools=[get_weather],\n",- " )\n",- "\n",- " # Define termination condition\n",- " termination = TextMentionTermination(\"TERMINATE\")\n",- "\n",- " # Define a team\n",- " agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)\n",- "\n",- " # Run the team and stream messages to the console\n",- " stream = agent_team.run_stream(task=\"What is the weather in New York?\")\n",- " await Console(stream)\n",- "\n",- "\n",- "# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n",- "await main()"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "The code snippet above introduces two high level concepts in AgentChat: *Agent* and *Team*. An Agent helps us define what actions are taken when a message is received. Specifically, we use the {py:class}`~autogen_agentchat.agents.AssistantAgent` preset - an agent that can be given access to a model (e.g., LLM) and tools (functions) that it can then use to address tasks. A Team helps us define the rules for how agents interact with each other. In the {py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` team, agents respond in a sequential round-robin fashion.\n",- "In this case, we have a single agent, so the same agent is used for each round."- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## What's Next?\n",- "\n",- "Now that you have a basic understanding of how to define an agent and a team, consider following the [tutorial](./tutorial/index) for a walkthrough on other features of AgentChat.\n",- "\n"- ]- }- ],- "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.5"- }- },- "nbformat": 4,- "nbformat_minor": 2+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "# Quickstart"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "```{include} warning.md\n",+ "\n",+ "```\n",+ "\n",+ ":::{note}\n",+ "For installation instructions, please refer to the [installation guide](./installation).\n",+ ":::\n",+ "\n",+ "In AutoGen AgentChat, you can build applications quickly using preset agents.\n",+ "To illustrate this, we will begin with creating a team of a single agent\n",+ "that can use tools and respond to messages.\n",+ "\n",+ "The following code uses the OpenAI model. If you haven't already, you need to\n",+ "install the following package and extension:"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {+ "vscode": {+ "languageId": "shellscript"+ }+ },+ "outputs": [],+ "source": [+ "pip install 'autogen-agentchat==0.4.0.dev8' 'autogen-ext[openai]==0.4.0.dev8'"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "To use Azure OpenAI models and AAD authentication,\n",+ "you can follow the instructions [here](./tutorial/models.ipynb#azure-openai)."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "---------- user ----------\n",+ "What is the weather in New York?\n",+ "---------- weather_agent ----------\n",+ "[FunctionCall(id='call_AhTZ2q3TNL8x0qs00e3wIZ7y', arguments='{\"city\":\"New York\"}', name='get_weather')]\n",+ "[Prompt tokens: 79, Completion tokens: 15]\n",+ "---------- weather_agent ----------\n",+ "[FunctionExecutionResult(content='The weather in New York is 73 degrees and Sunny.', call_id='call_AhTZ2q3TNL8x0qs00e3wIZ7y')]\n",+ "---------- weather_agent ----------\n",+ "The weather in New York is currently 73 degrees and sunny.\n",+ "[Prompt tokens: 90, Completion tokens: 14]\n",+ "---------- weather_agent ----------\n",+ "TERMINATE\n",+ "[Prompt tokens: 137, Completion tokens: 4]\n",+ "---------- Summary ----------\n",+ "Number of messages: 5\n",+ "Finish reason: Text 'TERMINATE' mentioned\n",+ "Total prompt tokens: 306\n",+ "Total completion tokens: 33\n",+ "Duration: 1.43 seconds\n"+ ]+ }+ ],+ "source": [+ "from autogen_agentchat.agents import AssistantAgent\n",+ "from autogen_agentchat.conditions import TextMentionTermination\n",+ "from autogen_agentchat.teams import RoundRobinGroupChat\n",+ "from autogen_agentchat.ui import Console\n",+ "from autogen_ext.models import OpenAIChatCompletionClient\n",+ "\n",+ "\n",+ "# Define a tool\n",+ "async def get_weather(city: str) -> str:\n",+ " return f\"The weather in {city} is 73 degrees and Sunny.\"\n",+ "\n",+ "\n",+ "async def main() -> None:\n",+ " # Define an agent\n",+ " weather_agent = AssistantAgent(\n",+ " name=\"weather_agent\",\n",+ " model_client=OpenAIChatCompletionClient(\n",+ " model=\"gpt-4o-2024-08-06\",\n",+ " # api_key=\"YOUR_API_KEY\",\n",+ " ),\n",+ " tools=[get_weather],\n",+ " )\n",+ "\n",+ " # Define termination condition\n",+ " termination = TextMentionTermination(\"TERMINATE\")\n",+ "\n",+ " # Define a team\n",+ " agent_team = RoundRobinGroupChat([weather_agent], termination_condition=termination)\n",+ "\n",+ " # Run the team and stream messages to the console\n",+ " stream = agent_team.run_stream(task=\"What is the weather in New York?\")\n",+ " await Console(stream)\n",+ "\n",+ "\n",+ "# NOTE: if running this inside a Python script you'll need to use asyncio.run(main()).\n",+ "await main()"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "The code snippet above introduces two high level concepts in AgentChat: *Agent* and *Team*. An Agent helps us define what actions are taken when a message is received. Specifically, we use the {py:class}`~autogen_agentchat.agents.AssistantAgent` preset - an agent that can be given access to a model (e.g., LLM) and tools (functions) that it can then use to address tasks. A Team helps us define the rules for how agents interact with each other. In the {py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` team, agents respond in a sequential round-robin fashion.\n",+ "In this case, we have a single agent, so the same agent is used for each round."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## What's Next?\n",+ "\n",+ "Now that you have a basic understanding of how to define an agent and a team, consider following the [tutorial](./tutorial/index) for a walkthrough on other features of AgentChat.\n",+ "\n"+ ]+ }+ ],+ "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.12.6"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 2}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.ipynbindex 74503c617..f94761c56 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@@ -108,13 +108,13 @@"\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",- "and use {py:class}`~autogen_agentchat.task.Console` to print the messages\n",+ "and use {py:class}`~autogen_agentchat.ui.Console` to print the messages\n","as they appear to the console."]},{"cell_type": "code",- "execution_count": 2,+ "execution_count": null,"metadata": {},"outputs": [{@@ -138,7 +138,7 @@}],"source": [- "from autogen_agentchat.task import Console\n",+ "from autogen_agentchat.ui import Console\n","\n","\n","async def assistant_run_stream() -> None:\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynbindex 3377d3d47..98b52b1ee 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/selector-group-chat.ipynb@@ -56,16 +56,17 @@},{"cell_type": "code",- "execution_count": 14,+ "execution_count": null,"metadata": {},"outputs": [],"source": ["from typing import Sequence\n","\n","from autogen_agentchat.agents import AssistantAgent\n",+ "from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination\n","from autogen_agentchat.messages import AgentMessage\n",- "from autogen_agentchat.task import Console, MaxMessageTermination, TextMentionTermination\n","from autogen_agentchat.teams import SelectorGroupChat\n",+ "from autogen_agentchat.ui import Console\n","from autogen_ext.models import OpenAIChatCompletionClient"]},@@ -208,8 +209,8 @@"metadata": {},"source": ["Let's create the team with two termination conditions:\n",- "{py:class}`~autogen_agentchat.task.TextMentionTermination` to end the conversation when the Planning Agent sends \"TERMINATE\",\n",- "and {py:class}`~autogen_agentchat.task.MaxMessageTermination` to limit the conversation to 25 messages to avoid infinite loop."+ "{py:class}`~autogen_agentchat.conditions.TextMentionTermination` to end the conversation when the Planning Agent sends \"TERMINATE\",\n",+ "and {py:class}`~autogen_agentchat.conditions.MaxMessageTermination` to limit the conversation to 25 messages to avoid infinite loop."]},{@@ -458,7 +459,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.12.7"+ "version": "3.12.6"}},"nbformat": 4,diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/swarm.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/swarm.ipynbindex 1505e697b..c1583848a 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/swarm.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/swarm.ipynb@@ -89,16 +89,17 @@},{"cell_type": "code",- "execution_count": 2,+ "execution_count": null,"metadata": {},"outputs": [],"source": ["from typing import Any, Dict, List\n","\n","from autogen_agentchat.agents import AssistantAgent\n",+ "from autogen_agentchat.conditions import HandoffTermination, TextMentionTermination\n","from autogen_agentchat.messages import HandoffMessage\n",- "from autogen_agentchat.task import Console, HandoffTermination, TextMentionTermination\n","from autogen_agentchat.teams import Swarm\n",+ "from autogen_agentchat.ui import Console\n","from autogen_ext.models import OpenAIChatCompletionClient"]},@@ -533,7 +534,7 @@],"metadata": {"kernelspec": {- "display_name": "autogen",+ "display_name": ".venv","language": "python","name": "python3"},@@ -547,7 +548,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.12.7"+ "version": "3.12.6"}},"nbformat": 4,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.ipynbindex a798c8e6d..a5599965f 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@@ -46,18 +46,18 @@"On its turn, each agent broadcasts its response to all other agents in the team, so all agents have the same 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.task.TextMentionTermination`\n",+ "and {py:class}`~autogen_agentchat.conditions.TextMentionTermination`\n","termination condition that stops the team when a word is detected."]},{"cell_type": "code",- "execution_count": 2,+ "execution_count": null,"metadata": {},"outputs": [],"source": ["from autogen_agentchat.agents import AssistantAgent\n",- "from autogen_agentchat.task import TextMentionTermination\n",+ "from autogen_agentchat.conditions import TextMentionTermination\n","from autogen_agentchat.teams import RoundRobinGroupChat\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n",@@ -212,7 +212,7 @@"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","\n",- "There is a covenient method {py:meth}`~autogen_agentchat.task.Console` that prints the messages to the console\n",+ "There is a covenient method {py:meth}`~autogen_agentchat.ui.Console` that prints the messages to the console\n","with proper formatting."]},@@ -248,7 +248,7 @@}],"source": [- "from autogen_agentchat.task import Console\n",+ "from autogen_agentchat.ui import Console\n","\n","# Use `asyncio.run(single_agent_team.reset())` when running in a script.\n","await single_agent_team.reset() # Reset the team for the next run.\n",@@ -272,20 +272,21 @@"\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.task.TextMentionTermination`\n",- "and {py:class}`~autogen_agentchat.task.MaxMessageTermination` termination conditions\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."]},{"cell_type": "code",- "execution_count": 21,+ "execution_count": null,"metadata": {},"outputs": [],"source": ["from autogen_agentchat.agents import AssistantAgent\n",- "from autogen_agentchat.task import Console, MaxMessageTermination, TextMentionTermination\n",+ "from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination\n","from autogen_agentchat.teams import RoundRobinGroupChat\n",+ "from autogen_agentchat.ui import Console\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n","# Create an OpenAI model client.\n",@@ -605,7 +606,7 @@"to continue processing the task. We will show two possible ways to do it:\n","\n","- Set the maximum number of turns such that the team stops after the specified number of turns.\n",- "- Use the {py:class}`~autogen_agentchat.task.HandoffTermination` termination condition.\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)."]@@ -641,7 +642,7 @@"source": ["#### Using Handoff to Pause Team\n","\n",- "You can use the {py:class}`~autogen_agentchat.task.HandoffTermination` termination condition\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","\n","Let's create a team with a single {py:class}`~autogen_agentchat.agents.AssistantAgent` agent\n",@@ -661,7 +662,7 @@"source": ["from autogen_agentchat.agents import AssistantAgent\n","from autogen_agentchat.base import Handoff\n",- "from autogen_agentchat.task import HandoffTermination, TextMentionTermination\n",+ "from autogen_agentchat.conditions import HandoffTermination, TextMentionTermination\n","from autogen_agentchat.teams import RoundRobinGroupChat\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n",@@ -698,7 +699,7 @@},{"cell_type": "code",- "execution_count": 16,+ "execution_count": null,"metadata": {},"outputs": [{@@ -724,7 +725,7 @@}],"source": [- "from autogen_agentchat.task import Console\n",+ "from autogen_agentchat.ui import Console\n","\n","# Use `asyncio.run(Console(lazy_agent_team.run_stream(task=\"What is the weather in New York?\")))` when running in a script.\n","await Console(lazy_agent_team.run_stream(task=\"What is the weather in New York?\"))"@@ -791,4 +792,4 @@},"nbformat": 4,"nbformat_minor": 2-}+}\ No newline at end of filediff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/termination.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/termination.ipynbindex 67c7582a3..683a9a8ac 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/termination.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/termination.ipynb@@ -31,14 +31,14 @@"metadata": {},"source": ["# AutoGen provides several built-in termination conditions: \n",- "1. {py:class}`~autogen_agentchat.task.MaxMessageTermination`: Stops after a specified number of messages have been produced, including both agent and task messages.\n",- "2. {py:class}`~autogen_agentchat.task.TextMentionTermination`: Stops when specific text or string is mentioned in a message (e.g., \"TERMINATE\").\n",- "3. {py:class}`~autogen_agentchat.task.TokenUsageTermination`: Stops when a certain number of prompt or completion tokens are used. This requires the agents to report token usage in their messages.\n",- "4. {py:class}`~autogen_agentchat.task.TimeoutTermination`: Stops after a specified duration in seconds.\n",- "5. {py:class}`~autogen_agentchat.task.HandoffTermination`: Stops when a handoff to a specific target is requested. Handoff messages can be used to build patterns such as {py:class}`~autogen_agentchat.teams.Swarm`. This is useful when you want to pause the run and allow application or user to provide input when an agent hands off to them.\n",- "6. {py:class}`~autogen_agentchat.task.SourceMatchTermination`: Stops after a specific agent responds.\n",- "7. {py:class}`~autogen_agentchat.task.ExternalTermination`: Enables programmatic control of termination from outside the run. This is useful for UI integration (e.g., \"Stop\" buttons in chat interfaces).\n",- "8. {py:class}`~autogen_agentchat.task.StopMessageTermination`: Stops when a {py:class}`~autogen_agentchat.messages.StopMessage` is produced by an agent."+ "1. {py:class}`~autogen_agentchat.conditions.MaxMessageTermination`: Stops after a specified number of messages have been produced, including both agent and task messages.\n",+ "2. {py:class}`~autogen_agentchat.conditions.TextMentionTermination`: Stops when specific text or string is mentioned in a message (e.g., \"TERMINATE\").\n",+ "3. {py:class}`~autogen_agentchat.conditions.TokenUsageTermination`: Stops when a certain number of prompt or completion tokens are used. This requires the agents to report token usage in their messages.\n",+ "4. {py:class}`~autogen_agentchat.conditions.TimeoutTermination`: Stops after a specified duration in seconds.\n",+ "5. {py:class}`~autogen_agentchat.conditions.HandoffTermination`: Stops when a handoff to a specific target is requested. Handoff messages can be used to build patterns such as {py:class}`~autogen_agentchat.teams.Swarm`. This is useful when you want to pause the run and allow application or user to provide input when an agent hands off to them.\n",+ "6. {py:class}`~autogen_agentchat.conditions.SourceMatchTermination`: Stops after a specific agent responds.\n",+ "7. {py:class}`~autogen_agentchat.conditions.ExternalTermination`: Enables programmatic control of termination from outside the run. This is useful for UI integration (e.g., \"Stop\" buttons in chat interfaces).\n",+ "8. {py:class}`~autogen_agentchat.conditions.StopMessageTermination`: Stops when a {py:class}`~autogen_agentchat.messages.StopMessage` is produced by an agent."]},{@@ -50,13 +50,14 @@},{"cell_type": "code",- "execution_count": 3,+ "execution_count": null,"metadata": {},"outputs": [],"source": ["from autogen_agentchat.agents import AssistantAgent\n",- "from autogen_agentchat.task import Console, MaxMessageTermination, TextMentionTermination\n",+ "from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination\n","from autogen_agentchat.teams import RoundRobinGroupChat\n",+ "from autogen_agentchat.ui import Console\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n","model_client = OpenAIChatCompletionClient(\n",@@ -295,7 +296,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.11.5"+ "version": "3.12.6"}},"nbformat": 4,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.pyindex 8f8bb276e..b9f809921 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@@ -39,7 +39,8 @@ class VideoSurferAgent(AssistantAgent):import asyncio- from autogen_agentchat.task import Console, TextMentionTermination+ from autogen_agentchat.ui import Console+ from autogen_agentchat.conditions import TextMentionTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_ext.models import OpenAIChatCompletionClientfrom autogen_ext.agents.video_surfer import VideoSurferAgent@@ -72,7 +73,7 @@ class VideoSurferAgent(AssistantAgent):import asyncio- from autogen_agentchat.task import Console+ from autogen_agentchat.ui import Consolefrom autogen_agentchat.teams import MagenticOneGroupChatfrom autogen_agentchat.agents import UserProxyAgentfrom autogen_ext.models import OpenAIChatCompletionClientdiff --git a/python/packages/autogen-studio/autogenstudio/database/component_factory.py b/python/packages/autogen-studio/autogenstudio/database/component_factory.pyindex 2e9e014d7..a3ae77b3b 100644--- a/python/packages/autogen-studio/autogenstudio/database/component_factory.py+++ b/python/packages/autogen-studio/autogenstudio/database/component_factory.py@@ -7,7 +7,7 @@ from typing import Callable, Dict, List, Literal, Optional, Unionimport aiofilesimport yamlfrom autogen_agentchat.agents import AssistantAgent, UserProxyAgent-from autogen_agentchat.task import MaxMessageTermination, StopMessageTermination, TextMentionTermination+from autogen_agentchat.conditions import MaxMessageTermination, StopMessageTermination, TextMentionTerminationfrom autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChatfrom autogen_core.components.tools import FunctionToolfrom autogen_ext.agents.web_surfer import MultimodalWebSurferdiff --git a/python/packages/autogen-studio/notebooks/tutorial.ipynb b/python/packages/autogen-studio/notebooks/tutorial.ipynbindex 432f94587..2515d1f37 100644--- a/python/packages/autogen-studio/notebooks/tutorial.ipynb+++ b/python/packages/autogen-studio/notebooks/tutorial.ipynb@@ -1,321 +1,321 @@{- "cells": [- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## AutoGen Studio Agent Workflow API Example\n",- "\n",- "This notebook focuses on demonstrating capabilities of the autogen studio workflow python api. \n",- "\n",- "- Declarative Specification of an Agent Team\n",- "- Loading the specification and running the resulting agent\n",- "\n",- " "- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "from autogenstudio.teammanager import TeamManager \n",- " \n",- "wm = TeamManager() \n",- "result = await wm.run(task=\"What is the weather in New York?\", team_config=\"team.json\") \n",- "print(result)"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "result_stream = wm.run_stream(task=\"What is the weather in New York?\", team_config=\"team.json\") \n",- "async for response in result_stream:\n",- " print(response)"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## AutoGen Studio Database API\n",- "\n",- "Api for creating objects and serializing to a database."- ]- },- {- "cell_type": "code",- "execution_count": 3,- "metadata": {},- "outputs": [- {- "data": {- "text/plain": [- "Response(message='Database is ready', status=True, data=None)"- ]- },- "execution_count": 3,- "metadata": {},- "output_type": "execute_result"- }- ],- "source": [- "from autogenstudio.database import DatabaseManager \n",- "import os \n",- "# delete database\n",- "# if os.path.exists(\"test.db\"):\n",- "# os.remove(\"test.db\") \n",- "\n",- "os.makedirs(\"test\", exist_ok=True)\n",- "# create a database\n",- "dbmanager = DatabaseManager(engine_uri=\"sqlite:///test.db\", base_dir=\"test\")\n",- "dbmanager.initialize_database() "- ]- },- {- "cell_type": "code",- "execution_count": 6,- "metadata": {},- "outputs": [],- "source": [- "\n",- "from sqlmodel import Session, text, select\n",- "from autogenstudio.datamodel import Model, ModelConfig, ModelTypes, Team, TeamConfig, TeamTypes, Agent, AgentConfig, AgentTypes, Tool, ToolConfig, LinkTypes,ToolTypes\n",- "\n",- "user_id = \"[email protected]\"\n",- "from autogenstudio.datamodel import ModelConfig, Model, TeamConfig, Team, Tool, Agent, AgentConfig, TerminationConfig, TerminationTypes, ModelTypes, TeamTypes, AgentTypes, ToolConfig, LinkTypes, TerminationTypes\n",- "\n",- "gpt4_model = Model(user_id=user_id, config= ModelConfig(model=\"gpt-4o-2024-08-06\", model_type=ModelTypes.OPENAI).model_dump() )\n",- "\n",- "weather_tool = Tool(user_id=user_id, config=ToolConfig(name=\"get_weather\", description=\"Get the weather for a city\", content=\"async def get_weather(city: str) -> str:\\n return f\\\"The weather in {city} is 73 degrees and Sunny.\\\"\",tool_type=ToolTypes.PYTHON_FUNCTION).model_dump() )\n",- "\n",- "adding_tool = Tool(user_id=user_id, config=ToolConfig(name=\"add\", description=\"Add two numbers\", content=\"async def add(a: int, b: int) -> int:\\n return a + b\", tool_type=ToolTypes.PYTHON_FUNCTION).model_dump() )\n",- "\n",- "writing_agent = Agent(user_id=user_id, \n",- " config=AgentConfig(\n",- " name=\"writing_agent\", \n",- " tools=[weather_tool.config], \n",- " agent_type=AgentTypes.ASSISTANT,\n",- " model_client=gpt4_model.config\n",- " ).model_dump()\n",- " )\n",- "\n",- "team = Team(user_id=user_id, config=TeamConfig(\n",- " name=\"weather_team\",\n",- " participants=[writing_agent.config],\n",- " termination_condition=TerminationConfig(termination_type=TerminationTypes.MAX_MESSAGES, max_messages=5).model_dump(),\n",- " team_type=TeamTypes.ROUND_ROBIN\n",- " ).model_dump()\n",- ")\n",- "\n",- "with Session(dbmanager.engine) as session:\n",- " session.add(gpt4_model)\n",- " session.add(weather_tool)\n",- " session.add(adding_tool)\n",- " session.add(writing_agent)\n",- " session.add(team)\n",- " session.commit()\n",- "\n",- " dbmanager.link(LinkTypes.AGENT_MODEL, writing_agent.id, gpt4_model.id)\n",- " dbmanager.link(LinkTypes.AGENT_TOOL, writing_agent.id, weather_tool.id)\n",- " dbmanager.link(LinkTypes.AGENT_TOOL, writing_agent.id, adding_tool.id)\n",- " dbmanager.link(LinkTypes.TEAM_AGENT, team.id, writing_agent.id)\n"- ]- },- {- "cell_type": "code",- "execution_count": 7,- "metadata": {},- "outputs": [- {- "name": "stdout",- "output_type": "stream",- "text": [- "2 teams in database\n"- ]- }- ],- "source": [- "all_teams = dbmanager.get(Team)\n",- "print(len(all_teams.data), \"teams in database\")"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## Configuration Manager\n",- "\n",- "Helper class to mostly import teams/agents/models/tools etc into a database."- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "from autogenstudio.database import ConfigurationManager \n",- "\n",- "config_manager = ConfigurationManager(dbmanager)\n",- " "- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "result = await config_manager.import_component(\"team.json\", user_id=\"user_id\", check_exists=True)\n",- "print(result)"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "result = await config_manager.import_directory(\".\", user_id=\"user_id\", check_exists=False)\n",- "print(result)"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "all_teams = dbmanager.get(Team)\n",- "print(len(all_teams.data), \"teams in database\")"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## Sample AgentChat Example (Python)"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "from autogen_agentchat.agents import AssistantAgent\n",- "from autogen_agentchat.task import TextMentionTermination\n",- "from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat\n",- "from autogen_ext.models import OpenAIChatCompletionClient \n",- "\n",- "planner_agent = AssistantAgent(\n",- " \"planner_agent\",\n",- " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",- " description=\"A helpful assistant that can plan trips.\",\n",- " system_message=\"You are a helpful assistant that can suggest a travel plan for a user based on their request. Respond with a single sentence\",\n",- ")\n",- "\n",- "local_agent = AssistantAgent(\n",- " \"local_agent\",\n",- " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",- " description=\"A local assistant that can suggest local activities or places to visit.\",\n",- " system_message=\"You are a helpful assistant that can suggest authentic and interesting local activities or places to visit for a user and can utilize any context information provided. Respond with a single sentence\",\n",- ")\n",- "\n",- "language_agent = AssistantAgent(\n",- " \"language_agent\",\n",- " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",- " description=\"A helpful assistant that can provide language tips for a given destination.\",\n",- " system_message=\"You are a helpful assistant that can review travel plans, providing feedback on important/critical tips about how best to address language or communication challenges for the given destination. If the plan already includes language tips, you can mention that the plan is satisfactory, with rationale.Respond with a single sentence\",\n",- ")\n",- "\n",- "travel_summary_agent = AssistantAgent(\n",- " \"travel_summary_agent\",\n",- " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",- " description=\"A helpful assistant that can summarize the travel plan.\",\n",- " system_message=\"You are a helpful assistant that can take in all of the suggestions and advice from the other agents and provide a detailed tfinal travel plan. You must ensure th b at the final plan is integrated and complete. YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN. When the plan is complete and all perspectives are integrated, you can respond with TERMINATE.Respond with a single sentence\",\n",- ")\n",- "\n",- "termination = TextMentionTermination(\"TERMINATE\")\n",- "group_chat = RoundRobinGroupChat(\n",- " [planner_agent, local_agent, language_agent, travel_summary_agent], termination_condition=termination\n",- ")"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "\n",- "result = group_chat.run_stream(task=\"Plan a 3 day trip to Nepal.\")\n",- "async for response in result:\n",- " print(response) "- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## Human in the Loop with a UserProxy Agent\n",- "\n",- "AutoGen studio provides a custom agent allows a human interact as part of the agent team.\n",- "\n"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "from autogenstudio.components import UserProxyAgent \n",- "\n",- "def input_func(prompt: str) -> str: \n",- " return \"Hello World there\" + str(prompt)\n",- "user_agent = UserProxyAgent(name=\"user_agent\", description=\"a human user\", input_func=input_func)"- ]- },- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "from autogen_core.base import CancellationToken \n",- "cancellation_token = CancellationToken()\n",- "stream = user_agent.run_stream(task=\"hello there\", cancellation_token=cancellation_token)\n",- "\n",- "async for response in stream:\n",- " print(response)"- ]- }- ],- "metadata": {- "kernelspec": {- "display_name": "agnext",- "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-}+ "cells": [+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## AutoGen Studio Agent Workflow API Example\n",+ "\n",+ "This notebook focuses on demonstrating capabilities of the autogen studio workflow python api. \n",+ "\n",+ "- Declarative Specification of an Agent Team\n",+ "- Loading the specification and running the resulting agent\n",+ "\n",+ " "+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "from autogenstudio.teammanager import TeamManager \n",+ " \n",+ "wm = TeamManager() \n",+ "result = await wm.run(task=\"What is the weather in New York?\", team_config=\"team.json\") \n",+ "print(result)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "result_stream = wm.run_stream(task=\"What is the weather in New York?\", team_config=\"team.json\") \n",+ "async for response in result_stream:\n",+ " print(response)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## AutoGen Studio Database API\n",+ "\n",+ "Api for creating objects and serializing to a database."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 3,+ "metadata": {},+ "outputs": [+ {+ "data": {+ "text/plain": [+ "Response(message='Database is ready', status=True, data=None)"+ ]+ },+ "execution_count": 3,+ "metadata": {},+ "output_type": "execute_result"+ }+ ],+ "source": [+ "from autogenstudio.database import DatabaseManager \n",+ "import os \n",+ "# delete database\n",+ "# if os.path.exists(\"test.db\"):\n",+ "# os.remove(\"test.db\") \n",+ "\n",+ "os.makedirs(\"test\", exist_ok=True)\n",+ "# create a database\n",+ "dbmanager = DatabaseManager(engine_uri=\"sqlite:///test.db\", base_dir=\"test\")\n",+ "dbmanager.initialize_database() "+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 6,+ "metadata": {},+ "outputs": [],+ "source": [+ "\n",+ "from sqlmodel import Session, text, select\n",+ "from autogenstudio.datamodel import Model, ModelConfig, ModelTypes, Team, TeamConfig, TeamTypes, Agent, AgentConfig, AgentTypes, Tool, ToolConfig, LinkTypes,ToolTypes\n",+ "\n",+ "user_id = \"[email protected]\"\n",+ "from autogenstudio.datamodel import ModelConfig, Model, TeamConfig, Team, Tool, Agent, AgentConfig, TerminationConfig, TerminationTypes, ModelTypes, TeamTypes, AgentTypes, ToolConfig, LinkTypes, TerminationTypes\n",+ "\n",+ "gpt4_model = Model(user_id=user_id, config= ModelConfig(model=\"gpt-4o-2024-08-06\", model_type=ModelTypes.OPENAI).model_dump() )\n",+ "\n",+ "weather_tool = Tool(user_id=user_id, config=ToolConfig(name=\"get_weather\", description=\"Get the weather for a city\", content=\"async def get_weather(city: str) -> str:\\n return f\\\"The weather in {city} is 73 degrees and Sunny.\\\"\",tool_type=ToolTypes.PYTHON_FUNCTION).model_dump() )\n",+ "\n",+ "adding_tool = Tool(user_id=user_id, config=ToolConfig(name=\"add\", description=\"Add two numbers\", content=\"async def add(a: int, b: int) -> int:\\n return a + b\", tool_type=ToolTypes.PYTHON_FUNCTION).model_dump() )\n",+ "\n",+ "writing_agent = Agent(user_id=user_id, \n",+ " config=AgentConfig(\n",+ " name=\"writing_agent\", \n",+ " tools=[weather_tool.config], \n",+ " agent_type=AgentTypes.ASSISTANT,\n",+ " model_client=gpt4_model.config\n",+ " ).model_dump()\n",+ " )\n",+ "\n",+ "team = Team(user_id=user_id, config=TeamConfig(\n",+ " name=\"weather_team\",\n",+ " participants=[writing_agent.config],\n",+ " termination_condition=TerminationConfig(termination_type=TerminationTypes.MAX_MESSAGES, max_messages=5).model_dump(),\n",+ " team_type=TeamTypes.ROUND_ROBIN\n",+ " ).model_dump()\n",+ ")\n",+ "\n",+ "with Session(dbmanager.engine) as session:\n",+ " session.add(gpt4_model)\n",+ " session.add(weather_tool)\n",+ " session.add(adding_tool)\n",+ " session.add(writing_agent)\n",+ " session.add(team)\n",+ " session.commit()\n",+ "\n",+ " dbmanager.link(LinkTypes.AGENT_MODEL, writing_agent.id, gpt4_model.id)\n",+ " dbmanager.link(LinkTypes.AGENT_TOOL, writing_agent.id, weather_tool.id)\n",+ " dbmanager.link(LinkTypes.AGENT_TOOL, writing_agent.id, adding_tool.id)\n",+ " dbmanager.link(LinkTypes.TEAM_AGENT, team.id, writing_agent.id)\n"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 7,+ "metadata": {},+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "2 teams in database\n"+ ]+ }+ ],+ "source": [+ "all_teams = dbmanager.get(Team)\n",+ "print(len(all_teams.data), \"teams in database\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Configuration Manager\n",+ "\n",+ "Helper class to mostly import teams/agents/models/tools etc into a database."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "from autogenstudio.database import ConfigurationManager \n",+ "\n",+ "config_manager = ConfigurationManager(dbmanager)\n",+ " "+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "result = await config_manager.import_component(\"team.json\", user_id=\"user_id\", check_exists=True)\n",+ "print(result)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "result = await config_manager.import_directory(\".\", user_id=\"user_id\", check_exists=False)\n",+ "print(result)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "all_teams = dbmanager.get(Team)\n",+ "print(len(all_teams.data), \"teams in database\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Sample AgentChat Example (Python)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "from autogen_agentchat.agents import AssistantAgent\n",+ "from autogen_agentchat.conditions import TextMentionTermination\n",+ "from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat\n",+ "from autogen_ext.models import OpenAIChatCompletionClient \n",+ "\n",+ "planner_agent = AssistantAgent(\n",+ " \"planner_agent\",\n",+ " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",+ " description=\"A helpful assistant that can plan trips.\",\n",+ " system_message=\"You are a helpful assistant that can suggest a travel plan for a user based on their request. Respond with a single sentence\",\n",+ ")\n",+ "\n",+ "local_agent = AssistantAgent(\n",+ " \"local_agent\",\n",+ " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",+ " description=\"A local assistant that can suggest local activities or places to visit.\",\n",+ " system_message=\"You are a helpful assistant that can suggest authentic and interesting local activities or places to visit for a user and can utilize any context information provided. Respond with a single sentence\",\n",+ ")\n",+ "\n",+ "language_agent = AssistantAgent(\n",+ " \"language_agent\",\n",+ " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",+ " description=\"A helpful assistant that can provide language tips for a given destination.\",\n",+ " system_message=\"You are a helpful assistant that can review travel plans, providing feedback on important/critical tips about how best to address language or communication challenges for the given destination. If the plan already includes language tips, you can mention that the plan is satisfactory, with rationale.Respond with a single sentence\",\n",+ ")\n",+ "\n",+ "travel_summary_agent = AssistantAgent(\n",+ " \"travel_summary_agent\",\n",+ " model_client=OpenAIChatCompletionClient(model=\"gpt-4\"),\n",+ " description=\"A helpful assistant that can summarize the travel plan.\",\n",+ " system_message=\"You are a helpful assistant that can take in all of the suggestions and advice from the other agents and provide a detailed tfinal travel plan. You must ensure th b at the final plan is integrated and complete. YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN. When the plan is complete and all perspectives are integrated, you can respond with TERMINATE.Respond with a single sentence\",\n",+ ")\n",+ "\n",+ "termination = TextMentionTermination(\"TERMINATE\")\n",+ "group_chat = RoundRobinGroupChat(\n",+ " [planner_agent, local_agent, language_agent, travel_summary_agent], termination_condition=termination\n",+ ")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "\n",+ "result = group_chat.run_stream(task=\"Plan a 3 day trip to Nepal.\")\n",+ "async for response in result:\n",+ " print(response) "+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Human in the Loop with a UserProxy Agent\n",+ "\n",+ "AutoGen studio provides a custom agent allows a human interact as part of the agent team.\n",+ "\n"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "from autogenstudio.components import UserProxyAgent \n",+ "\n",+ "def input_func(prompt: str) -> str: \n",+ " return \"Hello World there\" + str(prompt)\n",+ "user_agent = UserProxyAgent(name=\"user_agent\", description=\"a human user\", input_func=input_func)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "from autogen_core.base import CancellationToken \n",+ "cancellation_token = CancellationToken()\n",+ "stream = user_agent.run_stream(task=\"hello there\", cancellation_token=cancellation_token)\n",+ "\n",+ "async for response in stream:\n",+ " print(response)"+ ]+ }+ ],+ "metadata": {+ "kernelspec": {+ "display_name": "agnext",+ "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+}\ No newline at end of filediff --git a/python/packages/autogen-studio/tests/test_component_factory.py b/python/packages/autogen-studio/tests/test_component_factory.pyindex 4fc4aed8c..eb8255bbf 100644--- a/python/packages/autogen-studio/tests/test_component_factory.py+++ b/python/packages/autogen-studio/tests/test_component_factory.py@@ -3,7 +3,7 @@ from typing import Listfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat-from autogen_agentchat.task import MaxMessageTermination, StopMessageTermination, TextMentionTermination+from autogen_agentchat.conditions import MaxMessageTermination, StopMessageTermination, TextMentionTerminationfrom autogen_core.components.tools import FunctionToolfrom autogenstudio.datamodel.types import (