-
Notifications
You must be signed in to change notification settings - Fork 336
feat: Add server-side support for plumbing requested and activated extensions #333
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
56cb1f6
Add server support for propagating extensions, both input and output.
mikeas1 a941547
Add tests related to server side extensions.
mikeas1 b500742
Ruff format
mikeas1 091499c
Apply suggestions from code review
mikeas1 75849c0
Split headers by single space, handle trimming
mikeas1 b141ecf
Refactor to use common header value splitter
mikeas1 63d99bc
Merge branch 'main' into extensions-plumbing
mikeas1 c27d7f5
Fix bad merge
mikeas1 d279515
Refactors from review: sort extensions in response, small method refa…
mikeas1 edf38c1
Case insensitive comparison of grpc metadata keys
mikeas1 93675e1
Rename fields to camel_case, fix grpc import
mikeas1 ea78b6b
uv run ruff check --fix
mikeas1 772656c
Formatting
holtskinner 5bfa790
ci: Change no_implicit_optional execution in format.sh
holtskinner 3a4f9b9
Merge branch 'main' into extensions-plumbing
holtskinner 5c6722f
Merge branch 'main' into extensions-plumbing
holtskinner d2244e6
Merge branch 'main' into extensions-plumbing
mikeas1 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from a2a.types import AgentCard, AgentExtension | ||
|
|
||
|
|
||
| HTTP_EXTENSION_HEADER = 'X-A2A-Extensions' | ||
|
|
||
|
|
||
| def get_requested_extensions(values: list[str]) -> set[str]: | ||
| """Get the set of requested extensions from an input list. | ||
| This handles the list containing potentially comma-separated values, as | ||
| occurs when using a list in an HTTP header. | ||
| """ | ||
| return { | ||
| stripped | ||
| for v in values | ||
| for ext in v.split(',') | ||
| if (stripped := ext.strip()) | ||
| } | ||
|
|
||
|
|
||
| def find_extension_by_uri(card: AgentCard, uri: str) -> AgentExtension | None: | ||
| """Find an AgentExtension in an AgentCard given a uri.""" | ||
| for ext in card.capabilities.extensions or []: | ||
| if ext.uri == uri: | ||
| return ext | ||
holtskinner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return None | ||
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,58 @@ | ||
| from a2a.extensions.common import ( | ||
| find_extension_by_uri, | ||
| get_requested_extensions, | ||
| ) | ||
| from a2a.types import AgentCapabilities, AgentCard, AgentExtension | ||
|
|
||
|
|
||
| def test_get_requested_extensions(): | ||
| assert get_requested_extensions([]) == set() | ||
| assert get_requested_extensions(['foo']) == {'foo'} | ||
| assert get_requested_extensions(['foo', 'bar']) == {'foo', 'bar'} | ||
| assert get_requested_extensions(['foo, bar']) == {'foo', 'bar'} | ||
| assert get_requested_extensions(['foo,bar']) == {'foo', 'bar'} | ||
| assert get_requested_extensions(['foo', 'bar,baz']) == {'foo', 'bar', 'baz'} | ||
| assert get_requested_extensions(['foo,, bar', 'baz']) == { | ||
| 'foo', | ||
| 'bar', | ||
| 'baz', | ||
| } | ||
| assert get_requested_extensions([' foo , bar ', 'baz']) == { | ||
| 'foo', | ||
| 'bar', | ||
| 'baz', | ||
| } | ||
|
|
||
|
|
||
| def test_find_extension_by_uri(): | ||
| ext1 = AgentExtension(uri='foo', description='The Foo extension') | ||
| ext2 = AgentExtension(uri='bar', description='The Bar extension') | ||
| card = AgentCard( | ||
| name='Test Agent', | ||
| description='Test Agent Description', | ||
| version='1.0', | ||
| url='http://test.com', | ||
| skills=[], | ||
| default_input_modes=['text/plain'], | ||
| default_output_modes=['text/plain'], | ||
| capabilities=AgentCapabilities(extensions=[ext1, ext2]), | ||
| ) | ||
|
|
||
| assert find_extension_by_uri(card, 'foo') == ext1 | ||
| assert find_extension_by_uri(card, 'bar') == ext2 | ||
| assert find_extension_by_uri(card, 'baz') is None | ||
|
|
||
|
|
||
| def test_find_extension_by_uri_no_extensions(): | ||
| card = AgentCard( | ||
| name='Test Agent', | ||
| description='Test Agent Description', | ||
| version='1.0', | ||
| url='http://test.com', | ||
| skills=[], | ||
| default_input_modes=['text/plain'], | ||
| default_output_modes=['text/plain'], | ||
| capabilities=AgentCapabilities(extensions=None), | ||
| ) | ||
|
|
||
| assert find_extension_by_uri(card, 'foo') is None |
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.
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.