ag2 0.9.6__py3-none-any.whl → 0.9.8.post1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ag2 might be problematic. Click here for more details.
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/METADATA +102 -75
- ag2-0.9.8.post1.dist-info/RECORD +387 -0
- autogen/__init__.py +1 -2
- autogen/_website/generate_api_references.py +4 -5
- autogen/_website/generate_mkdocs.py +9 -15
- autogen/_website/notebook_processor.py +13 -14
- autogen/_website/process_notebooks.py +10 -10
- autogen/_website/utils.py +5 -4
- autogen/agentchat/agent.py +13 -13
- autogen/agentchat/assistant_agent.py +7 -6
- autogen/agentchat/contrib/agent_eval/agent_eval.py +3 -3
- autogen/agentchat/contrib/agent_eval/critic_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/quantifier_agent.py +3 -3
- autogen/agentchat/contrib/agent_eval/subcritic_agent.py +3 -3
- autogen/agentchat/contrib/agent_optimizer.py +3 -3
- autogen/agentchat/contrib/capabilities/generate_images.py +11 -11
- autogen/agentchat/contrib/capabilities/teachability.py +15 -15
- autogen/agentchat/contrib/capabilities/transforms.py +17 -18
- autogen/agentchat/contrib/capabilities/transforms_util.py +5 -5
- autogen/agentchat/contrib/capabilities/vision_capability.py +4 -3
- autogen/agentchat/contrib/captainagent/agent_builder.py +30 -30
- autogen/agentchat/contrib/captainagent/captainagent.py +22 -21
- autogen/agentchat/contrib/captainagent/tool_retriever.py +2 -3
- autogen/agentchat/contrib/gpt_assistant_agent.py +9 -9
- autogen/agentchat/contrib/graph_rag/document.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/graph_query_engine.py +3 -3
- autogen/agentchat/contrib/graph_rag/neo4j_graph_query_engine.py +5 -11
- autogen/agentchat/contrib/graph_rag/neo4j_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_query_engine.py +7 -7
- autogen/agentchat/contrib/graph_rag/neo4j_native_graph_rag_capability.py +6 -6
- autogen/agentchat/contrib/img_utils.py +1 -1
- autogen/agentchat/contrib/llamaindex_conversable_agent.py +11 -11
- autogen/agentchat/contrib/llava_agent.py +18 -4
- autogen/agentchat/contrib/math_user_proxy_agent.py +11 -11
- autogen/agentchat/contrib/multimodal_conversable_agent.py +8 -8
- autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +6 -5
- autogen/agentchat/contrib/rag/chromadb_query_engine.py +22 -26
- autogen/agentchat/contrib/rag/llamaindex_query_engine.py +14 -17
- autogen/agentchat/contrib/rag/mongodb_query_engine.py +27 -37
- autogen/agentchat/contrib/rag/query_engine.py +7 -5
- autogen/agentchat/contrib/retrieve_assistant_agent.py +5 -5
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +8 -7
- autogen/agentchat/contrib/society_of_mind_agent.py +15 -14
- autogen/agentchat/contrib/swarm_agent.py +76 -98
- autogen/agentchat/contrib/text_analyzer_agent.py +7 -7
- autogen/agentchat/contrib/vectordb/base.py +10 -18
- autogen/agentchat/contrib/vectordb/chromadb.py +2 -1
- autogen/agentchat/contrib/vectordb/couchbase.py +18 -20
- autogen/agentchat/contrib/vectordb/mongodb.py +6 -5
- autogen/agentchat/contrib/vectordb/pgvectordb.py +40 -41
- autogen/agentchat/contrib/vectordb/qdrant.py +5 -5
- autogen/agentchat/contrib/web_surfer.py +20 -19
- autogen/agentchat/conversable_agent.py +311 -295
- autogen/agentchat/group/context_str.py +1 -3
- autogen/agentchat/group/context_variables.py +15 -25
- autogen/agentchat/group/group_tool_executor.py +10 -10
- autogen/agentchat/group/group_utils.py +15 -15
- autogen/agentchat/group/guardrails.py +7 -7
- autogen/agentchat/group/handoffs.py +19 -36
- autogen/agentchat/group/multi_agent_chat.py +7 -7
- autogen/agentchat/group/on_condition.py +4 -7
- autogen/agentchat/group/on_context_condition.py +4 -7
- autogen/agentchat/group/patterns/auto.py +8 -7
- autogen/agentchat/group/patterns/manual.py +7 -6
- autogen/agentchat/group/patterns/pattern.py +13 -12
- autogen/agentchat/group/patterns/random.py +3 -3
- autogen/agentchat/group/patterns/round_robin.py +3 -3
- autogen/agentchat/group/reply_result.py +2 -4
- autogen/agentchat/group/speaker_selection_result.py +5 -5
- autogen/agentchat/group/targets/group_chat_target.py +7 -6
- autogen/agentchat/group/targets/group_manager_target.py +4 -4
- autogen/agentchat/group/targets/transition_target.py +2 -1
- autogen/agentchat/groupchat.py +58 -61
- autogen/agentchat/realtime/experimental/audio_adapters/twilio_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/audio_adapters/websocket_audio_adapter.py +4 -4
- autogen/agentchat/realtime/experimental/clients/gemini/client.py +7 -7
- autogen/agentchat/realtime/experimental/clients/oai/base_client.py +8 -8
- autogen/agentchat/realtime/experimental/clients/oai/rtc_client.py +6 -6
- autogen/agentchat/realtime/experimental/clients/realtime_client.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_agent.py +10 -9
- autogen/agentchat/realtime/experimental/realtime_observer.py +3 -3
- autogen/agentchat/realtime/experimental/realtime_swarm.py +44 -44
- autogen/agentchat/user_proxy_agent.py +10 -9
- autogen/agentchat/utils.py +3 -3
- autogen/agents/contrib/time/time_reply_agent.py +6 -5
- autogen/agents/contrib/time/time_tool_agent.py +2 -1
- autogen/agents/experimental/deep_research/deep_research.py +3 -3
- autogen/agents/experimental/discord/discord.py +2 -2
- autogen/agents/experimental/document_agent/chroma_query_engine.py +29 -44
- autogen/agents/experimental/document_agent/docling_doc_ingest_agent.py +9 -14
- autogen/agents/experimental/document_agent/document_agent.py +15 -16
- autogen/agents/experimental/document_agent/document_conditions.py +3 -3
- autogen/agents/experimental/document_agent/document_utils.py +5 -9
- autogen/agents/experimental/document_agent/inmemory_query_engine.py +14 -20
- autogen/agents/experimental/document_agent/parser_utils.py +4 -4
- autogen/agents/experimental/document_agent/url_utils.py +14 -23
- autogen/agents/experimental/reasoning/reasoning_agent.py +33 -33
- autogen/agents/experimental/slack/slack.py +2 -2
- autogen/agents/experimental/telegram/telegram.py +2 -3
- autogen/agents/experimental/websurfer/websurfer.py +4 -4
- autogen/agents/experimental/wikipedia/wikipedia.py +5 -7
- autogen/browser_utils.py +8 -8
- autogen/cache/abstract_cache_base.py +5 -5
- autogen/cache/cache.py +12 -12
- autogen/cache/cache_factory.py +4 -4
- autogen/cache/cosmos_db_cache.py +9 -9
- autogen/cache/disk_cache.py +6 -6
- autogen/cache/in_memory_cache.py +4 -4
- autogen/cache/redis_cache.py +4 -4
- autogen/code_utils.py +18 -18
- autogen/coding/base.py +6 -6
- autogen/coding/docker_commandline_code_executor.py +9 -9
- autogen/coding/func_with_reqs.py +7 -6
- autogen/coding/jupyter/base.py +3 -3
- autogen/coding/jupyter/docker_jupyter_server.py +3 -4
- autogen/coding/jupyter/import_utils.py +3 -3
- autogen/coding/jupyter/jupyter_client.py +5 -5
- autogen/coding/jupyter/jupyter_code_executor.py +3 -4
- autogen/coding/jupyter/local_jupyter_server.py +2 -6
- autogen/coding/local_commandline_code_executor.py +8 -7
- autogen/coding/markdown_code_extractor.py +1 -2
- autogen/coding/utils.py +1 -2
- autogen/doc_utils.py +3 -2
- autogen/environments/docker_python_environment.py +19 -29
- autogen/environments/python_environment.py +8 -17
- autogen/environments/system_python_environment.py +3 -4
- autogen/environments/venv_python_environment.py +8 -12
- autogen/environments/working_directory.py +1 -2
- autogen/events/agent_events.py +106 -109
- autogen/events/base_event.py +6 -5
- autogen/events/client_events.py +15 -14
- autogen/events/helpers.py +1 -1
- autogen/events/print_event.py +4 -5
- autogen/fast_depends/_compat.py +10 -15
- autogen/fast_depends/core/build.py +17 -36
- autogen/fast_depends/core/model.py +64 -113
- autogen/fast_depends/dependencies/model.py +2 -1
- autogen/fast_depends/dependencies/provider.py +3 -2
- autogen/fast_depends/library/model.py +4 -4
- autogen/fast_depends/schema.py +7 -7
- autogen/fast_depends/use.py +17 -25
- autogen/fast_depends/utils.py +10 -30
- autogen/formatting_utils.py +6 -6
- autogen/graph_utils.py +1 -4
- autogen/import_utils.py +13 -13
- autogen/interop/crewai/crewai.py +2 -2
- autogen/interop/interoperable.py +2 -2
- autogen/interop/langchain/langchain_chat_model_factory.py +3 -2
- autogen/interop/langchain/langchain_tool.py +2 -6
- autogen/interop/litellm/litellm_config_factory.py +6 -7
- autogen/interop/pydantic_ai/pydantic_ai.py +4 -7
- autogen/interop/registry.py +2 -1
- autogen/io/base.py +5 -5
- autogen/io/run_response.py +33 -32
- autogen/io/websockets.py +6 -5
- autogen/json_utils.py +1 -2
- autogen/llm_config/__init__.py +11 -0
- autogen/llm_config/client.py +58 -0
- autogen/llm_config/config.py +384 -0
- autogen/llm_config/entry.py +154 -0
- autogen/logger/base_logger.py +4 -3
- autogen/logger/file_logger.py +2 -1
- autogen/logger/logger_factory.py +2 -2
- autogen/logger/logger_utils.py +2 -2
- autogen/logger/sqlite_logger.py +3 -2
- autogen/math_utils.py +4 -5
- autogen/mcp/__main__.py +6 -6
- autogen/mcp/helpers.py +4 -4
- autogen/mcp/mcp_client.py +170 -29
- autogen/mcp/mcp_proxy/fastapi_code_generator_helpers.py +3 -4
- autogen/mcp/mcp_proxy/mcp_proxy.py +23 -26
- autogen/mcp/mcp_proxy/operation_grouping.py +4 -5
- autogen/mcp/mcp_proxy/operation_renaming.py +6 -10
- autogen/mcp/mcp_proxy/security.py +2 -3
- autogen/messages/agent_messages.py +96 -98
- autogen/messages/base_message.py +6 -5
- autogen/messages/client_messages.py +15 -14
- autogen/messages/print_message.py +4 -5
- autogen/oai/__init__.py +1 -2
- autogen/oai/anthropic.py +42 -41
- autogen/oai/bedrock.py +68 -57
- autogen/oai/cerebras.py +26 -25
- autogen/oai/client.py +118 -138
- autogen/oai/client_utils.py +3 -3
- autogen/oai/cohere.py +34 -11
- autogen/oai/gemini.py +40 -17
- autogen/oai/gemini_types.py +11 -12
- autogen/oai/groq.py +22 -10
- autogen/oai/mistral.py +17 -11
- autogen/oai/oai_models/__init__.py +14 -2
- autogen/oai/oai_models/_models.py +2 -2
- autogen/oai/oai_models/chat_completion.py +13 -14
- autogen/oai/oai_models/chat_completion_message.py +11 -9
- autogen/oai/oai_models/chat_completion_message_tool_call.py +26 -3
- autogen/oai/oai_models/chat_completion_token_logprob.py +3 -4
- autogen/oai/oai_models/completion_usage.py +8 -9
- autogen/oai/ollama.py +22 -10
- autogen/oai/openai_responses.py +40 -17
- autogen/oai/openai_utils.py +159 -85
- autogen/oai/together.py +29 -14
- autogen/retrieve_utils.py +6 -7
- autogen/runtime_logging.py +5 -4
- autogen/token_count_utils.py +7 -4
- autogen/tools/contrib/time/time.py +0 -1
- autogen/tools/dependency_injection.py +5 -6
- autogen/tools/experimental/browser_use/browser_use.py +10 -10
- autogen/tools/experimental/code_execution/python_code_execution.py +5 -7
- autogen/tools/experimental/crawl4ai/crawl4ai.py +12 -15
- autogen/tools/experimental/deep_research/deep_research.py +9 -8
- autogen/tools/experimental/duckduckgo/duckduckgo_search.py +5 -11
- autogen/tools/experimental/firecrawl/firecrawl_tool.py +98 -115
- autogen/tools/experimental/google/authentication/credentials_local_provider.py +1 -1
- autogen/tools/experimental/google/drive/drive_functions.py +4 -4
- autogen/tools/experimental/google/drive/toolkit.py +5 -5
- autogen/tools/experimental/google_search/google_search.py +5 -5
- autogen/tools/experimental/google_search/youtube_search.py +5 -5
- autogen/tools/experimental/messageplatform/discord/discord.py +8 -12
- autogen/tools/experimental/messageplatform/slack/slack.py +14 -20
- autogen/tools/experimental/messageplatform/telegram/telegram.py +8 -12
- autogen/tools/experimental/perplexity/perplexity_search.py +18 -29
- autogen/tools/experimental/reliable/reliable.py +68 -74
- autogen/tools/experimental/searxng/searxng_search.py +20 -19
- autogen/tools/experimental/tavily/tavily_search.py +12 -19
- autogen/tools/experimental/web_search_preview/web_search_preview.py +13 -7
- autogen/tools/experimental/wikipedia/wikipedia.py +7 -10
- autogen/tools/function_utils.py +7 -7
- autogen/tools/tool.py +6 -5
- autogen/types.py +2 -2
- autogen/version.py +1 -1
- ag2-0.9.6.dist-info/RECORD +0 -421
- autogen/llm_config.py +0 -385
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/WHEEL +0 -0
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.6.dist-info → ag2-0.9.8.post1.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
from abc import ABC
|
|
6
|
+
from collections.abc import Callable
|
|
6
7
|
from copy import deepcopy
|
|
7
|
-
from typing import TYPE_CHECKING, Any,
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
|
|
8
9
|
from uuid import UUID
|
|
9
10
|
|
|
10
11
|
from pydantic import BaseModel, field_validator
|
|
@@ -83,11 +84,11 @@ MessageRole = Literal["assistant", "function", "tool"]
|
|
|
83
84
|
|
|
84
85
|
|
|
85
86
|
class BasePrintReceivedMessage(BaseMessage, ABC):
|
|
86
|
-
content:
|
|
87
|
+
content: str | int | float | bool
|
|
87
88
|
sender_name: str
|
|
88
89
|
recipient_name: str
|
|
89
90
|
|
|
90
|
-
def print(self, f:
|
|
91
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
91
92
|
f = f or print
|
|
92
93
|
f(f"{colored(self.sender_name, 'yellow')} (to {self.recipient_name}):\n", flush=True)
|
|
93
94
|
|
|
@@ -95,11 +96,11 @@ class BasePrintReceivedMessage(BaseMessage, ABC):
|
|
|
95
96
|
@deprecated_by(FunctionResponseEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
|
|
96
97
|
@wrap_message
|
|
97
98
|
class FunctionResponseMessage(BasePrintReceivedMessage):
|
|
98
|
-
name:
|
|
99
|
+
name: str | None = None
|
|
99
100
|
role: MessageRole = "function"
|
|
100
|
-
content:
|
|
101
|
+
content: str | int | float | bool
|
|
101
102
|
|
|
102
|
-
def print(self, f:
|
|
103
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
103
104
|
f = f or print
|
|
104
105
|
super().print(f)
|
|
105
106
|
|
|
@@ -113,11 +114,11 @@ class FunctionResponseMessage(BasePrintReceivedMessage):
|
|
|
113
114
|
|
|
114
115
|
|
|
115
116
|
class ToolResponse(BaseModel):
|
|
116
|
-
tool_call_id:
|
|
117
|
+
tool_call_id: str | None = None
|
|
117
118
|
role: MessageRole = "tool"
|
|
118
|
-
content:
|
|
119
|
+
content: str | int | float | bool
|
|
119
120
|
|
|
120
|
-
def print(self, f:
|
|
121
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
121
122
|
f = f or print
|
|
122
123
|
id = self.tool_call_id or "No id found"
|
|
123
124
|
tool_print = f"***** Response from calling {self.role} ({id}) *****"
|
|
@@ -131,9 +132,9 @@ class ToolResponse(BaseModel):
|
|
|
131
132
|
class ToolResponseMessage(BasePrintReceivedMessage):
|
|
132
133
|
role: MessageRole = "tool"
|
|
133
134
|
tool_responses: list[ToolResponse]
|
|
134
|
-
content:
|
|
135
|
+
content: str | int | float | bool
|
|
135
136
|
|
|
136
|
-
def print(self, f:
|
|
137
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
137
138
|
f = f or print
|
|
138
139
|
super().print(f)
|
|
139
140
|
|
|
@@ -143,10 +144,10 @@ class ToolResponseMessage(BasePrintReceivedMessage):
|
|
|
143
144
|
|
|
144
145
|
|
|
145
146
|
class FunctionCall(BaseModel):
|
|
146
|
-
name:
|
|
147
|
-
arguments:
|
|
147
|
+
name: str | None = None
|
|
148
|
+
arguments: str | None = None
|
|
148
149
|
|
|
149
|
-
def print(self, f:
|
|
150
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
150
151
|
f = f or print
|
|
151
152
|
|
|
152
153
|
name = self.name or "(No function name found)"
|
|
@@ -166,10 +167,10 @@ class FunctionCall(BaseModel):
|
|
|
166
167
|
@deprecated_by(FunctionCallEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
|
|
167
168
|
@wrap_message
|
|
168
169
|
class FunctionCallMessage(BasePrintReceivedMessage):
|
|
169
|
-
content:
|
|
170
|
+
content: str | int | float | bool | None = None # type: ignore [assignment]
|
|
170
171
|
function_call: FunctionCall
|
|
171
172
|
|
|
172
|
-
def print(self, f:
|
|
173
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
173
174
|
f = f or print
|
|
174
175
|
super().print(f)
|
|
175
176
|
|
|
@@ -182,11 +183,11 @@ class FunctionCallMessage(BasePrintReceivedMessage):
|
|
|
182
183
|
|
|
183
184
|
|
|
184
185
|
class ToolCall(BaseModel):
|
|
185
|
-
id:
|
|
186
|
+
id: str | None = None
|
|
186
187
|
function: FunctionCall
|
|
187
188
|
type: str
|
|
188
189
|
|
|
189
|
-
def print(self, f:
|
|
190
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
190
191
|
f = f or print
|
|
191
192
|
|
|
192
193
|
id = self.id or "No tool call id found"
|
|
@@ -208,14 +209,14 @@ class ToolCall(BaseModel):
|
|
|
208
209
|
@deprecated_by(ToolCallEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
|
|
209
210
|
@wrap_message
|
|
210
211
|
class ToolCallMessage(BasePrintReceivedMessage):
|
|
211
|
-
content:
|
|
212
|
-
refusal:
|
|
213
|
-
role:
|
|
214
|
-
audio:
|
|
215
|
-
function_call:
|
|
212
|
+
content: str | int | float | bool | None = None # type: ignore [assignment]
|
|
213
|
+
refusal: str | None = None
|
|
214
|
+
role: MessageRole | None = None
|
|
215
|
+
audio: str | None = None
|
|
216
|
+
function_call: FunctionCall | None = None
|
|
216
217
|
tool_calls: list[ToolCall]
|
|
217
218
|
|
|
218
|
-
def print(self, f:
|
|
219
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
219
220
|
f = f or print
|
|
220
221
|
super().print(f)
|
|
221
222
|
|
|
@@ -231,7 +232,7 @@ class ToolCallMessage(BasePrintReceivedMessage):
|
|
|
231
232
|
@deprecated_by(TextEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
|
|
232
233
|
@wrap_message
|
|
233
234
|
class TextMessage(BasePrintReceivedMessage):
|
|
234
|
-
content:
|
|
235
|
+
content: str | int | float | bool | list[dict[str, str | dict[str, Any]]] | None = None # type: ignore [assignment]
|
|
235
236
|
|
|
236
237
|
@classmethod
|
|
237
238
|
@require_optional_import("PIL", "unknown")
|
|
@@ -242,8 +243,8 @@ class TextMessage(BasePrintReceivedMessage):
|
|
|
242
243
|
@field_validator("content", mode="before")
|
|
243
244
|
@classmethod
|
|
244
245
|
def validate_and_encode_content(
|
|
245
|
-
cls, content:
|
|
246
|
-
) ->
|
|
246
|
+
cls, content: str | int | float | bool | list[dict[str, str | dict[str, Any]]] | None
|
|
247
|
+
) -> str | int | float | bool | list[dict[str, str | dict[str, Any]]] | None:
|
|
247
248
|
if not IS_PIL_AVAILABLE:
|
|
248
249
|
return content
|
|
249
250
|
|
|
@@ -256,7 +257,7 @@ class TextMessage(BasePrintReceivedMessage):
|
|
|
256
257
|
|
|
257
258
|
return content
|
|
258
259
|
|
|
259
|
-
def print(self, f:
|
|
260
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
260
261
|
f = f or print
|
|
261
262
|
super().print(f)
|
|
262
263
|
|
|
@@ -267,11 +268,8 @@ class TextMessage(BasePrintReceivedMessage):
|
|
|
267
268
|
|
|
268
269
|
|
|
269
270
|
def create_received_message_model(
|
|
270
|
-
*, uuid:
|
|
271
|
-
) -> Union[FunctionResponseMessage, ToolResponseMessage, FunctionCallMessage, ToolCallMessage, TextMessage]:
|
|
272
|
-
# print(f"{message=}")
|
|
273
|
-
# print(f"{sender=}")
|
|
274
|
-
|
|
271
|
+
*, uuid: UUID | None = None, message: dict[str, Any], sender: "Agent", recipient: "Agent"
|
|
272
|
+
) -> Union[FunctionResponseMessage, ToolResponseMessage, FunctionCallMessage, ToolCallMessage, TextMessage]: # noqa: UP007
|
|
275
273
|
role = message.get("role")
|
|
276
274
|
if role == "function":
|
|
277
275
|
return FunctionResponseMessage(**message, sender_name=sender.name, recipient_name=recipient.name, uuid=uuid)
|
|
@@ -319,17 +317,17 @@ def create_received_message_model(
|
|
|
319
317
|
@deprecated_by(PostCarryoverProcessingEvent, param_mapping={"sender_name": "sender", "recipient_name": "recipient"})
|
|
320
318
|
@wrap_message
|
|
321
319
|
class PostCarryoverProcessingMessage(BaseMessage):
|
|
322
|
-
carryover:
|
|
320
|
+
carryover: str | list[str | dict[str, Any] | Any]
|
|
323
321
|
message: str
|
|
324
322
|
verbose: bool = False
|
|
325
323
|
|
|
326
324
|
sender_name: str
|
|
327
325
|
recipient_name: str
|
|
328
326
|
summary_method: str
|
|
329
|
-
summary_args:
|
|
330
|
-
max_turns:
|
|
327
|
+
summary_args: dict[str, Any] | None = None
|
|
328
|
+
max_turns: int | None = None
|
|
331
329
|
|
|
332
|
-
def __init__(self, *, uuid:
|
|
330
|
+
def __init__(self, *, uuid: UUID | None = None, chat_info: dict[str, Any]):
|
|
333
331
|
carryover = chat_info.get("carryover", "")
|
|
334
332
|
message = chat_info.get("message")
|
|
335
333
|
verbose = chat_info.get("verbose", False)
|
|
@@ -381,7 +379,7 @@ class PostCarryoverProcessingMessage(BaseMessage):
|
|
|
381
379
|
|
|
382
380
|
return ("\n").join(print_carryover)
|
|
383
381
|
|
|
384
|
-
def print(self, f:
|
|
382
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
385
383
|
f = f or print
|
|
386
384
|
|
|
387
385
|
print_carryover = self._process_carryover()
|
|
@@ -403,21 +401,21 @@ class PostCarryoverProcessingMessage(BaseMessage):
|
|
|
403
401
|
@deprecated_by(ClearAgentsHistoryEvent, param_mapping={"nr_messages_to_preserve": "nr_events_to_preserve"})
|
|
404
402
|
@wrap_message
|
|
405
403
|
class ClearAgentsHistoryMessage(BaseMessage):
|
|
406
|
-
agent_name:
|
|
407
|
-
nr_messages_to_preserve:
|
|
404
|
+
agent_name: str | None = None
|
|
405
|
+
nr_messages_to_preserve: int | None = None
|
|
408
406
|
|
|
409
407
|
def __init__(
|
|
410
408
|
self,
|
|
411
409
|
*,
|
|
412
|
-
uuid:
|
|
410
|
+
uuid: UUID | None = None,
|
|
413
411
|
agent: Optional["Agent"] = None,
|
|
414
|
-
nr_messages_to_preserve:
|
|
412
|
+
nr_messages_to_preserve: int | None = None,
|
|
415
413
|
):
|
|
416
414
|
return super().__init__(
|
|
417
415
|
uuid=uuid, agent_name=agent.name if agent else None, nr_messages_to_preserve=nr_messages_to_preserve
|
|
418
416
|
)
|
|
419
417
|
|
|
420
|
-
def print(self, f:
|
|
418
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
421
419
|
f = f or print
|
|
422
420
|
|
|
423
421
|
if self.agent_name:
|
|
@@ -439,16 +437,16 @@ class SpeakerAttemptSuccessfulMessage(BaseMessage):
|
|
|
439
437
|
mentions: dict[str, int]
|
|
440
438
|
attempt: int
|
|
441
439
|
attempts_left: int
|
|
442
|
-
verbose:
|
|
440
|
+
verbose: bool | None = False
|
|
443
441
|
|
|
444
442
|
def __init__(
|
|
445
443
|
self,
|
|
446
444
|
*,
|
|
447
|
-
uuid:
|
|
445
|
+
uuid: UUID | None = None,
|
|
448
446
|
mentions: dict[str, int],
|
|
449
447
|
attempt: int,
|
|
450
448
|
attempts_left: int,
|
|
451
|
-
select_speaker_auto_verbose:
|
|
449
|
+
select_speaker_auto_verbose: bool | None = False,
|
|
452
450
|
):
|
|
453
451
|
super().__init__(
|
|
454
452
|
uuid=uuid,
|
|
@@ -458,7 +456,7 @@ class SpeakerAttemptSuccessfulMessage(BaseMessage):
|
|
|
458
456
|
verbose=select_speaker_auto_verbose,
|
|
459
457
|
)
|
|
460
458
|
|
|
461
|
-
def print(self, f:
|
|
459
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
462
460
|
f = f or print
|
|
463
461
|
|
|
464
462
|
selected_agent_name = next(iter(self.mentions))
|
|
@@ -477,16 +475,16 @@ class SpeakerAttemptFailedMultipleAgentsMessage(BaseMessage):
|
|
|
477
475
|
mentions: dict[str, int]
|
|
478
476
|
attempt: int
|
|
479
477
|
attempts_left: int
|
|
480
|
-
verbose:
|
|
478
|
+
verbose: bool | None = False
|
|
481
479
|
|
|
482
480
|
def __init__(
|
|
483
481
|
self,
|
|
484
482
|
*,
|
|
485
|
-
uuid:
|
|
483
|
+
uuid: UUID | None = None,
|
|
486
484
|
mentions: dict[str, int],
|
|
487
485
|
attempt: int,
|
|
488
486
|
attempts_left: int,
|
|
489
|
-
select_speaker_auto_verbose:
|
|
487
|
+
select_speaker_auto_verbose: bool | None = False,
|
|
490
488
|
):
|
|
491
489
|
super().__init__(
|
|
492
490
|
uuid=uuid,
|
|
@@ -496,7 +494,7 @@ class SpeakerAttemptFailedMultipleAgentsMessage(BaseMessage):
|
|
|
496
494
|
verbose=select_speaker_auto_verbose,
|
|
497
495
|
)
|
|
498
496
|
|
|
499
|
-
def print(self, f:
|
|
497
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
500
498
|
f = f or print
|
|
501
499
|
|
|
502
500
|
f(
|
|
@@ -514,16 +512,16 @@ class SpeakerAttemptFailedNoAgentsMessage(BaseMessage):
|
|
|
514
512
|
mentions: dict[str, int]
|
|
515
513
|
attempt: int
|
|
516
514
|
attempts_left: int
|
|
517
|
-
verbose:
|
|
515
|
+
verbose: bool | None = False
|
|
518
516
|
|
|
519
517
|
def __init__(
|
|
520
518
|
self,
|
|
521
519
|
*,
|
|
522
|
-
uuid:
|
|
520
|
+
uuid: UUID | None = None,
|
|
523
521
|
mentions: dict[str, int],
|
|
524
522
|
attempt: int,
|
|
525
523
|
attempts_left: int,
|
|
526
|
-
select_speaker_auto_verbose:
|
|
524
|
+
select_speaker_auto_verbose: bool | None = False,
|
|
527
525
|
):
|
|
528
526
|
super().__init__(
|
|
529
527
|
uuid=uuid,
|
|
@@ -533,7 +531,7 @@ class SpeakerAttemptFailedNoAgentsMessage(BaseMessage):
|
|
|
533
531
|
verbose=select_speaker_auto_verbose,
|
|
534
532
|
)
|
|
535
533
|
|
|
536
|
-
def print(self, f:
|
|
534
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
537
535
|
f = f or print
|
|
538
536
|
|
|
539
537
|
f(
|
|
@@ -550,19 +548,19 @@ class SpeakerAttemptFailedNoAgentsMessage(BaseMessage):
|
|
|
550
548
|
class GroupChatResumeMessage(BaseMessage):
|
|
551
549
|
last_speaker_name: str
|
|
552
550
|
messages: list[LLMMessageType]
|
|
553
|
-
verbose:
|
|
551
|
+
verbose: bool | None = False
|
|
554
552
|
|
|
555
553
|
def __init__(
|
|
556
554
|
self,
|
|
557
555
|
*,
|
|
558
|
-
uuid:
|
|
556
|
+
uuid: UUID | None = None,
|
|
559
557
|
last_speaker_name: str,
|
|
560
558
|
messages: list["LLMMessageType"],
|
|
561
|
-
silent:
|
|
559
|
+
silent: bool | None = False,
|
|
562
560
|
):
|
|
563
561
|
super().__init__(uuid=uuid, last_speaker_name=last_speaker_name, messages=messages, verbose=not silent)
|
|
564
562
|
|
|
565
|
-
def print(self, f:
|
|
563
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
566
564
|
f = f or print
|
|
567
565
|
|
|
568
566
|
f(
|
|
@@ -576,12 +574,12 @@ class GroupChatResumeMessage(BaseMessage):
|
|
|
576
574
|
@wrap_message
|
|
577
575
|
class GroupChatRunChatMessage(BaseMessage):
|
|
578
576
|
speaker_name: str
|
|
579
|
-
verbose:
|
|
577
|
+
verbose: bool | None = False
|
|
580
578
|
|
|
581
|
-
def __init__(self, *, uuid:
|
|
579
|
+
def __init__(self, *, uuid: UUID | None = None, speaker: "Agent", silent: bool | None = False):
|
|
582
580
|
super().__init__(uuid=uuid, speaker_name=speaker.name, verbose=not silent)
|
|
583
581
|
|
|
584
|
-
def print(self, f:
|
|
582
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
585
583
|
f = f or print
|
|
586
584
|
|
|
587
585
|
f(colored(f"\nNext speaker: {self.speaker_name}\n", "green"), flush=True)
|
|
@@ -601,7 +599,7 @@ class TerminationAndHumanReplyNoInputMessage(BaseMessage):
|
|
|
601
599
|
def __init__(
|
|
602
600
|
self,
|
|
603
601
|
*,
|
|
604
|
-
uuid:
|
|
602
|
+
uuid: UUID | None = None,
|
|
605
603
|
no_human_input_msg: str,
|
|
606
604
|
sender: Optional["Agent"] = None,
|
|
607
605
|
recipient: "Agent",
|
|
@@ -613,7 +611,7 @@ class TerminationAndHumanReplyNoInputMessage(BaseMessage):
|
|
|
613
611
|
recipient_name=recipient.name,
|
|
614
612
|
)
|
|
615
613
|
|
|
616
|
-
def print(self, f:
|
|
614
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
617
615
|
f = f or print
|
|
618
616
|
|
|
619
617
|
f(colored(f"\n>>>>>>>> {self.no_human_input_msg}", "red"), flush=True)
|
|
@@ -629,7 +627,7 @@ class UsingAutoReplyMessage(BaseMessage):
|
|
|
629
627
|
def __init__(
|
|
630
628
|
self,
|
|
631
629
|
*,
|
|
632
|
-
uuid:
|
|
630
|
+
uuid: UUID | None = None,
|
|
633
631
|
human_input_mode: str,
|
|
634
632
|
sender: Optional["Agent"] = None,
|
|
635
633
|
recipient: "Agent",
|
|
@@ -641,7 +639,7 @@ class UsingAutoReplyMessage(BaseMessage):
|
|
|
641
639
|
recipient_name=recipient.name,
|
|
642
640
|
)
|
|
643
641
|
|
|
644
|
-
def print(self, f:
|
|
642
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
645
643
|
f = f or print
|
|
646
644
|
|
|
647
645
|
f(colored("\n>>>>>>>> USING AUTO REPLY...", "red"), flush=True)
|
|
@@ -657,7 +655,7 @@ class TerminationMessage(BaseMessage):
|
|
|
657
655
|
def __init__(
|
|
658
656
|
self,
|
|
659
657
|
*,
|
|
660
|
-
uuid:
|
|
658
|
+
uuid: UUID | None = None,
|
|
661
659
|
termination_reason: str,
|
|
662
660
|
):
|
|
663
661
|
super().__init__(
|
|
@@ -665,7 +663,7 @@ class TerminationMessage(BaseMessage):
|
|
|
665
663
|
termination_reason=termination_reason,
|
|
666
664
|
)
|
|
667
665
|
|
|
668
|
-
def print(self, f:
|
|
666
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
669
667
|
f = f or print
|
|
670
668
|
|
|
671
669
|
f(colored(f"\n>>>>>>>> TERMINATING RUN ({str(self.uuid)}): {self.termination_reason}", "red"), flush=True)
|
|
@@ -680,13 +678,13 @@ class ExecuteCodeBlockMessage(BaseMessage):
|
|
|
680
678
|
recipient_name: str
|
|
681
679
|
|
|
682
680
|
def __init__(
|
|
683
|
-
self, *, uuid:
|
|
681
|
+
self, *, uuid: UUID | None = None, code: str, language: str, code_block_count: int, recipient: "Agent"
|
|
684
682
|
):
|
|
685
683
|
super().__init__(
|
|
686
684
|
uuid=uuid, code=code, language=language, code_block_count=code_block_count, recipient_name=recipient.name
|
|
687
685
|
)
|
|
688
686
|
|
|
689
|
-
def print(self, f:
|
|
687
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
690
688
|
f = f or print
|
|
691
689
|
|
|
692
690
|
f(
|
|
@@ -702,16 +700,16 @@ class ExecuteCodeBlockMessage(BaseMessage):
|
|
|
702
700
|
@wrap_message
|
|
703
701
|
class ExecuteFunctionMessage(BaseMessage):
|
|
704
702
|
func_name: str
|
|
705
|
-
call_id:
|
|
703
|
+
call_id: str | None = None
|
|
706
704
|
arguments: dict[str, Any]
|
|
707
705
|
recipient_name: str
|
|
708
706
|
|
|
709
707
|
def __init__(
|
|
710
708
|
self,
|
|
711
709
|
*,
|
|
712
|
-
uuid:
|
|
710
|
+
uuid: UUID | None = None,
|
|
713
711
|
func_name: str,
|
|
714
|
-
call_id:
|
|
712
|
+
call_id: str | None = None,
|
|
715
713
|
arguments: dict[str, Any],
|
|
716
714
|
recipient: "Agent",
|
|
717
715
|
):
|
|
@@ -719,7 +717,7 @@ class ExecuteFunctionMessage(BaseMessage):
|
|
|
719
717
|
uuid=uuid, func_name=func_name, call_id=call_id, arguments=arguments, recipient_name=recipient.name
|
|
720
718
|
)
|
|
721
719
|
|
|
722
|
-
def print(self, f:
|
|
720
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
723
721
|
f = f or print
|
|
724
722
|
|
|
725
723
|
f(
|
|
@@ -735,7 +733,7 @@ class ExecuteFunctionMessage(BaseMessage):
|
|
|
735
733
|
@wrap_message
|
|
736
734
|
class ExecutedFunctionMessage(BaseMessage):
|
|
737
735
|
func_name: str
|
|
738
|
-
call_id:
|
|
736
|
+
call_id: str | None = None
|
|
739
737
|
arguments: dict[str, Any]
|
|
740
738
|
content: str
|
|
741
739
|
recipient_name: str
|
|
@@ -743,9 +741,9 @@ class ExecutedFunctionMessage(BaseMessage):
|
|
|
743
741
|
def __init__(
|
|
744
742
|
self,
|
|
745
743
|
*,
|
|
746
|
-
uuid:
|
|
744
|
+
uuid: UUID | None = None,
|
|
747
745
|
func_name: str,
|
|
748
|
-
call_id:
|
|
746
|
+
call_id: str | None = None,
|
|
749
747
|
arguments: dict[str, Any],
|
|
750
748
|
content: str,
|
|
751
749
|
recipient: "Agent",
|
|
@@ -759,7 +757,7 @@ class ExecutedFunctionMessage(BaseMessage):
|
|
|
759
757
|
recipient_name=recipient.name,
|
|
760
758
|
)
|
|
761
759
|
|
|
762
|
-
def print(self, f:
|
|
760
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
763
761
|
f = f or print
|
|
764
762
|
|
|
765
763
|
f(
|
|
@@ -774,13 +772,13 @@ class ExecutedFunctionMessage(BaseMessage):
|
|
|
774
772
|
@deprecated_by(SelectSpeakerEvent)
|
|
775
773
|
@wrap_message
|
|
776
774
|
class SelectSpeakerMessage(BaseMessage):
|
|
777
|
-
agent_names:
|
|
775
|
+
agent_names: list[str] | None = None
|
|
778
776
|
|
|
779
|
-
def __init__(self, *, uuid:
|
|
777
|
+
def __init__(self, *, uuid: UUID | None = None, agents: list["Agent"] | None = None):
|
|
780
778
|
agent_names = [agent.name for agent in agents] if agents else None
|
|
781
779
|
super().__init__(uuid=uuid, agent_names=agent_names)
|
|
782
780
|
|
|
783
|
-
def print(self, f:
|
|
781
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
784
782
|
f = f or print
|
|
785
783
|
|
|
786
784
|
f("Please select the next speaker from the following list:")
|
|
@@ -793,13 +791,13 @@ class SelectSpeakerMessage(BaseMessage):
|
|
|
793
791
|
@wrap_message
|
|
794
792
|
class SelectSpeakerTryCountExceededMessage(BaseMessage):
|
|
795
793
|
try_count: int
|
|
796
|
-
agent_names:
|
|
794
|
+
agent_names: list[str] | None = None
|
|
797
795
|
|
|
798
|
-
def __init__(self, *, uuid:
|
|
796
|
+
def __init__(self, *, uuid: UUID | None = None, try_count: int, agents: list["Agent"] | None = None):
|
|
799
797
|
agent_names = [agent.name for agent in agents] if agents else None
|
|
800
798
|
super().__init__(uuid=uuid, try_count=try_count, agent_names=agent_names)
|
|
801
799
|
|
|
802
|
-
def print(self, f:
|
|
800
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
803
801
|
f = f or print
|
|
804
802
|
|
|
805
803
|
f(f"You have tried {self.try_count} times. The next speaker will be selected automatically.")
|
|
@@ -808,13 +806,13 @@ class SelectSpeakerTryCountExceededMessage(BaseMessage):
|
|
|
808
806
|
@deprecated_by(SelectSpeakerInvalidInputEvent)
|
|
809
807
|
@wrap_message
|
|
810
808
|
class SelectSpeakerInvalidInputMessage(BaseMessage):
|
|
811
|
-
agent_names:
|
|
809
|
+
agent_names: list[str] | None = None
|
|
812
810
|
|
|
813
|
-
def __init__(self, *, uuid:
|
|
811
|
+
def __init__(self, *, uuid: UUID | None = None, agents: list["Agent"] | None = None):
|
|
814
812
|
agent_names = [agent.name for agent in agents] if agents else None
|
|
815
813
|
super().__init__(uuid=uuid, agent_names=agent_names)
|
|
816
814
|
|
|
817
|
-
def print(self, f:
|
|
815
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
818
816
|
f = f or print
|
|
819
817
|
|
|
820
818
|
f(f"Invalid input. Please enter a number between 1 and {len(self.agent_names or [])}.")
|
|
@@ -830,7 +828,7 @@ class ClearConversableAgentHistoryMessage(BaseMessage):
|
|
|
830
828
|
recipient_name: str
|
|
831
829
|
no_messages_preserved: int
|
|
832
830
|
|
|
833
|
-
def __init__(self, *, uuid:
|
|
831
|
+
def __init__(self, *, uuid: UUID | None = None, agent: "Agent", no_messages_preserved: int | None = None):
|
|
834
832
|
super().__init__(
|
|
835
833
|
uuid=uuid,
|
|
836
834
|
agent_name=agent.name,
|
|
@@ -838,7 +836,7 @@ class ClearConversableAgentHistoryMessage(BaseMessage):
|
|
|
838
836
|
no_messages_preserved=no_messages_preserved,
|
|
839
837
|
)
|
|
840
838
|
|
|
841
|
-
def print(self, f:
|
|
839
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
842
840
|
f = f or print
|
|
843
841
|
|
|
844
842
|
for _ in range(self.no_messages_preserved):
|
|
@@ -853,13 +851,13 @@ class ClearConversableAgentHistoryMessage(BaseMessage):
|
|
|
853
851
|
class ClearConversableAgentHistoryWarningMessage(BaseMessage):
|
|
854
852
|
recipient_name: str
|
|
855
853
|
|
|
856
|
-
def __init__(self, *, uuid:
|
|
854
|
+
def __init__(self, *, uuid: UUID | None = None, recipient: "Agent"):
|
|
857
855
|
super().__init__(
|
|
858
856
|
uuid=uuid,
|
|
859
857
|
recipient_name=recipient.name,
|
|
860
858
|
)
|
|
861
859
|
|
|
862
|
-
def print(self, f:
|
|
860
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
863
861
|
f = f or print
|
|
864
862
|
|
|
865
863
|
f(
|
|
@@ -878,13 +876,13 @@ class ClearConversableAgentHistoryWarningMessage(BaseMessage):
|
|
|
878
876
|
@wrap_message
|
|
879
877
|
class GenerateCodeExecutionReplyMessage(BaseMessage):
|
|
880
878
|
code_block_languages: list[str]
|
|
881
|
-
sender_name:
|
|
879
|
+
sender_name: str | None = None
|
|
882
880
|
recipient_name: str
|
|
883
881
|
|
|
884
882
|
def __init__(
|
|
885
883
|
self,
|
|
886
884
|
*,
|
|
887
|
-
uuid:
|
|
885
|
+
uuid: UUID | None = None,
|
|
888
886
|
code_blocks: list["CodeBlock"],
|
|
889
887
|
sender: Optional["Agent"] = None,
|
|
890
888
|
recipient: "Agent",
|
|
@@ -898,7 +896,7 @@ class GenerateCodeExecutionReplyMessage(BaseMessage):
|
|
|
898
896
|
recipient_name=recipient.name,
|
|
899
897
|
)
|
|
900
898
|
|
|
901
|
-
def print(self, f:
|
|
899
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
902
900
|
f = f or print
|
|
903
901
|
|
|
904
902
|
num_code_blocks = len(self.code_block_languages)
|
|
@@ -925,10 +923,10 @@ class GenerateCodeExecutionReplyMessage(BaseMessage):
|
|
|
925
923
|
class ConversableAgentUsageSummaryNoCostIncurredMessage(BaseMessage):
|
|
926
924
|
recipient_name: str
|
|
927
925
|
|
|
928
|
-
def __init__(self, *, uuid:
|
|
926
|
+
def __init__(self, *, uuid: UUID | None = None, recipient: "Agent"):
|
|
929
927
|
super().__init__(uuid=uuid, recipient_name=recipient.name)
|
|
930
928
|
|
|
931
|
-
def print(self, f:
|
|
929
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
932
930
|
f = f or print
|
|
933
931
|
|
|
934
932
|
f(f"No cost incurred from agent '{self.recipient_name}'.")
|
|
@@ -939,10 +937,10 @@ class ConversableAgentUsageSummaryNoCostIncurredMessage(BaseMessage):
|
|
|
939
937
|
class ConversableAgentUsageSummaryMessage(BaseMessage):
|
|
940
938
|
recipient_name: str
|
|
941
939
|
|
|
942
|
-
def __init__(self, *, uuid:
|
|
940
|
+
def __init__(self, *, uuid: UUID | None = None, recipient: "Agent"):
|
|
943
941
|
super().__init__(uuid=uuid, recipient_name=recipient.name)
|
|
944
942
|
|
|
945
|
-
def print(self, f:
|
|
943
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
946
944
|
f = f or print
|
|
947
945
|
|
|
948
946
|
f(f"Agent '{self.recipient_name}':")
|
autogen/messages/base_message.py
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
from abc import ABC
|
|
7
|
-
from
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
from typing import Annotated, Any, Literal, TypeVar, Union
|
|
8
9
|
from uuid import UUID, uuid4
|
|
9
10
|
|
|
10
11
|
from pydantic import BaseModel, Field, create_model
|
|
@@ -20,7 +21,7 @@ __all__ = ["BaseMessage", "get_annotated_type_for_message_classes", "wrap_messag
|
|
|
20
21
|
class BaseMessage(BaseModel, ABC):
|
|
21
22
|
uuid: UUID
|
|
22
23
|
|
|
23
|
-
def __init__(self, uuid:
|
|
24
|
+
def __init__(self, uuid: UUID | None = None, **kwargs: Any) -> None:
|
|
24
25
|
"""Base message class
|
|
25
26
|
|
|
26
27
|
Args:
|
|
@@ -30,7 +31,7 @@ class BaseMessage(BaseModel, ABC):
|
|
|
30
31
|
uuid = uuid or uuid4()
|
|
31
32
|
super().__init__(uuid=uuid, **kwargs)
|
|
32
33
|
|
|
33
|
-
def print(self, f:
|
|
34
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
34
35
|
"""Print message
|
|
35
36
|
|
|
36
37
|
Args:
|
|
@@ -78,7 +79,7 @@ def wrap_message(message_cls: type[BaseMessage]) -> type[BaseModel]:
|
|
|
78
79
|
else:
|
|
79
80
|
super().__init__(content=message_cls(*args, **data), **data)
|
|
80
81
|
|
|
81
|
-
def print(self, f:
|
|
82
|
+
def print(self, f: Callable[..., Any] | None = None) -> None:
|
|
82
83
|
self.content.print(f) # type: ignore[attr-defined]
|
|
83
84
|
|
|
84
85
|
wrapper_cls = create_model(message_cls.__name__, __base__=WrapperBase)
|
|
@@ -99,7 +100,7 @@ def wrap_message(message_cls: type[BaseMessage]) -> type[BaseModel]:
|
|
|
99
100
|
@export_module("autogen.messages")
|
|
100
101
|
def get_annotated_type_for_message_classes() -> type[Any]:
|
|
101
102
|
# this is a dynamic type so we need to disable the type checker
|
|
102
|
-
union_type = Union[tuple(_message_classes.values())] # type: ignore[valid-type]
|
|
103
|
+
union_type = Union[tuple(_message_classes.values())] # type: ignore[valid-type] # noqa: UP007
|
|
103
104
|
return Annotated[union_type, Field(discriminator="type")] # type: ignore[return-value]
|
|
104
105
|
|
|
105
106
|
|