-
Notifications
You must be signed in to change notification settings - Fork 1k
Upgrade fasta2a to A2A v0.2.3 and Enable Dependency Injection #2103
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
Closed
+1,254
−261
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eee8dc1
add metadata support to tasks
physicsrob 93684ea
feat: add deps_factory support to Agent.to_a2a()
physicsrob 810b91a
feat: update A2A schema to v0.2.1 specification
physicsrob 14f637c
feat: update application layer for new A2A protocol
physicsrob ce7cd6a
feat: update worker layer for new A2A protocol
physicsrob 89e2e4d
feat: update A2A client for new protocol
physicsrob 913b3e2
feat: complete A2A v0.2.1 protocol migration with full type safety
physicsrob a5edbfe
feat: update schema to match A2A v0.2.3 specification
physicsrob 7c65ff3
feat: update schema to fully match A2A v0.2.3 specification
physicsrob b4dc2ae
updated tests
physicsrob fb3671b
tests passing
physicsrob 129a17f
feat: add streaming support to A2A protocol implementation
physicsrob 0151b84
lint
physicsrob 0021884
fix: add exception logging to fasta2a worker and fix type errors
physicsrob 17af717
Fix lint; Rename tests/fasta2a to tests/test_fasta2a to avoid import …
physicsrob 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,39 @@ | ||
Example showing how to expose the [bank support agent](bank-support.md) as an A2A server with dependency injection. | ||
|
||
Demonstrates: | ||
|
||
* Converting an existing agent to A2A | ||
* Using `deps_factory` to provide customer context | ||
* Passing metadata through A2A protocol | ||
|
||
## Running the Example | ||
|
||
With [dependencies installed and environment variables set](./index.md#usage), run: | ||
|
||
```bash | ||
# Start the A2A server | ||
uvicorn pydantic_ai_examples.bank_support_a2a:app --reload | ||
|
||
# In another terminal, send a request | ||
curl -X POST http://localhost:8000/tasks.send \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"jsonrpc": "2.0", | ||
"method": "tasks.send", | ||
"params": { | ||
"id": "test-task-1", | ||
"message": { | ||
"role": "user", | ||
"parts": [{"type": "text", "text": "What is my balance?"}] | ||
}, | ||
"metadata": {"customer_id": 123} | ||
}, | ||
"id": "1" | ||
}' | ||
``` | ||
|
||
## Example Code | ||
|
||
```python {title="bank_support_a2a.py"} | ||
#! examples/pydantic_ai_examples/bank_support_a2a.py | ||
``` |
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,75 @@ | ||
"""Bank support agent exposed as an A2A server. | ||
|
||
Shows how to use deps_factory to provide customer context from task metadata. | ||
|
||
Run the server: | ||
python -m pydantic_ai_examples.bank_support_a2a | ||
# or | ||
uvicorn pydantic_ai_examples.bank_support_a2a:app --reload | ||
|
||
Test with curl: | ||
curl -X POST http://localhost:8000/ \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"jsonrpc": "2.0", | ||
"method": "tasks/send", | ||
"params": { | ||
"id": "test-task-1", | ||
"message": { | ||
"role": "user", | ||
"parts": [{"type": "text", "text": "What is my balance?"}] | ||
}, | ||
"metadata": {"customer_id": 123} | ||
}, | ||
"id": "1" | ||
}' | ||
|
||
Then get the result: | ||
curl -X POST http://localhost:8000/ \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"jsonrpc": "2.0", | ||
"method": "tasks/get", | ||
"params": {"id": "test-task-1"}, | ||
"id": "2" | ||
}' | ||
""" | ||
|
||
from fasta2a.schema import Task | ||
|
||
from pydantic_ai_examples.bank_support import ( | ||
DatabaseConn, | ||
SupportDependencies, | ||
support_agent, | ||
) | ||
|
||
|
||
def create_deps(task: Task) -> SupportDependencies: | ||
"""Create dependencies from A2A task metadata. | ||
|
||
In a real application, you might: | ||
- Validate the customer_id | ||
- Look up authentication from a session token | ||
- Connect to a real database with connection pooling | ||
""" | ||
metadata = task.get('metadata', {}) | ||
customer_id = metadata.get('customer_id', 0) | ||
|
||
# In production, you'd validate the customer exists | ||
# and the request is authorized | ||
return SupportDependencies(customer_id=customer_id, db=DatabaseConn()) | ||
|
||
|
||
# Create the A2A application | ||
app = support_agent.to_a2a( | ||
deps_factory=create_deps, | ||
name='Bank Support Agent', | ||
description='AI support agent for banking customers', | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
# For development convenience | ||
import uvicorn | ||
|
||
uvicorn.run(app, host='0.0.0.0', port=8000) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?