Skip to content

Commit 293dc75

Browse files
committed
fix: ensure correct agent URL path parsing and registration in Starlette app
Signed-off-by: Shingo OKAWA <[email protected]>
1 parent caed5d1 commit 293dc75

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

examples/apicatalog/__main__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@
55

66
import click
77
import uvicorn
8+
from dotenv import load_dotenv
89

9-
from agent_executors import (
10-
HelloWorldAgentExecutor, # type: ignore[import-untyped]
11-
EchoAgentExecutor, # type: ignore[import-untyped]
10+
from agent_executors import ( # type: ignore[import-untyped]
11+
EchoAgentExecutor,
12+
HelloWorldAgentExecutor,
1213
)
1314

14-
from a2a.server.apps import A2AStarletteRouteBuilder, A2AStarletteBuilder
15+
from a2a.server.apps import A2AStarletteBuilder, A2AStarletteRouteBuilder
1516
from a2a.server.request_handlers import DefaultRequestHandler
1617
from a2a.server.tasks import InMemoryTaskStore
17-
from a2a.types import (
18-
AgentCapabilities,
19-
AgentCard,
20-
AgentSkill,
21-
)
22-
from dotenv import load_dotenv
18+
from a2a.types import AgentCapabilities, AgentCard, AgentSkill
2319

2420

2521
load_dotenv()

examples/apicatalog/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import asyncio
2+
import json
23
import logging
34
import os
45
import sys
56
import traceback
67

78
import click
89
import httpx
9-
1010
from dotenv import load_dotenv
1111

1212

@@ -28,7 +28,7 @@ async def fetch_api_catalog(base_url: str):
2828
def main(host: str, port: int):
2929
base = f'http://{host}:{port}'
3030
catalog = asyncio.run(fetch_api_catalog(base))
31-
print(catalog)
31+
print(json.dumps(catalog))
3232

3333

3434
if __name__ == "__main__":

src/a2a/server/apps/starlette_app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,11 @@ def _join_url(base: str, *paths: str) -> str:
836836
"""
837837
parsed = urlparse(base)
838838
clean_paths = [p.strip('/') for p in paths]
839-
joined_path = posixpath.join(parsed.path.rstrip('/'), *clean_paths)
840-
return urlunparse(parsed._replace(path='/' + joined_path))
839+
base_path = parsed.path if parsed.path != '/' else ''
840+
base_path = base_path.strip('/')
841+
joined_path = posixpath.join(base_path, *clean_paths)
842+
final_path = '/' + joined_path if joined_path else '/'
843+
return urlunparse(parsed._replace(path=final_path))
841844

842845

843846
def _get_path_from_url(url: str) -> str:
@@ -916,13 +919,12 @@ def mount(
916919
routes = route_builder.build()
917920
self._mounts.append(Mount(path, routes=routes))
918921
anchor = _join_url(
919-
route_builder.agent_card.url, path, route_builder.rpc_path
922+
route_builder.agent_card.url, route_builder.rpc_path
920923
)
921924
describedby = [
922925
AgentLinkTarget(
923926
href=_join_url(
924927
route_builder.agent_card.url,
925-
path,
926928
route_builder.agent_card_path,
927929
)
928930
)
@@ -935,7 +937,6 @@ def mount(
935937
AgentLinkTarget(
936938
href=_join_url(
937939
route_builder.extended_agent_card.url,
938-
path,
939940
route_builder.extended_agent_card_path,
940941
)
941942
)

0 commit comments

Comments
 (0)