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.

@@ -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-script", "codeact-repl"],
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__ = [
@@ -1,4 +1,4 @@
1
- # agents/base.py
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
- async for event, meta in self._graph.astream(
61
- {"messages": [{"role": "user", "content": user_input}]},
62
- config=run_config,
63
- context={"system_prompt": self.instructions, "model": self.model},
64
- stream_mode=["messages", "custom"],
65
- stream_usage=True,
66
- ):
67
- if event == "messages" and isinstance(meta, (tuple, list)) and len(meta) == 2:
68
- payload, meta_dict = meta
69
- is_playbook = isinstance(meta_dict, dict) and meta_dict.get("langgraph_node") == "playbook"
70
- additional_kwargs = getattr(payload, "additional_kwargs", {}) or {}
71
- if is_playbook and not additional_kwargs.get("stream"):
72
- continue
73
- if isinstance(payload, AIMessageChunk):
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
- pass
81
- logger.debug(f"Event: {payload}, Metadata: {meta_dict}")
82
- yield payload
83
-
84
- if event == "custom":
85
- yield meta
86
-
87
- # Send a final finished message if we saw any AI chunks (to carry usage)
88
- if last_ai_chunk is not None and aggregate is not None:
89
- event = cast(AIMessageChunk, last_ai_chunk)
90
- event.usage_metadata = aggregate.usage_metadata
91
- logger.debug(f"Usage metadata: {event.usage_metadata}")
92
- event.content = "" # Clear the message since it would have already been streamed above
93
- yield event
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()
@@ -1,6 +1,6 @@
1
1
  from typing import Annotated
2
2
 
3
- from langgraph.prebuilt.chat_agent_executor import AgentState
3
+ from langchain.agents import AgentState
4
4
 
5
5
 
6
6
  def _enqueue(left: list, right: list) -> list:
@@ -18,14 +18,14 @@ app = Typer()
18
18
  mcp client run --config client_config.json
19
19
  """,
20
20
  )
21
- def run(name: str = "react"):
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/claude-sonnet-4-20250514",
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="anthropic:claude-4-sonnet-20250514",
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