-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: add Data Engineering Agent A2A client example [2/2] #14387
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
xtan999
wants to merge
2
commits into
GoogleCloudPlatform:main
Choose a base branch
from
xtan999:data-engineering-agent-client-complete
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.
+776
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,140 @@ | ||
| # Data Engineering Agent A2A Client Example | ||
|
|
||
| This directory contains a sample Python implementation of an | ||
| [Agent-to-Agent (A2A)](https://a2a-protocol.org/) client designed to interact | ||
| with the **Google Cloud Data Engineering Agent (DEA)**. | ||
|
|
||
| ## Background | ||
|
|
||
| The Data Engineering Agent is a BigQuery and Dataform ELT expert capable of | ||
| building, managing, and troubleshooting data pipelines. To enable | ||
| interoperability across different platforms and agents, it exposes an interface | ||
| following the A2A protocol. | ||
|
|
||
| Official Documentation: | ||
| [Data Engineering Agent API Overview](https://docs.cloud.google.com/gemini/data-agents/data-engineering-agent/api-overview) | ||
|
|
||
| This example demonstrates how to use the open-source | ||
| [A2A Python SDK](https://github.com/a2aproject/a2a-python) to: 1. **Discover** | ||
| the agent's capabilities via its Agent Card. 2. **Authenticate** using Google | ||
| Application Default Credentials (ADC). 3. **Maintain State** across multi-turn | ||
| conversations using Conversation Tokens persisted to a local file. 4. **Handle | ||
| Complex Tasks** by automatically resuming execution when agent finished with | ||
| `DEADLINE_EXCEEDED`. 5. **Configure Extensions** like `Instruction` to customize | ||
| agent behavior. | ||
|
|
||
| ## Features | ||
|
|
||
| - **Native A2A SDK Usage:** Uses `A2ACardResolver` and `create_client` for | ||
| idiomatic protocol interaction. | ||
| - **Streaming-only Execution:** Hardcoded to use response streaming for lowest | ||
| real-time latency and optimal interaction patterns. | ||
| - **Session Persistence:** Automatically saves and loads the | ||
| `conversationToken` from a local file, allowing multi-turn conversations via | ||
| repeated script executions. | ||
| - **Configurable Parameters:** Exposes `gcp_resource_id` for flexibility, | ||
| automatically extracting project and location details. | ||
| - **Instruction Loading:** Automatically reads custom instructions from local | ||
| files or directories, using filenames as the instruction name and file | ||
| content as the definition. | ||
| - **Extension Header Support:** Uses `ServiceParametersFactory` to correctly | ||
| set the `A2A-Extensions` HTTP header required by the agent. | ||
| - **Automated Resumption:** Detects `DEADLINE_EXCEEDED` via the | ||
| `finish_reason` extension and transparently continues the task. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.10 or higher. | ||
| - [Google Cloud SDK (gcloud)](https://cloud.google.com/sdk/docs/install) | ||
| installed and configured. | ||
| - Enable required APIs | ||
| [Use the Data Engineering Agent to build and modify data pipelines](https://docs.cloud.google.com/bigquery/docs/data-engineering-agent-pipelines#required-apis) | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. **Create and activate a virtual environment:** | ||
|
|
||
| ```bash | ||
| python3 -m venv .dea | ||
| source .dea/bin/activate | ||
| ``` | ||
|
|
||
| 2. **Install dependencies:** | ||
|
|
||
| ```bash | ||
| pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| 3. **Authenticate with Google Cloud:** | ||
|
|
||
| ```bash | ||
| gcloud auth application-default login | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Single Message Mode | ||
|
|
||
| Sends a single message and exits. `gcp_resource_id` and `message` are required. | ||
|
|
||
| ``` | ||
| python3 dea_a2a_client.py \ | ||
| --gcp_resource_id projects/my-project/locations/us-central1/repositories/my-repo/workspaces/default \ | ||
| --message "List my Dataform tables" | ||
| ``` | ||
|
|
||
| ### Multi-turn Conversation (State Persistence) | ||
|
|
||
| To maintain a conversation across multiple calls, use the | ||
| `--conversation_token_path` argument. The script will save the conversation | ||
| token to this file and reload it in subsequent calls. | ||
|
|
||
| ``` | ||
| # First turn (starts session) | ||
| python3 dea_a2a_client.py \ | ||
| --gcp_resource_id projects/my-project/locations/us-central1/repositories/my-repo/workspaces/default \ | ||
| --message "hi" \ | ||
| --conversation_token_path ./token.txt | ||
|
|
||
| # Second turn (continues previous context) | ||
| python3 dea_a2a_client.py \ | ||
| --gcp_resource_id projects/my-project/locations/us-central1/repositories/my-repo/workspaces/default \ | ||
| --message "Explain the first table" \ | ||
| --conversation_token_path ./token.txt | ||
| ``` | ||
|
|
||
| ### Advanced: Providing Local Instructions | ||
|
|
||
| You can point the client to local files (e.g., SQL style guides) to influence | ||
| the agent's behavior. | ||
|
|
||
| ``` | ||
| python3 dea_a2a_client.py \ | ||
| --gcp_resource_id projects/my-project/locations/us-central1/repositories/my-repo/workspaces/default \ | ||
| --message "List my tables" \ | ||
| --instruction_path ./style_guide.md | ||
| ``` | ||
|
|
||
| #### Command-line Arguments | ||
|
|
||
| Argument | Required | Description | ||
| :-------------------------- | :------- | :---------- | ||
| `--gcp_resource_id` | **Yes** | The target resource ID. Supported formats `projects/{p}/locations/{l}/repositories/{r}/workspaces/{w}` (Dataform) | ||
| `--message` | **Yes** | The message to send to the agent. | ||
| `--conversation_token_path` | No | Path to a local file to persist conversation token. Allows for multi-turn conversations. | ||
| `--instruction_path` | No | Path to a file or directory containing instructions. Can be repeated. | ||
|
|
||
| ### Running Unit Tests | ||
|
|
||
| Make sure the virtual environment is activated, then run: | ||
|
|
||
| ```bash | ||
| python3 dea_a2a_client_test.py | ||
| ``` | ||
|
|
||
| Alternatively, if the virtual environment is not activated, you can run it | ||
| directly using the venv python: | ||
|
|
||
| ```bash | ||
| ./.dea/bin/python3 dea_a2a_client_test.py | ||
| ``` | ||
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.
Please reformat this.