-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add AgentCard for self-describing agent capabilities #296
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
prassanna-ravishankar
wants to merge
6
commits into
main
Choose a base branch
from
feature/agent-card
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.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0157ed0
Add AgentCard feature for self-describing agent capabilities via regi…
prassanna-ravishankar 9eb9a20
Fix: preserve None registration_metadata when no agent_card is provided
prassanna-ravishankar 5903b07
Add tests for AgentCard feature, fix PEP 604 union unwrap in extract_…
prassanna-ravishankar d2b928b
Fix ruff import sorting in __init__.py and test file
prassanna-ravishankar 5269ead
Fix pyright strict errors: use Enum isinstance checks, add override d…
prassanna-ravishankar 156ab00
Add AgentCard.from_states() classmethod for list[State] + initial_sta…
prassanna-ravishankar 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
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
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,77 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import typing | ||
| from typing import Any, get_args, get_origin | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class LifecycleState(BaseModel): | ||
| name: str | ||
| description: str = "" | ||
| waits_for_input: bool = False | ||
| accepts: list[str] = [] | ||
| transitions: list[str] = [] | ||
|
|
||
|
|
||
| class AgentLifecycle(BaseModel): | ||
| states: list[LifecycleState] | ||
| initial_state: str | ||
| queries: list[str] = [] | ||
|
|
||
|
|
||
| class AgentCard(BaseModel): | ||
| protocol: str = "acp" | ||
| lifecycle: AgentLifecycle | None = None | ||
| data_events: list[str] = [] | ||
| input_types: list[str] = [] | ||
| output_schema: dict | None = None | ||
|
|
||
| @classmethod | ||
| def from_state_machine( | ||
| cls, | ||
| state_machine: Any, | ||
| output_event_model: type[BaseModel] | None = None, | ||
| extra_input_types: list[str] | None = None, | ||
| queries: list[str] | None = None, | ||
| ) -> AgentCard: | ||
| lifecycle_data = state_machine.get_lifecycle() | ||
| lifecycle_data["queries"] = queries or [] | ||
|
|
||
| data_events: list[str] = [] | ||
| output_schema: dict | None = None | ||
| if output_event_model: | ||
| data_events = extract_literal_values(output_event_model, "type") | ||
| output_schema = output_event_model.model_json_schema() | ||
|
|
||
| derived_input_types: set[str] = set() | ||
| for state in lifecycle_data["states"]: | ||
| derived_input_types.update(state.get("accepts", [])) | ||
|
|
||
| return cls( | ||
| lifecycle=AgentLifecycle.model_validate(lifecycle_data), | ||
| data_events=data_events, | ||
| input_types=sorted(derived_input_types | set(extra_input_types or [])), | ||
| output_schema=output_schema, | ||
| ) | ||
|
|
||
|
|
||
| def extract_literal_values(model: type[BaseModel], field: str) -> list[str]: | ||
| """Extract allowed values from a Literal[...] type annotation on a Pydantic model field.""" | ||
| field_info = model.model_fields.get(field) | ||
| if field_info is None: | ||
| return [] | ||
|
|
||
| annotation = field_info.annotation | ||
| if annotation is None: | ||
| return [] | ||
|
|
||
| # Unwrap Optional (Union[X, None]) to get the inner type | ||
| if get_origin(annotation) is typing.Union: | ||
| args = [a for a in get_args(annotation) if a is not type(None)] | ||
| annotation = args[0] if len(args) == 1 else annotation | ||
|
|
||
| if get_origin(annotation) is typing.Literal: | ||
| return list(get_args(annotation)) | ||
|
|
||
| return [] | ||
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
Oops, something went wrong.
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.