Skip to content

Commit 69f7778

Browse files
authored
fix: handle async tools when running async agents on playground (#3356)
## Summary Fixes a regression where using Agents with async tools (e.g. MCP tools) was breaking in the Playground. ## Type of change - [ x ] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Improvement - [ ] Model update - [ ] Other: --- ## Checklist - [ ] Code complies with style guidelines - [ ] Ran format/validation scripts (`./scripts/format.sh` and `./scripts/validate.sh`) - [ ] Self-review completed - [ ] Documentation updated (comments, docstrings) - [ ] Examples and guides: Relevant cookbook examples have been included or updated (if applicable) - [ ] Tested in clean environment - [ ] Tests added/updated (if applicable)
1 parent a249ea6 commit 69f7778

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

cookbook/apps/playground/mcp_demo.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""This example shows how to run an Agent using our MCP integration in the Agno Playground.
2+
3+
For this example to run you need:
4+
- Create a GitHub personal access token following these steps:
5+
- https://github.com/modelcontextprotocol/servers/tree/main/src/github#setup
6+
- Set the GITHUB_TOKEN environment variable: `export GITHUB_TOKEN=<Your GitHub access token>`
7+
- Run: `pip install agno mcp openai` to install the dependencies
8+
"""
9+
110
import asyncio
211
from os import getenv
312
from textwrap import dedent

libs/agno/agno/app/playground/async_router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,15 +616,15 @@ async def get_teams():
616616
if teams is None:
617617
return []
618618

619-
return [TeamGetResponse.from_team(team) for team in teams]
619+
return [TeamGetResponse.from_team(team, async_mode=True) for team in teams]
620620

621621
@playground_router.get("/teams/{team_id}")
622622
async def get_team(team_id: str):
623623
team = get_team_by_id(team_id, teams)
624624
if team is None:
625625
raise HTTPException(status_code=404, detail="Team not found")
626626

627-
return TeamGetResponse.from_team(team)
627+
return TeamGetResponse.from_team(team, async_mode=True)
628628

629629
@playground_router.post("/teams/{team_id}/runs")
630630
async def create_team_run(

libs/agno/agno/app/playground/schemas.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AgentGetResponse(BaseModel):
3232
instructions: Optional[Union[List[str], str, Callable]] = None
3333

3434
@classmethod
35-
def from_agent(self, agent: Agent) -> "AgentGetResponse":
35+
def from_agent(self, agent: Agent, async_mode: bool = False) -> "AgentGetResponse":
3636
if agent.memory:
3737
memory_dict: Optional[Dict[str, Any]] = {}
3838
if isinstance(agent.memory, AgentMemory) and agent.memory.db:
@@ -52,7 +52,7 @@ def from_agent(self, agent: Agent) -> "AgentGetResponse":
5252
memory_dict = None
5353
else:
5454
memory_dict = None
55-
tools = agent.get_tools(session_id=str(uuid4()))
55+
tools = agent.get_tools(session_id=str(uuid4()), async_mode=async_mode)
5656
return AgentGetResponse(
5757
agent_id=agent.agent_id,
5858
name=agent.name,
@@ -151,9 +151,10 @@ class TeamGetResponse(BaseModel):
151151
response_model: Optional[str] = None
152152
storage: Optional[Dict[str, Any]] = None
153153
memory: Optional[Dict[str, Any]] = None
154+
async_mode: bool = False
154155

155156
@classmethod
156-
def from_team(self, team: Team) -> "TeamGetResponse":
157+
def from_team(self, team: Team, async_mode: bool = False) -> "TeamGetResponse":
157158
import json
158159

159160
memory_dict: Optional[Dict[str, Any]] = {}
@@ -191,9 +192,9 @@ def from_team(self, team: Team) -> "TeamGetResponse":
191192
storage={"name": team.storage.__class__.__name__} if team.storage else None,
192193
memory=memory_dict,
193194
members=[
194-
AgentGetResponse.from_agent(member)
195+
AgentGetResponse.from_agent(member, async_mode=async_mode)
195196
if isinstance(member, Agent)
196-
else TeamGetResponse.from_team(member)
197+
else TeamGetResponse.from_team(member, async_mode=async_mode)
197198
if isinstance(member, Team)
198199
else None
199200
for member in team.members

0 commit comments

Comments
 (0)