Skip to content

Commit 6647618

Browse files
fix: a2a example (#709)
Co-authored-by: ds-sebastianchwilczynski <[email protected]>
1 parent ee1e43a commit 6647618

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

.github/scripts/run_examples.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export LOGFIRE_TOKEN
1313
GIT_URL_TEMPLATE="git+https://github.com/deepsense-ai/ragbits.git@%s#subdirectory=packages/%s"
1414
PR_BRANCH="${PR_BRANCH:-main}"
1515

16+
has_script_section() {
17+
local file="$1"
18+
grep -q "^# /// script" "$file"
19+
}
20+
1621
patch_dependencies() {
1722
local file="$1"
1823
local branch="$2"
@@ -51,8 +56,14 @@ patch_dependencies() {
5156
}
5257

5358
export -f patch_dependencies
59+
export -f has_script_section
5460

5561
find examples -name '*.py' | while read -r file; do
62+
if ! has_script_section "$file"; then
63+
echo "Skipping $file (no script section found)"
64+
continue
65+
fi
66+
5667
echo "Running the script: $file"
5768
patch_dependencies "$file" "$PR_BRANCH"
5869

examples/agents/a2a/agent_orchestrator.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ def _list_remote_agents(self) -> list[dict]:
195195
"name": data.get("name"),
196196
"agent_url": url,
197197
"description": data.get("description"),
198-
"skills": [
199-
{"id": skill.get("id"), "name": skill.get("name"), "description": skill.get("description")}
200-
for skill in data.get("skills", [])
201-
],
202198
}
203199
for url, data in self._remote_agents.items()
204200
]

examples/agents/a2a/hotel_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_hotel_recommendations(city: str) -> str:
5151
class HotelPromptInput(BaseModel):
5252
"""Defines the structured input for the hotel recommendation prompt."""
5353

54-
city: str
54+
input: str
5555

5656

5757
class HotelPrompt(Prompt[HotelPromptInput]):
@@ -62,7 +62,7 @@ class HotelPrompt(Prompt[HotelPromptInput]):
6262
"""
6363

6464
user_prompt = """
65-
I'm planning a trip to {{ city }}. Can you recommend some hotels?
65+
{{ input }}
6666
"""
6767

6868

@@ -71,4 +71,4 @@ class HotelPrompt(Prompt[HotelPromptInput]):
7171
use_structured_output=True,
7272
)
7373

74-
agent = Agent(llm=llm, prompt=HotelPrompt, tools=[get_hotel_recommendations])
74+
hotel_agent = Agent(llm=llm, prompt=HotelPrompt, tools=[get_hotel_recommendations])

examples/agents/a2a/run_orchestrator.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
To execute this script simply run:
1111
```bash
12-
uv run examples/agents/a2a/orchestrator_client.py
12+
uv run examples/agents/a2a/run_orchestrator.py
1313
```
1414
"""
1515

@@ -24,10 +24,8 @@
2424
import threading
2525

2626
from agent_orchestrator import AgentOrchestrator, ResultsSumarizationPromptInput, RoutingPromptInput
27-
from flight_agent import FlightPromptInput
28-
from flight_agent import agent as flight_agent
29-
from hotel_agent import HotelPromptInput
30-
from hotel_agent import agent as hotel_agent
27+
from flight_agent import FlightPromptInput, flight_agent
28+
from hotel_agent import HotelPromptInput, hotel_agent
3129
from uvicorn import Server
3230

3331
from ragbits.agents.a2a.server import create_agent_server
@@ -49,7 +47,7 @@ class RoutingPrompt(Prompt[RoutingPromptInput]):
4947
Each task must include:
5048
- agent_url: The base URL of the agent that should handle the task.
5149
- tool: The name of the skill/tool to call on that agent.
52-
- parameters: A dictionary of arguments needed for that tool.
50+
- parameters: A dictionary with input argument which is just the task for the agent to answer.
5351
5452
Currently available agents and their tools:
5553
{{ agents }}
@@ -66,12 +64,12 @@ class RoutingPrompt(Prompt[RoutingPromptInput]):
6664
{
6765
"agent_url": "http://weather-agent:8000",
6866
"tool": "get_weather",
69-
"parameters": { "location": "Paris" }
67+
"parameters": { "input": "What is the weather in Paris?" }
7068
},
7169
{
7270
"agent_url": "http://news-agent:8001",
7371
"tool": "get_news_summary",
74-
"parameters": { "region": "France" }
72+
"parameters": { "input": "What are the news in France?" }
7573
}
7674
]
7775
"""

examples/agents/mcp/sse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ async def main() -> None:
5757
params={
5858
"url": "http://localhost:8000/sse",
5959
},
60+
client_session_timeout_seconds=20,
6061
) as server:
6162
llm = LiteLLM(model_name="gpt-4o-2024-08-06")
6263
agent = Agent(llm=llm, mcp_servers=[server])

examples/agents/mcp/streamable_http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ async def main() -> None:
5757
params={
5858
"url": "http://localhost:8000/mcp",
5959
},
60+
client_session_timeout_seconds=20,
6061
) as server:
6162
llm = LiteLLM(model_name="gpt-4o-2024-08-06")
6263
agent = Agent(llm=llm, mcp_servers=[server])

0 commit comments

Comments
 (0)