Skip to content

Commit 746d5b3

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

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
@@ -824,8 +824,11 @@ def _join_url(base: str, *paths: str) -> str:
824824
"""
825825
parsed = urlparse(base)
826826
clean_paths = [p.strip('/') for p in paths]
827-
joined_path = posixpath.join(parsed.path.rstrip('/'), *clean_paths)
828-
return urlunparse(parsed._replace(path='/' + joined_path))
827+
base_path = parsed.path if parsed.path != '/' else ''
828+
base_path = base_path.strip('/')
829+
joined_path = posixpath.join(base_path, *clean_paths)
830+
final_path = '/' + joined_path if joined_path else '/'
831+
return urlunparse(parsed._replace(path=final_path))
829832

830833

831834
def _get_path_from_url(url: str) -> str:
@@ -904,13 +907,12 @@ def mount(
904907
routes = route_builder.build()
905908
self._mounts.append(Mount(path, routes=routes))
906909
anchor = _join_url(
907-
route_builder.agent_card.url, path, route_builder.rpc_path
910+
route_builder.agent_card.url, route_builder.rpc_path
908911
)
909912
describedby = [
910913
AgentLinkTarget(
911914
href=_join_url(
912915
route_builder.agent_card.url,
913-
path,
914916
route_builder.agent_card_path,
915917
)
916918
)
@@ -923,7 +925,6 @@ def mount(
923925
AgentLinkTarget(
924926
href=_join_url(
925927
route_builder.extended_agent_card.url,
926-
path,
927928
route_builder.extended_agent_card_path,
928929
)
929930
)

0 commit comments

Comments
 (0)