diff --git a/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/AssistantBench/Templates/MagenticOne/scenario.py index 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 AzureOpenAI from typing import List -from autogen_core.base import AgentId, AgentProxy, TopicId +from autogen_core import AgentId, AgentProxy, TopicId from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME from 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, DefaultTopicId from autogen_core.components.code_executor import LocalCommandLineCodeExecutor from autogen_core.components.models import AssistantMessage diff --git a/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/GAIA/Templates/MagenticOne/scenario.py index 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 AzureOpenAI from typing import List -from autogen_core.base import AgentId, AgentProxy, TopicId +from autogen_core import AgentId, AgentProxy, TopicId from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME from 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, DefaultTopicId from autogen_core.components.code_executor import LocalCommandLineCodeExecutor from autogen_core.components.models import AssistantMessage diff --git a/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py b/python/packages/agbench/benchmarks/HumanEval/Templates/MagenticOne/scenario.py index 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 asyncio import logging -from autogen_core.base import AgentId, AgentProxy, TopicId +from autogen_core import AgentId, AgentProxy, TopicId from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.components import DefaultSubscription, DefaultTopicId +from autogen_core import DefaultSubscription, DefaultTopicId from autogen_core.components.code_executor import LocalCommandLineCodeExecutor from 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.py index 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 nltk from typing import Any, Dict, List, Tuple, Union -from autogen_core.base import AgentId, AgentProxy, TopicId +from autogen_core import AgentId, AgentProxy, TopicId from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.components import DefaultSubscription, DefaultTopicId +from autogen_core import DefaultSubscription, DefaultTopicId from autogen_core.components.code_executor import LocalCommandLineCodeExecutor from 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 orchestrator await 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 you runtime.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 you subscriptions=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 you page = actual_surfer._page cdp_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 you client=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.py index 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 logging import warnings from 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, FunctionCall from autogen_core.components.models import ( AssistantMessage, ChatCompletionClient, @@ -74,7 +73,7 @@ class AssistantAgent(BaseChatAgent): .. code-block:: python import asyncio - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken from autogen_ext.models import OpenAIChatCompletionClient from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.messages import TextMessage @@ -107,7 +106,7 @@ class AssistantAgent(BaseChatAgent): from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.messages import TextMessage from autogen_agentchat.ui import Console - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken async def get_current_time() -> str: @@ -136,7 +135,7 @@ class AssistantAgent(BaseChatAgent): .. code-block:: python import asyncio - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken from autogen_ext.models import OpenAIChatCompletionClient from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.messages import TextMessage diff --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.py index 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, abstractmethod from typing import AsyncGenerator, List, Sequence -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from ..base import ChatAgent, Response, TaskResult from ..messages import AgentMessage, ChatMessage, HandoffMessage, MultiModalMessage, StopMessage, TextMessage diff --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.py index 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 CancellationToken from autogen_core.components.code_executor import CodeBlock, CodeExecutor, extract_markdown_code_blocks from ..base import Response @@ -28,7 +28,7 @@ class CodeExecutorAgent(BaseChatAgent): from autogen_agentchat.agents import CodeExecutorAgent from autogen_agentchat.messages import TextMessage from autogen_ext.code_executors import DockerCommandLineCodeExecutor - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken async 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.py index 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, Image from autogen_core.components.models import ChatCompletionClient from autogen_core.components.models._types import SystemMessage diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py index 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 asyncio from inspect import iscoroutinefunction from typing import Awaitable, Callable, List, Optional, Sequence, Union, cast -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from ..base import Response from ..messages import ChatMessage, HandoffMessage, TextMessage diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py index 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 dataclass from typing import AsyncGenerator, List, Protocol, Sequence, runtime_checkable -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from ..messages import AgentMessage, ChatMessage from ._task import TaskRunner diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_task.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_task.py index 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 dataclass from typing import AsyncGenerator, Protocol, Sequence -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from ..messages import AgentMessage, ChatMessage diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/messages.py b/python/packages/autogen-agentchat/src/autogen_agentchat/messages.py index 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, Image from autogen_core.components.models import FunctionExecutionResult, RequestUsage from pydantic import BaseModel, ConfigDict diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py index 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 uuid from abc import ABC, abstractmethod from 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 SingleThreadedAgentRuntime from ... import EVENT_LOGGER_NAME from ...base import ChatAgent, TaskResult, Team, TerminationCondition @@ -216,7 +217,7 @@ class BaseGroupChat(Team, ABC): from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.conditions import MaxMessageTermination from autogen_agentchat.teams import RoundRobinGroupChat - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken from autogen_ext.models import OpenAIChatCompletionClient @@ -317,7 +318,7 @@ class BaseGroupChat(Team, ABC): from autogen_agentchat.conditions import MaxMessageTermination from autogen_agentchat.ui import Console from autogen_agentchat.teams import RoundRobinGroupChat - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken from autogen_ext.models import OpenAIChatCompletionClient diff --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.py index 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 asyncio from abc import ABC, abstractmethod 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, rpc from ...base import TerminationCondition from ...messages import AgentMessage, ChatMessage, StopMessage diff --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.py index 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, rpc from ...base import ChatAgent, Response from ...messages import ChatMessage diff --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.py index 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 json import logging from 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, rpc from 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.py index 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 asyncio from typing import Any -from autogen_core.base import MessageContext -from autogen_core.components import RoutedAgent +from autogen_core import MessageContext, RoutedAgent class FIFOLock: diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.py b/python/packages/autogen-agentchat/src/autogen_agentchat/ui/_console.py index 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 sys import time from typing import AsyncGenerator, List, Optional, TypeVar, cast -from autogen_core.components import Image +from autogen_core import Image from autogen_core.components.models import RequestUsage from autogen_agentchat.base import Response, TaskResult diff --git a/python/packages/autogen-agentchat/tests/test_assistant_agent.py b/python/packages/autogen-agentchat/tests/test_assistant_agent.py index 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 Image from autogen_core.components.tools import FunctionTool from autogen_ext.models import OpenAIChatCompletionClient from openai.resources.chat.completions import AsyncCompletions diff --git a/python/packages/autogen-agentchat/tests/test_group_chat.py b/python/packages/autogen-agentchat/tests/test_group_chat.py index 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, FunctionCall from autogen_core.components.code_executor import LocalCommandLineCodeExecutor from autogen_core.components.models import FunctionExecutionResult from autogen_core.components.tools import FunctionTool diff --git a/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py b/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py index 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 CancellationToken from autogen_ext.models import ReplayChatCompletionClient from utils import FileLogHandler diff --git a/python/packages/autogen-agentchat/tests/test_sequential_routed_agent.py b/python/packages/autogen-agentchat/tests/test_sequential_routed_agent.py index 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 List import pytest from autogen_agentchat.teams._group_chat._sequential_routed_agent import SequentialRoutedAgent +from autogen_core import AgentId, DefaultTopicId, MessageContext, default_subscription, message_handler from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId, MessageContext -from autogen_core.components import DefaultTopicId, default_subscription, message_handler @dataclass diff --git a/python/packages/autogen-agentchat/tests/test_userproxy_agent.py b/python/packages/autogen-agentchat/tests/test_userproxy_agent.py index 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 pytest from autogen_agentchat.agents import UserProxyAgent from autogen_agentchat.base import Response from autogen_agentchat.messages import ChatMessage, HandoffMessage, TextMessage -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken @pytest.mark.asyncio diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/agents.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.ipynb index 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.py index 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 asyncio import logging from typing import Annotated, Literal +from autogen_core import AgentId, AgentInstantiationContext, AgentRuntime, DefaultSubscription, DefaultTopicId from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId, AgentInstantiationContext, AgentRuntime -from autogen_core.components import DefaultSubscription, DefaultTopicId from autogen_core.components.model_context import BufferedChatCompletionContext from autogen_core.components.models import SystemMessage from autogen_core.components.tools import FunctionTool diff --git a/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.py b/python/packages/autogen-core/samples/common/agents/_chat_completion_agent.py index 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 asyncio import json from 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.py index 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 logging from 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_handler from autogen_core.components.model_context import ChatCompletionContext from autogen_core.components.models import ChatCompletionClient, UserMessage diff --git a/python/packages/autogen-core/samples/common/patterns/_group_chat_utils.py b/python/packages/autogen-core/samples/common/patterns/_group_chat_utils.py index 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 re from typing import Dict, List -from autogen_core.base import AgentProxy +from autogen_core import AgentProxy from autogen_core.components.model_context import ChatCompletionContext from autogen_core.components.models import ChatCompletionClient, SystemMessage, UserMessage diff --git a/python/packages/autogen-core/samples/common/types.py b/python/packages/autogen-core/samples/common/types.py index 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, field from enum import Enum from typing import List, Union -from autogen_core.components import FunctionCall, Image +from autogen_core import FunctionCall, Image from autogen_core.components.models import FunctionExecutionResultMessage diff --git a/python/packages/autogen-core/samples/distributed-group-chat/_agents.py b/python/packages/autogen-core/samples/distributed-group-chat/_agents.py index 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, List from uuid import uuid4 from _types import GroupChatMessage, MessageChunk, RequestToSpeak, UIAgentConfig +from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, message_handler from autogen_core.application import WorkerAgentRuntime -from autogen_core.base import MessageContext -from autogen_core.components import DefaultTopicId, RoutedAgent, message_handler from 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.py index 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, Type import yaml from _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_type from autogen_ext.models import AzureOpenAIClientConfiguration from azure.identity import DefaultAzureCredential, get_bearer_token_provider diff --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.py index 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 warnings from _agents import BaseGroupChatAgent from _types import AppConfig, GroupChatMessage, MessageChunk, RequestToSpeak from _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 WorkerAgentRuntime from autogen_ext.models import AzureOpenAIChatCompletionClient from rich.console import Console from rich.markdown import Markdown diff --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.py index 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 warnings from _agents import GroupChatManager, publish_message_to_ui, publish_message_to_ui_and_backend from _types import AppConfig, GroupChatMessage, MessageChunk, RequestToSpeak from _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 WorkerAgentRuntime from autogen_ext.models import AzureOpenAIChatCompletionClient from rich.console import Console from rich.markdown import Markdown diff --git a/python/packages/autogen-core/samples/distributed-group-chat/run_ui.py b/python/packages/autogen-core/samples/distributed-group-chat/run_ui.py index 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 dependenc from _agents import MessageChunk, UIAgent from _types import AppConfig, GroupChatMessage, RequestToSpeak from _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 WorkerAgentRuntime from chainlit import Message # type: ignore [reportAttributeAccessIssue] from rich.console import Console from rich.markdown import Markdown diff --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.py index 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 warnings from _agents import BaseGroupChatAgent from _types import AppConfig, GroupChatMessage, MessageChunk, RequestToSpeak from _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 WorkerAgentRuntime from autogen_ext.models import AzureOpenAIChatCompletionClient from rich.console import Console from rich.markdown import Markdown diff --git a/python/packages/autogen-core/samples/semantic_router/_agents.py b/python/packages/autogen-core/samples/semantic_router/_agents.py index 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 asyncio import logging from _semantic_router_components import FinalResult, TerminationMessage, UserProxyMessage, WorkerAgentMessage +from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, message_handler from autogen_core.application.logging import TRACE_LOGGER_NAME -from autogen_core.base import MessageContext -from autogen_core.components import DefaultTopicId, RoutedAgent, message_handler logging.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.py index 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 logging from _semantic_router_components import AgentRegistryBase, IntentClassifierBase, TerminationMessage, UserProxyMessage +from autogen_core import DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler from autogen_core.application.logging import TRACE_LOGGER_NAME -from autogen_core.base import MessageContext -from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler logging.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.py index 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, MessageContext from autogen_core.application import WorkerAgentRuntime -from autogen_core.base import MessageContext -from autogen_core.components import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId class 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.py index 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 ThreadPoolExecutor from dataclasses import dataclass from 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 DefaultInterventionHandler from autogen_core.components.model_context import BufferedChatCompletionContext from 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.py index 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 @dataclass diff --git a/python/packages/autogen-core/samples/worker/run_cascading_publisher.py b/python/packages/autogen-core/samples/worker/run_cascading_publisher.py index 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_type from autogen_core.application import WorkerAgentRuntime -from autogen_core.base import try_get_known_serializers_for_type -from autogen_core.components import DefaultTopicId async 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.py index 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 uuid from agents import CascadingAgent, ReceiveMessageEvent +from autogen_core import try_get_known_serializers_for_type from autogen_core.application import WorkerAgentRuntime -from autogen_core.base import try_get_known_serializers_for_type async 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.py index 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 logging from dataclasses import dataclass from 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 @dataclass diff --git a/python/packages/autogen-core/samples/worker/run_worker_rpc.py b/python/packages/autogen-core/samples/worker/run_worker_rpc.py index 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 asyncio import logging from 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 @dataclass diff --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.py index 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 logging import os import 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.path thisdir = 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.py index 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 asyncio import logging from 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_handler from protos.agent_events_pb2 import ConversationClosed, Input, NewMessageReceived, Output # type: ignore input_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__.py index 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.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_agent.py rename to python/packages/autogen-core/src/autogen_core/_agent.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_id.py b/python/packages/autogen-core/src/autogen_core/_agent_id.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_agent_id.py rename to python/packages/autogen-core/src/autogen_core/_agent_id.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_instantiation.py b/python/packages/autogen-core/src/autogen_core/_agent_instantiation.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_agent_instantiation.py rename to python/packages/autogen-core/src/autogen_core/_agent_instantiation.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_metadata.py b/python/packages/autogen-core/src/autogen_core/_agent_metadata.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_agent_metadata.py rename to python/packages/autogen-core/src/autogen_core/_agent_metadata.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_proxy.py b/python/packages/autogen-core/src/autogen_core/_agent_proxy.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_agent_proxy.py rename to python/packages/autogen-core/src/autogen_core/_agent_proxy.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_runtime.py b/python/packages/autogen-core/src/autogen_core/_agent_runtime.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_agent_runtime.py rename to python/packages/autogen-core/src/autogen_core/_agent_runtime.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_agent_type.py b/python/packages/autogen-core/src/autogen_core/_agent_type.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_agent_type.py rename to python/packages/autogen-core/src/autogen_core/_agent_type.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_base_agent.py b/python/packages/autogen-core/src/autogen_core/_base_agent.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_base_agent.py rename to python/packages/autogen-core/src/autogen_core/_base_agent.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_cancellation_token.py b/python/packages/autogen-core/src/autogen_core/_cancellation_token.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_cancellation_token.py rename to python/packages/autogen-core/src/autogen_core/_cancellation_token.py diff --git a/python/packages/autogen-core/src/autogen_core/components/_closure_agent.py b/python/packages/autogen-core/src/autogen_core/_closure_agent.py similarity index 89% rename from python/packages/autogen-core/src/autogen_core/components/_closure_agent.py rename to python/packages/autogen-core/src/autogen_core/_closure_agent.py index 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 annotations import inspect from 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 CantHandleException T = 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.py similarity index 92% rename from python/packages/autogen-core/src/autogen_core/components/_default_subscription.py rename to python/packages/autogen-core/src/autogen_core/_default_subscription.py index 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 SubscriptionInstantiationContext from ._type_subscription import TypeSubscription +from .exceptions import CantHandleException class 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.py similarity index 92% rename from python/packages/autogen-core/src/autogen_core/components/_default_topic.py rename to python/packages/autogen-core/src/autogen_core/_default_topic.py index 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 TopicId class 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.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/components/_function_utils.py rename to python/packages/autogen-core/src/autogen_core/_function_utils.py diff --git a/python/packages/autogen-core/src/autogen_core/components/_image.py b/python/packages/autogen-core/src/autogen_core/_image.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/components/_image.py rename to python/packages/autogen-core/src/autogen_core/_image.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_message_context.py b/python/packages/autogen-core/src/autogen_core/_message_context.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_message_context.py rename to python/packages/autogen-core/src/autogen_core/_message_context.py diff --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.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_message_handler_context.py rename to python/packages/autogen-core/src/autogen_core/_message_handler_context.py diff --git a/python/packages/autogen-core/src/autogen_core/components/_pydantic_compat.py b/python/packages/autogen-core/src/autogen_core/_pydantic_compat.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/components/_pydantic_compat.py rename to python/packages/autogen-core/src/autogen_core/_pydantic_compat.py diff --git a/python/packages/autogen-core/src/autogen_core/components/_routed_agent.py b/python/packages/autogen-core/src/autogen_core/_routed_agent.py similarity index 96% rename from python/packages/autogen-core/src/autogen_core/components/_routed_agent.py rename to python/packages/autogen-core/src/autogen_core/_routed_agent.py index 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 warnings from functools import wraps from 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 CantHandleException logger = logging.getLogger("autogen_core") @@ -423,8 +424,8 @@ class RoutedAgent(BaseAgent): .. code-block:: python from 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.py similarity index 99% rename from python/packages/autogen-core/src/autogen_core/base/_serialization.py rename to python/packages/autogen-core/src/autogen_core/_serialization.py index 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_pb2 from google.protobuf.message import Message from pydantic import BaseModel -from autogen_core.base._type_helpers import is_union +from ._type_helpers import is_union T = TypeVar("T") diff --git a/python/packages/autogen-core/src/autogen_core/base/_subscription.py b/python/packages/autogen-core/src/autogen_core/_subscription.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_subscription.py rename to python/packages/autogen-core/src/autogen_core/_subscription.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_subscription_context.py b/python/packages/autogen-core/src/autogen_core/_subscription_context.py similarity index 96% rename from python/packages/autogen-core/src/autogen_core/base/_subscription_context.py rename to python/packages/autogen-core/src/autogen_core/_subscription_context.py index 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 contextmanager from contextvars import ContextVar from typing import Any, ClassVar, Generator -from autogen_core.base._agent_type import AgentType +from autogen_core._agent_type import AgentType class SubscriptionInstantiationContext: diff --git a/python/packages/autogen-core/src/autogen_core/base/_topic.py b/python/packages/autogen-core/src/autogen_core/_topic.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_topic.py rename to python/packages/autogen-core/src/autogen_core/_topic.py diff --git a/python/packages/autogen-core/src/autogen_core/base/_type_helpers.py b/python/packages/autogen-core/src/autogen_core/_type_helpers.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/base/_type_helpers.py rename to python/packages/autogen-core/src/autogen_core/_type_helpers.py diff --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.py similarity index 96% rename from python/packages/autogen-core/src/autogen_core/base/_type_prefix_subscription.py rename to python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.py index 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 TypePrefixSubscription subscription = 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.py similarity index 89% rename from python/packages/autogen-core/src/autogen_core/components/_type_subscription.py rename to python/packages/autogen-core/src/autogen_core/_type_subscription.py index 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 CantHandleException class TypeSubscription(Subscription): @@ -13,7 +15,7 @@ class TypeSubscription(Subscription): .. code-block:: python - from autogen_core.components import TypeSubscription + from autogen_core import TypeSubscription subscription = 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.py similarity index 100% rename from python/packages/autogen-core/src/autogen_core/components/_types.py rename to python/packages/autogen-core/src/autogen_core/_types.py diff --git a/python/packages/autogen-core/src/autogen_core/application/_helpers.py b/python/packages/autogen-core/src/autogen_core/application/_helpers.py index 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 defaultdict from 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 TopicId async 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.py index 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, Set from opentelemetry.trace import TracerProvider from 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 MessageDroppedException from ..base.intervention import DropMessage, InterventionHandler +from ..exceptions import MessageDroppedException from ._helpers import SubscriptionManager, get_impl from .telemetry import EnvelopeMetadata, MessageRuntimeTracingConfig, TraceHelper, get_telemetry_envelope_metadata diff --git a/python/packages/autogen-core/src/autogen_core/application/_worker_runtime.py b/python/packages/autogen-core/src/autogen_core/application/_worker_runtime.py index 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, deprecated from 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 TypeSubscription from . import _constants from ._constants import GRPC_IMPORT_ERROR_STR from ._helpers import SubscriptionManager, get_impl diff --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.py index 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 logging import signal from typing import Optional, Sequence -from ..base._type_helpers import ChannelArgumentType +from .._type_helpers import ChannelArgumentType from ._constants import GRPC_IMPORT_ERROR_STR from ._worker_runtime_host_servicer import WorkerAgentRuntimeHostServicer diff --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.py index 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, Iterator from asyncio import Future, Task from 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 TypePrefixSubscription from ._constants import GRPC_IMPORT_ERROR_STR from ._helpers import SubscriptionManager diff --git a/python/packages/autogen-core/src/autogen_core/application/logging/events.py b/python/packages/autogen-core/src/autogen_core/application/logging/events.py index 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 json from enum import Enum from typing import Any, cast -from autogen_core.base import AgentId +from autogen_core import AgentId class 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.py index 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 SpanKind from opentelemetry.util import types from typing_extensions import NotRequired -from ...base import AgentId, TopicId +from ... import AgentId, TopicId from ._constants import NAMESPACE logger = 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__.py index 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 +from typing import Any, TypeVar -__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_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: ignore diff --git a/python/packages/autogen-core/src/autogen_core/base/exceptions.py b/python/packages/autogen-core/src/autogen_core/base/exceptions.py index 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", -] +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, +) -class CantHandleException(Exception): +@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: ignore diff --git a/python/packages/autogen-core/src/autogen_core/base/intervention.py b/python/packages/autogen-core/src/autogen_core/base/intervention.py index 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__.py index 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 +from typing import Any, Callable, Type, TypeVar -__all__ = [ - "Image", - "RoutedAgent", - "TypeRoutedAgent", - "ClosureAgent", - "ClosureContext", - "message_handler", - "event", - "rpc", - "FunctionCall", - "TypeSubscription", - "DefaultSubscription", - "DefaultTopicId", - "default_subscription", - "type_subscription", - "TypePrefixSubscription", -] +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): + pass diff --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.py index 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 annotations from dataclasses import dataclass from typing import List, Protocol, runtime_checkable -from autogen_core.base import CancellationToken +from ... import CancellationToken @dataclass diff --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.py index 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, Union from typing_extensions import ParamSpec -from ....base import CancellationToken +from .... import CancellationToken from .._base import CodeBlock, CodeExecutor from .._func_with_reqs import ( FunctionWithRequirements, @@ -69,7 +69,7 @@ class LocalCommandLineCodeExecutor(CodeExecutor): from pathlib import Path import asyncio - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken from autogen_core.components.code_executor import CodeBlock, LocalCommandLineCodeExecutor diff --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.py index 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 FunctionCall from ..models import AssistantMessage, FunctionExecutionResultMessage, LLMMessage, UserMessage from ._chat_completion_context import ChatCompletionContext diff --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.py index 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 CancellationToken from ..tools import Tool, ToolSchema from ._types import CreateResult, LLMMessage, RequestUsage diff --git a/python/packages/autogen-core/src/autogen_core/components/models/_types.py b/python/packages/autogen-core/src/autogen_core/components/models/_types.py index 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 dataclass from typing import List, Literal, Optional, Union -from .. import FunctionCall, Image +from ... import FunctionCall, Image @dataclass diff --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.py index 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 asyncio from typing import List -from ...base import AgentId, AgentRuntime, BaseAgent, CancellationToken -from ...components import FunctionCall +from ... import AgentId, AgentRuntime, BaseAgent, CancellationToken, FunctionCall from ..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.py index 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 json from dataclasses import dataclass from typing import List -from ...base import MessageContext -from .. import FunctionCall, RoutedAgent, message_handler +from ... import FunctionCall, MessageContext, RoutedAgent, message_handler from ..models import FunctionExecutionResult from ..tools import Tool diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_base.py b/python/packages/autogen-core/src/autogen_core/components/tools/_base.py index 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 jsonref from pydantic import BaseModel from typing_extensions import NotRequired -from ...base import CancellationToken -from .._function_utils import normalize_annotated_type +from ... import CancellationToken +from ..._function_utils import normalize_annotated_type T = TypeVar("T", bound=BaseModel, contravariant=True) diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_code_execution.py b/python/packages/autogen-core/src/autogen_core/components/tools/_code_execution.py index 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 CancellationToken from ..code_executor import CodeBlock, CodeExecutor from ._base import BaseTool diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py b/python/packages/autogen-core/src/autogen_core/components/tools/_function_tool.py index 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, Callable from 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:: python import random - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken from autogen_core.components.tools import FunctionTool from typing_extensions import Annotated import asyncio diff --git a/python/packages/autogen-core/src/autogen_core/exceptions.py b/python/packages/autogen-core/src/autogen_core/exceptions.py new file mode 100644 index 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.py index 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, TypeAlias import pytest import pytest_asyncio from aiofiles import open -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from autogen_core.components.code_executor import CodeBlock, LocalCommandLineCodeExecutor diff --git a/python/packages/autogen-core/tests/execution/test_user_defined_functions.py b/python/packages/autogen-core/tests/execution/test_user_defined_functions.py index 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 tempfile import polars import pytest -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from 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.py index 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, AgentRuntime from pytest_mock import MockerFixture from test_utils import NoopAgent diff --git a/python/packages/autogen-core/tests/test_cancellation.py b/python/packages/autogen-core/tests/test_cancellation.py index 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 asyncio from dataclasses import dataclass import 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 @dataclass diff --git a/python/packages/autogen-core/tests/test_closure_agent.py b/python/packages/autogen-core/tests/test_closure_agent.py index 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 asyncio from dataclasses import dataclass import pytest +from autogen_core import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId, MessageContext from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import MessageContext -from autogen_core.components import ClosureAgent, ClosureContext, DefaultSubscription, DefaultTopicId @dataclass diff --git a/python/packages/autogen-core/tests/test_intervention.py b/python/packages/autogen-core/tests/test_intervention.py index 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 AgentId from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId -from autogen_core.base.exceptions import MessageDroppedException from autogen_core.base.intervention import DefaultInterventionHandler, DropMessage +from autogen_core.exceptions import MessageDroppedException from test_utils import LoopbackAgent, MessageType diff --git a/python/packages/autogen-core/tests/test_routed_agent.py b/python/packages/autogen-core/tests/test_routed_agent.py index 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 dataclass from typing import Callable, cast import pytest +from autogen_core import AgentId, MessageContext, RoutedAgent, TopicId, TypeSubscription, event, message_handler, rpc from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId, MessageContext, TopicId -from autogen_core.components import RoutedAgent, TypeSubscription, event, message_handler, rpc from test_utils import LoopbackAgent diff --git a/python/packages/autogen-core/tests/test_runtime.py b/python/packages/autogen-core/tests/test_runtime.py index 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 logging import 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 SingleThreadedAgentRuntime from opentelemetry.sdk.trace import TracerProvider from test_utils import ( CascadingAgent, diff --git a/python/packages/autogen-core/tests/test_serialization.py b/python/packages/autogen-core/tests/test_serialization.py index 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 dataclass from typing import Union import pytest -from autogen_core.base import ( +from autogen_core import Image +from autogen_core._serialization import ( JSON_DATA_CONTENT_TYPE, + PROTOBUF_DATA_CONTENT_TYPE, + DataclassJsonMessageSerializer, MessageSerializer, + PydanticJsonMessageSerializer, SerializationRegistry, try_get_known_serializers_for_type, ) -from autogen_core.base._serialization import ( - PROTOBUF_DATA_CONTENT_TYPE, - DataclassJsonMessageSerializer, - PydanticJsonMessageSerializer, -) -from autogen_core.components import Image from PIL import Image as PILImage from protos.serialization_test_pb2 import NestingProtoMessage, ProtoMessage from pydantic import BaseModel diff --git a/python/packages/autogen-core/tests/test_state.py b/python/packages/autogen-core/tests/test_state.py index 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, Mapping import pytest +from autogen_core import AgentId, BaseAgent, MessageContext from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId, BaseAgent, MessageContext class StatefulAgent(BaseAgent): diff --git a/python/packages/autogen-core/tests/test_subscription.py b/python/packages/autogen-core/tests/test_subscription.py index 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, TypeSubscription from 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 CantHandleException from test_utils import LoopbackAgent, MessageType diff --git a/python/packages/autogen-core/tests/test_tool_agent.py b/python/packages/autogen-core/tests/test_tool_agent.py index 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 json from typing import Any, AsyncGenerator, List, Mapping, Optional, Sequence, Union import pytest +from autogen_core import AgentId, CancellationToken, FunctionCall from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId, CancellationToken -from autogen_core.components import FunctionCall from 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.py index 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 inspect from typing import Annotated, List import 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_signature from autogen_core.components.tools import BaseTool, FunctionTool from autogen_core.components.tools._base import ToolSchema from pydantic import BaseModel, Field, model_serializer diff --git a/python/packages/autogen-core/tests/test_types.py b/python/packages/autogen-core/tests/test_types.py index 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 dataclass from types import NoneType from 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_types from pydantic import BaseModel diff --git a/python/packages/autogen-core/tests/test_utils/__init__.py b/python/packages/autogen-core/tests/test_utils/__init__.py index 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 dataclass from 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 @dataclass diff --git a/python/packages/autogen-core/tests/test_worker_runtime.py b/python/packages/autogen-core/tests/test_worker_runtime.py index 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 os from typing import Any, List import 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, WorkerAgentRuntimeHost from protos.serialization_test_pb2 import ProtoMessage from 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.py index 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, FunctionCall from autogen_core.components.models._types import FunctionExecutionResult from autogen_core.components.tools import FunctionTool, Tool @@ -125,7 +124,7 @@ class OpenAIAssistantAgent(BaseChatAgent): .. code-block:: python from openai import AsyncClient - from autogen_core.base import CancellationToken + from autogen_core import CancellationToken import asyncio from autogen_ext.agents import OpenAIAssistantAgent from autogen_agentchat.messages import TextMessage diff --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.py index 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, FunctionCall from 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.py index 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 cv2 import ffmpeg import numpy as np import whisper -from autogen_core.components import Image as AGImage +from autogen_core import Image as AGImage from 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.py index 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.Image from autogen_agentchat.agents import BaseChatAgent from autogen_agentchat.base import Response from autogen_agentchat.messages import ChatMessage, MultiModalMessage, TextMessage +from autogen_core import CancellationToken, FunctionCall +from autogen_core import Image as AGImage from 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 AGImage from 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.py index 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, Image from autogen_core.components.models import FunctionExecutionResult UserContent = 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.py index 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 Image from ._types import AssistantContent, FunctionExecutionContent, SystemContent, UserContent diff --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.py index 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 CancellationToken from 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.py index 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 Path from types import TracebackType from typing import Any, Callable, ClassVar, List, Optional, ParamSpec, Type, Union -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from 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.py index 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 LLMCallEvent from 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.py index 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 annotations import logging from typing import Any, AsyncGenerator, List, Mapping, Optional, Sequence, Union +from autogen_core import CancellationToken from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import CancellationToken from 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.py index 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 asyncio import inspect from typing import TYPE_CHECKING, Any, Callable, Dict, Type, cast -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from autogen_core.components.tools import BaseTool from pydantic import BaseModel, Field, create_model diff --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.py index 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 tempfile import pytest from anyio import open_file -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from autogen_core.components.code_executor import CodeBlock from autogen_ext.code_executors import ACADynamicSessionsCodeExecutor from azure.identity import DefaultAzureCredential diff --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.py index 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 os import polars import pytest -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from 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.py index 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, TypeAlias import pytest import pytest_asyncio from aiofiles import open -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from autogen_core.components.code_executor import CodeBlock from autogen_ext.code_executors import DockerCommandLineCodeExecutor diff --git a/python/packages/autogen-ext/tests/models/test_openai_model_client.py b/python/packages/autogen-ext/tests/models/test_openai_model_client.py index 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, Tuple from unittest.mock import MagicMock import pytest -from autogen_core.base import CancellationToken -from autogen_core.components import Image +from autogen_core import CancellationToken, Image from 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.py index 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 dataclass from typing import List import pytest +from autogen_core import AgentId, DefaultTopicId, MessageContext, RoutedAgent, default_subscription, message_handler from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId, MessageContext -from autogen_core.components import DefaultTopicId, RoutedAgent, default_subscription, message_handler from autogen_core.components.models import ChatCompletionClient, CreateResult, SystemMessage, UserMessage from autogen_ext.models import ReplayChatCompletionClient diff --git a/python/packages/autogen-ext/tests/test_openai_assistant_agent.py b/python/packages/autogen-ext/tests/test_openai_assistant_agent.py index 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, Union import pytest from autogen_agentchat.messages import TextMessage -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from autogen_core.components.tools._base import BaseTool, Tool from autogen_ext.agents import OpenAIAssistantAgent from azure.identity import DefaultAzureCredential, get_bearer_token_provider diff --git a/python/packages/autogen-ext/tests/test_tools.py b/python/packages/autogen-ext/tests/test_tools.py index 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, Type import pytest -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from autogen_ext.tools import LangChainToolAdapter # type: ignore from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun, CallbackManagerForToolRun from langchain_core.tools import BaseTool as LangChainTool diff --git a/python/packages/autogen-magentic-one/examples/example.py b/python/packages/autogen-magentic-one/examples/example.py index 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 asyncio import logging import os +from autogen_core import AgentId, AgentProxy from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import AgentId, AgentProxy from autogen_core.components.code_executor import CodeBlock from autogen_ext.code_executors import DockerCommandLineCodeExecutor from autogen_magentic_one.agents.coder import Coder, Executor diff --git a/python/packages/autogen-magentic-one/examples/example_coder.py b/python/packages/autogen-magentic-one/examples/example_coder.py index 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 c import asyncio import logging +from autogen_core import AgentId, AgentProxy from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import AgentId, AgentProxy from autogen_core.components.code_executor import CodeBlock from autogen_ext.code_executors import DockerCommandLineCodeExecutor from autogen_magentic_one.agents.coder import Coder, Executor diff --git a/python/packages/autogen-magentic-one/examples/example_file_surfer.py b/python/packages/autogen-magentic-one/examples/example_file_surfer.py index 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 a import asyncio import logging +from autogen_core import AgentId, AgentProxy from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import AgentId, AgentProxy from autogen_magentic_one.agents.file_surfer import FileSurfer from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator from autogen_magentic_one.agents.user_proxy import UserProxy diff --git a/python/packages/autogen-magentic-one/examples/example_userproxy.py b/python/packages/autogen-magentic-one/examples/example_userproxy.py index 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 asyncio import logging +from autogen_core import AgentId, AgentProxy from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import AgentId, AgentProxy # from typing import Any, Dict, List, Tuple, Union from autogen_magentic_one.agents.coder import Coder diff --git a/python/packages/autogen-magentic-one/examples/example_websurfer.py b/python/packages/autogen-magentic-one/examples/example_websurfer.py index 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 asyncio import logging import os +from autogen_core import AgentId, AgentProxy from autogen_core.application import SingleThreadedAgentRuntime from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import AgentId, AgentProxy from autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurfer from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator from autogen_magentic_one.agents.user_proxy import UserProxy diff --git a/python/packages/autogen-magentic-one/interface/magentic_one_helper.py b/python/packages/autogen-magentic-one/interface/magentic_one_helper.py index 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 asdict from autogen_core.application import SingleThreadedAgentRuntime from 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 DefaultTopicId from autogen_core.components.code_executor import LocalCommandLineCodeExecutor from autogen_ext.code_executor.docker_executor import DockerCommandLineCodeExecutor from autogen_core.components.code_executor import CodeBlock diff --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.py index 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 asyncio import logging from typing import Any +from autogen_core import MessageContext, RoutedAgent, message_handler from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import MessageContext -from autogen_core.components import RoutedAgent, message_handler from 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.py index 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 logging import time from typing import List, Optional +from autogen_core import AgentProxy, CancellationToken, MessageContext from autogen_core.application.logging import EVENT_LOGGER_NAME -from autogen_core.base import AgentProxy, CancellationToken, MessageContext from autogen_core.components.models import AssistantMessage, LLMMessage, UserMessage from ..messages import BroadcastMessage, OrchestrationEvent, RequestReplyMessage, ResetMessage diff --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.py index 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, TopicId from 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.py index 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 re from 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_subscription from autogen_core.components.code_executor import CodeBlock, CodeExecutor from 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.py index 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 json import time from 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_subscription from 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.py index 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 # An from urllib.parse import quote_plus # parse_qs, quote, unquote, urlparse, urlunparse import aiofiles +from autogen_core import CancellationToken, FunctionCall, default_subscription +from autogen_core import Image as AGImage from 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 AGImage from 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.py index 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 json from 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_subscription from 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.py index 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 asyncio from typing import Tuple -from autogen_core.base import CancellationToken -from autogen_core.components import default_subscription +from autogen_core import CancellationToken, default_subscription from ..messages import UserContent from .base_worker import BaseWorker diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/messages.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/messages.py index 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 dataclass from typing import Any, Dict, List, Union -from autogen_core.components import FunctionCall, Image +from autogen_core import FunctionCall, Image from autogen_core.components.models import FunctionExecutionResult, LLMMessage from pydantic import BaseModel diff --git a/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py b/python/packages/autogen-magentic-one/src/autogen_magentic_one/utils.py index 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 asdict from datetime import datetime from typing import Any, Dict, List, Literal +from autogen_core import Image from autogen_core.application.logging.events import LLMCallEvent -from autogen_core.components import Image from 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.py index 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 ceil from typing import Mapping import pytest +from autogen_core import AgentId, AgentProxy, FunctionCall from autogen_core.application import SingleThreadedAgentRuntime -from autogen_core.base import AgentId, AgentProxy -from autogen_core.components import FunctionCall from autogen_core.components.models import ( UserMessage, ) diff --git a/python/packages/autogen-studio/autogenstudio/teammanager.py b/python/packages/autogen-studio/autogenstudio/teammanager.py index 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, Union from autogen_agentchat.base import TaskResult from autogen_agentchat.messages import AgentMessage, ChatMessage -from autogen_core.base import CancellationToken +from autogen_core import CancellationToken from .database import Component, ComponentFactory from .datamodel import ComponentConfigInput, TeamResult diff --git a/python/packages/autogen-studio/autogenstudio/web/managers/connection.py b/python/packages/autogen-studio/autogenstudio/web/managers/connection.py index 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 UUID from autogen_agentchat.base._task import TaskResult from 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 AGImage from fastapi import WebSocket, WebSocketDisconnect from ...database import DatabaseManager diff --git a/python/packages/autogen-studio/notebooks/tutorial.ipynb b/python/packages/autogen-studio/notebooks/tutorial.ipynb index 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 = \"guestuser@gmail.com\"\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 = \"guestuser@gmail.com\"\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 +}