ag2 0.9.7__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.7.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 +292 -290
- 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 +2 -1
- 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 +113 -139
- autogen/oai/client_utils.py +3 -3
- autogen/oai/cohere.py +34 -11
- autogen/oai/gemini.py +39 -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 +19 -9
- autogen/oai/openai_responses.py +40 -17
- autogen/oai/openai_utils.py +48 -38
- 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 +8 -6
- autogen/types.py +2 -2
- autogen/version.py +1 -1
- ag2-0.9.7.dist-info/RECORD +0 -421
- autogen/llm_config.py +0 -385
- {ag2-0.9.7.dist-info → ag2-0.9.8.post1.dist-info}/WHEEL +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.8.post1.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.7.dist-info → ag2-0.9.8.post1.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
7
|
|
|
7
8
|
from ..context_variables import ContextVariables
|
|
8
9
|
from ..targets.group_manager_target import GroupManagerSelectionMessage, GroupManagerTarget
|
|
@@ -28,11 +29,11 @@ class AutoPattern(Pattern):
|
|
|
28
29
|
initial_agent: "ConversableAgent",
|
|
29
30
|
agents: list["ConversableAgent"],
|
|
30
31
|
user_agent: Optional["ConversableAgent"] = None,
|
|
31
|
-
group_manager_args:
|
|
32
|
-
context_variables:
|
|
33
|
-
selection_message:
|
|
32
|
+
group_manager_args: dict[str, Any] | None = None,
|
|
33
|
+
context_variables: ContextVariables | None = None,
|
|
34
|
+
selection_message: GroupManagerSelectionMessage | None = None,
|
|
34
35
|
exclude_transit_message: bool = True,
|
|
35
|
-
summary_method:
|
|
36
|
+
summary_method: str | Callable[..., Any] | None = "last_msg",
|
|
36
37
|
):
|
|
37
38
|
"""Initialize the AutoPattern.
|
|
38
39
|
|
|
@@ -70,8 +71,8 @@ class AutoPattern(Pattern):
|
|
|
70
71
|
def prepare_group_chat(
|
|
71
72
|
self,
|
|
72
73
|
max_rounds: int,
|
|
73
|
-
messages:
|
|
74
|
-
) ->
|
|
74
|
+
messages: list[dict[str, Any]] | str,
|
|
75
|
+
) -> tuple[
|
|
75
76
|
list["ConversableAgent"],
|
|
76
77
|
list["ConversableAgent"],
|
|
77
78
|
Optional["ConversableAgent"],
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
7
|
|
|
7
8
|
from ..context_variables import ContextVariables
|
|
8
9
|
from ..group_tool_executor import GroupToolExecutor
|
|
@@ -22,10 +23,10 @@ class ManualPattern(Pattern):
|
|
|
22
23
|
initial_agent: "ConversableAgent",
|
|
23
24
|
agents: list["ConversableAgent"],
|
|
24
25
|
user_agent: Optional["ConversableAgent"] = None,
|
|
25
|
-
group_manager_args:
|
|
26
|
-
context_variables:
|
|
26
|
+
group_manager_args: dict[str, Any] | None = None,
|
|
27
|
+
context_variables: ContextVariables | None = None,
|
|
27
28
|
exclude_transit_message: bool = True,
|
|
28
|
-
summary_method:
|
|
29
|
+
summary_method: str | Callable[..., Any] | None = "last_msg",
|
|
29
30
|
):
|
|
30
31
|
"""Initialize the ManualPattern.
|
|
31
32
|
|
|
@@ -57,8 +58,8 @@ class ManualPattern(Pattern):
|
|
|
57
58
|
def prepare_group_chat(
|
|
58
59
|
self,
|
|
59
60
|
max_rounds: int,
|
|
60
|
-
messages:
|
|
61
|
-
) ->
|
|
61
|
+
messages: list[dict[str, Any]] | str,
|
|
62
|
+
) -> tuple[
|
|
62
63
|
list["ConversableAgent"],
|
|
63
64
|
list["ConversableAgent"],
|
|
64
65
|
Optional["ConversableAgent"],
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
# Uses the group chat or the agents' handoffs to create a pattern
|
|
7
7
|
|
|
8
8
|
from abc import ABC, abstractmethod
|
|
9
|
-
from
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
10
11
|
|
|
11
12
|
from ..context_variables import ContextVariables
|
|
12
13
|
from ..group_utils import (
|
|
@@ -43,11 +44,11 @@ class Pattern(ABC):
|
|
|
43
44
|
initial_agent: "ConversableAgent",
|
|
44
45
|
agents: list["ConversableAgent"],
|
|
45
46
|
user_agent: Optional["ConversableAgent"] = None,
|
|
46
|
-
group_manager_args:
|
|
47
|
-
context_variables:
|
|
48
|
-
group_after_work:
|
|
47
|
+
group_manager_args: dict[str, Any] | None = None,
|
|
48
|
+
context_variables: ContextVariables | None = None,
|
|
49
|
+
group_after_work: TransitionTarget | None = None,
|
|
49
50
|
exclude_transit_message: bool = True,
|
|
50
|
-
summary_method:
|
|
51
|
+
summary_method: str | Callable[..., Any] | None = "last_msg",
|
|
51
52
|
):
|
|
52
53
|
"""Initialize the pattern with the required components.
|
|
53
54
|
|
|
@@ -74,8 +75,8 @@ class Pattern(ABC):
|
|
|
74
75
|
def prepare_group_chat(
|
|
75
76
|
self,
|
|
76
77
|
max_rounds: int,
|
|
77
|
-
messages:
|
|
78
|
-
) ->
|
|
78
|
+
messages: list[dict[str, Any]] | str,
|
|
79
|
+
) -> tuple[
|
|
79
80
|
list["ConversableAgent"],
|
|
80
81
|
list["ConversableAgent"],
|
|
81
82
|
Optional["ConversableAgent"],
|
|
@@ -185,10 +186,10 @@ class Pattern(ABC):
|
|
|
185
186
|
initial_agent: "ConversableAgent",
|
|
186
187
|
agents: list["ConversableAgent"],
|
|
187
188
|
user_agent: Optional["ConversableAgent"] = None,
|
|
188
|
-
group_manager_args:
|
|
189
|
-
context_variables:
|
|
189
|
+
group_manager_args: dict[str, Any] | None = None,
|
|
190
|
+
context_variables: ContextVariables | None = None,
|
|
190
191
|
exclude_transit_message: bool = True,
|
|
191
|
-
summary_method:
|
|
192
|
+
summary_method: str | Callable[..., Any] | None = "last_msg",
|
|
192
193
|
) -> "DefaultPattern":
|
|
193
194
|
"""Create a default pattern with minimal configuration.
|
|
194
195
|
|
|
@@ -228,8 +229,8 @@ class DefaultPattern(Pattern):
|
|
|
228
229
|
def prepare_group_chat(
|
|
229
230
|
self,
|
|
230
231
|
max_rounds: int,
|
|
231
|
-
messages:
|
|
232
|
-
) ->
|
|
232
|
+
messages: list[dict[str, Any]] | str,
|
|
233
|
+
) -> tuple[
|
|
233
234
|
list["ConversableAgent"],
|
|
234
235
|
list["ConversableAgent"],
|
|
235
236
|
Optional["ConversableAgent"],
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Optional
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
6
|
|
|
7
7
|
from ..context_variables import ContextVariables
|
|
8
8
|
from ..targets.transition_target import RandomAgentTarget, TransitionTarget
|
|
@@ -36,8 +36,8 @@ class RandomPattern(Pattern):
|
|
|
36
36
|
def prepare_group_chat(
|
|
37
37
|
self,
|
|
38
38
|
max_rounds: int,
|
|
39
|
-
messages:
|
|
40
|
-
) ->
|
|
39
|
+
messages: list[dict[str, Any]] | str,
|
|
40
|
+
) -> tuple[
|
|
41
41
|
list["ConversableAgent"],
|
|
42
42
|
list["ConversableAgent"],
|
|
43
43
|
Optional["ConversableAgent"],
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Optional
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
6
|
|
|
7
7
|
from ..context_variables import ContextVariables
|
|
8
8
|
from ..targets.transition_target import AgentTarget, TransitionTarget
|
|
@@ -47,8 +47,8 @@ class RoundRobinPattern(Pattern):
|
|
|
47
47
|
def prepare_group_chat(
|
|
48
48
|
self,
|
|
49
49
|
max_rounds: int,
|
|
50
|
-
messages:
|
|
51
|
-
) ->
|
|
50
|
+
messages: list[dict[str, Any]] | str,
|
|
51
|
+
) -> tuple[
|
|
52
52
|
list["ConversableAgent"],
|
|
53
53
|
list["ConversableAgent"],
|
|
54
54
|
Optional["ConversableAgent"],
|
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
__all__ = ["ReplyResult"]
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
from typing import Optional
|
|
10
|
-
|
|
11
9
|
from pydantic import BaseModel
|
|
12
10
|
|
|
13
11
|
from .context_variables import ContextVariables
|
|
@@ -18,8 +16,8 @@ class ReplyResult(BaseModel):
|
|
|
18
16
|
"""Result of a tool call that is used to provide the return message and the target to transition to."""
|
|
19
17
|
|
|
20
18
|
message: str
|
|
21
|
-
target:
|
|
22
|
-
context_variables:
|
|
19
|
+
target: TransitionTarget | None = None
|
|
20
|
+
context_variables: ContextVariables | None = None
|
|
23
21
|
|
|
24
22
|
def __str__(self) -> str:
|
|
25
23
|
"""The string representation for ReplyResult will be just the message."""
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel
|
|
8
8
|
|
|
@@ -19,11 +19,11 @@ class SpeakerSelectionResult(BaseModel):
|
|
|
19
19
|
This class can return an Agent, a None to end the conversation, or a string for a speaker selection method.
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
|
-
terminate:
|
|
23
|
-
agent_name:
|
|
24
|
-
speaker_selection_method:
|
|
22
|
+
terminate: bool | None = None
|
|
23
|
+
agent_name: str | None = None
|
|
24
|
+
speaker_selection_method: str | None = None
|
|
25
25
|
|
|
26
|
-
def get_speaker_selection_result(self, groupchat: "GroupChat") ->
|
|
26
|
+
def get_speaker_selection_result(self, groupchat: "GroupChat") -> Agent | str | None:
|
|
27
27
|
"""Get the speaker selection result. If None, the conversation will end."""
|
|
28
28
|
if self.agent_name is not None:
|
|
29
29
|
# Find the agent by name in the groupchat
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Optional
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel
|
|
8
8
|
|
|
@@ -25,10 +25,11 @@ __all__ = ["GroupChatConfig", "GroupChatTarget"]
|
|
|
25
25
|
class GroupChatConfig(BaseModel):
|
|
26
26
|
"""Configuration for a group chat transition target.
|
|
27
27
|
|
|
28
|
-
Note: If context_variables are not passed in, the outer context variables will be passed in
|
|
28
|
+
Note: If context_variables are not passed in, the outer context variables will be passed in
|
|
29
|
+
"""
|
|
29
30
|
|
|
30
31
|
pattern: "Pattern"
|
|
31
|
-
messages:
|
|
32
|
+
messages: list[dict[str, Any]] | str
|
|
32
33
|
max_rounds: int = 20
|
|
33
34
|
|
|
34
35
|
|
|
@@ -88,10 +89,10 @@ class GroupChatTarget(TransitionTarget):
|
|
|
88
89
|
# Define the reply function that will run the group chat
|
|
89
90
|
def group_chat_reply(
|
|
90
91
|
agent: "ConversableAgent",
|
|
91
|
-
messages:
|
|
92
|
+
messages: list[dict[str, Any]] | None = None,
|
|
92
93
|
sender: Optional["Agent"] = None,
|
|
93
|
-
config:
|
|
94
|
-
) -> tuple[bool,
|
|
94
|
+
config: Any | None = None,
|
|
95
|
+
) -> tuple[bool, dict[str, Any] | None]:
|
|
95
96
|
"""Run the inner group chat and return its results as a reply."""
|
|
96
97
|
# Get the configuration stored directly on the agent
|
|
97
98
|
group_config = agent._group_chat_config # type: ignore[attr-defined]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Optional
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel, field_validator
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ __all__ = ["GroupManagerTarget"]
|
|
|
24
24
|
def prepare_groupchat_auto_speaker(
|
|
25
25
|
groupchat: "GroupChat",
|
|
26
26
|
last_group_agent: "ConversableAgent",
|
|
27
|
-
group_chat_manager_selection_msg:
|
|
27
|
+
group_chat_manager_selection_msg: Any | None,
|
|
28
28
|
) -> None:
|
|
29
29
|
"""Prepare the group chat for auto speaker selection, includes updating or restore the groupchat speaker selection message.
|
|
30
30
|
|
|
@@ -88,7 +88,7 @@ class GroupManagerSelectionMessageContextStr(GroupManagerSelectionMessage):
|
|
|
88
88
|
# We will replace {agentlist} with another term and return it later for use with the internal group chat auto speaker selection
|
|
89
89
|
# Otherwise our format will fail
|
|
90
90
|
@field_validator("context_str_template", mode="before")
|
|
91
|
-
def _replace_agentlist_placeholder(cls:
|
|
91
|
+
def _replace_agentlist_placeholder(cls: type["GroupManagerSelectionMessageContextStr"], v: Any) -> str | Any: # noqa: N805
|
|
92
92
|
"""Replace {agentlist} placeholder before validation/assignment."""
|
|
93
93
|
if isinstance(v, str):
|
|
94
94
|
if "{agentlist}" in v:
|
|
@@ -112,7 +112,7 @@ class GroupManagerSelectionMessageContextStr(GroupManagerSelectionMessage):
|
|
|
112
112
|
class GroupManagerTarget(TransitionTarget):
|
|
113
113
|
"""Target that represents an agent by name."""
|
|
114
114
|
|
|
115
|
-
selection_message:
|
|
115
|
+
selection_message: GroupManagerSelectionMessage | None = None
|
|
116
116
|
|
|
117
117
|
def can_resolve_for_speaker_selection(self) -> bool:
|
|
118
118
|
"""Check if the target can resolve for speaker selection."""
|
|
@@ -71,7 +71,8 @@ class TransitionTarget(BaseModel):
|
|
|
71
71
|
def activate_target(self, groupchat: "GroupChat") -> None:
|
|
72
72
|
"""Activate the target in the groupchat, setting the next target for GroupToolExecutor.
|
|
73
73
|
|
|
74
|
-
The Tool Executor's next target attribute will be picked up on the next iteration when _determine_next_agent is called
|
|
74
|
+
The Tool Executor's next target attribute will be picked up on the next iteration when _determine_next_agent is called
|
|
75
|
+
"""
|
|
75
76
|
for agent in groupchat.agents: # type: ignore[attr-defined]
|
|
76
77
|
# get the GroupToolExecutor agent
|
|
77
78
|
if type(agent).__name__ == "GroupToolExecutor":
|
autogen/agentchat/groupchat.py
CHANGED
|
@@ -10,8 +10,9 @@ import logging
|
|
|
10
10
|
import random
|
|
11
11
|
import re
|
|
12
12
|
import sys
|
|
13
|
+
from collections.abc import Callable
|
|
13
14
|
from dataclasses import dataclass, field
|
|
14
|
-
from typing import Any,
|
|
15
|
+
from typing import Any, Literal
|
|
15
16
|
|
|
16
17
|
from ..code_utils import content_str
|
|
17
18
|
from ..doc_utils import export_module
|
|
@@ -30,8 +31,7 @@ from ..events.agent_events import (
|
|
|
30
31
|
from ..exception_utils import AgentNameConflictError, NoEligibleSpeakerError, UndefinedNextAgentError
|
|
31
32
|
from ..graph_utils import check_graph_validity, invert_disallowed_to_allowed
|
|
32
33
|
from ..io.base import IOStream
|
|
33
|
-
from ..llm_config import LLMConfig
|
|
34
|
-
from ..oai.client import ModelClient
|
|
34
|
+
from ..llm_config import LLMConfig, ModelClient
|
|
35
35
|
from ..runtime_logging import log_new_agent, logging_enabled
|
|
36
36
|
from .agent import Agent
|
|
37
37
|
from .contrib.capabilities import transform_messages
|
|
@@ -134,10 +134,10 @@ class GroupChat:
|
|
|
134
134
|
max_round: int = 10
|
|
135
135
|
admin_name: str = "Admin"
|
|
136
136
|
func_call_filter: bool = True
|
|
137
|
-
speaker_selection_method:
|
|
137
|
+
speaker_selection_method: Literal["auto", "manual", "random", "round_robin"] | Callable[..., Any] = "auto"
|
|
138
138
|
max_retries_for_selecting_speaker: int = 2
|
|
139
|
-
allow_repeat_speaker:
|
|
140
|
-
allowed_or_disallowed_speaker_transitions:
|
|
139
|
+
allow_repeat_speaker: bool | list[Agent] | None = None
|
|
140
|
+
allowed_or_disallowed_speaker_transitions: dict[str, Any] | None = None
|
|
141
141
|
speaker_transitions_type: Literal["allowed", "disallowed", None] = None
|
|
142
142
|
enable_clear_history: bool = False
|
|
143
143
|
send_introductions: bool = False
|
|
@@ -159,11 +159,11 @@ class GroupChat:
|
|
|
159
159
|
The names are case-sensitive and should not be abbreviated or changed.
|
|
160
160
|
The only names that are accepted are {agentlist}.
|
|
161
161
|
Respond with ONLY the name of the speaker and DO NOT provide a reason."""
|
|
162
|
-
select_speaker_transform_messages:
|
|
163
|
-
select_speaker_auto_verbose:
|
|
164
|
-
select_speaker_auto_model_client_cls:
|
|
165
|
-
select_speaker_auto_llm_config:
|
|
166
|
-
role_for_select_speaker_messages:
|
|
162
|
+
select_speaker_transform_messages: transform_messages.TransformMessages | None = None
|
|
163
|
+
select_speaker_auto_verbose: bool | None = False
|
|
164
|
+
select_speaker_auto_model_client_cls: ModelClient | list[ModelClient] | None = None
|
|
165
|
+
select_speaker_auto_llm_config: LLMConfig | dict[str, Any] | Literal[False] | None = None
|
|
166
|
+
role_for_select_speaker_messages: str | None = "system"
|
|
167
167
|
|
|
168
168
|
_VALID_SPEAKER_SELECTION_METHODS = ["auto", "manual", "random", "round_robin"]
|
|
169
169
|
_VALID_SPEAKER_TRANSITIONS_TYPE = ["allowed", "disallowed", None]
|
|
@@ -315,9 +315,7 @@ class GroupChat:
|
|
|
315
315
|
message["content"] = content_str(message["content"])
|
|
316
316
|
self.messages.append(message)
|
|
317
317
|
|
|
318
|
-
def agent_by_name(
|
|
319
|
-
self, name: str, recursive: bool = False, raise_on_name_conflict: bool = False
|
|
320
|
-
) -> Optional[Agent]:
|
|
318
|
+
def agent_by_name(self, name: str, recursive: bool = False, raise_on_name_conflict: bool = False) -> Agent | None:
|
|
321
319
|
"""Returns the agent with a given name. If recursive is True, it will search in nested teams."""
|
|
322
320
|
agents = self.nested_agents() if recursive else self.agents
|
|
323
321
|
filtered_agents = [agent for agent in agents if agent.name == name]
|
|
@@ -336,7 +334,7 @@ class GroupChat:
|
|
|
336
334
|
agents.extend(agent.groupchat.nested_agents())
|
|
337
335
|
return agents
|
|
338
336
|
|
|
339
|
-
def next_agent(self, agent: Agent, agents:
|
|
337
|
+
def next_agent(self, agent: Agent, agents: list[Agent] | None = None) -> Agent:
|
|
340
338
|
"""Return the next agent in the list."""
|
|
341
339
|
if agents is None:
|
|
342
340
|
agents = self.agents
|
|
@@ -360,7 +358,7 @@ class GroupChat:
|
|
|
360
358
|
# Explicitly handle cases where no valid next agent exists in the provided subset.
|
|
361
359
|
raise UndefinedNextAgentError()
|
|
362
360
|
|
|
363
|
-
def select_speaker_msg(self, agents:
|
|
361
|
+
def select_speaker_msg(self, agents: list[Agent] | None = None) -> str:
|
|
364
362
|
"""Return the system message for selecting the next speaker. This is always the *first* message in the context."""
|
|
365
363
|
if agents is None:
|
|
366
364
|
agents = self.agents
|
|
@@ -371,7 +369,7 @@ class GroupChat:
|
|
|
371
369
|
return_msg = self.select_speaker_message_template.format(roles=roles, agentlist=agentlist)
|
|
372
370
|
return return_msg
|
|
373
371
|
|
|
374
|
-
def select_speaker_prompt(self, agents:
|
|
372
|
+
def select_speaker_prompt(self, agents: list[Agent] | None = None) -> str:
|
|
375
373
|
"""Return the floating system prompt selecting the next speaker.
|
|
376
374
|
This is always the *last* message in the context.
|
|
377
375
|
Will return None if the select_speaker_prompt_template is None.
|
|
@@ -387,7 +385,7 @@ class GroupChat:
|
|
|
387
385
|
return_prompt = f"{self.select_speaker_prompt_template}".replace("{agentlist}", agentlist)
|
|
388
386
|
return return_prompt
|
|
389
387
|
|
|
390
|
-
def introductions_msg(self, agents:
|
|
388
|
+
def introductions_msg(self, agents: list[Agent] | None = None) -> str:
|
|
391
389
|
"""Return the system message for selecting the next speaker. This is always the *first* message in the context."""
|
|
392
390
|
if agents is None:
|
|
393
391
|
agents = self.agents
|
|
@@ -398,7 +396,7 @@ class GroupChat:
|
|
|
398
396
|
|
|
399
397
|
return f"{intro_msg}\n\n{participant_roles}"
|
|
400
398
|
|
|
401
|
-
def manual_select_speaker(self, agents:
|
|
399
|
+
def manual_select_speaker(self, agents: list[Agent] | None = None) -> Agent | None:
|
|
402
400
|
"""Manually select the next speaker."""
|
|
403
401
|
iostream = IOStream.get_default()
|
|
404
402
|
|
|
@@ -429,7 +427,7 @@ class GroupChat:
|
|
|
429
427
|
iostream.send(SelectSpeakerInvalidInputEvent(agents=agents))
|
|
430
428
|
return None
|
|
431
429
|
|
|
432
|
-
def random_select_speaker(self, agents:
|
|
430
|
+
def random_select_speaker(self, agents: list[Agent] | None = None) -> Agent | None:
|
|
433
431
|
"""Randomly select the next speaker."""
|
|
434
432
|
if agents is None:
|
|
435
433
|
agents = self.agents
|
|
@@ -438,7 +436,7 @@ class GroupChat:
|
|
|
438
436
|
def _prepare_and_select_agents(
|
|
439
437
|
self,
|
|
440
438
|
last_speaker: Agent,
|
|
441
|
-
) -> tuple[
|
|
439
|
+
) -> tuple[Agent | None, list[Agent], list[dict[str, Any]] | None]:
|
|
442
440
|
# If self.speaker_selection_method is a callable, call it to get the next speaker.
|
|
443
441
|
# If self.speaker_selection_method is a string, return it.
|
|
444
442
|
speaker_selection_method = self.speaker_selection_method
|
|
@@ -591,7 +589,7 @@ class GroupChat:
|
|
|
591
589
|
# auto speaker selection with 2-agent chat
|
|
592
590
|
return await self.a_auto_select_speaker(last_speaker, selector, messages, agents)
|
|
593
591
|
|
|
594
|
-
def _finalize_speaker(self, last_speaker: Agent, final: bool, name: str, agents:
|
|
592
|
+
def _finalize_speaker(self, last_speaker: Agent, final: bool, name: str, agents: list[Agent] | None) -> Agent:
|
|
595
593
|
if not final:
|
|
596
594
|
# the LLM client is None, thus no reply is generated. Use round robin instead.
|
|
597
595
|
return self.next_agent(last_speaker, agents)
|
|
@@ -653,7 +651,7 @@ class GroupChat:
|
|
|
653
651
|
self._register_client_from_config(agent, self.select_speaker_auto_llm_config)
|
|
654
652
|
|
|
655
653
|
def _create_internal_agents(
|
|
656
|
-
self, agents, max_attempts, messages, validate_speaker_name, selector:
|
|
654
|
+
self, agents, max_attempts, messages, validate_speaker_name, selector: ConversableAgent | None = None
|
|
657
655
|
):
|
|
658
656
|
checking_agent = ConversableAgent("checking_agent", default_auto_reply=max_attempts)
|
|
659
657
|
|
|
@@ -691,8 +689,8 @@ class GroupChat:
|
|
|
691
689
|
self,
|
|
692
690
|
last_speaker: Agent,
|
|
693
691
|
selector: ConversableAgent,
|
|
694
|
-
messages:
|
|
695
|
-
agents:
|
|
692
|
+
messages: list[dict[str, Any]] | None,
|
|
693
|
+
agents: list[Agent] | None,
|
|
696
694
|
) -> Agent:
|
|
697
695
|
"""Selects next speaker for the "auto" speaker selection method. Utilises its own two-agent chat to determine the next speaker and supports requerying.
|
|
698
696
|
|
|
@@ -726,9 +724,7 @@ class GroupChat:
|
|
|
726
724
|
attempt = 0
|
|
727
725
|
|
|
728
726
|
# Registered reply function for checking_agent, checks the result of the response for agent names
|
|
729
|
-
def validate_speaker_name(
|
|
730
|
-
recipient, messages, sender, config
|
|
731
|
-
) -> tuple[bool, Optional[Union[str, dict[str, Any]]]]:
|
|
727
|
+
def validate_speaker_name(recipient, messages, sender, config) -> tuple[bool, str | dict[str, Any] | None]:
|
|
732
728
|
# The number of retries left, starting at max_retries_for_selecting_speaker
|
|
733
729
|
nonlocal attempts_left
|
|
734
730
|
nonlocal attempt
|
|
@@ -776,8 +772,8 @@ class GroupChat:
|
|
|
776
772
|
self,
|
|
777
773
|
last_speaker: Agent,
|
|
778
774
|
selector: ConversableAgent,
|
|
779
|
-
messages:
|
|
780
|
-
agents:
|
|
775
|
+
messages: list[dict[str, Any]] | None,
|
|
776
|
+
agents: list[Agent] | None,
|
|
781
777
|
) -> Agent:
|
|
782
778
|
"""(Asynchronous) Selects next speaker for the "auto" speaker selection method. Utilises its own two-agent chat to determine the next speaker and supports requerying.
|
|
783
779
|
|
|
@@ -810,9 +806,7 @@ class GroupChat:
|
|
|
810
806
|
attempt = 0
|
|
811
807
|
|
|
812
808
|
# Registered reply function for checking_agent, checks the result of the response for agent names
|
|
813
|
-
def validate_speaker_name(
|
|
814
|
-
recipient, messages, sender, config
|
|
815
|
-
) -> tuple[bool, Optional[Union[str, dict[str, Any]]]]:
|
|
809
|
+
def validate_speaker_name(recipient, messages, sender, config) -> tuple[bool, str | dict[str, Any] | None]:
|
|
816
810
|
# The number of retries left, starting at max_retries_for_selecting_speaker
|
|
817
811
|
nonlocal attempts_left
|
|
818
812
|
nonlocal attempt
|
|
@@ -857,21 +851,22 @@ class GroupChat:
|
|
|
857
851
|
|
|
858
852
|
def _validate_speaker_name(
|
|
859
853
|
self, recipient, messages, sender, config, attempts_left, attempt, agents
|
|
860
|
-
) -> tuple[bool,
|
|
854
|
+
) -> tuple[bool, str | dict[str, Any] | None]:
|
|
861
855
|
"""Validates the speaker response for each round in the internal 2-agent
|
|
862
856
|
chat within the auto select speaker method.
|
|
863
857
|
|
|
864
858
|
Used by auto_select_speaker and a_auto_select_speaker.
|
|
865
859
|
"""
|
|
866
860
|
# Validate the speaker name selected
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
861
|
+
if messages and (name := messages[-1].get("content")):
|
|
862
|
+
mentions = self._mentioned_agents(name.strip(), agents)
|
|
863
|
+
else:
|
|
864
|
+
mentions = []
|
|
865
|
+
no_of_mentions = len(mentions)
|
|
870
866
|
|
|
871
867
|
# Output the query and requery results
|
|
872
868
|
if self.select_speaker_auto_verbose:
|
|
873
869
|
iostream = IOStream.get_default()
|
|
874
|
-
no_of_mentions = len(mentions)
|
|
875
870
|
if no_of_mentions == 1:
|
|
876
871
|
# Success on retry, we have just one name mentioned
|
|
877
872
|
iostream.send(
|
|
@@ -901,14 +896,14 @@ class GroupChat:
|
|
|
901
896
|
)
|
|
902
897
|
)
|
|
903
898
|
|
|
904
|
-
if
|
|
899
|
+
if no_of_mentions == 1:
|
|
905
900
|
# Success on retry, we have just one name mentioned
|
|
906
901
|
selected_agent_name = next(iter(mentions))
|
|
907
902
|
|
|
908
903
|
# Add the selected agent to the response so we can return it
|
|
909
904
|
messages.append({"role": "user", "content": f"[AGENT SELECTED]{selected_agent_name}"})
|
|
910
905
|
|
|
911
|
-
elif
|
|
906
|
+
elif no_of_mentions > 1:
|
|
912
907
|
# More than one name on requery so add additional reminder prompt for next retry
|
|
913
908
|
|
|
914
909
|
if attempts_left:
|
|
@@ -948,7 +943,7 @@ class GroupChat:
|
|
|
948
943
|
|
|
949
944
|
return True, None
|
|
950
945
|
|
|
951
|
-
def _process_speaker_selection_result(self, result, last_speaker: ConversableAgent, agents:
|
|
946
|
+
def _process_speaker_selection_result(self, result, last_speaker: ConversableAgent, agents: list[Agent] | None):
|
|
952
947
|
"""Checks the result of the auto_select_speaker function, returning the
|
|
953
948
|
agent to speak.
|
|
954
949
|
|
|
@@ -983,7 +978,7 @@ class GroupChat:
|
|
|
983
978
|
roles.append(f"{agent.name}: {agent.description}".strip())
|
|
984
979
|
return "\n".join(roles)
|
|
985
980
|
|
|
986
|
-
def _mentioned_agents(self, message_content:
|
|
981
|
+
def _mentioned_agents(self, message_content: str | list, agents: list[Agent] | None) -> dict:
|
|
987
982
|
"""Counts the number of times each agent is mentioned in the provided message content.
|
|
988
983
|
Agent names will match under any of the following conditions (all case-sensitive):
|
|
989
984
|
- Exact name match
|
|
@@ -1026,9 +1021,10 @@ class GroupChat:
|
|
|
1026
1021
|
def _run_input_guardrails(
|
|
1027
1022
|
self,
|
|
1028
1023
|
agent: "ConversableAgent",
|
|
1029
|
-
messages:
|
|
1030
|
-
) ->
|
|
1024
|
+
messages: list[dict[str, Any]] | None = None,
|
|
1025
|
+
) -> str | None:
|
|
1031
1026
|
"""Run input guardrails for an agent before the reply is generated.
|
|
1027
|
+
|
|
1032
1028
|
Args:
|
|
1033
1029
|
agent (ConversableAgent): The agent whose input guardrails to run.
|
|
1034
1030
|
messages (Optional[list[dict[str, Any]]]): The messages to check against the guardrails.
|
|
@@ -1043,6 +1039,7 @@ class GroupChat:
|
|
|
1043
1039
|
|
|
1044
1040
|
def _run_output_guardrails(self, agent: "ConversableAgent", reply: str) -> None:
|
|
1045
1041
|
"""Run output guardrails for an agent after the reply is generated.
|
|
1042
|
+
|
|
1046
1043
|
Args:
|
|
1047
1044
|
agent (ConversableAgent): The agent whose output guardrails to run.
|
|
1048
1045
|
reply (str): The reply generated by the agent.
|
|
@@ -1063,11 +1060,11 @@ class GroupChatManager(ConversableAgent):
|
|
|
1063
1060
|
def __init__(
|
|
1064
1061
|
self,
|
|
1065
1062
|
groupchat: GroupChat,
|
|
1066
|
-
name:
|
|
1063
|
+
name: str | None = "chat_manager",
|
|
1067
1064
|
# unlimited consecutive auto reply by default
|
|
1068
|
-
max_consecutive_auto_reply:
|
|
1065
|
+
max_consecutive_auto_reply: int | None = sys.maxsize,
|
|
1069
1066
|
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
|
|
1070
|
-
system_message:
|
|
1067
|
+
system_message: str | list | None = "Group chat manager.",
|
|
1071
1068
|
silent: bool = False,
|
|
1072
1069
|
**kwargs: Any,
|
|
1073
1070
|
):
|
|
@@ -1177,10 +1174,10 @@ class GroupChatManager(ConversableAgent):
|
|
|
1177
1174
|
|
|
1178
1175
|
def run_chat(
|
|
1179
1176
|
self,
|
|
1180
|
-
messages:
|
|
1181
|
-
sender:
|
|
1182
|
-
config:
|
|
1183
|
-
) -> tuple[bool,
|
|
1177
|
+
messages: list[dict[str, Any]] | None = None,
|
|
1178
|
+
sender: Agent | None = None,
|
|
1179
|
+
config: GroupChat | None = None,
|
|
1180
|
+
) -> tuple[bool, str | None]:
|
|
1184
1181
|
"""Run a group chat."""
|
|
1185
1182
|
iostream = IOStream.get_default()
|
|
1186
1183
|
|
|
@@ -1293,9 +1290,9 @@ class GroupChatManager(ConversableAgent):
|
|
|
1293
1290
|
|
|
1294
1291
|
async def a_run_chat(
|
|
1295
1292
|
self,
|
|
1296
|
-
messages:
|
|
1297
|
-
sender:
|
|
1298
|
-
config:
|
|
1293
|
+
messages: list[dict[str, Any]] | None = None,
|
|
1294
|
+
sender: Agent | None = None,
|
|
1295
|
+
config: GroupChat | None = None,
|
|
1299
1296
|
):
|
|
1300
1297
|
"""Run a group chat asynchronously."""
|
|
1301
1298
|
iostream = IOStream.get_default()
|
|
@@ -1410,9 +1407,9 @@ class GroupChatManager(ConversableAgent):
|
|
|
1410
1407
|
|
|
1411
1408
|
def resume(
|
|
1412
1409
|
self,
|
|
1413
|
-
messages:
|
|
1414
|
-
remove_termination_string:
|
|
1415
|
-
silent:
|
|
1410
|
+
messages: list[dict[str, Any]] | str,
|
|
1411
|
+
remove_termination_string: str | Callable[[str], str] | None = None,
|
|
1412
|
+
silent: bool | None = False,
|
|
1416
1413
|
) -> tuple[ConversableAgent, dict[str, Any]]:
|
|
1417
1414
|
"""Resumes a group chat using the previous messages as a starting point. Requires the agents, group chat, and group chat manager to be established
|
|
1418
1415
|
as per the original group chat.
|
|
@@ -1513,9 +1510,9 @@ class GroupChatManager(ConversableAgent):
|
|
|
1513
1510
|
|
|
1514
1511
|
async def a_resume(
|
|
1515
1512
|
self,
|
|
1516
|
-
messages:
|
|
1517
|
-
remove_termination_string:
|
|
1518
|
-
silent:
|
|
1513
|
+
messages: list[dict[str, Any]] | str,
|
|
1514
|
+
remove_termination_string: str | Callable[[str], str] | None = None,
|
|
1515
|
+
silent: bool | None = False,
|
|
1519
1516
|
) -> tuple[ConversableAgent, dict[str, Any]]:
|
|
1520
1517
|
"""Resumes a group chat using the previous messages as a starting point, asynchronously. Requires the agents, group chat, and group chat manager to be established
|
|
1521
1518
|
as per the original group chat.
|
|
@@ -1639,7 +1636,7 @@ class GroupChatManager(ConversableAgent):
|
|
|
1639
1636
|
raise Exception(f"Agent name in message doesn't exist as agent in group chat: {message['name']}")
|
|
1640
1637
|
|
|
1641
1638
|
def _process_resume_termination(
|
|
1642
|
-
self, remove_termination_string:
|
|
1639
|
+
self, remove_termination_string: str | Callable[[str], str], messages: list[dict[str, Any]]
|
|
1643
1640
|
):
|
|
1644
1641
|
"""Removes termination string, if required, and checks if termination may occur.
|
|
1645
1642
|
|