Skip to content

Commit b0fc8ad

Browse files
committed
feat: passing protocol
1 parent 70be817 commit b0fc8ad

File tree

6 files changed

+53
-49
lines changed

6 files changed

+53
-49
lines changed

contributing/samples/a2a_auth/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,16 @@ When deploying the remote BigQuery A2A agent to different environments (e.g., Cl
185185
}
186186
```
187187

188-
**Important:** The `url` field in `remote_a2a/bigquery_agent/agent.json` must point to the actual RPC endpoint where your remote BigQuery A2A agent is deployed and accessible. If the `url` field is an empty string, it will be automatically filled by the base URL provided to `get_fast_api_app`.
188+
**Important:** The `url` field in `remote_a2a/bigquery_agent/agent.json` must point to the actual RPC endpoint where your remote BigQuery A2A agent is deployed and accessible.
189+
If the `url` field is an empty string, it will be automatically filled by the `--host`, `--host`, and `--protocol` provided to `adk api_server`.
189190

190191
## Troubleshooting
191192

192193
**Connection Issues:**
193194
- Ensure the local ADK web server is running on port 8000
194195
- Ensure the remote A2A server is running on port 8001
195196
- Check that no firewall is blocking localhost connections
196-
- **Verify the `url` field in `remote_a2a/bigquery_agent/agent.json` matches the actual deployed location of your remote A2A server**
197+
- **Verify the `url` field in `remote_a2a/human_in_loop/agent.json` matches the actual deployed location of your remote A2A server, or if it's empty, make sure the `--host`, `--port`, and `--protocol` provided to `adk api_server` match the actual deployed location of your remote A2A server**
197198
- Verify the agent card URL passed to RemoteA2AAgent constructor matches the running A2A server
198199

199200

contributing/samples/a2a_basic/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ When deploying the remote A2A agent to different environments (e.g., Cloud Run,
135135
}
136136
```
137137

138-
**Important:** The `url` field in `remote_a2a/check_prime_agent/agent.json` must point to the actual RPC endpoint where your remote A2A agent is deployed and accessible. If the `url` field is an empty string, it will be automatically filled by the base URL provided to `get_fast_api_app`.
138+
**Important:** The `url` field in `remote_a2a/check_prime_agent/agent.json` must point to the actual RPC endpoint where your remote A2A agent is deployed and accessible.
139+
If the `url` field is an empty string, it will be automatically filled by the `--host`, `--host`, and `--protocol` provided to `adk api_server`.
139140

140141
## Troubleshooting
141142

142143
**Connection Issues:**
143144
- Ensure the local ADK web server is running on port 8000
144145
- Ensure the remote A2A server is running on port 8001
145146
- Check that no firewall is blocking localhost connections
146-
- **Verify the `url` field in `remote_a2a/check_prime_agent/agent.json` matches the actual deployed location of your remote A2A server**
147+
- **Verify the `url` field in `remote_a2a/human_in_loop/agent.json` matches the actual deployed location of your remote A2A server, or if it's empty, make sure the `--host`, `--port`, and `--protocol` provided to `adk api_server` match the actual deployed location of your remote A2A server**
147148
- Verify the agent card URL passed to RemoteA2AAgent constructor matches the running A2A server
148149

149150

