Skip to content

Commit a6716a5

Browse files
holtskinnercopybara-github
authored andcommitted
fix: Import A2A well known path from A2A sdk
PiperOrigin-RevId: 783036797
1 parent a4baa35 commit a6716a5

6 files changed

Lines changed: 26 additions & 8 deletions

File tree

contributing/samples/a2a_auth/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
from google.adk.agents import Agent
17+
from google.adk.agents.remote_a2a_agent import AGENT_CARD_WELL_KNOWN_PATH
1718
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
1819
from google.adk.tools.langchain_tool import LangchainTool
1920
from langchain_community.tools import YouTubeSearchTool
@@ -41,7 +42,7 @@
4142
name="bigquery_agent",
4243
description="Help customer to manage notion workspace.",
4344
agent_card=(
44-
"http://localhost:8001/a2a/bigquery_agent/.well-known/agent.json"
45+
f"http://localhost:8001/a2a/bigquery_agent{AGENT_CARD_WELL_KNOWN_PATH}"
4546
),
4647
)
4748

contributing/samples/a2a_basic/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import random
1616

1717
from google.adk.agents import Agent
18+
from google.adk.agents.remote_a2a_agent import AGENT_CARD_WELL_KNOWN_PATH
1819
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
1920
from google.adk.tools.example_tool import ExampleTool
2021
from google.genai import types
@@ -87,7 +88,7 @@ def roll_die(sides: int) -> int:
8788
name="prime_agent",
8889
description="Agent that handles checking if numbers are prime.",
8990
agent_card=(
90-
"http://localhost:8001/a2a/check_prime_agent/.well-known/agent.json"
91+
f"http://localhost:8001/a2a/check_prime_agent{AGENT_CARD_WELL_KNOWN_PATH}"
9192
),
9293
)
9394

contributing/samples/a2a_human_in_loop/agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
from google.adk import Agent
17+
from google.adk.agents.remote_a2a_agent import AGENT_CARD_WELL_KNOWN_PATH
1718
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
1819
from google.genai import types
1920

@@ -28,7 +29,9 @@ def reimburse(purpose: str, amount: float) -> str:
2829
approval_agent = RemoteA2aAgent(
2930
name='approval_agent',
3031
description='Help approve the reimburse if the amount is greater than 100.',
31-
agent_card='http://localhost:8001/a2a/human_in_loop/.well-known/agent.json',
32+
agent_card=(
33+
f'http://localhost:8001/a2a/human_in_loop{AGENT_CARD_WELL_KNOWN_PATH}'
34+
),
3235
)
3336

3437

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dev = [
8080

8181
a2a = [
8282
# go/keep-sorted start
83-
"a2a-sdk>=0.2.7;python_version>='3.10'"
83+
"a2a-sdk>=0.2.11;python_version>='3.10'"
8484
# go/keep-sorted end
8585
]
8686

src/google/adk/agents/remote_a2a_agent.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
try:
2828
from a2a.client import A2AClient
29-
from a2a.client.client import A2ACardResolver # Import A2ACardResolver
29+
from a2a.client.client import A2ACardResolver
3030
from a2a.types import AgentCard
3131
from a2a.types import Message as A2AMessage
3232
from a2a.types import MessageSendParams as A2AMessageSendParams
@@ -35,7 +35,6 @@
3535
from a2a.types import SendMessageRequest
3636
from a2a.types import SendMessageSuccessResponse
3737
from a2a.types import Task as A2ATask
38-
3938
except ImportError as e:
4039
import sys
4140

@@ -46,6 +45,12 @@
4645
else:
4746
raise e
4847

48+
try:
49+
from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH
50+
except ImportError:
51+
# Fallback for older versions of a2a-sdk.
52+
AGENT_CARD_WELL_KNOWN_PATH = "/.well-known/agent.json"
53+
4954
from google.genai import types as genai_types
5055
import httpx
5156

@@ -63,11 +68,18 @@
6368
from ..utils.feature_decorator import experimental
6469
from .base_agent import BaseAgent
6570

71+
__all__ = [
72+
"A2AClientError",
73+
"AGENT_CARD_WELL_KNOWN_PATH",
74+
"AgentCardResolutionError",
75+
"RemoteA2aAgent",
76+
]
77+
78+
6679
# Constants
6780
A2A_METADATA_PREFIX = "a2a:"
6881
DEFAULT_TIMEOUT = 600.0
6982

70-
7183
logger = logging.getLogger("google_adk." + __name__)
7284

7385

src/google/adk/cli/fast_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ async def _get_runner_async(app_name: str) -> Runner:
10031003
from a2a.server.request_handlers import DefaultRequestHandler
10041004
from a2a.server.tasks import InMemoryTaskStore
10051005
from a2a.types import AgentCard
1006+
from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH
10061007

10071008
from ..a2a.executor.a2a_agent_executor import A2aAgentExecutor
10081009

@@ -1066,7 +1067,7 @@ async def _get_a2a_runner_async() -> Runner:
10661067

10671068
routes = a2a_app.routes(
10681069
rpc_url=f"/a2a/{app_name}",
1069-
agent_card_url=f"/a2a/{app_name}/.well-known/agent.json",
1070+
agent_card_url=f"/a2a/{app_name}{AGENT_CARD_WELL_KNOWN_PATH}",
10701071
)
10711072

10721073
for new_route in routes:

0 commit comments

Comments
 (0)