-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add a2a agent card generation with the CLI #3606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
guillaumeblaquiere
wants to merge
19
commits into
google:main
Choose a base branch
from
guillaumeblaquiere:add-generate-card-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+322
−4
Open
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e49c692
feat: add a2a agent card generation with the CLI
guillaumeblaquiere 291a473
feat: add a2a agent card generation with the CLI
guillaumeblaquiere 6051de6
Merge remote-tracking branch 'origin/add-generate-card-command' into …
guillaumeblaquiere 921a203
Update src/google/adk/cli/cli_generate_agent_card.py
guillaumeblaquiere 0e97442
Update src/google/adk/cli/cli_generate_agent_card.py
guillaumeblaquiere 3141abc
chore: remove useless line
guillaumeblaquiere 6044144
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere 3557f02
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere 2d49d1d
chore: fix format
guillaumeblaquiere 67a6739
Merge remote-tracking branch 'origin/add-generate-card-command' into …
guillaumeblaquiere b06f74d
fix: remove useless test
guillaumeblaquiere d0a7b90
test: add tests on new CLI entry point
guillaumeblaquiere 5fa7105
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere 7fe4931
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere 10202f1
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere c1de9a7
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere 191a5ea
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere d9dcce1
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere b5ef552
Merge branch 'main' into add-generate-card-command
guillaumeblaquiere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import asyncio | ||
| import json | ||
| import os | ||
| import click | ||
|
|
||
| from .utils.agent_loader import AgentLoader | ||
|
|
||
|
|
||
| @click.command(name="generate_agent_card") | ||
| @click.option( | ||
| "--protocol", | ||
| default="https", | ||
| help="Protocol for the agent URL (default: https)", | ||
| ) | ||
| @click.option( | ||
| "--host", | ||
| default="127.0.0.1", | ||
| help="Host for the agent URL (default: 127.0.0.1)", | ||
| ) | ||
| @click.option( | ||
| "--port", | ||
| default="8000", | ||
| help="Port for the agent URL (default: 8000)", | ||
| ) | ||
| @click.option( | ||
| "--create-file", | ||
| is_flag=True, | ||
| default=False, | ||
| help="Create agent.json file in each agent directory", | ||
| ) | ||
| def generate_agent_card( | ||
| protocol: str, host: str, port: str, create_file: bool | ||
| ) -> None: | ||
| """Generates agent cards for all detected agents.""" | ||
| asyncio.run( | ||
| _generate_agent_card_async(protocol, host, port, create_file) | ||
| ) | ||
|
|
||
|
|
||
| async def _generate_agent_card_async( | ||
| protocol: str, host: str, port: str, create_file: bool | ||
| ) -> None: | ||
| try: | ||
| from ..a2a.utils.agent_card_builder import AgentCardBuilder | ||
| except ImportError as e: | ||
| click.secho( | ||
| "Error: 'a2a' package is required for this command. " | ||
| "Please install it with 'pip install google-adk[a2a]'.", | ||
| fg="red", | ||
| err=True, | ||
| ) | ||
| return | ||
|
|
||
| cwd = os.getcwd() | ||
| loader = AgentLoader(agents_dir=cwd) | ||
| agent_names = loader.list_agents() | ||
|
|
||
guillaumeblaquiere marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| agent_cards = [] | ||
|
|
||
| for agent_name in agent_names: | ||
| try: | ||
| agent = loader.load_agent(agent_name) | ||
| # If it's an App, get the root agent | ||
| if hasattr(agent, "root_agent"): | ||
| agent = agent.root_agent | ||
|
|
||
guillaumeblaquiere marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| builder = AgentCardBuilder( | ||
| agent=agent, | ||
| rpc_url=f"{protocol}://{host}:{port}/{agent_name}", | ||
| ) | ||
| card = await builder.build() | ||
| card_dict = card.model_dump(exclude_none=True) | ||
| agent_cards.append(card_dict) | ||
|
|
||
| if create_file: | ||
| agent_dir = os.path.join(cwd, agent_name) | ||
| agent_json_path = os.path.join(agent_dir, "agent.json") | ||
| with open(agent_json_path, "w", encoding="utf-8") as f: | ||
| json.dump(card_dict, f, indent=2) | ||
|
|
||
guillaumeblaquiere marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| except Exception as e: | ||
| # Log error but continue with other agents | ||
| # Using click.echo to print to stderr to not mess up JSON output on stdout | ||
| click.echo(f"Error processing agent {agent_name}: {e}", err=True) | ||
|
|
||
| click.echo(json.dumps(agent_cards, indent=2)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.