Skip to content

Commit 69b6374

Browse files
zzstoatzzclaude
andauthored
Fix Team.get_agentlet() signature to accept active_mcp_servers parameter (#1219)
The Team class was missing the active_mcp_servers parameter that was added to support MCP servers in the Agent class. This caused a TypeError when teams were used in environments with MCP servers enabled. Fixes #1218 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6b0e7ce commit 69b6374

4 files changed

Lines changed: 80 additions & 1 deletion

File tree

docs/api-reference/marvin-agents-team.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ A team is a container that maintains state for a group of agents.
5454
```
5555
- **`get_agentlet`**
5656
```python
57-
def get_agentlet(self, tools: list[Callable[..., Any]], end_turn_tools: list[EndTurn]) -> pydantic_ai.Agent[Any, Any]
57+
def get_agentlet(self, tools: list[Callable[..., Any]], end_turn_tools: list[EndTurn], active_mcp_servers: list[MCPServer] | None = None) -> pydantic_ai.Agent[Any, Any]
5858
```
5959
- **`get_end_turn_tools`**
6060
```python

examples/hello_team.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Example demonstrating Teams functionality in Marvin.
3+
"""
4+
5+
from marvin import Agent, Task
6+
from marvin.agents.team import Swarm
7+
8+
9+
def main():
10+
print("=" * 60)
11+
print("MARVIN TEAMS EXAMPLE")
12+
print("=" * 60)
13+
14+
# Create simple agents
15+
researcher = Agent(
16+
name="Researcher", instructions="You find and analyze information."
17+
)
18+
19+
writer = Agent(name="Writer", instructions="You write clear, engaging content.")
20+
21+
# Create a Swarm team
22+
team = Swarm([researcher, writer])
23+
24+
# Create a task with the team
25+
task = Task(
26+
instructions="Write a one-sentence description of Python programming.",
27+
agents=team,
28+
)
29+
30+
# Run the task
31+
result = task.run()
32+
33+
print(f"\nResult: {result}")
34+
print("\n" + "=" * 60)
35+
print("Teams example completed successfully!")
36+
print("=" * 60)
37+
38+
39+
if __name__ == "__main__":
40+
main()

src/marvin/agents/team.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pydantic_ai
77
from pydantic_ai.agent import AgentRunResult
8+
from pydantic_ai.mcp import MCPServer
89

910
from marvin.agents.actor import Actor
1011
from marvin.agents.names import TEAM_NAMES
@@ -74,10 +75,12 @@ async def get_agentlet(
7475
self,
7576
tools: list[Callable[..., Any]],
7677
end_turn_tools: list["EndTurn"],
78+
active_mcp_servers: list[MCPServer] | None = None,
7779
) -> pydantic_ai.Agent[Any, Any]:
7880
return await self.active_member.get_agentlet(
7981
tools=self.get_tools() + tools,
8082
end_turn_tools=self.get_end_turn_tools() + end_turn_tools,
83+
active_mcp_servers=active_mcp_servers,
8184
)
8285

8386
def friendly_name(self, verbose: bool = True) -> str:

tests/basic/actors/test_team.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,39 @@ async def test_team_delegation():
291291
# Delegation tools when agent1 is active (can delegate to agent2)
292292
team.active_member = agent1
293293
assert len(team.get_end_turn_tools()) == 1
294+
295+
296+
async def test_team_get_agentlet_with_mcp_servers():
297+
"""Test that Team.get_agentlet() properly handles active_mcp_servers parameter."""
298+
from unittest.mock import AsyncMock, MagicMock
299+
300+
from pydantic_ai.mcp import MCPServer
301+
302+
# Create agents
303+
agent1 = Agent(name="Agent 1")
304+
agent2 = Agent(name="Agent 2")
305+
306+
# Create team
307+
team = Team(members=[agent1, agent2])
308+
309+
# Mock the active member's get_agentlet method to verify it receives mcp_servers
310+
mock_agentlet = AsyncMock()
311+
team.active_member.get_agentlet = mock_agentlet
312+
313+
# Create mock MCP server
314+
mock_mcp_server = MagicMock(spec=MCPServer)
315+
316+
# Call get_agentlet with mcp_servers
317+
tools = []
318+
end_turn_tools = []
319+
mcp_servers = [mock_mcp_server]
320+
321+
await team.get_agentlet(
322+
tools=tools, end_turn_tools=end_turn_tools, active_mcp_servers=mcp_servers
323+
)
324+
325+
# Verify the active member's get_agentlet was called with the mcp_servers
326+
mock_agentlet.assert_called_once()
327+
call_kwargs = mock_agentlet.call_args.kwargs
328+
assert "active_mcp_servers" in call_kwargs
329+
assert call_kwargs["active_mcp_servers"] == mcp_servers

0 commit comments

Comments
 (0)