ag2 0.9.10__py3-none-any.whl → 0.10.0__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.10.dist-info → ag2-0.10.0.dist-info}/METADATA +14 -7
- {ag2-0.9.10.dist-info → ag2-0.10.0.dist-info}/RECORD +42 -24
- autogen/a2a/__init__.py +36 -0
- autogen/a2a/agent_executor.py +105 -0
- autogen/a2a/client.py +280 -0
- autogen/a2a/errors.py +18 -0
- autogen/a2a/httpx_client_factory.py +79 -0
- autogen/a2a/server.py +221 -0
- autogen/a2a/utils.py +165 -0
- autogen/agentchat/__init__.py +3 -0
- autogen/agentchat/agent.py +0 -2
- autogen/agentchat/chat.py +5 -1
- autogen/agentchat/contrib/llava_agent.py +1 -13
- autogen/agentchat/conversable_agent.py +178 -73
- autogen/agentchat/group/group_tool_executor.py +46 -15
- autogen/agentchat/group/guardrails.py +41 -33
- autogen/agentchat/group/multi_agent_chat.py +53 -0
- autogen/agentchat/group/safeguards/api.py +19 -2
- autogen/agentchat/group/safeguards/enforcer.py +134 -40
- autogen/agentchat/groupchat.py +45 -33
- autogen/agentchat/realtime/experimental/realtime_swarm.py +1 -3
- autogen/interop/pydantic_ai/pydantic_ai.py +1 -1
- autogen/llm_config/client.py +3 -2
- autogen/oai/bedrock.py +0 -13
- autogen/oai/client.py +15 -8
- autogen/oai/client_utils.py +30 -0
- autogen/oai/cohere.py +0 -10
- autogen/remote/__init__.py +18 -0
- autogen/remote/agent.py +199 -0
- autogen/remote/agent_service.py +142 -0
- autogen/remote/errors.py +17 -0
- autogen/remote/httpx_client_factory.py +131 -0
- autogen/remote/protocol.py +37 -0
- autogen/remote/retry.py +102 -0
- autogen/remote/runtime.py +96 -0
- autogen/testing/__init__.py +12 -0
- autogen/testing/messages.py +45 -0
- autogen/testing/test_agent.py +111 -0
- autogen/version.py +1 -1
- {ag2-0.9.10.dist-info → ag2-0.10.0.dist-info}/WHEEL +0 -0
- {ag2-0.9.10.dist-info → ag2-0.10.0.dist-info}/licenses/LICENSE +0 -0
- {ag2-0.9.10.dist-info → ag2-0.10.0.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from types import TracebackType
|
|
8
|
+
from typing import Any, TypedDict
|
|
9
|
+
|
|
10
|
+
from autogen import ConversableAgent, ModelClient
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestAgent:
|
|
14
|
+
"""A context manager for testing ConversableAgent instances with predefined messages.
|
|
15
|
+
|
|
16
|
+
This class allows you to temporarily replace an agent's LLM client with a fake client
|
|
17
|
+
that returns predefined messages. It's useful for testing agent behavior without
|
|
18
|
+
making actual API calls.
|
|
19
|
+
|
|
20
|
+
Attributes:
|
|
21
|
+
agent (ConversableAgent): The agent to be tested.
|
|
22
|
+
messages (Iterable[str | dict[str, Any]]): An iterable of messages to be returned by the fake client.
|
|
23
|
+
suppress_messages_end (bool): Whether to suppress StopIteration exceptions from the fake client.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
>>> with TestAgent(agent, ["Hello", "How are you?"]) as test_agent:
|
|
27
|
+
... # Agent will respond with "Hello" then "How are you?"
|
|
28
|
+
... pass
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
agent: ConversableAgent,
|
|
34
|
+
messages: Iterable[str | dict[str, Any]] = (),
|
|
35
|
+
*,
|
|
36
|
+
suppress_messages_end: bool = False,
|
|
37
|
+
) -> None:
|
|
38
|
+
self.agent = agent
|
|
39
|
+
|
|
40
|
+
self.__original_human_input = self.agent.human_input_mode
|
|
41
|
+
|
|
42
|
+
self.__original_client = agent.client
|
|
43
|
+
self.__fake_client = FakeClient(messages)
|
|
44
|
+
|
|
45
|
+
self.suppress_messages_end = suppress_messages_end
|
|
46
|
+
|
|
47
|
+
def __enter__(self) -> None:
|
|
48
|
+
self.agent.human_input_mode = "NEVER"
|
|
49
|
+
|
|
50
|
+
self.__original_client = self.agent.client
|
|
51
|
+
self.agent.client = self.__fake_client # type: ignore[assignment]
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
def __exit__(
|
|
55
|
+
self,
|
|
56
|
+
exc_type: type[BaseException] | None,
|
|
57
|
+
exc_value: BaseException | None,
|
|
58
|
+
traceback: TracebackType | None,
|
|
59
|
+
) -> None | bool:
|
|
60
|
+
self.agent.human_input_mode = self.__original_human_input
|
|
61
|
+
|
|
62
|
+
self.agent.client = self.__original_client
|
|
63
|
+
|
|
64
|
+
if isinstance(exc_value, StopIteration):
|
|
65
|
+
# suppress fake client iterator ending
|
|
66
|
+
return self.suppress_messages_end
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class FakeClient:
|
|
71
|
+
def __init__(self, messages: Iterable[str | dict[str, Any]]) -> None:
|
|
72
|
+
# do not unpack messages to allow endless generators pass
|
|
73
|
+
self.choice_iterator = iter(map(convert_fake_message, messages))
|
|
74
|
+
|
|
75
|
+
self.total_usage_summary = None
|
|
76
|
+
self.actual_usage_summary = None
|
|
77
|
+
|
|
78
|
+
def create(self, **params: Any) -> ModelClient.ModelClientResponseProtocol:
|
|
79
|
+
choice = next(self.choice_iterator)
|
|
80
|
+
return FakeClientResponse(choices=[choice])
|
|
81
|
+
|
|
82
|
+
def extract_text_or_completion_object(
|
|
83
|
+
self,
|
|
84
|
+
response: "FakeClientResponse",
|
|
85
|
+
) -> list[str] | list["FakeMessage"]:
|
|
86
|
+
return response.message_retrieval_function()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def convert_fake_message(message: str | dict[str, Any]) -> "FakeChoice":
|
|
90
|
+
if isinstance(message, str):
|
|
91
|
+
return FakeChoice({"content": message})
|
|
92
|
+
else:
|
|
93
|
+
return FakeChoice({"role": "assistant", **message}) # type: ignore[typeddict-item]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class FakeMessage(TypedDict):
|
|
97
|
+
content: str | dict[str, Any]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass
|
|
101
|
+
class FakeChoice(ModelClient.ModelClientResponseProtocol.Choice):
|
|
102
|
+
message: FakeMessage # type: ignore[assignment]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass
|
|
106
|
+
class FakeClientResponse(ModelClient.ModelClientResponseProtocol):
|
|
107
|
+
choices: list[FakeChoice]
|
|
108
|
+
model: str = "fake-model"
|
|
109
|
+
|
|
110
|
+
def message_retrieval_function(self) -> list[str] | list[FakeMessage]:
|
|
111
|
+
return [c.message for c in self.choices]
|
autogen/version.py
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|