A programming framework for agentic AI
Flatten core base and components (#4513)
Jack Gerrits3022369eebc6
diff --git a/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.pyindex 17d912519..09925ebe1 100644--- a/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py@@ -8,7 +8,7 @@ from openai import AzureOpenAIfrom typing import List-from autogen_core.base import AgentId, AgentProxy, TopicId+from autogen_core import AgentId, AgentProxy, TopicIdfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAMEfrom autogen_core.components.models import (@@ -16,7 +16,7 @@ from autogen_core.components.models import (UserMessage,LLMMessage,)-from autogen_core.components import DefaultSubscription, DefaultTopicId+from autogen_core import DefaultSubscription, DefaultTopicIdfrom autogen_core.components.code_executor import LocalCommandLineCodeExecutorfrom autogen_core.components.models import AssistantMessagediff --git a/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.pyindex 6c7f8ab76..15b312c51 100644--- a/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py@@ -8,7 +8,7 @@ from openai import AzureOpenAIfrom typing import List-from autogen_core.base import AgentId, AgentProxy, TopicId+from autogen_core import AgentId, AgentProxy, TopicIdfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAMEfrom autogen_core.components.models import (@@ -17,7 +17,7 @@ from autogen_core.components.models import (UserMessage,LLMMessage,)-from autogen_core.components import DefaultSubscription, DefaultTopicId+from autogen_core import DefaultSubscription, DefaultTopicIdfrom autogen_core.components.code_executor import LocalCommandLineCodeExecutorfrom autogen_core.components.models import AssistantMessagediff --git a/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.pyindex a9b62a1e3..a0a2707aa 100644--- a/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py@@ -1,10 +1,10 @@import asyncioimport logging-from autogen_core.base import AgentId, AgentProxy, TopicId+from autogen_core import AgentId, AgentProxy, TopicIdfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.components import DefaultSubscription, DefaultTopicId+from autogen_core import DefaultSubscription, DefaultTopicIdfrom autogen_core.components.code_executor import LocalCommandLineCodeExecutorfrom autogen_core.components.models import (UserMessage,@@ -41,7 +41,7 @@ async def main() -> None:executor = AgentProxy(AgentId("Executor", "default"), runtime)await runtime.register(- "Orchestrator",+ "Orchestrator",lambda: RoundRobinOrchestrator([coder, executor]),subscriptions=lambda: [DefaultSubscription()],)diff --git a/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.pyindex 5cbf5c4c2..306c87826 100644--- a/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.py+++ b/python/packages/agbench/benchmarks/WebArena/Templates/MagenticOne/scenario.py@@ -7,10 +7,10 @@ import nltkfrom typing import Any, Dict, List, Tuple, Union-from autogen_core.base import AgentId, AgentProxy, TopicId+from autogen_core import AgentId, AgentProxy, TopicIdfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.components import DefaultSubscription, DefaultTopicId+from autogen_core import DefaultSubscription, DefaultTopicIdfrom autogen_core.components.code_executor import LocalCommandLineCodeExecutorfrom autogen_core.components.models import (ChatCompletionClient,@@ -105,7 +105,7 @@ async def main() -> None:task_prompt = task_prompt.replace(k, REPLACEMENTS[k])fh.write(task_prompt)TASK = json.loads(task_prompt)- if TASK["start_url"] == REDDIT:+ if TASK["start_url"] == REDDIT:TASK["start_url"] = TASK["start_url"] + "/forums/all"full_task = ""@@ -150,7 +150,7 @@ Once the user has taken the final necessary action to complete the task, and you# Round-robin orchestratorawait runtime.register(- "round_robin_orc",+ "round_robin_orc",lambda: RoundRobinOrchestrator(agents=[web_surfer, login_assistant],),subscriptions=lambda: [DefaultSubscription()],)@@ -163,7 +163,7 @@ Once the user has taken the final necessary action to complete the task, and youruntime.start()await runtime.publish_message(- ResetMessage(),+ ResetMessage(),topic_id=DefaultTopicId(),)await runtime.publish_message(@@ -192,16 +192,16 @@ Once the user has taken the final necessary action to complete the task, and yousubscriptions=lambda: [DefaultSubscription()],)executor = AgentProxy(AgentId("ComputerTerminal", "default"), runtime)-+await runtime.register("FileSurfer",lambda: FileSurfer(model_client=client),subscriptions=lambda: [DefaultSubscription()],)file_surfer = AgentProxy(AgentId("FileSurfer", "default"), runtime)-+await runtime.register(- "orchestrator",+ "orchestrator",lambda: LedgerOrchestrator(agents=[coder, executor, file_surfer, web_surfer],model_client=client,@@ -251,7 +251,7 @@ Once the user has taken the final necessary action to complete the task, and youpage = actual_surfer._pagecdp_session = await context.new_cdp_session(page)config_file = "full_task.json"-+evaluator = evaluation_harness.evaluator_router(config_file)score = await evaluator(trajectory=evaluation_harness.make_answer_trajecotry(final_answer),@@ -260,7 +260,7 @@ Once the user has taken the final necessary action to complete the task, and youclient=cdp_session,# azure_config=llm_config,)-+print("FINAL SCORE: " + str(score))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.pyindex e2bb8fd71..de2087382 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@@ -4,8 +4,7 @@ import loggingimport warningsfrom typing import Any, AsyncGenerator, Awaitable, Callable, Dict, List, Sequence-from autogen_core.base import CancellationToken-from autogen_core.components import FunctionCall+from autogen_core import CancellationToken, FunctionCallfrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,@@ -74,7 +73,7 @@ class AssistantAgent(BaseChatAgent):.. code-block:: pythonimport asyncio- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenfrom autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.messages import TextMessage@@ -107,7 +106,7 @@ class AssistantAgent(BaseChatAgent):from autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.messages import TextMessagefrom autogen_agentchat.ui import Console- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenasync def get_current_time() -> str:@@ -136,7 +135,7 @@ class AssistantAgent(BaseChatAgent):.. code-block:: pythonimport asyncio- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenfrom autogen_ext.models import OpenAIChatCompletionClientfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.messages import TextMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.pyindex 622a4d491..01eafa86a 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py@@ -1,7 +1,7 @@from abc import ABC, abstractmethodfrom typing import AsyncGenerator, List, Sequence-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom ..base import ChatAgent, Response, TaskResultfrom ..messages import AgentMessage, ChatMessage, HandoffMessage, MultiModalMessage, StopMessage, TextMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.pyindex 5dd4c9008..4667c4a58 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py@@ -1,6 +1,6 @@from typing import List, Sequence-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import CodeBlock, CodeExecutor, extract_markdown_code_blocksfrom ..base import Response@@ -28,7 +28,7 @@ class CodeExecutorAgent(BaseChatAgent):from autogen_agentchat.agents import CodeExecutorAgentfrom autogen_agentchat.messages import TextMessagefrom autogen_ext.code_executors import DockerCommandLineCodeExecutor- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenasync def run_code_executor_agent() -> None:diff --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 6ed878bc2..4bef5664f 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@@ -1,7 +1,6 @@from typing import AsyncGenerator, List, Sequence-from autogen_core.base import CancellationToken-from autogen_core.components import Image+from autogen_core import CancellationToken, Imagefrom autogen_core.components.models import ChatCompletionClientfrom autogen_core.components.models._types import SystemMessagediff --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 5997816d1..d4ba81a3a 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@@ -2,7 +2,7 @@ import asynciofrom inspect import iscoroutinefunctionfrom typing import Awaitable, Callable, List, Optional, Sequence, Union, cast-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom ..base import Responsefrom ..messages import ChatMessage, HandoffMessage, TextMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.pyindex dd3a2be2c..861389cb7 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py@@ -1,7 +1,7 @@from dataclasses import dataclassfrom typing import AsyncGenerator, List, Protocol, Sequence, runtime_checkable-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom ..messages import AgentMessage, ChatMessagefrom ._task import TaskRunnerdiff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_task.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_task.pyindex d2cb39eb6..f617b3823 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_task.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_task.py@@ -1,7 +1,7 @@from dataclasses import dataclassfrom typing import AsyncGenerator, Protocol, Sequence-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom ..messages import AgentMessage, ChatMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/messages.py b/python/packages/autogen-agentchat/src/autogen_agentchat/messages.pyindex c5a9ac21e..b7650d581 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/messages.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/messages.py@@ -1,6 +1,6 @@from typing import List-from autogen_core.components import FunctionCall, Image+from autogen_core import FunctionCall, Imagefrom autogen_core.components.models import FunctionExecutionResult, RequestUsagefrom pydantic import BaseModel, ConfigDictdiff --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 371e58014..fdb79b119 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@@ -4,17 +4,18 @@ import uuidfrom abc import ABC, abstractmethodfrom typing import AsyncGenerator, Callable, List-from autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import (+from autogen_core import (AgentId,AgentInstantiationContext,AgentRuntime,AgentType,CancellationToken,+ ClosureAgent,MessageContext,+ TypeSubscription,)-from autogen_core.components import ClosureAgent, TypeSubscription-from autogen_core.components._closure_agent import ClosureContext+from autogen_core._closure_agent import ClosureContext+from autogen_core.application import SingleThreadedAgentRuntimefrom ... import EVENT_LOGGER_NAMEfrom ...base import ChatAgent, TaskResult, Team, TerminationCondition@@ -216,7 +217,7 @@ class BaseGroupChat(Team, ABC):from autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.conditions import MaxMessageTerminationfrom autogen_agentchat.teams import RoundRobinGroupChat- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenfrom autogen_ext.models import OpenAIChatCompletionClient@@ -317,7 +318,7 @@ class BaseGroupChat(Team, ABC):from autogen_agentchat.conditions import MaxMessageTerminationfrom autogen_agentchat.ui import Consolefrom autogen_agentchat.teams import RoundRobinGroupChat- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenfrom autogen_ext.models import OpenAIChatCompletionClientdiff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.pyindex 201db26bf..aefe4f8d4 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py@@ -2,8 +2,7 @@ import asynciofrom abc import ABC, abstractmethodfrom typing import Any, List-from autogen_core.base import MessageContext-from autogen_core.components import DefaultTopicId, event, rpc+from autogen_core import DefaultTopicId, MessageContext, event, rpcfrom ...base import TerminationConditionfrom ...messages import AgentMessage, ChatMessage, StopMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.pyindex 17c983008..01638def8 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py@@ -1,7 +1,6 @@from typing import Any, List-from autogen_core.base import MessageContext-from autogen_core.components import DefaultTopicId, event, rpc+from autogen_core import DefaultTopicId, MessageContext, event, rpcfrom ...base import ChatAgent, Responsefrom ...messages import ChatMessagediff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.pyindex d4509a61b..4758ddd8d 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py@@ -2,8 +2,7 @@ import jsonimport loggingfrom typing import Any, Dict, List-from autogen_core.base import AgentId, CancellationToken, MessageContext-from autogen_core.components import DefaultTopicId, Image, event, rpc+from autogen_core import AgentId, CancellationToken, DefaultTopicId, Image, MessageContext, event, rpcfrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.pyindex ff76586a0..ceb63d23c 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py@@ -1,8 +1,7 @@import asynciofrom typing import Any-from autogen_core.base import MessageContext-from autogen_core.components import RoutedAgent+from autogen_core import MessageContext, RoutedAgentclass FIFOLock:diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.py b/python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.pyindex 596f9de48..4059bc477 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.py@@ -3,7 +3,7 @@ import sysimport timefrom typing import AsyncGenerator, List, Optional, TypeVar, cast-from autogen_core.components import Image+from autogen_core import Imagefrom autogen_core.components.models import RequestUsagefrom autogen_agentchat.base import Response, TaskResultdiff --git a/python/packages/autogen-agentchat/tests/test_assistant_agent.py b/python/packages/autogen-agentchat/tests/test_assistant_agent.pyindex 2828893bc..b68ef70cc 100644--- a/python/packages/autogen-agentchat/tests/test_assistant_agent.py+++ b/python/packages/autogen-agentchat/tests/test_assistant_agent.py@@ -14,7 +14,7 @@ from autogen_agentchat.messages import (ToolCallMessage,ToolCallResultMessage,)-from autogen_core.components import Image+from autogen_core import Imagefrom autogen_core.components.tools import FunctionToolfrom autogen_ext.models import OpenAIChatCompletionClientfrom openai.resources.chat.completions import AsyncCompletionsdiff --git a/python/packages/autogen-agentchat/tests/test_group_chat.py b/python/packages/autogen-agentchat/tests/test_group_chat.pyindex 207b87882..5c1d681fc 100644--- a/python/packages/autogen-agentchat/tests/test_group_chat.py+++ b/python/packages/autogen-agentchat/tests/test_group_chat.py@@ -29,8 +29,7 @@ from autogen_agentchat.teams import (Swarm,)from autogen_agentchat.ui import Console-from autogen_core.base import CancellationToken-from autogen_core.components import FunctionCall+from autogen_core import CancellationToken, FunctionCallfrom autogen_core.components.code_executor import LocalCommandLineCodeExecutorfrom autogen_core.components.models import FunctionExecutionResultfrom autogen_core.components.tools import FunctionTooldiff --git a/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py b/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.pyindex 1ce4bf11a..005649284 100644--- a/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py+++ b/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py@@ -16,7 +16,7 @@ from autogen_agentchat.messages import (from autogen_agentchat.teams import (MagenticOneGroupChat,)-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_ext.models import ReplayChatCompletionClientfrom utils import FileLogHandlerdiff --git a/python/packages/autogen-agentchat/tests/test_sequential_routed_agent.py b/python/packages/autogen-agentchat/tests/test_sequential_routed_agent.pyindex 0d5f7c370..9291882cc 100644--- a/python/packages/autogen-agentchat/tests/test_sequential_routed_agent.py+++ b/python/packages/autogen-agentchat/tests/test_sequential_routed_agent.py@@ -5,9 +5,8 @@ from typing import Listimport pytestfrom autogen_agentchat.teams._group_chat._sequential_routed_agent import SequentialRoutedAgent+from autogen_core import AgentId, DefaultTopicId, MessageContext, default_subscription, message_handlerfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, MessageContext-from autogen_core.components import DefaultTopicId, default_subscription, message_handler@dataclassdiff --git a/python/packages/autogen-agentchat/tests/test_userproxy_agent.py b/python/packages/autogen-agentchat/tests/test_userproxy_agent.pyindex d06e209cf..8ff6422a6 100644--- a/python/packages/autogen-agentchat/tests/test_userproxy_agent.py+++ b/python/packages/autogen-agentchat/tests/test_userproxy_agent.py@@ -5,7 +5,7 @@ import pytestfrom autogen_agentchat.agents import UserProxyAgentfrom autogen_agentchat.base import Responsefrom autogen_agentchat.messages import ChatMessage, HandoffMessage, TextMessage-from autogen_core.base import CancellationToken+from autogen_core import CancellationToken@pytest.mark.asynciodiff --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 f94761c56..7f9d789ac 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@@ -35,7 +35,7 @@"source": ["from autogen_agentchat.agents import AssistantAgent\n","from autogen_agentchat.messages import TextMessage\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n","\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/custom-agents.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/custom-agents.ipynbindex 7c90a0444..35e145c14 100644--- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/custom-agents.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/custom-agents.ipynb@@ -43,7 +43,7 @@"from autogen_agentchat.agents import BaseChatAgent\n","from autogen_agentchat.base import Response\n","from autogen_agentchat.messages import AgentMessage, ChatMessage, TextMessage\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","\n","\n","class CountDownAgent(BaseChatAgent):\n",@@ -120,7 +120,7 @@"from autogen_agentchat.agents import BaseChatAgent\n","from autogen_agentchat.base import Response\n","from autogen_agentchat.messages import ChatMessage\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","\n","\n","class UserProxyAgent(BaseChatAgent):\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/extracting-results-with-an-agent.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/extracting-results-with-an-agent.ipynbindex e86b807d7..81cdaecac 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/extracting-results-with-an-agent.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/extracting-results-with-an-agent.ipynb@@ -25,9 +25,8 @@"import asyncio\n","from dataclasses import dataclass\n","\n",- "from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import MessageContext\n",- "from autogen_core.components import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId"+ "from autogen_core import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId, MessageContext\n",+ "from autogen_core.application import SingleThreadedAgentRuntime"]},{diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/langgraph-agent.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/langgraph-agent.ipynbindex 5516bdc42..513ec5576 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/langgraph-agent.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/langgraph-agent.ipynb@@ -42,9 +42,8 @@"from dataclasses import dataclass\n","from typing import Any, Callable, List, Literal\n","\n",+ "from autogen_core import AgentId, MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n","from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n","from langchain_core.messages import HumanMessage, SystemMessage\n","from langchain_core.tools import tool # pyright: ignore\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/llamaindex-agent.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/llamaindex-agent.ipynbindex 1bd489f6f..71e1dc196 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/llamaindex-agent.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/llamaindex-agent.ipynb@@ -41,9 +41,8 @@"from dataclasses import dataclass\n","from typing import List, Optional\n","\n",+ "from autogen_core import AgentId, MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n","from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n","from llama_index.core import Settings\n","from llama_index.core.agent import ReActAgent\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/local-llms-ollama-litellm.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/local-llms-ollama-litellm.ipynbindex 80fde2b71..69edc8478 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/local-llms-ollama-litellm.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/local-llms-ollama-litellm.ipynb@@ -39,9 +39,8 @@"source": ["from dataclasses import dataclass\n","\n",+ "from autogen_core import AgentId, DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, MessageContext\n",- "from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler\n","from autogen_core.components.model_context import BufferedChatCompletionContext\n","from autogen_core.components.models import (\n"," AssistantMessage,\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/openai-assistant-agent.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/openai-assistant-agent.ipynbindex 09d18a78f..337e754fa 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/openai-assistant-agent.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/openai-assistant-agent.ipynb@@ -104,8 +104,7 @@"from typing import Any, Callable, List\n","\n","import aiofiles\n",- "from autogen_core.base import AgentId, MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n",+ "from autogen_core import AgentId, MessageContext, RoutedAgent, message_handler\n","from openai import AsyncAssistantEventHandler, AsyncClient\n","from openai.types.beta.thread import ToolResources, ToolResourcesFileSearch\n","\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/termination-with-intervention.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/termination-with-intervention.ipynbindex bd37a7545..1d5387e7c 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/termination-with-intervention.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/termination-with-intervention.ipynb@@ -22,10 +22,9 @@"from dataclasses import dataclass\n","from typing import Any\n","\n",+ "from autogen_core import AgentId, DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, MessageContext\n",- "from autogen_core.base.intervention import DefaultInterventionHandler\n",- "from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler"+ "from autogen_core.base.intervention import DefaultInterventionHandler"]},{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.ipynbindex e7c41c41f..f5ac5bb2a 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@@ -19,18 +19,17 @@"from dataclasses import dataclass\n","from typing import Any, List\n","\n",+ "from autogen_core import AgentId, AgentType, FunctionCall, MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, AgentType, MessageContext\n","from autogen_core.base.intervention import DefaultInterventionHandler, DropMessage\n",- "from autogen_core.components import FunctionCall, RoutedAgent, message_handler\n","from autogen_core.components.models import (\n"," ChatCompletionClient,\n"," LLMMessage,\n"," SystemMessage,\n"," UserMessage,\n",")\n",- "from autogen_core.components.tool_agent import ToolAgent, ToolException, tool_agent_caller_loop\n","from autogen_core.components.tools import PythonCodeExecutionTool, ToolSchema\n",+ "from autogen_core.tool_agent import ToolAgent, ToolException, tool_agent_caller_loop\n","from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n","from autogen_ext.models import OpenAIChatCompletionClient"]diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/topic-subscription-scenarios.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/topic-subscription-scenarios.ipynbindex e424dddf6..70e2b9847 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/topic-subscription-scenarios.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/topic-subscription-scenarios.ipynb@@ -44,11 +44,10 @@"from enum import Enum\n","from typing import List\n","\n",+ "from autogen_core import MessageContext, RoutedAgent, TopicId, TypeSubscription, message_handler\n",+ "from autogen_core._default_subscription import DefaultSubscription\n",+ "from autogen_core._default_topic import DefaultTopicId\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import MessageContext, TopicId\n",- "from autogen_core.components import RoutedAgent, TypeSubscription, message_handler\n",- "from autogen_core.components._default_subscription import DefaultSubscription\n",- "from autogen_core.components._default_topic import DefaultTopicId\n","from autogen_core.components.models import (\n"," SystemMessage,\n",")"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.ipynbindex 3238656c4..e5b613812 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@@ -72,16 +72,17 @@"from typing import List\n","\n","import openai\n",- "from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import MessageContext, TopicId\n",- "from autogen_core.components import (\n",+ "from autogen_core import (\n"," DefaultTopicId,\n"," FunctionCall,\n"," Image,\n",+ " MessageContext,\n"," RoutedAgent,\n",+ " TopicId,\n"," TypeSubscription,\n"," message_handler,\n",")\n",+ "from autogen_core.application import SingleThreadedAgentRuntime\n","from autogen_core.components.models import (\n"," AssistantMessage,\n"," ChatCompletionClient,\n",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.ipynbindex 6fb9f7178..c8379e97f 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@@ -56,9 +56,8 @@"import uuid\n","from typing import List, Tuple\n","\n",+ "from autogen_core import FunctionCall, MessageContext, RoutedAgent, TopicId, TypeSubscription, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import MessageContext, TopicId\n",- "from autogen_core.components import FunctionCall, RoutedAgent, TypeSubscription, message_handler\n","from autogen_core.components.models import (\n"," AssistantMessage,\n"," ChatCompletionClient,\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/mixture-of-agents.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/mixture-of-agents.ipynbindex 61b8b62bc..c008eff71 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/mixture-of-agents.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/mixture-of-agents.ipynb@@ -38,9 +38,8 @@"from dataclasses import dataclass\n","from typing import List\n","\n",+ "from autogen_core import AgentId, MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n","from autogen_core.components.models import ChatCompletionClient, SystemMessage, UserMessage\n","from autogen_ext.models import OpenAIChatCompletionClient"]diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/multi-agent-debate.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/multi-agent-debate.ipynbindex 72b653687..a737c0963 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/multi-agent-debate.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/multi-agent-debate.ipynb@@ -43,9 +43,15 @@"from dataclasses import dataclass\n","from typing import Dict, List\n","\n",+ "from autogen_core import (\n",+ " DefaultTopicId,\n",+ " MessageContext,\n",+ " RoutedAgent,\n",+ " TypeSubscription,\n",+ " default_subscription,\n",+ " message_handler,\n",+ ")\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import MessageContext\n",- "from autogen_core.components import DefaultTopicId, RoutedAgent, TypeSubscription, default_subscription, message_handler\n","from autogen_core.components.models import (\n"," AssistantMessage,\n"," ChatCompletionClient,\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/reflection.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/reflection.ipynbindex f00e313b1..40a6dd680 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/reflection.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/design-patterns/reflection.ipynb@@ -100,8 +100,7 @@"import uuid\n","from typing import Dict, List, Union\n","\n",- "from autogen_core.base import MessageContext, TopicId\n",- "from autogen_core.components import RoutedAgent, default_subscription, message_handler\n",+ "from autogen_core import MessageContext, RoutedAgent, TopicId, default_subscription, message_handler\n","from autogen_core.components.models import (\n"," AssistantMessage,\n"," ChatCompletionClient,\n",@@ -442,8 +441,8 @@}],"source": [+ "from autogen_core import DefaultTopicId\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.components import DefaultTopicId\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n","runtime = SingleThreadedAgentRuntime()\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/agent-and-agent-runtime.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/agent-and-agent-runtime.ipynbindex c8ea98d42..ac61eadd3 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/agent-and-agent-runtime.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/agent-and-agent-runtime.ipynb@@ -55,7 +55,7 @@"source": ["from dataclasses import dataclass\n","\n",- "from autogen_core.base import AgentId, BaseAgent, MessageContext\n",+ "from autogen_core import AgentId, BaseAgent, MessageContext\n","\n","\n","@dataclass\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/command-line-code-executors.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/command-line-code-executors.ipynbindex 244d258aa..19d0ad489 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/command-line-code-executors.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/command-line-code-executors.ipynb@@ -54,7 +54,7 @@"source": ["from pathlib import Path\n","\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","from autogen_core.components.code_executor import CodeBlock\n","from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n","\n",@@ -125,7 +125,7 @@"source": ["from pathlib import Path\n","\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","from autogen_core.components.code_executor import CodeBlock, LocalCommandLineCodeExecutor\n","\n","work_dir = Path(\"coding\")\n",@@ -171,7 +171,7 @@"import venv\n","from pathlib import Path\n","\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","from autogen_core.components.code_executor import CodeBlock, LocalCommandLineCodeExecutor\n","\n","work_dir = Path(\"coding\")\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/distributed-agent-runtime.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/distributed-agent-runtime.ipynbindex 355b5a1f7..50f703610 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/distributed-agent-runtime.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/distributed-agent-runtime.ipynb@@ -1,223 +1,222 @@{- "cells": [- {- "cell_type": "markdown",- "metadata": {},- "source": [- "# Distributed Agent Runtime\n",- "\n",- "```{attention}\n",- "The distributed agent runtime is an experimental feature. Expect breaking changes\n",- "to the API.\n",- "```\n",- "\n",- "A distributed agent runtime facilitates communication and agent lifecycle management\n",- "across process boundaries.\n",- "It consists of a host service and at least one worker runtime.\n",- "\n",- "The host service maintains connections to all active worker runtimes,\n",- "facilitates message delivery, and keeps sessions for all direct messages (i.e., RPCs).\n",- "A worker runtime processes application code (agents) and connects to the host service.\n",- "It also advertises the agents which they support to the host service,\n",- "so the host service can deliver messages to the correct worker.\n",- "\n",- "````{note}\n",- "The distributed agent runtime requires extra dependencies, install them using:\n",- "```bash\n",- "pip install autogen-core[grpc]==0.4.0.dev8\n",- "```\n",- "````\n",- "\n",- "We can start a host service using {py:class}`~autogen_core.application.WorkerAgentRuntimeHost`."- ]- },- {- "cell_type": "code",- "execution_count": 1,- "metadata": {},- "outputs": [],- "source": [- "from autogen_core.application import WorkerAgentRuntimeHost\n",- "\n",- "host = WorkerAgentRuntimeHost(address=\"localhost:50051\")\n",- "host.start() # Start a host service in the background."- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "The above code starts the host service in the background and accepts\n",- "worker connections on port 50051.\n",- "\n",- "Before running worker runtimes, let's define our agent.\n",- "The agent will publish a new message on every message it receives.\n",- "It also keeps track of how many messages it has published, and \n",- "stops publishing new messages once it has published 5 messages."- ]- },- {- "cell_type": "code",- "execution_count": 2,- "metadata": {},- "outputs": [],- "source": [- "from dataclasses import dataclass\n",- "\n",- "from autogen_core.base import MessageContext\n",- "from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler\n",- "\n",- "\n",- "@dataclass\n",- "class MyMessage:\n",- " content: str\n",- "\n",- "\n",- "@default_subscription\n",- "class MyAgent(RoutedAgent):\n",- " def __init__(self, name: str) -> None:\n",- " super().__init__(\"My agent\")\n",- " self._name = name\n",- " self._counter = 0\n",- "\n",- " @message_handler\n",- " async def my_message_handler(self, message: MyMessage, ctx: MessageContext) -> None:\n",- " self._counter += 1\n",- " if self._counter > 5:\n",- " return\n",- " content = f\"{self._name}: Hello x {self._counter}\"\n",- " print(content)\n",- " await self.publish_message(MyMessage(content=content), DefaultTopicId())"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "Now we can set up the worker agent runtimes.\n",- "We use {py:class}`~autogen_core.application.WorkerAgentRuntime`.\n",- "We set up two worker runtimes. Each runtime hosts one agent.\n",- "All agents publish and subscribe to the default topic, so they can see all\n",- "messages being published.\n",- "\n",- "To run the agents, we publishes a message from a worker."- ]- },- {- "cell_type": "code",- "execution_count": 3,- "metadata": {},- "outputs": [- {- "name": "stdout",- "output_type": "stream",- "text": [- "worker1: Hello x 1\n",- "worker2: Hello x 1\n",- "worker2: Hello x 2\n",- "worker1: Hello x 2\n",- "worker1: Hello x 3\n",- "worker2: Hello x 3\n",- "worker2: Hello x 4\n",- "worker1: Hello x 4\n",- "worker1: Hello x 5\n",- "worker2: Hello x 5\n"- ]- }- ],- "source": [- "import asyncio\n",- "\n",- "from autogen_core.application import WorkerAgentRuntime\n",- "\n",- "worker1 = WorkerAgentRuntime(host_address=\"localhost:50051\")\n",- "worker1.start()\n",- "await MyAgent.register(worker1, \"worker1\", lambda: MyAgent(\"worker1\"))\n",- "\n",- "worker2 = WorkerAgentRuntime(host_address=\"localhost:50051\")\n",- "worker2.start()\n",- "await MyAgent.register(worker2, \"worker2\", lambda: MyAgent(\"worker2\"))\n",- "\n",- "await worker2.publish_message(MyMessage(content=\"Hello!\"), DefaultTopicId())\n",- "\n",- "# Let the agents run for a while.\n",- "await asyncio.sleep(5)"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "We can see each agent published exactly 5 messages.\n",- "\n",- "To stop the worker runtimes, we can call {py:meth}`~autogen_core.application.WorkerAgentRuntime.stop`."- ]- },- {- "cell_type": "code",- "execution_count": 4,- "metadata": {},- "outputs": [],- "source": [- "await worker1.stop()\n",- "await worker2.stop()\n",- "\n",- "# To keep the worker running until a termination signal is received (e.g., SIGTERM).\n",- "# await worker1.stop_when_signal()"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "We can call {py:meth}`~autogen_core.application.WorkerAgentRuntimeHost.stop`\n",- "to stop the host service."- ]- },- {- "cell_type": "code",- "execution_count": 5,- "metadata": {},- "outputs": [],- "source": [- "await host.stop()\n",- "\n",- "# To keep the host service running until a termination signal (e.g., SIGTERM)\n",- "# await host.stop_when_signal()"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "# Next Steps\n",- "To see complete examples of using distributed runtime, please take a look at the following samples:\n",- "\n",- "- [Distributed Workers](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-core/samples/worker) \n",- "- [Distributed Semantic Router](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-core/samples/semantic_router) \n",- "- [Distributed Group Chat](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-core/samples/distributed-group-chat) \n"- ]- }- ],- "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": [+ "# Distributed Agent Runtime\n",+ "\n",+ "```{attention}\n",+ "The distributed agent runtime is an experimental feature. Expect breaking changes\n",+ "to the API.\n",+ "```\n",+ "\n",+ "A distributed agent runtime facilitates communication and agent lifecycle management\n",+ "across process boundaries.\n",+ "It consists of a host service and at least one worker runtime.\n",+ "\n",+ "The host service maintains connections to all active worker runtimes,\n",+ "facilitates message delivery, and keeps sessions for all direct messages (i.e., RPCs).\n",+ "A worker runtime processes application code (agents) and connects to the host service.\n",+ "It also advertises the agents which they support to the host service,\n",+ "so the host service can deliver messages to the correct worker.\n",+ "\n",+ "````{note}\n",+ "The distributed agent runtime requires extra dependencies, install them using:\n",+ "```bash\n",+ "pip install autogen-core[grpc]==0.4.0.dev8\n",+ "```\n",+ "````\n",+ "\n",+ "We can start a host service using {py:class}`~autogen_core.application.WorkerAgentRuntimeHost`."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 1,+ "metadata": {},+ "outputs": [],+ "source": [+ "from autogen_core.application import WorkerAgentRuntimeHost\n",+ "\n",+ "host = WorkerAgentRuntimeHost(address=\"localhost:50051\")\n",+ "host.start() # Start a host service in the background."+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "The above code starts the host service in the background and accepts\n",+ "worker connections on port 50051.\n",+ "\n",+ "Before running worker runtimes, let's define our agent.\n",+ "The agent will publish a new message on every message it receives.\n",+ "It also keeps track of how many messages it has published, and \n",+ "stops publishing new messages once it has published 5 messages."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "metadata": {},+ "outputs": [],+ "source": [+ "from dataclasses import dataclass\n",+ "\n",+ "from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler\n",+ "\n",+ "\n",+ "@dataclass\n",+ "class MyMessage:\n",+ " content: str\n",+ "\n",+ "\n",+ "@default_subscription\n",+ "class MyAgent(RoutedAgent):\n",+ " def __init__(self, name: str) -> None:\n",+ " super().__init__(\"My agent\")\n",+ " self._name = name\n",+ " self._counter = 0\n",+ "\n",+ " @message_handler\n",+ " async def my_message_handler(self, message: MyMessage, ctx: MessageContext) -> None:\n",+ " self._counter += 1\n",+ " if self._counter > 5:\n",+ " return\n",+ " content = f\"{self._name}: Hello x {self._counter}\"\n",+ " print(content)\n",+ " await self.publish_message(MyMessage(content=content), DefaultTopicId())"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "Now we can set up the worker agent runtimes.\n",+ "We use {py:class}`~autogen_core.application.WorkerAgentRuntime`.\n",+ "We set up two worker runtimes. Each runtime hosts one agent.\n",+ "All agents publish and subscribe to the default topic, so they can see all\n",+ "messages being published.\n",+ "\n",+ "To run the agents, we publishes a message from a worker."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 3,+ "metadata": {},+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "worker1: Hello x 1\n",+ "worker2: Hello x 1\n",+ "worker2: Hello x 2\n",+ "worker1: Hello x 2\n",+ "worker1: Hello x 3\n",+ "worker2: Hello x 3\n",+ "worker2: Hello x 4\n",+ "worker1: Hello x 4\n",+ "worker1: Hello x 5\n",+ "worker2: Hello x 5\n"+ ]+ }+ ],+ "source": [+ "import asyncio\n",+ "\n",+ "from autogen_core.application import WorkerAgentRuntime\n",+ "\n",+ "worker1 = WorkerAgentRuntime(host_address=\"localhost:50051\")\n",+ "worker1.start()\n",+ "await MyAgent.register(worker1, \"worker1\", lambda: MyAgent(\"worker1\"))\n",+ "\n",+ "worker2 = WorkerAgentRuntime(host_address=\"localhost:50051\")\n",+ "worker2.start()\n",+ "await MyAgent.register(worker2, \"worker2\", lambda: MyAgent(\"worker2\"))\n",+ "\n",+ "await worker2.publish_message(MyMessage(content=\"Hello!\"), DefaultTopicId())\n",+ "\n",+ "# Let the agents run for a while.\n",+ "await asyncio.sleep(5)"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "We can see each agent published exactly 5 messages.\n",+ "\n",+ "To stop the worker runtimes, we can call {py:meth}`~autogen_core.application.WorkerAgentRuntime.stop`."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 4,+ "metadata": {},+ "outputs": [],+ "source": [+ "await worker1.stop()\n",+ "await worker2.stop()\n",+ "\n",+ "# To keep the worker running until a termination signal is received (e.g., SIGTERM).\n",+ "# await worker1.stop_when_signal()"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "We can call {py:meth}`~autogen_core.application.WorkerAgentRuntimeHost.stop`\n",+ "to stop the host service."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 5,+ "metadata": {},+ "outputs": [],+ "source": [+ "await host.stop()\n",+ "\n",+ "# To keep the host service running until a termination signal (e.g., SIGTERM)\n",+ "# await host.stop_when_signal()"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "# Next Steps\n",+ "To see complete examples of using distributed runtime, please take a look at the following samples:\n",+ "\n",+ "- [Distributed Workers](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-core/samples/worker) \n",+ "- [Distributed Semantic Router](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-core/samples/semantic_router) \n",+ "- [Distributed Group Chat](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-core/samples/distributed-group-chat) \n"+ ]+ }+ ],+ "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}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.ipynbindex f51b31d9d..d4f5b0ed0 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@@ -90,9 +90,8 @@"metadata": {},"outputs": [],"source": [+ "from autogen_core import AgentId, MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n","\n","\n","class MyAgent(RoutedAgent):\n",@@ -299,9 +298,8 @@"source": ["from dataclasses import dataclass\n","\n",+ "from autogen_core import MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n","\n","\n","@dataclass\n",@@ -420,7 +418,7 @@"metadata": {},"outputs": [],"source": [- "from autogen_core.components import RoutedAgent, message_handler, type_subscription\n",+ "from autogen_core import RoutedAgent, message_handler, type_subscription\n","\n","\n","@type_subscription(topic_type=\"default\")\n",@@ -452,7 +450,7 @@"metadata": {},"outputs": [],"source": [- "from autogen_core.base import TopicId\n",+ "from autogen_core import TopicId\n","\n","\n","class BroadcastingAgent(RoutedAgent):\n",@@ -498,7 +496,7 @@}],"source": [- "from autogen_core.components import TypeSubscription\n",+ "from autogen_core import TypeSubscription\n","\n","runtime = SingleThreadedAgentRuntime()\n","\n",@@ -561,7 +559,7 @@"metadata": {},"outputs": [],"source": [- "from autogen_core.components import DefaultTopicId, default_subscription\n",+ "from autogen_core import DefaultTopicId, default_subscription\n","\n","\n","@default_subscription\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/model-clients.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/model-clients.ipynbindex e074eb970..1dbb0840b 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/model-clients.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/model-clients.ipynb@@ -329,9 +329,8 @@"source": ["from dataclasses import dataclass\n","\n",+ "from autogen_core import MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n","from autogen_core.components.models import ChatCompletionClient, SystemMessage, UserMessage\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n",@@ -422,7 +421,7 @@],"source": ["# Create the runtime and register the agent.\n",- "from autogen_core.base import AgentId\n",+ "from autogen_core import AgentId\n","\n","runtime = SingleThreadedAgentRuntime()\n","await SimpleAgent.register(\n",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.ipynbindex ff24095e8..b7859dfc6 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@@ -43,7 +43,7 @@}],"source": [- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","from autogen_core.components.tools import PythonCodeExecutionTool\n","from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n","\n",@@ -113,7 +113,7 @@"source": ["import random\n","\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","from autogen_core.components.tools import FunctionTool\n","from typing_extensions import Annotated\n","\n",@@ -155,17 +155,16 @@"from dataclasses import dataclass\n","from typing import List\n","\n",+ "from autogen_core import AgentId, AgentInstantiationContext, MessageContext, RoutedAgent, message_handler\n","from autogen_core.application import SingleThreadedAgentRuntime\n",- "from autogen_core.base import AgentId, AgentInstantiationContext, MessageContext\n",- "from autogen_core.components import RoutedAgent, message_handler\n","from autogen_core.components.models import (\n"," ChatCompletionClient,\n"," LLMMessage,\n"," SystemMessage,\n"," UserMessage,\n",")\n",- "from autogen_core.components.tool_agent import ToolAgent, tool_agent_caller_loop\n","from autogen_core.components.tools import FunctionTool, Tool, ToolSchema\n",+ "from autogen_core.tool_agent import ToolAgent, tool_agent_caller_loop\n","from autogen_ext.models import OpenAIChatCompletionClient\n","\n","\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/quickstart.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/quickstart.ipynbindex 9cc36b8fd..1ad55133f 100644--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/quickstart.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/quickstart.ipynb@@ -34,8 +34,7 @@"from dataclasses import dataclass\n","from typing import List\n","\n",- "from autogen_core.base import MessageContext\n",- "from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler\n",+ "from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler\n","from autogen_core.components.code_executor import CodeExecutor, extract_markdown_code_blocks\n","from autogen_core.components.models import (\n"," AssistantMessage,\n",diff --git a/python/packages/autogen-core/docs/src/user-guide/extensions-user-guide/azure-container-code-executor.ipynb b/python/packages/autogen-core/docs/src/user-guide/extensions-user-guide/azure-container-code-executor.ipynbindex 98c6b848c..5b06b13ef 100644--- a/python/packages/autogen-core/docs/src/user-guide/extensions-user-guide/azure-container-code-executor.ipynb+++ b/python/packages/autogen-core/docs/src/user-guide/extensions-user-guide/azure-container-code-executor.ipynb@@ -61,7 +61,7 @@"import tempfile\n","\n","from anyio import open_file\n",- "from autogen_core.base import CancellationToken\n",+ "from autogen_core import CancellationToken\n","from autogen_core.components.code_executor import CodeBlock\n","from autogen_ext.code_executor.aca_dynamic_sessions import AzureContainerCodeExecutor\n","from azure.identity import DefaultAzureCredential"diff --git a/python/packages/autogen-core/samples/chess_game.py b/python/packages/autogen-core/samples/chess_game.pyindex e0bc95e1d..4936c3242 100644--- a/python/packages/autogen-core/samples/chess_game.py+++ b/python/packages/autogen-core/samples/chess_game.py@@ -7,9 +7,8 @@ import asyncioimport loggingfrom typing import Annotated, Literal+from autogen_core import AgentId, AgentInstantiationContext, AgentRuntime, DefaultSubscription, DefaultTopicIdfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, AgentInstantiationContext, AgentRuntime-from autogen_core.components import DefaultSubscription, DefaultTopicIdfrom autogen_core.components.model_context import BufferedChatCompletionContextfrom autogen_core.components.models import SystemMessagefrom autogen_core.components.tools import FunctionTooldiff --git a/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.py b/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.pyindex 51f53c9a2..c36edea18 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@@ -2,10 +2,12 @@ import asyncioimport jsonfrom typing import Any, Coroutine, Dict, List, Mapping, Sequence, Tuple-from autogen_core.base import AgentId, CancellationToken, MessageContext-from autogen_core.components import (+from autogen_core import (+ AgentId,+ CancellationToken,DefaultTopicId,FunctionCall,+ MessageContext,RoutedAgent,message_handler,)diff --git a/python/packages/autogen-core/samples/common/patterns/_group_chat_manager.py b/python/packages/autogen-core/samples/common/patterns/_group_chat_manager.pyindex 22d429118..485614ce6 100644--- a/python/packages/autogen-core/samples/common/patterns/_group_chat_manager.py+++ b/python/packages/autogen-core/samples/common/patterns/_group_chat_manager.py@@ -1,8 +1,7 @@import loggingfrom typing import Any, Callable, List, Mapping-from autogen_core.base import AgentId, AgentProxy, MessageContext-from autogen_core.components import RoutedAgent, message_handler+from autogen_core import AgentId, AgentProxy, MessageContext, RoutedAgent, message_handlerfrom autogen_core.components.model_context import ChatCompletionContextfrom autogen_core.components.models import ChatCompletionClient, UserMessagediff --git a/python/packages/autogen-core/samples/common/patterns/_group_chat_utils.py b/python/packages/autogen-core/samples/common/patterns/_group_chat_utils.pyindex 74633f812..b87fdc8ca 100644--- a/python/packages/autogen-core/samples/common/patterns/_group_chat_utils.py+++ b/python/packages/autogen-core/samples/common/patterns/_group_chat_utils.py@@ -3,7 +3,7 @@import refrom typing import Dict, List-from autogen_core.base import AgentProxy+from autogen_core import AgentProxyfrom autogen_core.components.model_context import ChatCompletionContextfrom autogen_core.components.models import ChatCompletionClient, SystemMessage, UserMessagediff --git a/python/packages/autogen-core/samples/common/types.py b/python/packages/autogen-core/samples/common/types.pyindex 028f0ab7b..1aee6aa60 100644--- a/python/packages/autogen-core/samples/common/types.py+++ b/python/packages/autogen-core/samples/common/types.py@@ -4,7 +4,7 @@ from dataclasses import dataclass, fieldfrom enum import Enumfrom typing import List, Union-from autogen_core.components import FunctionCall, Image+from autogen_core import FunctionCall, Imagefrom autogen_core.components.models import FunctionExecutionResultMessagediff --git a/python/packages/autogen-core/samples/distributed-group-chat/_agents.py b/python/packages/autogen-core/samples/distributed-group-chat/_agents.pyindex 8ff935600..ce0547775 100644--- a/python/packages/autogen-core/samples/distributed-group-chat/_agents.py+++ b/python/packages/autogen-core/samples/distributed-group-chat/_agents.py@@ -4,9 +4,8 @@ from typing import Awaitable, Callable, Listfrom uuid import uuid4from _types import GroupChatMessage, MessageChunk, RequestToSpeak, UIAgentConfig+from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, message_handlerfrom autogen_core.application import WorkerAgentRuntime-from autogen_core.base import MessageContext-from autogen_core.components import DefaultTopicId, RoutedAgent, message_handlerfrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,diff --git a/python/packages/autogen-core/samples/distributed-group-chat/_utils.py b/python/packages/autogen-core/samples/distributed-group-chat/_utils.pyindex 431a94319..3869b88c2 100644--- a/python/packages/autogen-core/samples/distributed-group-chat/_utils.py+++ b/python/packages/autogen-core/samples/distributed-group-chat/_utils.py@@ -4,7 +4,7 @@ from typing import Any, Iterable, Typeimport yamlfrom _types import AppConfig-from autogen_core.base import MessageSerializer, try_get_known_serializers_for_type+from autogen_core import MessageSerializer, try_get_known_serializers_for_typefrom autogen_ext.models import AzureOpenAIClientConfigurationfrom azure.identity import DefaultAzureCredential, get_bearer_token_providerdiff --git a/python/packages/autogen-core/samples/distributed-group-chat/run_editor_agent.py b/python/packages/autogen-core/samples/distributed-group-chat/run_editor_agent.pyindex 8a08bfe6b..fee5e91e6 100644--- a/python/packages/autogen-core/samples/distributed-group-chat/run_editor_agent.py+++ b/python/packages/autogen-core/samples/distributed-group-chat/run_editor_agent.py@@ -5,10 +5,10 @@ import warningsfrom _agents import BaseGroupChatAgentfrom _types import AppConfig, GroupChatMessage, MessageChunk, RequestToSpeakfrom _utils import get_serializers, load_config, set_all_log_levels-from autogen_core.application import WorkerAgentRuntime-from autogen_core.components import (+from autogen_core import (TypeSubscription,)+from autogen_core.application import WorkerAgentRuntimefrom autogen_ext.models import AzureOpenAIChatCompletionClientfrom rich.console import Consolefrom rich.markdown import Markdowndiff --git a/python/packages/autogen-core/samples/distributed-group-chat/run_group_chat_manager.py b/python/packages/autogen-core/samples/distributed-group-chat/run_group_chat_manager.pyindex e0b2880aa..aa68f3c19 100644--- a/python/packages/autogen-core/samples/distributed-group-chat/run_group_chat_manager.py+++ b/python/packages/autogen-core/samples/distributed-group-chat/run_group_chat_manager.py@@ -5,10 +5,10 @@ import warningsfrom _agents import GroupChatManager, publish_message_to_ui, publish_message_to_ui_and_backendfrom _types import AppConfig, GroupChatMessage, MessageChunk, RequestToSpeakfrom _utils import get_serializers, load_config, set_all_log_levels-from autogen_core.application import WorkerAgentRuntime-from autogen_core.components import (+from autogen_core import (TypeSubscription,)+from autogen_core.application import WorkerAgentRuntimefrom autogen_ext.models import AzureOpenAIChatCompletionClientfrom rich.console import Consolefrom rich.markdown import Markdowndiff --git a/python/packages/autogen-core/samples/distributed-group-chat/run_ui.py b/python/packages/autogen-core/samples/distributed-group-chat/run_ui.pyindex aeb24e8d1..e4d127aa0 100644--- a/python/packages/autogen-core/samples/distributed-group-chat/run_ui.py+++ b/python/packages/autogen-core/samples/distributed-group-chat/run_ui.py@@ -6,10 +6,10 @@ import chainlit as cl # type: ignore [reportUnknownMemberType] # This dependencfrom _agents import MessageChunk, UIAgentfrom _types import AppConfig, GroupChatMessage, RequestToSpeakfrom _utils import get_serializers, load_config, set_all_log_levels-from autogen_core.application import WorkerAgentRuntime-from autogen_core.components import (+from autogen_core import (TypeSubscription,)+from autogen_core.application import WorkerAgentRuntimefrom chainlit import Message # type: ignore [reportAttributeAccessIssue]from rich.console import Consolefrom rich.markdown import Markdowndiff --git a/python/packages/autogen-core/samples/distributed-group-chat/run_writer_agent.py b/python/packages/autogen-core/samples/distributed-group-chat/run_writer_agent.pyindex 674ed59ce..1168dcf0b 100644--- a/python/packages/autogen-core/samples/distributed-group-chat/run_writer_agent.py+++ b/python/packages/autogen-core/samples/distributed-group-chat/run_writer_agent.py@@ -5,10 +5,10 @@ import warningsfrom _agents import BaseGroupChatAgentfrom _types import AppConfig, GroupChatMessage, MessageChunk, RequestToSpeakfrom _utils import get_serializers, load_config, set_all_log_levels-from autogen_core.application import WorkerAgentRuntime-from autogen_core.components import (+from autogen_core import (TypeSubscription,)+from autogen_core.application import WorkerAgentRuntimefrom autogen_ext.models import AzureOpenAIChatCompletionClientfrom rich.console import Consolefrom rich.markdown import Markdowndiff --git a/python/packages/autogen-core/samples/semantic_router/_agents.py b/python/packages/autogen-core/samples/semantic_router/_agents.pyindex ddfc1ed6b..e3ca4f2e6 100644--- a/python/packages/autogen-core/samples/semantic_router/_agents.py+++ b/python/packages/autogen-core/samples/semantic_router/_agents.py@@ -2,9 +2,8 @@ import asyncioimport loggingfrom _semantic_router_components import FinalResult, TerminationMessage, UserProxyMessage, WorkerAgentMessage+from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, message_handlerfrom autogen_core.application.logging import TRACE_LOGGER_NAME-from autogen_core.base import MessageContext-from autogen_core.components import DefaultTopicId, RoutedAgent, message_handlerlogging.basicConfig(level=logging.DEBUG)logger = logging.getLogger(f"{TRACE_LOGGER_NAME}.workers")diff --git a/python/packages/autogen-core/samples/semantic_router/_semantic_router_agent.py b/python/packages/autogen-core/samples/semantic_router/_semantic_router_agent.pyindex 5b9067073..6d64c510c 100644--- a/python/packages/autogen-core/samples/semantic_router/_semantic_router_agent.py+++ b/python/packages/autogen-core/samples/semantic_router/_semantic_router_agent.py@@ -1,9 +1,8 @@import loggingfrom _semantic_router_components import AgentRegistryBase, IntentClassifierBase, TerminationMessage, UserProxyMessage+from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handlerfrom autogen_core.application.logging import TRACE_LOGGER_NAME-from autogen_core.base import MessageContext-from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handlerlogging.basicConfig(level=logging.WARNING)logger = logging.getLogger(f"{TRACE_LOGGER_NAME}.semantic_router")diff --git a/python/packages/autogen-core/samples/semantic_router/run_semantic_router.py b/python/packages/autogen-core/samples/semantic_router/run_semantic_router.pyindex 35d057fb9..aacae5784 100644--- a/python/packages/autogen-core/samples/semantic_router/run_semantic_router.py+++ b/python/packages/autogen-core/samples/semantic_router/run_semantic_router.py@@ -31,9 +31,8 @@ from _semantic_router_components import (UserProxyMessage,WorkerAgentMessage,)+from autogen_core import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId, MessageContextfrom autogen_core.application import WorkerAgentRuntime-from autogen_core.base import MessageContext-from autogen_core.components import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicIdclass MockIntentClassifier(IntentClassifierBase):diff --git a/python/packages/autogen-core/samples/slow_human_in_loop.py b/python/packages/autogen-core/samples/slow_human_in_loop.pyindex 348b15649..e973717c9 100644--- a/python/packages/autogen-core/samples/slow_human_in_loop.py+++ b/python/packages/autogen-core/samples/slow_human_in_loop.py@@ -30,16 +30,18 @@ from concurrent.futures import ThreadPoolExecutorfrom dataclasses import dataclassfrom typing import Any, Mapping, Optional-from autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, CancellationToken, MessageContext-from autogen_core.base.intervention import DefaultInterventionHandler-from autogen_core.components import (+from autogen_core import (+ AgentId,+ CancellationToken,DefaultTopicId,FunctionCall,+ MessageContext,RoutedAgent,message_handler,type_subscription,)+from autogen_core.application import SingleThreadedAgentRuntime+from autogen_core.base.intervention import DefaultInterventionHandlerfrom autogen_core.components.model_context import BufferedChatCompletionContextfrom autogen_core.components.models import (AssistantMessage,diff --git a/python/packages/autogen-core/samples/worker/agents.py b/python/packages/autogen-core/samples/worker/agents.pyindex d90f4b31e..844ac558b 100644--- a/python/packages/autogen-core/samples/worker/agents.py+++ b/python/packages/autogen-core/samples/worker/agents.py@@ -1,7 +1,6 @@from dataclasses import dataclass-from autogen_core.base import MessageContext-from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler+from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler@dataclassdiff --git a/python/packages/autogen-core/samples/worker/run_cascading_publisher.py b/python/packages/autogen-core/samples/worker/run_cascading_publisher.pyindex 850ced584..6e6b256c1 100644--- a/python/packages/autogen-core/samples/worker/run_cascading_publisher.py+++ b/python/packages/autogen-core/samples/worker/run_cascading_publisher.py@@ -1,7 +1,6 @@from agents import CascadingMessage, ObserverAgent+from autogen_core import DefaultTopicId, try_get_known_serializers_for_typefrom autogen_core.application import WorkerAgentRuntime-from autogen_core.base import try_get_known_serializers_for_type-from autogen_core.components import DefaultTopicIdasync def main() -> None:diff --git a/python/packages/autogen-core/samples/worker/run_cascading_worker.py b/python/packages/autogen-core/samples/worker/run_cascading_worker.pyindex 31f47b693..052361d19 100644--- a/python/packages/autogen-core/samples/worker/run_cascading_worker.py+++ b/python/packages/autogen-core/samples/worker/run_cascading_worker.py@@ -1,8 +1,8 @@import uuidfrom agents import CascadingAgent, ReceiveMessageEvent+from autogen_core import try_get_known_serializers_for_typefrom autogen_core.application import WorkerAgentRuntime-from autogen_core.base import try_get_known_serializers_for_typeasync def main() -> None:diff --git a/python/packages/autogen-core/samples/worker/run_worker_pub_sub.py b/python/packages/autogen-core/samples/worker/run_worker_pub_sub.pyindex 616346770..5287e7da8 100644--- a/python/packages/autogen-core/samples/worker/run_worker_pub_sub.py+++ b/python/packages/autogen-core/samples/worker/run_worker_pub_sub.py@@ -3,9 +3,15 @@ import loggingfrom dataclasses import dataclassfrom typing import Any, NoReturn+from autogen_core import (+ DefaultSubscription,+ DefaultTopicId,+ MessageContext,+ RoutedAgent,+ message_handler,+ try_get_known_serializers_for_type,+)from autogen_core.application import WorkerAgentRuntime-from autogen_core.base import MessageContext, try_get_known_serializers_for_type-from autogen_core.components import DefaultSubscription, DefaultTopicId, RoutedAgent, message_handler@dataclassdiff --git a/python/packages/autogen-core/samples/worker/run_worker_rpc.py b/python/packages/autogen-core/samples/worker/run_worker_rpc.pyindex 804474ee0..bf5dcffaf 100644--- a/python/packages/autogen-core/samples/worker/run_worker_rpc.py+++ b/python/packages/autogen-core/samples/worker/run_worker_rpc.py@@ -2,12 +2,15 @@ import asyncioimport loggingfrom dataclasses import dataclass-from autogen_core.application import WorkerAgentRuntime-from autogen_core.base import (+from autogen_core import (AgentId,+ DefaultSubscription,+ DefaultTopicId,MessageContext,+ RoutedAgent,+ message_handler,)-from autogen_core.components import DefaultSubscription, DefaultTopicId, RoutedAgent, message_handler+from autogen_core.application import WorkerAgentRuntime@dataclassdiff --git a/python/packages/autogen-core/samples/xlang/hello_python_agent/hello_python_agent.py b/python/packages/autogen-core/samples/xlang/hello_python_agent/hello_python_agent.pyindex cc131f5f2..df9dd6332 100644--- a/python/packages/autogen-core/samples/xlang/hello_python_agent/hello_python_agent.py+++ b/python/packages/autogen-core/samples/xlang/hello_python_agent/hello_python_agent.py@@ -3,11 +3,16 @@ import loggingimport osimport sys-from autogen_core.application import WorkerAgentRuntime-# from protos.agents_events_pb2 import NewMessageReceived-from autogen_core.base import PROTOBUF_DATA_CONTENT_TYPE, AgentId, try_get_known_serializers_for_type-from autogen_core.components import DefaultSubscription, DefaultTopicId, TypeSubscription+from autogen_core import (+ PROTOBUF_DATA_CONTENT_TYPE,+ AgentId,+ DefaultSubscription,+ DefaultTopicId,+ TypeSubscription,+ try_get_known_serializers_for_type,+)+from autogen_core.application import WorkerAgentRuntime# Add the local package directory to sys.paththisdir = os.path.dirname(os.path.abspath(__file__))diff --git a/python/packages/autogen-core/samples/xlang/hello_python_agent/user_input.py b/python/packages/autogen-core/samples/xlang/hello_python_agent/user_input.pyindex d2ab73e6f..71a0c0929 100644--- a/python/packages/autogen-core/samples/xlang/hello_python_agent/user_input.py+++ b/python/packages/autogen-core/samples/xlang/hello_python_agent/user_input.py@@ -2,8 +2,7 @@ import asyncioimport loggingfrom typing import Union-from autogen_core.base import MessageContext-from autogen_core.components import DefaultTopicId, RoutedAgent, message_handler+from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, message_handlerfrom protos.agent_events_pb2 import ConversationClosed, Input, NewMessageReceived, Output # type: ignoreinput_types = Union[ConversationClosed, Input, Output]diff --git a/python/packages/autogen-core/src/autogen_core/__init__.py b/python/packages/autogen-core/src/autogen_core/__init__.pyindex 9935d7ecf..41ac49b95 100644--- a/python/packages/autogen-core/src/autogen_core/__init__.py+++ b/python/packages/autogen-core/src/autogen_core/__init__.py@@ -1,3 +1,69 @@import importlib.metadata__version__ = importlib.metadata.version("autogen_core")++from ._agent import Agent+from ._agent_id import AgentId+from ._agent_instantiation import AgentInstantiationContext+from ._agent_metadata import AgentMetadata+from ._agent_proxy import AgentProxy+from ._agent_runtime import AgentRuntime+from ._agent_type import AgentType+from ._base_agent import BaseAgent+from ._cancellation_token import CancellationToken+from ._closure_agent import ClosureAgent, ClosureContext+from ._default_subscription import DefaultSubscription, default_subscription, type_subscription+from ._default_topic import DefaultTopicId+from ._image import Image+from ._message_context import MessageContext+from ._message_handler_context import MessageHandlerContext+from ._routed_agent import RoutedAgent, event, message_handler, rpc+from ._serialization import (+ JSON_DATA_CONTENT_TYPE,+ PROTOBUF_DATA_CONTENT_TYPE,+ MessageSerializer,+ UnknownPayload,+ try_get_known_serializers_for_type,+)+from ._subscription import Subscription+from ._subscription_context import SubscriptionInstantiationContext+from ._topic import TopicId+from ._type_prefix_subscription import TypePrefixSubscription+from ._type_subscription import TypeSubscription+from ._types import FunctionCall++__all__ = [+ "Agent",+ "AgentId",+ "AgentProxy",+ "AgentMetadata",+ "AgentRuntime",+ "BaseAgent",+ "CancellationToken",+ "AgentInstantiationContext",+ "TopicId",+ "Subscription",+ "MessageContext",+ "AgentType",+ "SubscriptionInstantiationContext",+ "MessageHandlerContext",+ "MessageSerializer",+ "try_get_known_serializers_for_type",+ "UnknownPayload",+ "Image",+ "RoutedAgent",+ "ClosureAgent",+ "ClosureContext",+ "message_handler",+ "event",+ "rpc",+ "FunctionCall",+ "TypeSubscription",+ "DefaultSubscription",+ "DefaultTopicId",+ "default_subscription",+ "type_subscription",+ "TypePrefixSubscription",+ "JSON_DATA_CONTENT_TYPE",+ "PROTOBUF_DATA_CONTENT_TYPE",+]diff --git a/python/packages/autogen-core/src/autogen_core/base/_agent.py b/python/packages/autogen-core/src/autogen_core/_agent.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_agent.pyrename to python/packages/autogen-core/src/autogen_core/_agent.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_id.py b/python/packages/autogen-core/src/autogen_core/_agent_id.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_agent_id.pyrename to python/packages/autogen-core/src/autogen_core/_agent_id.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_instantiation.py b/python/packages/autogen-core/src/autogen_core/_agent_instantiation.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_agent_instantiation.pyrename to python/packages/autogen-core/src/autogen_core/_agent_instantiation.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_metadata.py b/python/packages/autogen-core/src/autogen_core/_agent_metadata.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_agent_metadata.pyrename to python/packages/autogen-core/src/autogen_core/_agent_metadata.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_proxy.py b/python/packages/autogen-core/src/autogen_core/_agent_proxy.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_agent_proxy.pyrename to python/packages/autogen-core/src/autogen_core/_agent_proxy.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_runtime.py b/python/packages/autogen-core/src/autogen_core/_agent_runtime.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_agent_runtime.pyrename to python/packages/autogen-core/src/autogen_core/_agent_runtime.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_type.py b/python/packages/autogen-core/src/autogen_core/_agent_type.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_agent_type.pyrename to python/packages/autogen-core/src/autogen_core/_agent_type.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_base_agent.py b/python/packages/autogen-core/src/autogen_core/_base_agent.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_base_agent.pyrename to python/packages/autogen-core/src/autogen_core/_base_agent.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_cancellation_token.py b/python/packages/autogen-core/src/autogen_core/_cancellation_token.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_cancellation_token.pyrename to python/packages/autogen-core/src/autogen_core/_cancellation_token.pydiff --git a/python/packages/autogen-core/src/autogen_core/components/_closure_agent.py b/python/packages/autogen-core/src/autogen_core/_closure_agent.pysimilarity index 89%rename from python/packages/autogen-core/src/autogen_core/components/_closure_agent.pyrename to python/packages/autogen-core/src/autogen_core/_closure_agent.pyindex df8d8154a..9a5e1a2c6 100644--- a/python/packages/autogen-core/src/autogen_core/components/_closure_agent.py+++ b/python/packages/autogen-core/src/autogen_core/_closure_agent.py@@ -3,23 +3,20 @@ from __future__ import annotationsimport inspectfrom typing import Any, Awaitable, Callable, List, Mapping, Protocol, Sequence, TypeVar, get_type_hints-from autogen_core.base._serialization import try_get_known_serializers_for_type-from autogen_core.base._subscription_context import SubscriptionInstantiationContext--from ..base import (- AgentId,- AgentInstantiationContext,- AgentMetadata,- AgentRuntime,- AgentType,- BaseAgent,- CancellationToken,- MessageContext,- Subscription,- TopicId,-)-from ..base._type_helpers import get_types-from ..base.exceptions import CantHandleException+from ._agent_id import AgentId+from ._agent_instantiation import AgentInstantiationContext+from ._agent_metadata import AgentMetadata+from ._agent_runtime import AgentRuntime+from ._agent_type import AgentType+from ._base_agent import BaseAgent+from ._cancellation_token import CancellationToken+from ._message_context import MessageContext+from ._serialization import try_get_known_serializers_for_type+from ._subscription import Subscription+from ._subscription_context import SubscriptionInstantiationContext+from ._topic import TopicId+from ._type_helpers import get_types+from .exceptions import CantHandleExceptionT = TypeVar("T")ClosureAgentType = TypeVar("ClosureAgentType", bound="ClosureAgent")diff --git a/python/packages/autogen-core/src/autogen_core/components/_default_subscription.py b/python/packages/autogen-core/src/autogen_core/_default_subscription.pysimilarity index 92%rename from python/packages/autogen-core/src/autogen_core/components/_default_subscription.pyrename to python/packages/autogen-core/src/autogen_core/_default_subscription.pyindex 3e1c0c430..d47c62109 100644--- a/python/packages/autogen-core/src/autogen_core/components/_default_subscription.py+++ b/python/packages/autogen-core/src/autogen_core/_default_subscription.py@@ -1,8 +1,9 @@from typing import Callable, Type, TypeVar, overload-from ..base import BaseAgent, SubscriptionInstantiationContext, subscription_factory-from ..base.exceptions import CantHandleException+from ._base_agent import BaseAgent, subscription_factory+from ._subscription_context import SubscriptionInstantiationContextfrom ._type_subscription import TypeSubscription+from .exceptions import CantHandleExceptionclass DefaultSubscription(TypeSubscription):diff --git a/python/packages/autogen-core/src/autogen_core/components/_default_topic.py b/python/packages/autogen-core/src/autogen_core/_default_topic.pysimilarity index 92%rename from python/packages/autogen-core/src/autogen_core/components/_default_topic.pyrename to python/packages/autogen-core/src/autogen_core/_default_topic.pyindex 201ff57db..b5dde0a0e 100644--- a/python/packages/autogen-core/src/autogen_core/components/_default_topic.py+++ b/python/packages/autogen-core/src/autogen_core/_default_topic.py@@ -1,4 +1,5 @@-from ..base import MessageHandlerContext, TopicId+from ._message_handler_context import MessageHandlerContext+from ._topic import TopicIdclass DefaultTopicId(TopicId):diff --git a/python/packages/autogen-core/src/autogen_core/components/_function_utils.py b/python/packages/autogen-core/src/autogen_core/_function_utils.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/components/_function_utils.pyrename to python/packages/autogen-core/src/autogen_core/_function_utils.pydiff --git a/python/packages/autogen-core/src/autogen_core/components/_image.py b/python/packages/autogen-core/src/autogen_core/_image.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/components/_image.pyrename to python/packages/autogen-core/src/autogen_core/_image.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_message_context.py b/python/packages/autogen-core/src/autogen_core/_message_context.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_message_context.pyrename to python/packages/autogen-core/src/autogen_core/_message_context.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_message_handler_context.py b/python/packages/autogen-core/src/autogen_core/_message_handler_context.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_message_handler_context.pyrename to python/packages/autogen-core/src/autogen_core/_message_handler_context.pydiff --git a/python/packages/autogen-core/src/autogen_core/components/_pydantic_compat.py b/python/packages/autogen-core/src/autogen_core/_pydantic_compat.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/components/_pydantic_compat.pyrename to python/packages/autogen-core/src/autogen_core/_pydantic_compat.pydiff --git a/python/packages/autogen-core/src/autogen_core/components/_routed_agent.py b/python/packages/autogen-core/src/autogen_core/_routed_agent.pysimilarity index 96%rename from python/packages/autogen-core/src/autogen_core/components/_routed_agent.pyrename to python/packages/autogen-core/src/autogen_core/_routed_agent.pyindex 6f21681fb..ea23dfe63 100644--- a/python/packages/autogen-core/src/autogen_core/components/_routed_agent.py+++ b/python/packages/autogen-core/src/autogen_core/_routed_agent.py@@ -1,5 +1,4 @@import logging-import warningsfrom functools import wrapsfrom typing import (Any,@@ -19,9 +18,11 @@ from typing import (runtime_checkable,)-from ..base import BaseAgent, MessageContext, MessageSerializer, try_get_known_serializers_for_type-from ..base._type_helpers import AnyType, get_types-from ..base.exceptions import CantHandleException+from ._base_agent import BaseAgent+from ._message_context import MessageContext+from ._serialization import MessageSerializer, try_get_known_serializers_for_type+from ._type_helpers import AnyType, get_types+from .exceptions import CantHandleExceptionlogger = logging.getLogger("autogen_core")@@ -423,8 +424,8 @@ class RoutedAgent(BaseAgent):.. code-block:: pythonfrom dataclasses import dataclass- from autogen_core.base import MessageContext- from autogen_core.components import RoutedAgent, event, rpc+ from autogen_core import MessageContext+ from autogen_core import RoutedAgent, event, rpc@dataclass@@ -515,12 +516,3 @@ class RoutedAgent(BaseAgent):types.append((t, try_get_known_serializers_for_type(t)))return types---# Deprecation warning for TypeRoutedAgent-class TypeRoutedAgent(RoutedAgent):- """Deprecated. Use :class:`RoutedAgent` instead."""-- def __init__(self, description: str) -> None:- warnings.warn("TypeRoutedAgent is deprecated. Use RoutedAgent instead.", DeprecationWarning, stacklevel=2)- super().__init__(description)diff --git a/python/packages/autogen-core/src/autogen_core/base/_serialization.py b/python/packages/autogen-core/src/autogen_core/_serialization.pysimilarity index 99%rename from python/packages/autogen-core/src/autogen_core/base/_serialization.pyrename to python/packages/autogen-core/src/autogen_core/_serialization.pyindex 608fe9180..37ec9de56 100644--- a/python/packages/autogen-core/src/autogen_core/base/_serialization.py+++ b/python/packages/autogen-core/src/autogen_core/_serialization.py@@ -6,7 +6,7 @@ from google.protobuf import any_pb2from google.protobuf.message import Messagefrom pydantic import BaseModel-from autogen_core.base._type_helpers import is_union+from ._type_helpers import is_unionT = TypeVar("T")diff --git a/python/packages/autogen-core/src/autogen_core/base/_subscription.py b/python/packages/autogen-core/src/autogen_core/_subscription.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_subscription.pyrename to python/packages/autogen-core/src/autogen_core/_subscription.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_subscription_context.py b/python/packages/autogen-core/src/autogen_core/_subscription_context.pysimilarity index 96%rename from python/packages/autogen-core/src/autogen_core/base/_subscription_context.pyrename to python/packages/autogen-core/src/autogen_core/_subscription_context.pyindex e67bcfc9b..1cfd3fd88 100644--- a/python/packages/autogen-core/src/autogen_core/base/_subscription_context.py+++ b/python/packages/autogen-core/src/autogen_core/_subscription_context.py@@ -2,7 +2,7 @@ from contextlib import contextmanagerfrom contextvars import ContextVarfrom typing import Any, ClassVar, Generator-from autogen_core.base._agent_type import AgentType+from autogen_core._agent_type import AgentTypeclass SubscriptionInstantiationContext:diff --git a/python/packages/autogen-core/src/autogen_core/base/_topic.py b/python/packages/autogen-core/src/autogen_core/_topic.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_topic.pyrename to python/packages/autogen-core/src/autogen_core/_topic.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_type_helpers.py b/python/packages/autogen-core/src/autogen_core/_type_helpers.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/base/_type_helpers.pyrename to python/packages/autogen-core/src/autogen_core/_type_helpers.pydiff --git a/python/packages/autogen-core/src/autogen_core/base/_type_prefix_subscription.py b/python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.pysimilarity index 96%rename from python/packages/autogen-core/src/autogen_core/base/_type_prefix_subscription.pyrename to python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.pyindex f00119165..4c88f12a4 100644--- a/python/packages/autogen-core/src/autogen_core/base/_type_prefix_subscription.py+++ b/python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.py@@ -15,7 +15,7 @@ class TypePrefixSubscription(Subscription):.. code-block:: python- from autogen_core.components import TypePrefixSubscription+ from autogen_core import TypePrefixSubscriptionsubscription = TypePrefixSubscription(topic_type_prefix="t1", agent_type="a1")diff --git a/python/packages/autogen-core/src/autogen_core/components/_type_subscription.py b/python/packages/autogen-core/src/autogen_core/_type_subscription.pysimilarity index 89%rename from python/packages/autogen-core/src/autogen_core/components/_type_subscription.pyrename to python/packages/autogen-core/src/autogen_core/_type_subscription.pyindex 94def7659..4ad815418 100644--- a/python/packages/autogen-core/src/autogen_core/components/_type_subscription.py+++ b/python/packages/autogen-core/src/autogen_core/_type_subscription.py@@ -1,7 +1,9 @@import uuid-from ..base import AgentId, Subscription, TopicId-from ..base.exceptions import CantHandleException+from ._agent_id import AgentId+from ._subscription import Subscription+from ._topic import TopicId+from .exceptions import CantHandleExceptionclass TypeSubscription(Subscription):@@ -13,7 +15,7 @@ class TypeSubscription(Subscription):.. code-block:: python- from autogen_core.components import TypeSubscription+ from autogen_core import TypeSubscriptionsubscription = TypeSubscription(topic_type="t1", agent_type="a1")diff --git a/python/packages/autogen-core/src/autogen_core/components/_types.py b/python/packages/autogen-core/src/autogen_core/_types.pysimilarity index 100%rename from python/packages/autogen-core/src/autogen_core/components/_types.pyrename to python/packages/autogen-core/src/autogen_core/_types.pydiff --git a/python/packages/autogen-core/src/autogen_core/application/_helpers.py b/python/packages/autogen-core/src/autogen_core/application/_helpers.pyindex 18286c617..fe4e1697f 100644--- a/python/packages/autogen-core/src/autogen_core/application/_helpers.py+++ b/python/packages/autogen-core/src/autogen_core/application/_helpers.py@@ -1,11 +1,11 @@from collections import defaultdictfrom typing import Awaitable, Callable, DefaultDict, List, Set-from ..base._agent import Agent-from ..base._agent_id import AgentId-from ..base._agent_type import AgentType-from ..base._subscription import Subscription-from ..base._topic import TopicId+from .._agent import Agent+from .._agent_id import AgentId+from .._agent_type import AgentType+from .._subscription import Subscription+from .._topic import TopicIdasync def get_impl(diff --git a/python/packages/autogen-core/src/autogen_core/application/_single_threaded_agent_runtime.py b/python/packages/autogen-core/src/autogen_core/application/_single_threaded_agent_runtime.pyindex 3d81f15eb..ebd764bc7 100644--- a/python/packages/autogen-core/src/autogen_core/application/_single_threaded_agent_runtime.py+++ b/python/packages/autogen-core/src/autogen_core/application/_single_threaded_agent_runtime.py@@ -15,9 +15,9 @@ from typing import Any, Awaitable, Callable, Dict, List, Mapping, ParamSpec, Setfrom opentelemetry.trace import TracerProviderfrom typing_extensions import deprecated-from autogen_core.base._serialization import MessageSerializer, SerializationRegistry+from autogen_core._serialization import MessageSerializer, SerializationRegistry-from ..base import (+from .. import (Agent,AgentId,AgentInstantiationContext,@@ -31,8 +31,8 @@ from ..base import (SubscriptionInstantiationContext,TopicId,)-from ..base.exceptions import MessageDroppedExceptionfrom ..base.intervention import DropMessage, InterventionHandler+from ..exceptions import MessageDroppedExceptionfrom ._helpers import SubscriptionManager, get_implfrom .telemetry import EnvelopeMetadata, MessageRuntimeTracingConfig, TraceHelper, get_telemetry_envelope_metadatadiff --git a/python/packages/autogen-core/src/autogen_core/application/_worker_runtime.py b/python/packages/autogen-core/src/autogen_core/application/_worker_runtime.pyindex f1208ea11..9d186d91f 100644--- a/python/packages/autogen-core/src/autogen_core/application/_worker_runtime.py+++ b/python/packages/autogen-core/src/autogen_core/application/_worker_runtime.py@@ -34,9 +34,7 @@ from typing_extensions import Self, deprecatedfrom autogen_core.application.protos import cloudevent_pb2-from ..base import (- JSON_DATA_CONTENT_TYPE,- PROTOBUF_DATA_CONTENT_TYPE,+from .. import (Agent,AgentId,AgentInstantiationContext,@@ -50,9 +48,15 @@ from ..base import (SubscriptionInstantiationContext,TopicId,)-from ..base._serialization import MessageSerializer, SerializationRegistry-from ..base._type_helpers import ChannelArgumentType-from ..components import TypePrefixSubscription, TypeSubscription+from .._serialization import (+ JSON_DATA_CONTENT_TYPE,+ PROTOBUF_DATA_CONTENT_TYPE,+ MessageSerializer,+ SerializationRegistry,+)+from .._type_helpers import ChannelArgumentType+from .._type_prefix_subscription import TypePrefixSubscription+from .._type_subscription import TypeSubscriptionfrom . import _constantsfrom ._constants import GRPC_IMPORT_ERROR_STRfrom ._helpers import SubscriptionManager, get_impldiff --git a/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host.py b/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host.pyindex b9befce58..ab1239a68 100644--- a/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host.py+++ b/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host.py@@ -3,7 +3,7 @@ import loggingimport signalfrom typing import Optional, Sequence-from ..base._type_helpers import ChannelArgumentType+from .._type_helpers import ChannelArgumentTypefrom ._constants import GRPC_IMPORT_ERROR_STRfrom ._worker_runtime_host_servicer import WorkerAgentRuntimeHostServicerdiff --git a/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host_servicer.py b/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host_servicer.pyindex e24a7db3f..574f0a1b1 100644--- a/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host_servicer.py+++ b/python/packages/autogen-core/src/autogen_core/application/_worker_runtime_host_servicer.py@@ -4,10 +4,8 @@ from _collections_abc import AsyncIterator, Iteratorfrom asyncio import Future, Taskfrom typing import Any, Dict, Set, cast-from autogen_core.base._type_prefix_subscription import TypePrefixSubscription--from ..base import Subscription, TopicId-from ..components import TypeSubscription+from .. import Subscription, TopicId, TypeSubscription+from .._type_prefix_subscription import TypePrefixSubscriptionfrom ._constants import GRPC_IMPORT_ERROR_STRfrom ._helpers import SubscriptionManagerdiff --git a/python/packages/autogen-core/src/autogen_core/application/logging/events.py b/python/packages/autogen-core/src/autogen_core/application/logging/events.pyindex b1446bbb9..82affae90 100644--- a/python/packages/autogen-core/src/autogen_core/application/logging/events.py+++ b/python/packages/autogen-core/src/autogen_core/application/logging/events.py@@ -2,7 +2,7 @@ import jsonfrom enum import Enumfrom typing import Any, cast-from autogen_core.base import AgentId+from autogen_core import AgentIdclass LLMCallEvent:diff --git a/python/packages/autogen-core/src/autogen_core/application/telemetry/_tracing_config.py b/python/packages/autogen-core/src/autogen_core/application/telemetry/_tracing_config.pyindex 478712444..c21e1bfc6 100644--- a/python/packages/autogen-core/src/autogen_core/application/telemetry/_tracing_config.py+++ b/python/packages/autogen-core/src/autogen_core/application/telemetry/_tracing_config.py@@ -6,7 +6,7 @@ from opentelemetry.trace import SpanKindfrom opentelemetry.util import typesfrom typing_extensions import NotRequired-from ...base import AgentId, TopicId+from ... import AgentId, TopicIdfrom ._constants import NAMESPACElogger = logging.getLogger("autogen_core")diff --git a/python/packages/autogen-core/src/autogen_core/base/__init__.py b/python/packages/autogen-core/src/autogen_core/base/__init__.pyindex 24af0b307..3691ade5a 100644--- a/python/packages/autogen-core/src/autogen_core/base/__init__.py+++ b/python/packages/autogen-core/src/autogen_core/base/__init__.py@@ -2,49 +2,137 @@The :mod:`autogen_core.base` module provides the foundational generic interfaces upon which all else is built. This module must not depend on any other module."""-from ._agent import Agent-from ._agent_id import AgentId-from ._agent_instantiation import AgentInstantiationContext-from ._agent_metadata import AgentMetadata-from ._agent_proxy import AgentProxy-from ._agent_runtime import AgentRuntime-from ._agent_type import AgentType-from ._base_agent import BaseAgent, subscription_factory-from ._cancellation_token import CancellationToken-from ._message_context import MessageContext-from ._message_handler_context import MessageHandlerContext-from ._serialization import (- JSON_DATA_CONTENT_TYPE,- PROTOBUF_DATA_CONTENT_TYPE,- MessageSerializer,- SerializationRegistry,- UnknownPayload,- try_get_known_serializers_for_type,-)-from ._subscription import Subscription-from ._subscription_context import SubscriptionInstantiationContext-from ._topic import TopicId--__all__ = [- "Agent",- "AgentId",- "AgentProxy",- "AgentMetadata",- "AgentRuntime",- "BaseAgent",- "CancellationToken",- "AgentInstantiationContext",- "TopicId",- "Subscription",- "MessageContext",- "SerializationRegistry",- "AgentType",- "SubscriptionInstantiationContext",- "MessageHandlerContext",- "JSON_DATA_CONTENT_TYPE",- "PROTOBUF_DATA_CONTENT_TYPE",- "MessageSerializer",- "try_get_known_serializers_for_type",- "UnknownPayload",- "subscription_factory",-]+from typing import Any, TypeVar++from typing_extensions import deprecated++from .._agent import Agent as AgentAlias+from .._agent_id import AgentId as AgentIdAlias+from .._agent_instantiation import AgentInstantiationContext as AgentInstantiationContextAlias+from .._agent_metadata import AgentMetadata as AgentMetadataAlias+from .._agent_proxy import AgentProxy as AgentProxyAlias+from .._agent_runtime import AgentRuntime as AgentRuntimeAlias+from .._agent_type import AgentType as AgentTypeAlias+from .._base_agent import BaseAgent as BaseAgentAlias+from .._cancellation_token import CancellationToken as CancellationTokenAlias+from .._message_context import MessageContext as MessageContextAlias+from .._message_handler_context import MessageHandlerContext as MessageHandlerContextAlias+from .._serialization import (+ MessageSerializer as MessageSerializerAlias,+)+from .._serialization import (+ UnknownPayload as UnknownPayloadAlias,+)+from .._serialization import (+ try_get_known_serializers_for_type as try_get_known_serializers_for_type_alias,+)+from .._subscription import Subscription as SubscriptionAlias+from .._subscription_context import SubscriptionInstantiationContext as SubscriptionInstantiationContextAlias+from .._topic import TopicId as TopicIdAlias+++@deprecated("autogen_core.base.Agent moved to autogen_core.Agent. This alias will be removed in 0.4.0.")+class Agent(AgentAlias):+ pass+++@deprecated("autogen_core.base.AgentId moved to autogen_core.AgentId. This alias will be removed in 0.4.0.")+class AgentId(AgentIdAlias):+ pass+++@deprecated(+ "autogen_core.base.AgentInstantiationContext moved to autogen_core.AgentInstantiationContext. This alias will be removed in 0.4.0."+)+class AgentInstantiationContext(AgentInstantiationContextAlias):+ pass+++@deprecated("autogen_core.base.AgentMetadata moved to autogen_core.AgentMetadata. This alias will be removed in 0.4.0.")+class AgentMetadata(AgentMetadataAlias):+ pass+++@deprecated("autogen_core.base.AgentProxy moved to autogen_core.AgentProxy. This alias will be removed in 0.4.0.")+class AgentProxy(AgentProxyAlias):+ pass+++@deprecated("autogen_core.base.AgentRuntime moved to autogen_core.AgentRuntime. This alias will be removed in 0.4.0.")+class AgentRuntime(AgentRuntimeAlias):+ pass+++@deprecated("autogen_core.base.AgentType moved to autogen_core.AgentType. This alias will be removed in 0.4.0.")+class AgentType(AgentTypeAlias):+ pass+++@deprecated("autogen_core.base.BaseAgent moved to autogen_core.BaseAgent. This alias will be removed in 0.4.0.")+class BaseAgent(BaseAgentAlias):+ pass+++@deprecated(+ "autogen_core.base.CancellationToken moved to autogen_core.CancellationToken. This alias will be removed in 0.4.0."+)+class CancellationToken(CancellationTokenAlias):+ pass+++@deprecated(+ "autogen_core.base.MessageContext moved to autogen_core.MessageContext. This alias will be removed in 0.4.0."+)+class MessageContext(MessageContextAlias):+ pass+++@deprecated(+ "autogen_core.base.MessageHandlerContext moved to autogen_core.MessageHandlerContext. This alias will be removed in 0.4.0."+)+class MessageHandlerContext(MessageHandlerContextAlias):+ pass+++@deprecated(+ "autogen_core.base.UnknownPayloadAlias moved to autogen_core.UnknownPayloadAlias. This alias will be removed in 0.4.0."+)+class UnknownPayload(UnknownPayloadAlias):+ pass+++T = TypeVar("T")+++@deprecated(+ "autogen_core.base.MessageSerializer moved to autogen_core.MessageSerializer. This alias will be removed in 0.4.0."+)+class MessageSerializer(MessageSerializerAlias[T]):+ pass+++@deprecated("autogen_core.base.Subscription moved to autogen_core.Subscription. This alias will be removed in 0.4.0.")+class Subscription(SubscriptionAlias):+ pass+++@deprecated(+ "autogen_core.base.try_get_known_serializers_for_type moved to autogen_core.try_get_known_serializers_for_type. This alias will be removed in 0.4.0."+)+def try_get_known_serializers_for_type(cls: type[Any]) -> list[MessageSerializerAlias[Any]]:+ return try_get_known_serializers_for_type_alias(cls)+++@deprecated(+ "autogen_core.base.SubscriptionInstantiationContext moved to autogen_core.SubscriptionInstantiationContext. This alias will be removed in 0.4.0."+)+class SubscriptionInstantiationContext(SubscriptionInstantiationContextAlias):+ pass+++@deprecated("autogen_core.base.TopicId moved to autogen_core.TopicId. This alias will be removed in 0.4.0.")+class TopicId(TopicIdAlias):+ pass+++__all__ = [] # type: ignorediff --git a/python/packages/autogen-core/src/autogen_core/base/exceptions.py b/python/packages/autogen-core/src/autogen_core/base/exceptions.pyindex f35c3fbfe..f1fea9f81 100644--- a/python/packages/autogen-core/src/autogen_core/base/exceptions.py+++ b/python/packages/autogen-core/src/autogen_core/base/exceptions.py@@ -1,21 +1,37 @@-__all__ = [- "CantHandleException",- "UndeliverableException",- "MessageDroppedException",-]---class CantHandleException(Exception):+from typing_extensions import deprecated++from ..exceptions import (+ CantHandleException as CantHandleExceptionAlias,+)+from ..exceptions import (+ MessageDroppedException as MessageDroppedExceptionAlias,+)+from ..exceptions import (+ NotAccessibleError as NotAccessibleErrorAlias,+)+from ..exceptions import (+ UndeliverableException as UndeliverableExceptionAlias,+)+++@deprecated("Moved to autogen_core.exceptions.CantHandleException. Alias will be removed in 0.4.0")+class CantHandleException(CantHandleExceptionAlias):"""Raised when a handler can't handle the exception."""-class UndeliverableException(Exception):+@deprecated("Moved to autogen_core.exceptions.UndeliverableException. Alias will be removed in 0.4.0")+class UndeliverableException(UndeliverableExceptionAlias):"""Raised when a message can't be delivered."""-class MessageDroppedException(Exception):+@deprecated("Moved to autogen_core.exceptions.MessageDroppedException. Alias will be removed in 0.4.0")+class MessageDroppedException(MessageDroppedExceptionAlias):"""Raised when a message is dropped."""-class NotAccessibleError(Exception):+@deprecated("Moved to autogen_core.exceptions.NotAccessibleError. Alias will be removed in 0.4.0")+class NotAccessibleError(NotAccessibleErrorAlias):"""Tried to access a value that is not accessible. For example if it is remote cannot be accessed locally."""+++__all__ = [] # type: ignorediff --git a/python/packages/autogen-core/src/autogen_core/base/intervention.py b/python/packages/autogen-core/src/autogen_core/base/intervention.pyindex 3b771c931..5fe337b87 100644--- a/python/packages/autogen-core/src/autogen_core/base/intervention.py+++ b/python/packages/autogen-core/src/autogen_core/base/intervention.py@@ -1,6 +1,6 @@from typing import Any, Awaitable, Callable, Protocol, final-from autogen_core.base import AgentId+from .._agent_id import AgentId__all__ = ["DropMessage",diff --git a/python/packages/autogen-core/src/autogen_core/components/__init__.py b/python/packages/autogen-core/src/autogen_core/components/__init__.pyindex 37d1ad48a..7ef165f16 100644--- a/python/packages/autogen-core/src/autogen_core/components/__init__.py+++ b/python/packages/autogen-core/src/autogen_core/components/__init__.py@@ -2,29 +2,114 @@The :mod:`autogen_core.components` module provides building blocks for creating single agents"""-from ..base._type_prefix_subscription import TypePrefixSubscription-from ._closure_agent import ClosureAgent, ClosureContext-from ._default_subscription import DefaultSubscription, default_subscription, type_subscription-from ._default_topic import DefaultTopicId-from ._image import Image-from ._routed_agent import RoutedAgent, TypeRoutedAgent, event, message_handler, rpc-from ._type_subscription import TypeSubscription-from ._types import FunctionCall--__all__ = [- "Image",- "RoutedAgent",- "TypeRoutedAgent",- "ClosureAgent",- "ClosureContext",- "message_handler",- "event",- "rpc",- "FunctionCall",- "TypeSubscription",- "DefaultSubscription",- "DefaultTopicId",- "default_subscription",- "type_subscription",- "TypePrefixSubscription",-]+from typing import Any, Callable, Type, TypeVar++from typing_extensions import deprecated++from .._base_agent import BaseAgent+from .._closure_agent import ClosureAgent as ClosureAgentAlias+from .._closure_agent import ClosureContext as ClosureContextAlias+from .._default_subscription import (+ DefaultSubscription as DefaultSubscriptionAlias,+)+from .._default_subscription import (+ default_subscription as default_subscription_alias,+)+from .._default_subscription import (+ type_subscription as type_subscription_alias,+)+from .._default_topic import DefaultTopicId as DefaultTopicIdAlias+from .._image import Image as ImageAlias+from .._routed_agent import (+ RoutedAgent as RoutedAgentAlias,+)+from .._routed_agent import (+ event as event_alias,+)+from .._routed_agent import (+ message_handler as message_handler_alias,+)+from .._routed_agent import (+ rpc as rpc_aliass,+)+from .._type_prefix_subscription import TypePrefixSubscription as TypePrefixSubscriptionAlias+from .._type_subscription import TypeSubscription as TypeSubscriptionAlias+from .._types import FunctionCall as FunctionCallAlias++__all__ = [] # type: ignore+++@deprecated("Moved to autogen_core.TypePrefixSubscription. Will be removed in 0.4.0")+class TypePrefixSubscription(TypePrefixSubscriptionAlias):+ pass+++@deprecated("Moved to autogen_core.TypeSubscription. Will be removed in 0.4.0")+class TypeSubscription(TypeSubscriptionAlias):+ pass+++@deprecated("Moved to autogen_core.ClosureAgent. Will be removed in 0.4.0")+class ClosureAgent(ClosureAgentAlias):+ pass+++@deprecated("Moved to autogen_core.ClosureContext. Will be removed in 0.4.0")+class ClosureContext(ClosureContextAlias):+ pass+++@deprecated("Moved to autogen_core.DefaultSubscription. Will be removed in 0.4.0")+class DefaultSubscription(DefaultSubscriptionAlias):+ pass+++BaseAgentType = TypeVar("BaseAgentType", bound="BaseAgent")+++@deprecated("Moved to autogen_core.default_subscription. Will be removed in 0.4.0")+def default_subscription(+ cls: Type[BaseAgentType] | None = None,+) -> Callable[[Type[BaseAgentType]], Type[BaseAgentType]] | Type[BaseAgentType]:+ return default_subscription_alias(cls) # type: ignore+++@deprecated("Moved to autogen_core.type_subscription. Will be removed in 0.4.0")+def type_subscription(topic_type: str) -> Callable[[Type[BaseAgentType]], Type[BaseAgentType]]:+ return type_subscription_alias(topic_type)+++@deprecated("Moved to autogen_core.DefaultTopicId. Will be removed in 0.4.0")+class DefaultTopicId(DefaultTopicIdAlias):+ pass+++@deprecated("Moved to autogen_core.Image. Will be removed in 0.4.0")+class Image(ImageAlias):+ pass+++@deprecated("Moved to autogen_core.RoutedAgent. Will be removed in 0.4.0")+class RoutedAgent(RoutedAgentAlias):+ pass+++# Generic forwarding of all args to the alias+@deprecated("Moved to autogen_core.event. Will be removed in 0.4.0")+def event(*args: Any, **kwargs: Any) -> Any:+ return event_alias(*args, **kwargs) # type: ignore+++@deprecated("Moved to autogen_core.message_handler. Will be removed in 0.4.0")+def message_handler(*args: Any, **kwargs: Any) -> Any:+ return message_handler_alias(*args, **kwargs) # type: ignore+++@deprecated("Moved to autogen_core.rpc. Will be removed in 0.4.0")+def rpc(*args: Any, **kwargs: Any) -> Any:+ return rpc_aliass(*args, **kwargs) # type: ignore+++@deprecated("Moved to autogen_core.FunctionCall. Will be removed in 0.4.0")+class FunctionCall(FunctionCallAlias):+ passdiff --git a/python/packages/autogen-core/src/autogen_core/components/code_executor/_base.py b/python/packages/autogen-core/src/autogen_core/components/code_executor/_base.pyindex 238c8d014..4c12f5735 100644--- a/python/packages/autogen-core/src/autogen_core/components/code_executor/_base.py+++ b/python/packages/autogen-core/src/autogen_core/components/code_executor/_base.py@@ -6,7 +6,7 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import List, Protocol, runtime_checkable-from autogen_core.base import CancellationToken+from ... import CancellationToken@dataclassdiff --git a/python/packages/autogen-core/src/autogen_core/components/code_executor/_impl/local_commandline_code_executor.py b/python/packages/autogen-core/src/autogen_core/components/code_executor/_impl/local_commandline_code_executor.pyindex 31779f656..01e098881 100644--- a/python/packages/autogen-core/src/autogen_core/components/code_executor/_impl/local_commandline_code_executor.py+++ b/python/packages/autogen-core/src/autogen_core/components/code_executor/_impl/local_commandline_code_executor.py@@ -14,7 +14,7 @@ from typing import Any, Callable, ClassVar, List, Optional, Sequence, Unionfrom typing_extensions import ParamSpec-from ....base import CancellationToken+from .... import CancellationTokenfrom .._base import CodeBlock, CodeExecutorfrom .._func_with_reqs import (FunctionWithRequirements,@@ -69,7 +69,7 @@ class LocalCommandLineCodeExecutor(CodeExecutor):from pathlib import Pathimport asyncio- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import CodeBlock, LocalCommandLineCodeExecutordiff --git a/python/packages/autogen-core/src/autogen_core/components/model_context/_head_and_tail_chat_completion_context.py b/python/packages/autogen-core/src/autogen_core/components/model_context/_head_and_tail_chat_completion_context.pyindex ab50df416..0caa55460 100644--- a/python/packages/autogen-core/src/autogen_core/components/model_context/_head_and_tail_chat_completion_context.py+++ b/python/packages/autogen-core/src/autogen_core/components/model_context/_head_and_tail_chat_completion_context.py@@ -1,6 +1,6 @@from typing import Any, List, Mapping-from .._types import FunctionCall+from ..._types import FunctionCallfrom ..models import AssistantMessage, FunctionExecutionResultMessage, LLMMessage, UserMessagefrom ._chat_completion_context import ChatCompletionContextdiff --git a/python/packages/autogen-core/src/autogen_core/components/models/_model_client.py b/python/packages/autogen-core/src/autogen_core/components/models/_model_client.pyindex 532bb2ea1..dec6dd221 100644--- a/python/packages/autogen-core/src/autogen_core/components/models/_model_client.py+++ b/python/packages/autogen-core/src/autogen_core/components/models/_model_client.py@@ -11,7 +11,7 @@ from typing_extensions import (Union,)-from ...base import CancellationToken+from ... import CancellationTokenfrom ..tools import Tool, ToolSchemafrom ._types import CreateResult, LLMMessage, RequestUsagediff --git a/python/packages/autogen-core/src/autogen_core/components/models/_types.py b/python/packages/autogen-core/src/autogen_core/components/models/_types.pyindex d2048f4b7..3bc047d27 100644--- a/python/packages/autogen-core/src/autogen_core/components/models/_types.py+++ b/python/packages/autogen-core/src/autogen_core/components/models/_types.py@@ -1,7 +1,7 @@from dataclasses import dataclassfrom typing import List, Literal, Optional, Union-from .. import FunctionCall, Image+from ... import FunctionCall, Image@dataclassdiff --git a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_caller_loop.py b/python/packages/autogen-core/src/autogen_core/components/tool_agent/_caller_loop.pyindex ea2922f23..28cff5066 100644--- a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_caller_loop.py+++ b/python/packages/autogen-core/src/autogen_core/components/tool_agent/_caller_loop.py@@ -1,8 +1,7 @@import asynciofrom typing import List-from ...base import AgentId, AgentRuntime, BaseAgent, CancellationToken-from ...components import FunctionCall+from ... import AgentId, AgentRuntime, BaseAgent, CancellationToken, FunctionCallfrom ..models import (AssistantMessage,ChatCompletionClient,diff --git a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_tool_agent.py b/python/packages/autogen-core/src/autogen_core/components/tool_agent/_tool_agent.pyindex 8e1c2993e..2794a3e4e 100644--- a/python/packages/autogen-core/src/autogen_core/components/tool_agent/_tool_agent.py+++ b/python/packages/autogen-core/src/autogen_core/components/tool_agent/_tool_agent.py@@ -2,8 +2,7 @@ import jsonfrom dataclasses import dataclassfrom typing import List-from ...base import MessageContext-from .. import FunctionCall, RoutedAgent, message_handler+from ... import FunctionCall, MessageContext, RoutedAgent, message_handlerfrom ..models import FunctionExecutionResultfrom ..tools import Tooldiff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_base.py b/python/packages/autogen-core/src/autogen_core/components/tools/_base.pyindex eb6a2067e..b41d747d6 100644--- a/python/packages/autogen-core/src/autogen_core/components/tools/_base.py+++ b/python/packages/autogen-core/src/autogen_core/components/tools/_base.py@@ -7,8 +7,8 @@ import jsonreffrom pydantic import BaseModelfrom typing_extensions import NotRequired-from ...base import CancellationToken-from .._function_utils import normalize_annotated_type+from ... import CancellationToken+from ..._function_utils import normalize_annotated_typeT = 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/components/tools/_code_execution.pyindex 48dbe729a..5b3f0bcad 100644--- a/python/packages/autogen-core/src/autogen_core/components/tools/_code_execution.py+++ b/python/packages/autogen-core/src/autogen_core/components/tools/_code_execution.py@@ -1,6 +1,6 @@from pydantic import BaseModel, Field, model_serializer-from ...base import CancellationToken+from ... import CancellationTokenfrom ..code_executor import CodeBlock, CodeExecutorfrom ._base import BaseTooldiff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py b/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.pyindex cc9145fab..45041121c 100644--- a/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py+++ b/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py@@ -4,8 +4,8 @@ from typing import Any, Callablefrom pydantic import BaseModel-from ...base import CancellationToken-from .._function_utils import (+from ... import CancellationToken+from ..._function_utils import (args_base_model_from_signature,get_typed_signature,)@@ -38,7 +38,7 @@ class FunctionTool(BaseTool[BaseModel, BaseModel]):.. code-block:: pythonimport random- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenfrom autogen_core.components.tools import FunctionToolfrom typing_extensions import Annotatedimport asynciodiff --git a/python/packages/autogen-core/src/autogen_core/exceptions.py b/python/packages/autogen-core/src/autogen_core/exceptions.pynew file mode 100644index 000000000..3f4d76dbc--- /dev/null+++ b/python/packages/autogen-core/src/autogen_core/exceptions.py@@ -0,0 +1,17 @@+__all__ = ["CantHandleException", "UndeliverableException", "MessageDroppedException", "NotAccessibleError"]+++class CantHandleException(Exception):+ """Raised when a handler can't handle the exception."""+++class UndeliverableException(Exception):+ """Raised when a message can't be delivered."""+++class MessageDroppedException(Exception):+ """Raised when a message is dropped."""+++class NotAccessibleError(Exception):+ """Tried to access a value that is not accessible. For example if it is remote cannot be accessed locally."""diff --git a/python/packages/autogen-core/tests/execution/test_commandline_code_executor.py b/python/packages/autogen-core/tests/execution/test_commandline_code_executor.pyindex aff36b216..482330714 100644--- a/python/packages/autogen-core/tests/execution/test_commandline_code_executor.py+++ b/python/packages/autogen-core/tests/execution/test_commandline_code_executor.py@@ -13,7 +13,7 @@ from typing import AsyncGenerator, TypeAliasimport pytestimport pytest_asynciofrom aiofiles import open-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import CodeBlock, LocalCommandLineCodeExecutordiff --git a/python/packages/autogen-core/tests/execution/test_user_defined_functions.py b/python/packages/autogen-core/tests/execution/test_user_defined_functions.pyindex 84fdec3fa..6aa3a9e45 100644--- a/python/packages/autogen-core/tests/execution/test_user_defined_functions.py+++ b/python/packages/autogen-core/tests/execution/test_user_defined_functions.py@@ -6,7 +6,7 @@ import tempfileimport polarsimport pytest-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import (CodeBlock,FunctionWithRequirements,diff --git a/python/packages/autogen-core/tests/test_base_agent.py b/python/packages/autogen-core/tests/test_base_agent.pyindex 884a42527..c7ccfc2d4 100644--- a/python/packages/autogen-core/tests/test_base_agent.py+++ b/python/packages/autogen-core/tests/test_base_agent.py@@ -1,5 +1,5 @@import pytest-from autogen_core.base import AgentId, AgentInstantiationContext, AgentRuntime+from autogen_core import AgentId, AgentInstantiationContext, AgentRuntimefrom pytest_mock import MockerFixturefrom test_utils import NoopAgentdiff --git a/python/packages/autogen-core/tests/test_cancellation.py b/python/packages/autogen-core/tests/test_cancellation.pyindex 67852636f..930f16d9e 100644--- a/python/packages/autogen-core/tests/test_cancellation.py+++ b/python/packages/autogen-core/tests/test_cancellation.py@@ -2,9 +2,15 @@ import asynciofrom dataclasses import dataclassimport pytest+from autogen_core import (+ AgentId,+ AgentInstantiationContext,+ CancellationToken,+ MessageContext,+ RoutedAgent,+ message_handler,+)from autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, AgentInstantiationContext, CancellationToken, MessageContext-from autogen_core.components import RoutedAgent, message_handler@dataclassdiff --git a/python/packages/autogen-core/tests/test_closure_agent.py b/python/packages/autogen-core/tests/test_closure_agent.pyindex 328fe2374..38f66cc7b 100644--- a/python/packages/autogen-core/tests/test_closure_agent.py+++ b/python/packages/autogen-core/tests/test_closure_agent.py@@ -2,9 +2,8 @@ import asynciofrom dataclasses import dataclassimport pytest+from autogen_core import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId, MessageContextfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import MessageContext-from autogen_core.components import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId@dataclassdiff --git a/python/packages/autogen-core/tests/test_intervention.py b/python/packages/autogen-core/tests/test_intervention.pyindex 105df3298..66b45cca0 100644--- a/python/packages/autogen-core/tests/test_intervention.py+++ b/python/packages/autogen-core/tests/test_intervention.py@@ -1,8 +1,8 @@import pytest+from autogen_core import AgentIdfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId-from autogen_core.base.exceptions import MessageDroppedExceptionfrom autogen_core.base.intervention import DefaultInterventionHandler, DropMessage+from autogen_core.exceptions import MessageDroppedExceptionfrom test_utils import LoopbackAgent, MessageTypediff --git a/python/packages/autogen-core/tests/test_routed_agent.py b/python/packages/autogen-core/tests/test_routed_agent.pyindex cab1b1d46..2408c2b1d 100644--- a/python/packages/autogen-core/tests/test_routed_agent.py+++ b/python/packages/autogen-core/tests/test_routed_agent.py@@ -3,9 +3,8 @@ from dataclasses import dataclassfrom typing import Callable, castimport pytest+from autogen_core import AgentId, MessageContext, RoutedAgent, TopicId, TypeSubscription, event, message_handler, rpcfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, MessageContext, TopicId-from autogen_core.components import RoutedAgent, TypeSubscription, event, message_handler, rpcfrom test_utils import LoopbackAgentdiff --git a/python/packages/autogen-core/tests/test_runtime.py b/python/packages/autogen-core/tests/test_runtime.pyindex b327be146..86441b40a 100644--- a/python/packages/autogen-core/tests/test_runtime.py+++ b/python/packages/autogen-core/tests/test_runtime.py@@ -1,15 +1,17 @@import loggingimport pytest-from autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import (+from autogen_core import (AgentId,AgentInstantiationContext,AgentType,+ DefaultTopicId,TopicId,+ TypeSubscription,try_get_known_serializers_for_type,+ type_subscription,)-from autogen_core.components import DefaultTopicId, TypeSubscription, type_subscription+from autogen_core.application import SingleThreadedAgentRuntimefrom opentelemetry.sdk.trace import TracerProviderfrom test_utils import (CascadingAgent,diff --git a/python/packages/autogen-core/tests/test_serialization.py b/python/packages/autogen-core/tests/test_serialization.pyindex f6ab2067c..ea4ab4d22 100644--- a/python/packages/autogen-core/tests/test_serialization.py+++ b/python/packages/autogen-core/tests/test_serialization.py@@ -2,18 +2,16 @@ from dataclasses import dataclassfrom typing import Unionimport pytest-from autogen_core.base import (+from autogen_core import Image+from autogen_core._serialization import (JSON_DATA_CONTENT_TYPE,- MessageSerializer,- SerializationRegistry,- try_get_known_serializers_for_type,-)-from autogen_core.base._serialization import (PROTOBUF_DATA_CONTENT_TYPE,DataclassJsonMessageSerializer,+ MessageSerializer,PydanticJsonMessageSerializer,+ SerializationRegistry,+ try_get_known_serializers_for_type,)-from autogen_core.components import Imagefrom PIL import Image as PILImagefrom protos.serialization_test_pb2 import NestingProtoMessage, ProtoMessagefrom pydantic import BaseModeldiff --git a/python/packages/autogen-core/tests/test_state.py b/python/packages/autogen-core/tests/test_state.pyindex ba4fe86cf..99a7b132f 100644--- a/python/packages/autogen-core/tests/test_state.py+++ b/python/packages/autogen-core/tests/test_state.py@@ -1,8 +1,8 @@from typing import Any, Mappingimport pytest+from autogen_core import AgentId, BaseAgent, MessageContextfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, BaseAgent, MessageContextclass StatefulAgent(BaseAgent):diff --git a/python/packages/autogen-core/tests/test_subscription.py b/python/packages/autogen-core/tests/test_subscription.pyindex 91223acbb..f2c3bd3ee 100644--- a/python/packages/autogen-core/tests/test_subscription.py+++ b/python/packages/autogen-core/tests/test_subscription.py@@ -1,8 +1,7 @@import pytest+from autogen_core import AgentId, DefaultSubscription, DefaultTopicId, TopicId, TypeSubscriptionfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, TopicId-from autogen_core.base.exceptions import CantHandleException-from autogen_core.components import DefaultSubscription, DefaultTopicId, TypeSubscription+from autogen_core.exceptions import CantHandleExceptionfrom test_utils import LoopbackAgent, MessageTypediff --git a/python/packages/autogen-core/tests/test_tool_agent.py b/python/packages/autogen-core/tests/test_tool_agent.pyindex bdbd3b96b..c7f02b260 100644--- a/python/packages/autogen-core/tests/test_tool_agent.py+++ b/python/packages/autogen-core/tests/test_tool_agent.py@@ -3,9 +3,8 @@ import jsonfrom typing import Any, AsyncGenerator, List, Mapping, Optional, Sequence, Unionimport pytest+from autogen_core import AgentId, CancellationToken, FunctionCallfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, CancellationToken-from autogen_core.components import FunctionCallfrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,diff --git a/python/packages/autogen-core/tests/test_tools.py b/python/packages/autogen-core/tests/test_tools.pyindex e79959698..b35986423 100644--- a/python/packages/autogen-core/tests/test_tools.py+++ b/python/packages/autogen-core/tests/test_tools.py@@ -2,8 +2,8 @@ import inspectfrom typing import Annotated, Listimport pytest-from autogen_core.base import CancellationToken-from autogen_core.components._function_utils import get_typed_signature+from autogen_core import CancellationToken+from autogen_core._function_utils import get_typed_signaturefrom autogen_core.components.tools import BaseTool, FunctionToolfrom autogen_core.components.tools._base import ToolSchemafrom pydantic import BaseModel, Field, model_serializerdiff --git a/python/packages/autogen-core/tests/test_types.py b/python/packages/autogen-core/tests/test_types.pyindex 3959456b3..16697e006 100644--- a/python/packages/autogen-core/tests/test_types.py+++ b/python/packages/autogen-core/tests/test_types.py@@ -2,10 +2,10 @@ from dataclasses import dataclassfrom types import NoneTypefrom typing import Any, List, Optional, Union-from autogen_core.base import MessageContext-from autogen_core.base._serialization import has_nested_base_model-from autogen_core.base._type_helpers import AnyType, get_types-from autogen_core.components._routed_agent import RoutedAgent, message_handler+from autogen_core import MessageContext+from autogen_core._routed_agent import RoutedAgent, message_handler+from autogen_core._serialization import has_nested_base_model+from autogen_core._type_helpers import AnyType, get_typesfrom pydantic import BaseModeldiff --git a/python/packages/autogen-core/tests/test_utils/__init__.py b/python/packages/autogen-core/tests/test_utils/__init__.pyindex 3b1ac1101..f1aeed229 100644--- a/python/packages/autogen-core/tests/test_utils/__init__.py+++ b/python/packages/autogen-core/tests/test_utils/__init__.py@@ -1,8 +1,7 @@from dataclasses import dataclassfrom typing import Any-from autogen_core.base import BaseAgent, MessageContext-from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler+from autogen_core import BaseAgent, DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler@dataclassdiff --git a/python/packages/autogen-core/tests/test_worker_runtime.py b/python/packages/autogen-core/tests/test_worker_runtime.pyindex 2a7d3acdc..5f2061fa8 100644--- a/python/packages/autogen-core/tests/test_worker_runtime.py+++ b/python/packages/autogen-core/tests/test_worker_runtime.py@@ -4,24 +4,22 @@ import osfrom typing import Any, Listimport pytest-from autogen_core.application import WorkerAgentRuntime, WorkerAgentRuntimeHost-from autogen_core.base import (+from autogen_core import (PROTOBUF_DATA_CONTENT_TYPE,AgentId,AgentType,+ DefaultTopicId,MessageContext,+ RoutedAgent,Subscription,TopicId,- try_get_known_serializers_for_type,-)-from autogen_core.components import (- DefaultTopicId,- RoutedAgent,TypeSubscription,default_subscription,event,+ try_get_known_serializers_for_type,type_subscription,)+from autogen_core.application import WorkerAgentRuntime, WorkerAgentRuntimeHostfrom protos.serialization_test_pb2 import ProtoMessagefrom test_utils import (CascadingAgent,diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/_openai_assistant_agent.py b/python/packages/autogen-ext/src/autogen_ext/agents/_openai_assistant_agent.pyindex c72f051ff..f672b832c 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/_openai_assistant_agent.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/_openai_assistant_agent.py@@ -32,8 +32,7 @@ from autogen_agentchat.messages import (ToolCallMessage,ToolCallResultMessage,)-from autogen_core.base import CancellationToken-from autogen_core.components import FunctionCall+from autogen_core import CancellationToken, FunctionCallfrom autogen_core.components.models._types import FunctionExecutionResultfrom autogen_core.components.tools import FunctionTool, Tool@@ -125,7 +124,7 @@ class OpenAIAssistantAgent(BaseChatAgent):.. code-block:: pythonfrom openai import AsyncClient- from autogen_core.base import CancellationToken+ from autogen_core import CancellationTokenimport asynciofrom autogen_ext.agents import OpenAIAssistantAgentfrom autogen_agentchat.messages import TextMessagediff --git a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.py b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.pyindex 2a925643c..fcbc4f58e 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.py@@ -9,8 +9,7 @@ from autogen_agentchat.messages import (MultiModalMessage,TextMessage,)-from autogen_core.base import CancellationToken-from autogen_core.components import FunctionCall+from autogen_core import CancellationToken, FunctionCallfrom autogen_core.components.models import (ChatCompletionClient,LLMMessage,diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/tools.py b/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/tools.pyindex bbba4b79a..395daacb5 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/tools.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/video_surfer/tools.py@@ -5,7 +5,7 @@ import cv2import ffmpegimport numpy as npimport whisper-from autogen_core.components import Image as AGImage+from autogen_core import Image as AGImagefrom autogen_core.components.models import (ChatCompletionClient,UserMessage,diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.py b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.pyindex eb3d2434c..69cd067c7 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_multimodal_web_surfer.py@@ -26,10 +26,9 @@ import PIL.Imagefrom autogen_agentchat.agents import BaseChatAgentfrom autogen_agentchat.base import Responsefrom autogen_agentchat.messages import ChatMessage, MultiModalMessage, TextMessage+from autogen_core import CancellationToken, FunctionCall+from autogen_core import Image as AGImagefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import CancellationToken-from autogen_core.components import FunctionCall-from autogen_core.components import Image as AGImagefrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_types.py b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_types.pyindex f7fa2cdea..a3b1cf6c5 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_types.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_types.py@@ -1,6 +1,6 @@from typing import Any, Dict, List, TypedDict, Union-from autogen_core.components import FunctionCall, Image+from autogen_core import FunctionCall, Imagefrom autogen_core.components.models import FunctionExecutionResultUserContent = Union[str, List[Union[str, Image]]]diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_utils.py b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_utils.pyindex ddafc8d92..c492135b4 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_utils.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/_utils.py@@ -1,6 +1,6 @@from typing import List-from autogen_core.components import Image+from autogen_core import Imagefrom ._types import AssistantContent, FunctionExecutionContent, SystemContent, UserContentdiff --git a/python/packages/autogen-ext/src/autogen_ext/code_executors/_azure_container_code_executor.py b/python/packages/autogen-ext/src/autogen_ext/code_executors/_azure_container_code_executor.pyindex d7c5bd555..f984cdf3a 100644--- a/python/packages/autogen-ext/src/autogen_ext/code_executors/_azure_container_code_executor.py+++ b/python/packages/autogen-ext/src/autogen_ext/code_executors/_azure_container_code_executor.py@@ -13,7 +13,7 @@ import aiohttp# async functions shouldn't use open()from anyio import open_file-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import (CodeBlock,CodeExecutor,diff --git a/python/packages/autogen-ext/src/autogen_ext/code_executors/_docker_code_executor.py b/python/packages/autogen-ext/src/autogen_ext/code_executors/_docker_code_executor.pyindex eb807db46..442486a83 100644--- a/python/packages/autogen-ext/src/autogen_ext/code_executors/_docker_code_executor.py+++ b/python/packages/autogen-ext/src/autogen_ext/code_executors/_docker_code_executor.py@@ -14,7 +14,7 @@ from pathlib import Pathfrom types import TracebackTypefrom typing import Any, Callable, ClassVar, List, Optional, ParamSpec, Type, Union-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import (CodeBlock,CodeExecutor,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.pyindex 1d46ecc7e..851c62358 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@@ -21,13 +21,13 @@ from typing import ()import tiktoken-from autogen_core.application.logging import EVENT_LOGGER_NAME, TRACE_LOGGER_NAME-from autogen_core.application.logging.events import LLMCallEvent-from autogen_core.base import CancellationToken-from autogen_core.components import (+from autogen_core import (+ CancellationToken,FunctionCall,Image,)+from autogen_core.application.logging import EVENT_LOGGER_NAME, TRACE_LOGGER_NAME+from autogen_core.application.logging.events import LLMCallEventfrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,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.pyindex 187dfdace..9403f2f33 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@@ -3,8 +3,8 @@ from __future__ import annotationsimport loggingfrom typing import Any, AsyncGenerator, List, Mapping, Optional, Sequence, Union+from autogen_core import CancellationTokenfrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import CancellationTokenfrom autogen_core.components.models import (ChatCompletionClient,CreateResult,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.pyindex 4ac3e6b63..cb6e82aa8 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@@ -4,7 +4,7 @@ import asyncioimport inspectfrom typing import TYPE_CHECKING, Any, Callable, Dict, Type, cast-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.tools import BaseToolfrom pydantic import BaseModel, Field, create_modeldiff --git a/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.py b/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.pyindex 40eb07213..df5caf5ce 100644--- a/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.py+++ b/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.py@@ -8,7 +8,7 @@ import tempfileimport pytestfrom anyio import open_file-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import CodeBlockfrom autogen_ext.code_executors import ACADynamicSessionsCodeExecutorfrom azure.identity import DefaultAzureCredentialdiff --git a/python/packages/autogen-ext/tests/code_executors/test_aca_user_defined_functions.py b/python/packages/autogen-ext/tests/code_executors/test_aca_user_defined_functions.pyindex 857a0333a..7b8f2ef2a 100644--- a/python/packages/autogen-ext/tests/code_executors/test_aca_user_defined_functions.py+++ b/python/packages/autogen-ext/tests/code_executors/test_aca_user_defined_functions.py@@ -5,7 +5,7 @@ import osimport polarsimport pytest-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import (CodeBlock,FunctionWithRequirements,diff --git a/python/packages/autogen-ext/tests/code_executors/test_docker_commandline_code_executor.py b/python/packages/autogen-ext/tests/code_executors/test_docker_commandline_code_executor.pyindex 25c316115..bee4957f3 100644--- a/python/packages/autogen-ext/tests/code_executors/test_docker_commandline_code_executor.py+++ b/python/packages/autogen-ext/tests/code_executors/test_docker_commandline_code_executor.py@@ -8,7 +8,7 @@ from typing import AsyncGenerator, TypeAliasimport pytestimport pytest_asynciofrom aiofiles import open-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.code_executor import CodeBlockfrom autogen_ext.code_executors import DockerCommandLineCodeExecutordiff --git a/python/packages/autogen-ext/tests/models/test_openai_model_client.py b/python/packages/autogen-ext/tests/models/test_openai_model_client.pyindex b2dc504ab..dfaef0cce 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@@ -3,8 +3,7 @@ from typing import Annotated, Any, AsyncGenerator, List, Tuplefrom unittest.mock import MagicMockimport pytest-from autogen_core.base import CancellationToken-from autogen_core.components import Image+from autogen_core import CancellationToken, Imagefrom autogen_core.components.models import (AssistantMessage,CreateResult,diff --git a/python/packages/autogen-ext/tests/models/test_reply_chat_completion_client.py b/python/packages/autogen-ext/tests/models/test_reply_chat_completion_client.pyindex 2f0ba52a8..6f79188c7 100644--- a/python/packages/autogen-ext/tests/models/test_reply_chat_completion_client.py+++ b/python/packages/autogen-ext/tests/models/test_reply_chat_completion_client.py@@ -3,9 +3,8 @@ from dataclasses import dataclassfrom typing import Listimport pytest+from autogen_core import AgentId, DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handlerfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, MessageContext-from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handlerfrom autogen_core.components.models import ChatCompletionClient, CreateResult, SystemMessage, UserMessagefrom autogen_ext.models import ReplayChatCompletionClientdiff --git a/python/packages/autogen-ext/tests/test_openai_assistant_agent.py b/python/packages/autogen-ext/tests/test_openai_assistant_agent.pyindex efc01dead..f21d510d3 100644--- a/python/packages/autogen-ext/tests/test_openai_assistant_agent.py+++ b/python/packages/autogen-ext/tests/test_openai_assistant_agent.py@@ -4,7 +4,7 @@ from typing import List, Literal, Optional, Unionimport pytestfrom autogen_agentchat.messages import TextMessage-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_core.components.tools._base import BaseTool, Toolfrom autogen_ext.agents import OpenAIAssistantAgentfrom azure.identity import DefaultAzureCredential, get_bearer_token_providerdiff --git a/python/packages/autogen-ext/tests/test_tools.py b/python/packages/autogen-ext/tests/test_tools.pyindex c79d25af3..3c9cf4159 100644--- a/python/packages/autogen-ext/tests/test_tools.py+++ b/python/packages/autogen-ext/tests/test_tools.py@@ -1,7 +1,7 @@from typing import Optional, Typeimport pytest-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom autogen_ext.tools import LangChainToolAdapter # type: ignorefrom langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun, CallbackManagerForToolRunfrom langchain_core.tools import BaseTool as LangChainTooldiff --git a/python/packages/autogen-magentic-one/examples/example.py b/python/packages/autogen-magentic-one/examples/example.pyindex 3274ca458..400e8ddcc 100644--- a/python/packages/autogen-magentic-one/examples/example.py+++ b/python/packages/autogen-magentic-one/examples/example.py@@ -5,9 +5,9 @@ import asyncioimport loggingimport os+from autogen_core import AgentId, AgentProxyfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import AgentId, AgentProxyfrom autogen_core.components.code_executor import CodeBlockfrom autogen_ext.code_executors import DockerCommandLineCodeExecutorfrom autogen_magentic_one.agents.coder import Coder, Executordiff --git a/python/packages/autogen-magentic-one/examples/example_coder.py b/python/packages/autogen-magentic-one/examples/example_coder.pyindex 4824f7338..5e8b36686 100644--- a/python/packages/autogen-magentic-one/examples/example_coder.py+++ b/python/packages/autogen-magentic-one/examples/example_coder.py@@ -7,9 +7,9 @@ round-robin orchestrator agent. The code snippets are executed inside a docker cimport asyncioimport logging+from autogen_core import AgentId, AgentProxyfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import AgentId, AgentProxyfrom autogen_core.components.code_executor import CodeBlockfrom autogen_ext.code_executors import DockerCommandLineCodeExecutorfrom autogen_magentic_one.agents.coder import Coder, Executordiff --git a/python/packages/autogen-magentic-one/examples/example_file_surfer.py b/python/packages/autogen-magentic-one/examples/example_file_surfer.pyindex 9b81ad905..4f752896b 100644--- a/python/packages/autogen-magentic-one/examples/example_file_surfer.py+++ b/python/packages/autogen-magentic-one/examples/example_file_surfer.py@@ -5,9 +5,9 @@ to write input or perform actions, orchestrated by an round-robin orchestrator aimport asyncioimport logging+from autogen_core import AgentId, AgentProxyfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import AgentId, AgentProxyfrom autogen_magentic_one.agents.file_surfer import FileSurferfrom autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxydiff --git a/python/packages/autogen-magentic-one/examples/example_userproxy.py b/python/packages/autogen-magentic-one/examples/example_userproxy.pyindex adf69d0a5..24e907a4f 100644--- a/python/packages/autogen-magentic-one/examples/example_userproxy.py+++ b/python/packages/autogen-magentic-one/examples/example_userproxy.py@@ -7,9 +7,9 @@ The code snippets are not executed in this example."""import asyncioimport logging+from autogen_core import AgentId, AgentProxyfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import AgentId, AgentProxy# from typing import Any, Dict, List, Tuple, Unionfrom autogen_magentic_one.agents.coder import Coderdiff --git a/python/packages/autogen-magentic-one/examples/example_websurfer.py b/python/packages/autogen-magentic-one/examples/example_websurfer.pyindex 99450dab0..302949fbf 100644--- a/python/packages/autogen-magentic-one/examples/example_websurfer.py+++ b/python/packages/autogen-magentic-one/examples/example_websurfer.py@@ -7,9 +7,9 @@ import asyncioimport loggingimport os+from autogen_core import AgentId, AgentProxyfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import AgentId, AgentProxyfrom autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurferfrom autogen_magentic_one.agents.orchestrator import RoundRobinOrchestratorfrom autogen_magentic_one.agents.user_proxy import UserProxydiff --git a/python/packages/autogen-magentic-one/interface/magentic_one_helper.py b/python/packages/autogen-magentic-one/interface/magentic_one_helper.pyindex bf0dd05f6..40edc8ace 100644--- a/python/packages/autogen-magentic-one/interface/magentic_one_helper.py+++ b/python/packages/autogen-magentic-one/interface/magentic_one_helper.py@@ -8,8 +8,8 @@ from dataclasses import asdictfrom autogen_core.application import SingleThreadedAgentRuntimefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import AgentId, AgentProxy-from autogen_core.components import DefaultTopicId+from autogen_core import AgentId, AgentProxy+from autogen_core import DefaultTopicIdfrom autogen_core.components.code_executor import LocalCommandLineCodeExecutorfrom autogen_ext.code_executor.docker_executor import DockerCommandLineCodeExecutorfrom autogen_core.components.code_executor import CodeBlockdiff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_agent.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_agent.pyindex cfca93d33..aa7628115 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_agent.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_agent.py@@ -2,9 +2,8 @@ import asyncioimport loggingfrom typing import Any+from autogen_core import MessageContext, RoutedAgent, message_handlerfrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import MessageContext-from autogen_core.components import RoutedAgent, message_handlerfrom autogen_magentic_one.messages import (AgentEvent,diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_orchestrator.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_orchestrator.pyindex 75a5c2b76..fee0d6c52 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_orchestrator.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_orchestrator.py@@ -2,8 +2,8 @@ import loggingimport timefrom typing import List, Optional+from autogen_core import AgentProxy, CancellationToken, MessageContextfrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import AgentProxy, CancellationToken, MessageContextfrom autogen_core.components.models import AssistantMessage, LLMMessage, UserMessagefrom ..messages import BroadcastMessage, OrchestrationEvent, RequestReplyMessage, ResetMessagediff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_worker.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_worker.pyindex f92b9dede..dadd16021 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_worker.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/base_worker.py@@ -1,6 +1,6 @@from typing import List, Tuple-from autogen_core.base import CancellationToken, MessageContext, TopicId+from autogen_core import CancellationToken, MessageContext, TopicIdfrom autogen_core.components.models import (AssistantMessage,LLMMessage,diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/coder.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/coder.pyindex e8b3e8442..1d3e8dbd2 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/coder.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/coder.py@@ -1,8 +1,7 @@import refrom typing import Awaitable, Callable, List, Literal, Tuple, Union-from autogen_core.base import CancellationToken-from autogen_core.components import default_subscription+from autogen_core import CancellationToken, default_subscriptionfrom autogen_core.components.code_executor import CodeBlock, CodeExecutorfrom autogen_core.components.models import (ChatCompletionClient,diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/file_surfer.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/file_surfer.pyindex af798af5c..3321e9c0a 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/file_surfer.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/file_surfer/file_surfer.py@@ -2,8 +2,7 @@ import jsonimport timefrom typing import List, Optional, Tuple-from autogen_core.base import CancellationToken-from autogen_core.components import FunctionCall, default_subscription+from autogen_core import CancellationToken, FunctionCall, default_subscriptionfrom autogen_core.components.models import (ChatCompletionClient,SystemMessage,diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/multimodal_web_surfer.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/multimodal_web_surfer.pyindex e90c50ff9..94454b80e 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/multimodal_web_surfer.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/multimodal_web_surfer/multimodal_web_surfer.py@@ -12,10 +12,9 @@ from typing import Any, BinaryIO, Dict, List, Optional, Tuple, Union, cast # Anfrom urllib.parse import quote_plus # parse_qs, quote, unquote, urlparse, urlunparseimport aiofiles+from autogen_core import CancellationToken, FunctionCall, default_subscription+from autogen_core import Image as AGImagefrom autogen_core.application.logging import EVENT_LOGGER_NAME-from autogen_core.base import CancellationToken-from autogen_core.components import FunctionCall, default_subscription-from autogen_core.components import Image as AGImagefrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/orchestrator.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/orchestrator.pyindex 986ab3a60..dedd160a2 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/orchestrator.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/orchestrator.py@@ -1,8 +1,7 @@import jsonfrom typing import Any, Dict, List, Optional-from autogen_core.base import AgentProxy, CancellationToken, MessageContext, TopicId-from autogen_core.components import default_subscription+from autogen_core import AgentProxy, CancellationToken, MessageContext, TopicId, default_subscriptionfrom autogen_core.components.models import (AssistantMessage,ChatCompletionClient,diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/user_proxy.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/user_proxy.pyindex 67ef2887b..805983e10 100755--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/user_proxy.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/agents/user_proxy.py@@ -1,8 +1,7 @@import asynciofrom typing import Tuple-from autogen_core.base import CancellationToken-from autogen_core.components import default_subscription+from autogen_core import CancellationToken, default_subscriptionfrom ..messages import UserContentfrom .base_worker import BaseWorkerdiff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/messages.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/messages.pyindex c46ba997b..35020532f 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/messages.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/messages.py@@ -1,7 +1,7 @@from dataclasses import dataclassfrom typing import Any, Dict, List, Union-from autogen_core.components import FunctionCall, Image+from autogen_core import FunctionCall, Imagefrom autogen_core.components.models import FunctionExecutionResult, LLMMessagefrom pydantic import BaseModeldiff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.pyindex 9b4d62a29..36da9fc0f 100644--- a/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py+++ b/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py@@ -5,8 +5,8 @@ from dataclasses import asdictfrom datetime import datetimefrom typing import Any, Dict, List, Literal+from autogen_core import Imagefrom autogen_core.application.logging.events import LLMCallEvent-from autogen_core.components import Imagefrom autogen_core.components.models import (ChatCompletionClient,ModelCapabilities,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.pyindex 769ac5080..9298fd0a6 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@@ -8,9 +8,8 @@ from math import ceilfrom typing import Mappingimport pytest+from autogen_core import AgentId, AgentProxy, FunctionCallfrom autogen_core.application import SingleThreadedAgentRuntime-from autogen_core.base import AgentId, AgentProxy-from autogen_core.components import FunctionCallfrom autogen_core.components.models import (UserMessage,)diff --git a/python/packages/autogen-studio/autogenstudio/teammanager.py b/python/packages/autogen-studio/autogenstudio/teammanager.pyindex 9dcca06c8..bc3e01577 100644--- a/python/packages/autogen-studio/autogenstudio/teammanager.py+++ b/python/packages/autogen-studio/autogenstudio/teammanager.py@@ -3,7 +3,7 @@ from typing import AsyncGenerator, Callable, Optional, Unionfrom autogen_agentchat.base import TaskResultfrom autogen_agentchat.messages import AgentMessage, ChatMessage-from autogen_core.base import CancellationToken+from autogen_core import CancellationTokenfrom .database import Component, ComponentFactoryfrom .datamodel import ComponentConfigInput, TeamResultdiff --git a/python/packages/autogen-studio/autogenstudio/web/managers/connection.py b/python/packages/autogen-studio/autogenstudio/web/managers/connection.pyindex cc83995be..1b7550bdc 100644--- a/python/packages/autogen-studio/autogenstudio/web/managers/connection.py+++ b/python/packages/autogen-studio/autogenstudio/web/managers/connection.py@@ -6,8 +6,8 @@ from uuid import UUIDfrom autogen_agentchat.base._task import TaskResultfrom autogen_agentchat.messages import AgentMessage, ChatMessage, MultiModalMessage, TextMessage-from autogen_core.base import CancellationToken-from autogen_core.components import Image as AGImage+from autogen_core import CancellationToken+from autogen_core import Image as AGImagefrom fastapi import WebSocket, WebSocketDisconnectfrom ...database import DatabaseManagerdiff --git a/python/packages/autogen-studio/notebooks/tutorial.ipynb b/python/packages/autogen-studio/notebooks/tutorial.ipynbindex 2515d1f37..17dbab020 100644--- a/python/packages/autogen-studio/notebooks/tutorial.ipynb+++ b/python/packages/autogen-studio/notebooks/tutorial.ipynb@@ -1,321 +1,320 @@{- "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 file+ "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": null,+ "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": null,+ "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 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+}