contributing/samples/a2a_human_in_loop/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,16 @@ When deploying the remote approval A2A agent to different environments (e.g., Cl
144144
}
145145
```
146146

147-
**Important:** The `url` field in `remote_a2a/human_in_loop/agent.json` must point to the actual RPC endpoint where your remote approval A2A agent is deployed and accessible. If the `url` field is an empty string, it will be automatically filled by the base URL provided to `get_fast_api_app`.
147+
**Important:** The `url` field in `remote_a2a/human_in_loop/agent.json` must point to the actual RPC endpoint where your remote approval A2A agent is deployed and accessible.
148+
If the `url` field is an empty string, it will be automatically filled by the `--host`, `--host`, and `--protocol` provided to `adk api_server`.
148149

149150
## Troubleshooting
150151

151152
**Connection Issues:**
152153
- Ensure the local ADK web server is running on port 8000
153154
- Ensure the remote A2A server is running on port 8001
154155
- Check that no firewall is blocking localhost connections
155-
- **Verify the `url` field in `remote_a2a/human_in_loop/agent.json` matches the actual deployed location of your remote A2A server**
156+
- **Verify the `url` field in `remote_a2a/human_in_loop/agent.json` matches the actual deployed location of your remote A2A server, or if it's empty, make sure the `--host`, `--port`, and `--protocol` provided to `adk api_server` match the actual deployed location of your remote A2A server**
156157
- Verify the agent card URL passed to RemoteA2AAgent constructor matches the running A2A server
157158

158159
**Agent Not Responding:**

src/google/adk/cli/cli_tools_click.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,23 @@ def fast_api_common_options():
617617

618618
def decorator(func):
619619
@click.option(
620-
"--base_url",
620+
"--host",
621621
type=str,
622-
help="Optional. The base URL of the server.",
623-
default="http://127.0.0.1:8000",
622+
help="Optional. The binding host of the server",
623+
default="127.0.0.1",
624+
show_default=True,
625+
)
626+
@click.option(
627+
"--port",
628+
type=int,
629+
help="Optional. The port of the server",
630+
default=8000,
631+
)
632+
@click.option(
633+
"--protocol",
634+
type=str,
635+
help="Protocol, either http or https.",
636+
default="http",
624637
show_default=True,
625638
)
626639
@click.option(
@@ -714,7 +727,9 @@ def cli_web(
714727
eval_storage_uri: Optional[str] = None,
715728
log_level: str = "INFO",
716729
allow_origins: Optional[list[str]] = None,
717-
base_url="http://127.0.0.1:8000",
730+
host: str = "127.0.0.1",
731+
port: int = 8000,
732+
protocol: str = "http",
718733
trace_to_cloud: bool = False,
719734
reload: bool = True,
720735
session_service_uri: Optional[str] = None,
@@ -735,9 +750,6 @@ def cli_web(
735750
adk web --session_service_uri=[uri] --port=[port] path/to/agents_dir
736751
"""
737752
logs.setup_adk_logger(getattr(logging, log_level.upper()))
738-
parsed_url = urlparse(base_url)
739-
host = parsed_url.hostname
740-
port = parsed_url.port
741753

742754
@asynccontextmanager
743755
async def _lifespan(app: FastAPI):
@@ -746,7 +758,7 @@ async def _lifespan(app: FastAPI):
746758
+-----------------------------------------------------------------------------+
747759
| ADK Web Server started |
748760
| |
749-
| For local testing, access at http://{host}:{port}.{" "*(29 - len(str(port)))}|
761+
| For local testing, access at {protocol}://{host}:{port}.{" "*(29 - len(str(port)))}|
750762
+-----------------------------------------------------------------------------+
751763
""",
752764
fg="green",
@@ -806,7 +818,9 @@ def cli_api_server(
806818
eval_storage_uri: Optional[str] = None,
807819
log_level: str = "INFO",
808820
allow_origins: Optional[list[str]] = None,
809-
base_url="http://127.0.0.1:8000",
821+
host: str = "127.0.0.1",
822+
port: int = 8000,
823+
protocol: str = "http",
810824
trace_to_cloud: bool = False,
811825
reload: bool = True,
812826
session_service_uri: Optional[str] = None,
@@ -828,9 +842,6 @@ def cli_api_server(
828842
"""
829843
logs.setup_adk_logger(getattr(logging, log_level.upper()))
830844

831-
parsed_url = urlparse(base_url)
832-
host = parsed_url.hostname
833-
port = parsed_url.port
834845
session_service_uri = session_service_uri or session_db_url
835846
artifact_service_uri = artifact_service_uri or artifact_storage_uri
836847
config = uvicorn.Config(
@@ -844,7 +855,6 @@ def cli_api_server(
844855
web=False,
845856
trace_to_cloud=trace_to_cloud,
846857
a2a=a2a,
847-
base_url=base_url,
848858
reload_agents=reload_agents,
849859
),
850860
host=host,

src/google/adk/cli/fast_api.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def get_fast_api_app(
6464
allow_origins: Optional[list[str]] = None,
6565
web: bool,
6666
a2a: bool = False,
67-
base_url: str = "http://127.0.0.1:8000",
67+
host: str = "127.0.0.1",
68+
port: int = 8000,
69+
protocol: str = "http",
6870
trace_to_cloud: bool = False,
6971
reload_agents: bool = False,
7072
lifespan: Optional[Lifespan[FastAPI]] = None,
@@ -351,7 +353,7 @@ async def _get_a2a_runner_async() -> Runner:
351353
logger.info("Setting up A2A agent: %s", app_name)
352354

353355
try:
354-
a2a_rpc_path = f"{base_url}/a2a/{app_name}"
356+
a2a_rpc_path = f"{protocol}://{host}:{port}/a2a/{app_name}"
355357

356358
agent_executor = A2aAgentExecutor(
357359
runner=create_a2a_runner_loader(app_name),
@@ -364,8 +366,10 @@ async def _get_a2a_runner_async() -> Runner:
364366
with (p / "agent.json").open("r", encoding="utf-8") as f:
365367
data = json.load(f)
366368
agent_card = AgentCard(**data)
367-
if agent_card.url == "": # empty url is a placeholder to be filled with the provided url
368-
agent_card.url = a2a_rpc_path
369+
if (
370+
agent_card.url == ""
371+
): # empty url is a placeholder to be filled with the provided url
372+
agent_card.url = a2a_rpc_path
369373

370374
a2a_app = A2AStarletteApplication(
371375
agent_card=agent_card,

tests/unittests/cli/test_fast_api.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -502,36 +502,21 @@ def temp_agents_dir_with_a2a():
502502

503503
# Create agent.json file
504504
agent_card = {
505-
"capabilities": {
506-
"pushNotifications": True,
507-
"streaming": True
508-
},
509-
"defaultInputModes": [
510-
"text",
511-
"text/plain"
512-
],
513-
"defaultOutputModes": [
514-
"text",
515-
"text/plain"
516-
],
505+
"capabilities": {"pushNotifications": True, "streaming": True},
506+
"defaultInputModes": ["text", "text/plain"],
507+
"defaultOutputModes": ["text", "text/plain"],
517508
"name": "test_a2a_agent",
518509
"description": "Test A2A agent",
519510
"version": "1.0.0",
520511
"author": "test",
521512
"protocolVersion": "0.2.6",
522-
"skills": [
523-
{
524-
"description": "Makes the tests pass",
525-
"examples": [
526-
"Fix the tests."
527-
],
528-
"id": "test_a2a_agent",
529-
"name": "Test A2A agent",
530-
"tags": [
531-
"testing"
532-
]
533-
}
534-
],
513+
"skills": [{
514+
"description": "Makes the tests pass",
515+
"examples": ["Fix the tests."],
516+
"id": "test_a2a_agent",
517+
"name": "Test A2A agent",
518+
"tags": ["testing"],
519+
}],
535520
"url": "",
536521
}
537522

@@ -902,7 +887,9 @@ def test_a2a_agent_discovery(test_app_with_a2a):
902887
# and that the well known card works
903888
response = test_app_with_a2a.get("/list-apps")
904889
assert response.status_code == 200
905-
response2 = test_app_with_a2a.get(f"/a2a/test_a2a_agent{AGENT_CARD_WELL_KNOWN_PATH}")
890+
response2 = test_app_with_a2a.get(
891+
f"/a2a/test_a2a_agent{AGENT_CARD_WELL_KNOWN_PATH}"
892+
)
906893
assert response2.status_code == 200
907894
logger.info("A2A agent discovery test passed")
908895

0 commit comments

Comments
 (0)