universal-mcp-agents 0.1.22__py3-none-any.whl → 0.1.23__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 universal-mcp-agents might be problematic. Click here for more details.
- universal_mcp/agents/__init__.py +2 -8
- universal_mcp/agents/base.py +44 -34
- universal_mcp/agents/bigtool/state.py +1 -1
- universal_mcp/agents/cli.py +2 -2
- universal_mcp/agents/codeact0/__main__.py +2 -5
- universal_mcp/agents/codeact0/agent.py +314 -154
- universal_mcp/agents/codeact0/prompts.py +210 -128
- universal_mcp/agents/codeact0/sandbox.py +21 -17
- universal_mcp/agents/codeact0/state.py +14 -14
- universal_mcp/agents/codeact0/tools.py +384 -163
- universal_mcp/agents/codeact0/utils.py +77 -6
- universal_mcp/agents/llm.py +10 -4
- universal_mcp/agents/react.py +3 -3
- universal_mcp/agents/sandbox.py +124 -69
- universal_mcp/applications/llm/app.py +20 -19
- {universal_mcp_agents-0.1.22.dist-info → universal_mcp_agents-0.1.23.dist-info}/METADATA +6 -5
- {universal_mcp_agents-0.1.22.dist-info → universal_mcp_agents-0.1.23.dist-info}/RECORD +18 -18
- {universal_mcp_agents-0.1.22.dist-info → universal_mcp_agents-0.1.23.dist-info}/WHEEL +0 -0
universal_mcp/agents/__init__.py
CHANGED
|
@@ -9,22 +9,16 @@ from universal_mcp.agents.simple import SimpleAgent
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def get_agent(
|
|
12
|
-
agent_name: Literal["react", "simple", "builder", "bigtool", "codeact-
|
|
12
|
+
agent_name: Literal["react", "simple", "builder", "bigtool", "codeact-repl"],
|
|
13
13
|
):
|
|
14
14
|
if agent_name == "react":
|
|
15
15
|
return ReactAgent
|
|
16
16
|
elif agent_name == "simple":
|
|
17
17
|
return SimpleAgent
|
|
18
|
-
elif agent_name == "builder":
|
|
19
|
-
return BuilderAgent
|
|
20
|
-
elif agent_name == "bigtool":
|
|
21
|
-
return BigToolAgent
|
|
22
18
|
elif agent_name == "codeact-repl":
|
|
23
19
|
return CodeActPlaybookAgent
|
|
24
20
|
else:
|
|
25
|
-
raise ValueError(
|
|
26
|
-
f"Unknown agent: {agent_name}. Possible values: react, simple, builder, bigtool, codeact-script, codeact-repl"
|
|
27
|
-
)
|
|
21
|
+
raise ValueError(f"Unknown agent: {agent_name}. Possible values: react, simple, codeact-repl")
|
|
28
22
|
|
|
29
23
|
|
|
30
24
|
__all__ = [
|
universal_mcp/agents/base.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import asyncio
|
|
2
2
|
from typing import cast
|
|
3
3
|
from uuid import uuid4
|
|
4
4
|
|
|
@@ -57,40 +57,50 @@ class BaseAgent:
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
last_ai_chunk = None
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
last_ai_chunk = payload
|
|
75
|
-
aggregate = payload if aggregate is None else aggregate + payload
|
|
76
|
-
if "finish_reason" in payload.response_metadata:
|
|
77
|
-
logger.debug(
|
|
78
|
-
f"Finish event: {payload}, reason: {payload.response_metadata['finish_reason']}, Metadata: {meta_dict}"
|
|
60
|
+
try:
|
|
61
|
+
async for event, meta in self._graph.astream(
|
|
62
|
+
{"messages": [{"role": "user", "content": user_input}]},
|
|
63
|
+
config=run_config,
|
|
64
|
+
context={"system_prompt": self.instructions, "model": self.model},
|
|
65
|
+
stream_mode=["messages", "custom"],
|
|
66
|
+
stream_usage=True,
|
|
67
|
+
):
|
|
68
|
+
if event == "messages" and isinstance(meta, (tuple, list)) and len(meta) == 2: # noqa: PLR2004
|
|
69
|
+
payload, meta_dict = meta
|
|
70
|
+
if meta_dict.get("tags") and "quiet" in meta_dict.get("tags"):
|
|
71
|
+
continue
|
|
72
|
+
is_agent_builder = (
|
|
73
|
+
isinstance(meta_dict, dict) and meta_dict.get("langgraph_node") == "agent_builder"
|
|
79
74
|
)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
additional_kwargs = getattr(payload, "additional_kwargs", {}) or {}
|
|
76
|
+
if is_agent_builder and not additional_kwargs.get("stream"):
|
|
77
|
+
continue
|
|
78
|
+
if isinstance(payload, AIMessageChunk):
|
|
79
|
+
last_ai_chunk = payload
|
|
80
|
+
aggregate = payload if aggregate is None else aggregate + payload
|
|
81
|
+
if "finish_reason" in payload.response_metadata:
|
|
82
|
+
logger.debug(
|
|
83
|
+
f"Finish event: {payload}, reason: {payload.response_metadata['finish_reason']}, Metadata: {meta_dict}"
|
|
84
|
+
)
|
|
85
|
+
pass
|
|
86
|
+
logger.debug(f"Event: {payload}, Metadata: {meta_dict}")
|
|
87
|
+
yield payload
|
|
88
|
+
|
|
89
|
+
if event == "custom":
|
|
90
|
+
yield meta
|
|
91
|
+
|
|
92
|
+
except asyncio.CancelledError:
|
|
93
|
+
logger.info(f"Stream for thread_id {thread_id} was cancelled by the user.")
|
|
94
|
+
# Perform any cleanup here if necessary
|
|
95
|
+
finally:
|
|
96
|
+
# This block will run whether the stream finished normally or was cancelled
|
|
97
|
+
# Send a final finished message if we saw any AI chunks (to carry usage)
|
|
98
|
+
if last_ai_chunk is not None and aggregate is not None:
|
|
99
|
+
event = cast(AIMessageChunk, last_ai_chunk)
|
|
100
|
+
event.usage_metadata = aggregate.usage_metadata
|
|
101
|
+
logger.debug(f"Usage metadata: {event.usage_metadata}")
|
|
102
|
+
event.content = "" # Clear the message
|
|
103
|
+
yield event
|
|
94
104
|
|
|
95
105
|
async def stream_interactive(self, thread_id: str, user_input: str):
|
|
96
106
|
await self.ainit()
|
universal_mcp/agents/cli.py
CHANGED
|
@@ -18,14 +18,14 @@ app = Typer()
|
|
|
18
18
|
mcp client run --config client_config.json
|
|
19
19
|
""",
|
|
20
20
|
)
|
|
21
|
-
def run(name: str = "
|
|
21
|
+
def run(name: str = "codeact-repl"):
|
|
22
22
|
"""Run the agent CLI"""
|
|
23
23
|
|
|
24
24
|
setup_logger(log_file=None, level="ERROR")
|
|
25
25
|
client = AgentrClient()
|
|
26
26
|
params = {
|
|
27
27
|
"instructions": "You are a helpful assistant",
|
|
28
|
-
"model": "anthropic
|
|
28
|
+
"model": "anthropic:claude-4-sonnet-20250514",
|
|
29
29
|
"registry": AgentrRegistry(client=client),
|
|
30
30
|
"memory": MemorySaver(),
|
|
31
31
|
}
|
|
@@ -13,15 +13,12 @@ async def main():
|
|
|
13
13
|
agent = CodeActPlaybookAgent(
|
|
14
14
|
name="CodeAct Agent",
|
|
15
15
|
instructions="Be very concise in your answers.",
|
|
16
|
-
model="
|
|
17
|
-
tools={"google_mail": ["list_messages"]},
|
|
16
|
+
model="azure/gpt-4.1",
|
|
18
17
|
registry=AgentrRegistry(),
|
|
19
18
|
memory=memory,
|
|
20
19
|
)
|
|
21
20
|
print("Starting agent...")
|
|
22
|
-
result = await agent.invoke(
|
|
23
|
-
user_input="Fetch unsubscribe links from my Gmail inbox for promo emails I have received in the last 7 days"
|
|
24
|
-
)
|
|
21
|
+
result = await agent.invoke(user_input="Check my google calendar and show my todays agenda")
|
|
25
22
|
print(messages_to_list(result["messages"]))
|
|
26
23
|
|
|
27
24
|
|