Compare commits

..

64 Commits

Author SHA1 Message Date
Hangfei Lin 8f94a0c7b3 ADK v0.4.0 release.
PiperOrigin-RevId: 754103716
2025-05-02 12:56:42 -07:00
Divyansh Shukla 4f48ea1c08 ADK changes
PiperOrigin-RevId: 754103075
2025-05-02 12:54:38 -07:00
Wei Sun (Jack) 3fddac5813 Merge pull request #256 from sumant-pangotra/#247-OpenAPIToolSet-Considering-Required-parameters
fix: #247 OpenAPIToolSet Parameter required field and description 

Merged in https://github.com/google/adk-python/commit/e8fb4ed3fcba1f455507c38275ee17218017a409
2025-05-02 10:47:28 -07:00
Wei Sun (Jack) 9b52ce28f5 Merge branch 'main' into #247-OpenAPIToolSet-Considering-Required-parameters 2025-05-02 10:46:47 -07:00
sumant-pangotra e8fb4ed3fc Copybara import of the project:
--
27b214df3e by Sumant Pangotra <sumantpangotra@gmail.com>:

Fixed Parameter required field and description

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/256 from sumant-pangotra:#247-OpenAPIToolSet-Considering-Required-parameters 42f87a9c94
PiperOrigin-RevId: 754050217
2025-05-02 10:23:49 -07:00
sumant-pangotra 42f87a9c94 Merge branch 'main' into #247-OpenAPIToolSet-Considering-Required-parameters 2025-05-02 12:06:41 +05:30
Xiang (Sean) Zhou d387ab0c38 don't send content with empty text to LLM
PiperOrigin-RevId: 753869699
2025-05-01 23:01:50 -07:00
Wei Sun (Jack) f12300113d Merge branch 'main' into #247-OpenAPIToolSet-Considering-Required-parameters 2025-05-01 18:47:28 -07:00
Selcuk Gun 6c0a0d69ca Add pyink-annotation-pragmas to match google formatting
PiperOrigin-RevId: 753778114
2025-05-01 16:50:36 -07:00
Wei Sun 23b41c3f94 Uses google's profile for isort.
PiperOrigin-RevId: 753619497
2025-05-01 09:31:06 -07:00
Shangjie Chen 14933ba470 feat: Extract content encode/decode logic to a shared util and resolve issues with JSON serialization.
feat: Update key length for DB table to avoid key too long issue in mysql

PiperOrigin-RevId: 753614879
2025-05-01 09:13:28 -07:00
Wei Sun b691904e57 chore: Adds a github action to check pyformat via pyink.
PiperOrigin-RevId: 753246116
2025-04-30 11:28:12 -07:00
Wei Sun (Jack) 641781bced Merge pull request #434 from AlankritVerma01/support-async-tool-callbacks
feat(llm_flows): support async before/after tool callbacks
2025-04-29 22:49:18 -07:00
Wei Sun (Jack) c4e09a2edb Merge branch 'main' into support-async-tool-callbacks 2025-04-29 22:48:45 -07:00
JoĂŁo Campista acbbdb7266 Copybara import of the project:
--
709e1dd079d03d7eb4d742b9448ed3d1b946ff30 by joao.campista <joaocampista@proton.me>:

feat: add ordering to recent events in database session service
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/454 from lugui-co:main 912503f972c9cbd8982f2b7f8b210d4e0fe08b69
PiperOrigin-RevId: 753013663
2025-04-29 22:13:41 -07:00
Alankrit Verma 27ce65ff50 Copybara import of the project:
--
21736067f9 by Alankrit Verma <alankrit386@gmail.com>:

feat(llm_flows): support async before/after tool callbacks

Previously, callbacks were treated as purely synchronous,
so passing an async coroutine caused “was never awaited”
errors and Pydantic serialization failures.

Now we detect awaitable return values from
before_tool_callback and after_tool_callback,
and `await` them if necessary.

Fixes: #380

--
08ac9a117e by Alankrit Verma <alankrit386@gmail.com>:

Refactor function callback handling and update type signatures

- Simplify variable names in `functions.py`: always use `function_response` and `altered_function_response`
- Update LlmAgent callback type aliases to support async:
  - Import `Awaitable`
  - Change `BeforeToolCallback` and `AfterToolCallback` signatures to return `Awaitable[Optional[dict]]`
- Ensure `after_tool_callback` uses `await` when necessary

--
fcbf57466e by Alankrit Verma <alankrit386@gmail.com>:

refactor: update callback type signatures to support sync and async responses
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/434 from AlankritVerma01:support-async-tool-callbacks 926b0ef1a6
PiperOrigin-RevId: 753005846
2025-04-29 21:40:33 -07:00
Alankrit Verma 926b0ef1a6 Merge branch 'main' into support-async-tool-callbacks 2025-04-29 22:08:18 -04:00
Xiang (Sean) Zhou dbbeb190b0 Add two adk run options:
--replay : a json file that contains the initial session state and user queries, adk run will create a new session based on the state and run the user queries against the session. Users cannot continue to interact with agent.

--resume : a json file that contains the previously saved session (by --save_session option), adk run will replay this session and then user can continue to interact with the agent.
PiperOrigin-RevId: 752923403
2025-04-29 16:23:10 -07:00
Shangjie Chen 2a9ddec7e3 Set the max size of strings in database columns.
PiperOrigin-RevId: 752918808
2025-04-29 16:07:45 -07:00
Xiang (Sean) Zhou 2ea4315e9f update the doc comments of requested_auth_configs to make it more precise.
PiperOrigin-RevId: 752861847
2025-04-29 13:33:37 -07:00
Wei Sun (Jack) 67b6fbbe01 chore: Adds a github action to check pyformat via pyink. (#440)
* Adds pyink.yml github action to check file format

* Update pyink.yml to give recommended commands.
2025-04-29 09:39:18 -07:00
Alankrit Verma fcbf57466e refactor: update callback type signatures to support sync and async responses 2025-04-29 09:02:09 -04:00
Alankrit Verma 504aa6ba06 Merge branch 'main' into support-async-tool-callbacks 2025-04-28 23:21:10 -04:00
Alankrit Verma 08ac9a117e Refactor function callback handling and update type signatures
- Simplify variable names in `functions.py`: always use `function_response` and `altered_function_response`
- Update LlmAgent callback type aliases to support async:
  - Import `Awaitable`
  - Change `BeforeToolCallback` and `AfterToolCallback` signatures to return `Awaitable[Optional[dict]]`
- Ensure `after_tool_callback` uses `await` when necessary
2025-04-28 23:16:43 -04:00
Paul Lam 4ae8d72a8d docs: correct typo in conversion_utils.py (#351)
* docs: correct typo in conversion_utils.py

* docs: edited for conciseness
2025-04-28 19:47:34 -07:00
Alankrit Verma 21736067f9 feat(llm_flows): support async before/after tool callbacks
Previously, callbacks were treated as purely synchronous,
so passing an async coroutine caused “was never awaited”
errors and Pydantic serialization failures.

Now we detect awaitable return values from
before_tool_callback and after_tool_callback,
and `await` them if necessary.

Fixes: #380
2025-04-28 14:36:25 -04:00
Shangjie Chen 9a9f7a3765 Update callback comments.
PiperOrigin-RevId: 752162448
2025-04-27 22:20:02 -07:00
Hangfei Lin aa7a98ad9d update readme
PiperOrigin-RevId: 751168005
2025-04-24 15:50:09 -07:00
Yifan Wang a5bf6e3608 ADK changes
PiperOrigin-RevId: 751099184
2025-04-24 12:48:31 -07:00
Ankur Sharma f872577f68 Currently if a model calls a FunctionTool without all the mandatory parameters, the code will just break. This change basically adds the capability for the FunctionTool to identify if the model is missing required arguments, and in that case, instead of breaking the execution, it provides a error message to the model so it could fix the request and retry.
PiperOrigin-RevId: 751023475
2025-04-24 09:31:40 -07:00
Wei Sun (Jack) e6109b1dd6 Copybara import of the project:
--
005028831b2e0873414db62af9ec02ef47a670d2 by Wei Sun (Jack) <weisun@google.com>:

Excludes tests/unittests/tools/application_integration_tool/clients/test_connections_client.py from python-unit-tests.yml
--
42ed38ff814f1a4811468d78cf1872869279919d by Wei Sun (Jack) <weisun@google.com>:

reorder skipped tests in python-unit-tests.yml

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/368 from google:fix-unittests 42ed38ff814f1a4811468d78cf1872869279919d
PiperOrigin-RevId: 750782234
2025-04-23 17:35:34 -07:00
Google Team Member ca993277de ADK changes
PiperOrigin-RevId: 750763037
2025-04-23 16:28:57 -07:00
Wei Sun a49d339251 bump version number to 0.3.0.
PiperOrigin-RevId: 750661619
2025-04-23 11:22:54 -07:00
Wei Sun (Jack) 04e4c85b4e Merge pull request #355 from wyf7107/live-error-toast
fix: Add error toast message when live does not work with certain models
2025-04-22 22:26:38 -07:00
Yifan 3ad939d34c Copybara import of the project:
--
dc53678606 by Yifan Wang <wanyif@google.com>:

Update Google Search Tool display to the correct one

--
bbeb6525ea by Yifan Wang <wanyif@google.com>:

add license header to complied js file

--
db5ea6bc56 by Yifan Wang <wanyif@google.com>:

fix: Enable error toast when live does not work with certain models
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/355 from wyf7107:live-error-toast 2062aa38a7
PiperOrigin-RevId: 750449832
2025-04-22 22:09:59 -07:00
Yifan 2062aa38a7 Merge branch 'main' into live-error-toast 2025-04-22 21:19:43 -07:00
Yifan Wang db5ea6bc56 fix: Enable error toast when live does not work with certain models 2025-04-22 21:16:20 -07:00
Hangfei Lin 5c069cca8f chore: Update README.md (#353)
add instruction about our releases.
2025-04-22 18:18:44 -07:00
Hangfei Lin 22cab9e9a4 chore: Update README.md (#328)
* chore: Update README.md

chore: update readme for contributing guideline

* chore: Update CONTRIBUTING.md

chore: Update CONTRIBUTING.md

* Update CONTRIBUTING.md
2025-04-22 17:20:24 -07:00
Shangjie Chen a9da7a8fc3 feat: Add session_db_url to adk deploy option.
PiperOrigin-RevId: 750355535
2025-04-22 15:53:09 -07:00
Xiang (Sean) Zhou 956fb912e8 feat(auth)!: expose access_token and refresh_token at top level of auth credentails
BREAKING CHANGE: `token` attribute of OAuth2Auth credentials used to be a dict containing both access_token and refresh_token, given that may cause confusions, now we replace it with access_token and refresh_token at top level of the auth credentials

PiperOrigin-RevId: 750346172
2025-04-22 15:23:21 -07:00
Wei Sun 49d8c0fbb2 bump min version of google-genai sdk to latest.
PiperOrigin-RevId: 750324961
2025-04-22 14:17:27 -07:00
Yifan Wang 645402903a ADK changes
PiperOrigin-RevId: 750287732
2025-04-22 12:32:01 -07:00
Yifan c531bb6ef1 Merge branch 'main' into google-search-display 2025-04-22 12:18:57 -07:00
Yifan 7cc3167e54 Copybara import of the project:
--
dc53678606 by Yifan Wang <wanyif@google.com>:

Update Google Search Tool display to the correct one

--
bbeb6525ea by Yifan Wang <wanyif@google.com>:

add license header to complied js file

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/325 from wyf7107:google-search-display 353ff50611
PiperOrigin-RevId: 750284170
2025-04-22 12:17:25 -07:00
Yifan 353ff50611 Merge branch 'main' into google-search-display 2025-04-22 11:30:38 -07:00
Yifan Wang bbeb6525ea add license header to complied js file 2025-04-22 11:21:22 -07:00
Vignesh Iyer 0e9096d865 chore: add support for overriding skip_summarization in AgentTool (#324) 2025-04-22 09:41:31 -07:00
Vignesh Iyer 923d806637 Copybara import of the project:
--
94c7f9579c56cb20252fd61b5fe568f73d864679 by Vignesh Iyer <vgnshiyer@gmail.com>:

chore: add support for overriding `skip_summarization` in AgentTool
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/324 from vgnshiyer:main 94c7f9579c56cb20252fd61b5fe568f73d864679
PiperOrigin-RevId: 750060638
2025-04-21 23:24:25 -07:00
Yifan 463797be25 Merge branch 'main' into google-search-display 2025-04-21 20:53:06 -07:00
Yifan Wang dc53678606 Update Google Search Tool display to the correct one 2025-04-21 20:50:26 -07:00
Che Liu 21d2047ddc ADK changes
PiperOrigin-RevId: 749973427
2025-04-21 17:28:53 -07:00
Wei Sun a5f191650b chore: update the readme for a2a integration.
PiperOrigin-RevId: 749856734
2025-04-21 11:17:04 -07:00
Wei Sun 1e752b1378 chore: Fixes type hints in google_api_tool_set.py.
PiperOrigin-RevId: 749844560
2025-04-21 10:42:48 -07:00
Hangfei Lin 5ab43e804a chore: update the readme for a2a integration (#319)
chore: update the readme for a2a integration
2025-04-21 09:55:30 -07:00
Nilanjan De 220b327a73 chore: fix typos (#272)
Co-authored-by: Hangfei Lin <hangfei@google.com>
2025-04-21 09:26:02 -07:00
Nilanjan De 1664b45562 Copybara import of the project:
--
16994cb2d5d646341f5285ca71d72697d81d18fe by Nilanjan De <nilanjan.de@gmail.com>:

chore: fix typos
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/272 from n1lanjan:fix-typos a1ab655b08ec08c5dd2da71aab9a2386e3610e84
PiperOrigin-RevId: 749690489
2025-04-20 22:53:15 -07:00
Hangfei Lin 23f0383284 fix: The previous commit has a merge conflict. Fix it by adding this back.
The previous commit has a merge conflict. Fix it by adding this back.
2025-04-20 17:08:25 -07:00
Hangfei Lin f7b436a985 No public description
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/282 from hangfei:main 7b9c5e3bff76ed475fb57d45333a9ab135cac32d
PiperOrigin-RevId: 749616712
2025-04-20 16:05:06 -07:00
Wei Sun 2af777af6d No public description
PiperOrigin-RevId: 749409258
2025-04-19 16:34:44 -07:00
Shangjie Chen 32dc145ace No public description
PiperOrigin-RevId: 749399264
2025-04-19 15:16:19 -07:00
Wei Sun 6742ab9236 No public description
PiperOrigin-RevId: 749202950
2025-04-18 18:08:03 -07:00
Rasheedat atinuke jamiu daed456125 Fix AttributeError in run_live when using AgentTool (#274)
Co-authored-by: Hangfei Lin <hangfei@google.com>
2025-04-18 13:37:17 -07:00
Sumant Pangotra 27b214df3e Fixed Parameter required field and description 2025-04-18 03:49:59 +05:30
58 changed files with 1595 additions and 446 deletions
+59
View File
@@ -0,0 +1,59 @@
name: Check Pyink Formatting
on:
pull_request:
paths:
- 'src/**/*.py'
- 'tests/**/*.py'
- 'pyproject.toml'
jobs:
pyink-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install pyink
run: |
pip install pyink
- name: Detect changed Python files
id: detect_changes
run: |
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.py$' || true)
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
- name: Run pyink on changed files
if: env.CHANGED_FILES != ''
run: |
echo "Changed Python files:"
echo "$CHANGED_FILES"
# Run pyink --check
set +e
pyink --check --config pyproject.toml $CHANGED_FILES
RESULT=$?
set -e
if [ $RESULT -ne 0 ]; then
echo ""
echo "❌ Pyink formatting check failed!"
echo "👉 To fix formatting, run locally:"
echo ""
echo " pyink --config pyproject.toml $CHANGED_FILES"
echo ""
exit $RESULT
fi
- name: No changed Python files detected
if: env.CHANGED_FILES == ''
run: |
echo "No Python files changed. Skipping pyink check."
+4 -2
View File
@@ -35,5 +35,7 @@ jobs:
run: |
source .venv/bin/activate
pytest tests/unittests \
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py \
--ignore=tests/unittests/artifacts/test_artifact_service.py
--ignore=tests/unittests/artifacts/test_artifact_service.py \
--ignore=tests/unittests/tools/application_integration_tool/clients/test_connections_client.py \
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py
+57 -2
View File
@@ -1,5 +1,60 @@
# Changelog
## 0.4.0
### âš  BREAKING CHANGES
* Set the max size of strings in database columns. MySQL mandates that all VARCHAR-type fields must specify their lengths.
* Extract content encode/decode logic to a shared util, resolve issues with JSON serialization, and update key length for DB table to avoid key too long issue in mysql.
* Enhance `FunctionTool` to verify if the model is providing all the mandatory arguments.
### Features
* Update ADK setup guide to improve onboarding experience.
* feat: add ordering to recent events in database session service.
* feat(llm_flows): support async before/after tool callbacks.
* feat: Added --replay and --resume options to adk run cli. Check adk run --help for more details.
* Created a new Integration Connector Tool (underlying of the ApplicationIntegrationToolSet) so that we do not force LLM to provide default value.
### Bug Fixes
* Don't send content with empty text to LLM.
* Fix google search reading undefined for `renderedContent`.
### Miscellaneous Chores
* Docstring improvements, typo fixings, github action to enfore code styles on formatting and imports, etc.
## 0.3.0
### âš  BREAKING CHANGES
* Auth: expose `access_token` and `refresh_token` at top level of auth
credentails, instead of a `dict`
([commit](https://github.com/google/adk-python/commit/956fb912e8851b139668b1ccb8db10fd252a6990)).
### Features
* Added support for running agents with MCPToolset easily on `adk web`.
* Added `custom_metadata` field to `LlmResponse`, which can be used to tag
LlmResponse via `after_model_callback`.
* Added `--session_db_url` to `adk deploy cloud_run` option.
* Many Dev UI improvements:
* Better google search result rendering.
* Show websocket close reason in Dev UI.
* Better error message showing for audio/video.
### Bug Fixes
* Fixed MCP tool json schema parsing issue.
* Fixed issues in DatabaseSessionService that leads to crash.
* Fixed functions.py.
* Fixed `skip_summarization` behavior in `AgentTool`.
### Miscellaneous Chores
* README.md impprovements.
* Various code improvements.
* Various typo fixes.
* Bump min version of google-genai to 1.11.0.
## 0.2.0
### âš  BREAKING CHANGES
@@ -45,12 +100,12 @@
* Initial release of the Agent Development Kit (ADK).
* Multi-agent, agent-as-workflow, and custom agent support
* Tool authentication support
* Rich tool support, e.g. bult-in tools, google-cloud tools, third-party tools, and MCP tools
* Rich tool support, e.g. built-in tools, google-cloud tools, third-party tools, and MCP tools
* Rich callback support
* Built-in code execution capability
* Asynchronous runtime and execution
* Session, and memory support
* Built-in evaluation support
* Development UI that makes local devlopment easy
* Development UI that makes local development easy
* Deploy to Google Cloud Run, Agent Engine
* (Experimental) Live(Bidi) auido/video agent support and Compositional Function Calling(CFC) support
+14 -1
View File
@@ -25,9 +25,22 @@ This project follows
## Contribution process
### Requirement for PRs
- All PRs, other than small documentation or typo fixes, should have a Issue assoicated. If not, please create one.
- Small, focused PRs. Keep changes minimal—one concern per PR.
- For bug fixes or features, please provide logs or screenshot after the fix is applied to help reviewers better understand the fix.
- Please add corresponding testing for your code change if it's not covered by existing tests.
### Large or Complex Changes
For substantial features or architectural revisions:
- Open an Issue First: Outline your proposal, including design considerations and impact.
- Gather Feedback: Discuss with maintainers and the community to ensure alignment and avoid duplicate work
### Code reviews
All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.
information on using pull requests.
+26 -7
View File
@@ -18,11 +18,7 @@
</h3>
</html>
Agent Development Kit (ADK) is designed for developers seeking fine-grained
control and flexibility when building advanced AI agents that are tightly
integrated with services in Google Cloud. It allows you to define agent
behavior, orchestration, and tool use directly in code, enabling robust
debugging, versioning, and deployment anywhere – from your laptop to the cloud.
Agent Development Kit (ADK) is a flexible and modular framework for developing and deploying AI agents. While optimized for Gemini and the Google ecosystem, ADK is model-agnostic, deployment-agnostic, and is built for compatibility with other frameworks. ADK was designed to make agent development feel more like software development, to make it easier for developers to create, deploy, and orchestrate agentic architectures that range from simple tasks to complex workflows.
---
@@ -45,12 +41,27 @@ debugging, versioning, and deployment anywhere – from your laptop to the cloud
## 🚀 Installation
You can install the ADK using `pip`:
### Stable Release (Recommended)
You can install the latest stable version of ADK using `pip`:
```bash
pip install google-adk
```
The release cadence is weekly.
This version is recommended for most users as it represents the most recent official release.
### Development Version
Bug fixes and new features are merged into the main branch on GitHub first. If you need access to changes that haven't been included in an official PyPI release yet, you can install directly from the main branch:
```bash
pip install git+https://github.com/google/adk-python.git@main
```
Note: The development version is built directly from the latest code commits. While it includes the newest fixes and features, it may also contain experimental changes or bugs not present in the stable release. Use it primarily for testing upcoming changes or accessing critical fixes before they are officially released.
## 📚 Documentation
Explore the full documentation for detailed guides on building, evaluating, and
@@ -112,10 +123,18 @@ adk eval \
samples_for_testing/hello_world/hello_world_eval_set_001.evalset.json
```
## 🤖 A2A and ADK integration
For remote agent-to-agent communication, ADK integrates with the
[A2A protocol](https://github.com/google/A2A/).
See this [example](https://github.com/google/A2A/tree/main/samples/python/agents/google_adk)
for how they can work together.
## 🤝 Contributing
We welcome contributions from the community! Whether it's bug reports, feature requests, documentation improvements, or code contributions, please see our [**Contributing Guidelines**](./CONTRIBUTING.md) to get started.
We welcome contributions from the community! Whether it's bug reports, feature requests, documentation improvements, or code contributions, please see our
- [General contribution guideline and flow](https://google.github.io/adk-docs/contributing-guide/#questions).
- Then if you want to contribute code, please read [Code Contributing Guidelines](./CONTRIBUTING.md) to get started.
## đź“„ License
+1 -1
View File
@@ -45,7 +45,7 @@ confidence=
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once).You can also use "--disable=all" to
# disable everything first and then reenable specific checks. For example, if
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
+13 -9
View File
@@ -33,7 +33,7 @@ dependencies = [
"google-cloud-secret-manager>=2.22.0", # Fetching secrets in RestAPI Tool
"google-cloud-speech>=2.30.0", # For Audo Transcription
"google-cloud-storage>=2.18.0, <3.0.0", # For GCS Artifact service
"google-genai>=1.9.0", # Google GenAI SDK
"google-genai>=1.11.0", # Google GenAI SDK
"graphviz>=0.20.2", # Graphviz for graph rendering
"mcp>=1.5.0;python_version>='3.10'", # For MCP Toolset
"opentelemetry-api>=1.31.0", # OpenTelemetry
@@ -119,6 +119,15 @@ line-length = 80
unstable = true
pyink-indentation = 2
pyink-use-majority-quotes = true
pyink-annotation-pragmas = [
"noqa",
"pylint:",
"type: ignore",
"pytype:",
"mypy:",
"pyright:",
"pyre-",
]
[build-system]
@@ -135,15 +144,10 @@ exclude = ['src/**/*.sh']
name = "google.adk"
[tool.isort]
# Organize imports following Google style-guide
force_single_line = true
force_sort_within_sections = true
honor_case_in_force_sorted_sections = true
order_by_type = false
sort_relative_in_force_sorted_sections = true
multi_line_output = 3
line_length = 200
profile = "google"
[tool.pytest.ini_options]
testpaths = ["tests"]
asyncio_default_fixture_loop_scope = "function"
asyncio_mode = "auto"
+7 -7
View File
@@ -44,7 +44,7 @@ Args:
callback_context: MUST be named 'callback_context' (enforced).
Returns:
The content to return to the user. When set, the agent run will skipped and
The content to return to the user. When set, the agent run will be skipped and
the provided content will be returned to user.
"""
@@ -55,8 +55,8 @@ Args:
callback_context: MUST be named 'callback_context' (enforced).
Returns:
The content to return to the user. When set, the agent run will skipped and
the provided content will be appended to event history as agent response.
The content to return to the user. When set, the provided content will be
appended to event history as agent response.
"""
@@ -101,8 +101,8 @@ class BaseAgent(BaseModel):
callback_context: MUST be named 'callback_context' (enforced).
Returns:
The content to return to the user. When set, the agent run will skipped and
the provided content will be returned to user.
The content to return to the user. When set, the agent run will be skipped
and the provided content will be returned to user.
"""
after_agent_callback: Optional[AfterAgentCallback] = None
"""Callback signature that is invoked after the agent run.
@@ -111,8 +111,8 @@ class BaseAgent(BaseModel):
callback_context: MUST be named 'callback_context' (enforced).
Returns:
The content to return to the user. When set, the agent run will skipped and
the provided content will be appended to event history as agent response.
The content to return to the user. When set, the provided content will be
appended to event history as agent response.
"""
@final
@@ -23,7 +23,6 @@ from .readonly_context import ReadonlyContext
if TYPE_CHECKING:
from google.genai import types
from ..events.event import Event
from ..events.event_actions import EventActions
from ..sessions.state import State
from .invocation_context import InvocationContext
+3 -8
View File
@@ -15,12 +15,7 @@
from __future__ import annotations
import logging
from typing import Any
from typing import AsyncGenerator
from typing import Callable
from typing import Literal
from typing import Optional
from typing import Union
from typing import Any, AsyncGenerator, Awaitable, Callable, Literal, Optional, Union
from google.genai import types
from pydantic import BaseModel
@@ -62,11 +57,11 @@ AfterModelCallback: TypeAlias = Callable[
]
BeforeToolCallback: TypeAlias = Callable[
[BaseTool, dict[str, Any], ToolContext],
Optional[dict],
Union[Awaitable[Optional[dict]], Optional[dict]],
]
AfterToolCallback: TypeAlias = Callable[
[BaseTool, dict[str, Any], ToolContext, dict],
Optional[dict],
Union[Awaitable[Optional[dict]], Optional[dict]],
]
InstructionProvider: TypeAlias = Callable[[ReadonlyContext], str]
+2 -1
View File
@@ -66,7 +66,8 @@ class OAuth2Auth(BaseModelWithConfig):
redirect_uri: Optional[str] = None
auth_response_uri: Optional[str] = None
auth_code: Optional[str] = None
token: Optional[Dict[str, Any]] = None
access_token: Optional[str] = None
refresh_token: Optional[str] = None
class ServiceAccountCredential(BaseModelWithConfig):
+7 -3
View File
@@ -82,7 +82,8 @@ class AuthHandler:
or not auth_credential.oauth2
or not auth_credential.oauth2.client_id
or not auth_credential.oauth2.client_secret
or auth_credential.oauth2.token
or auth_credential.oauth2.access_token
or auth_credential.oauth2.refresh_token
):
return self.auth_config.exchanged_auth_credential
@@ -93,7 +94,7 @@ class AuthHandler:
redirect_uri=auth_credential.oauth2.redirect_uri,
state=auth_credential.oauth2.state,
)
token = client.fetch_token(
tokens = client.fetch_token(
token_endpoint,
authorization_response=auth_credential.oauth2.auth_response_uri,
code=auth_credential.oauth2.auth_code,
@@ -102,7 +103,10 @@ class AuthHandler:
updated_credential = AuthCredential(
auth_type=AuthCredentialTypes.OAUTH2,
oauth2=OAuth2Auth(token=dict(token)),
oauth2=OAuth2Auth(
access_token=tokens.get("access_token"),
refresh_token=tokens.get("refresh_token"),
),
)
return updated_credential
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+54 -47
View File
@@ -39,12 +39,12 @@ class InputFile(BaseModel):
async def run_input_file(
app_name: str,
user_id: str,
root_agent: LlmAgent,
artifact_service: BaseArtifactService,
session: Session,
session_service: BaseSessionService,
input_path: str,
) -> None:
) -> Session:
runner = Runner(
app_name=app_name,
agent=root_agent,
@@ -55,9 +55,11 @@ async def run_input_file(
input_file = InputFile.model_validate_json(f.read())
input_file.state['_time'] = datetime.now()
session.state = input_file.state
session = session_service.create_session(
app_name=app_name, user_id=user_id, state=input_file.state
)
for query in input_file.queries:
click.echo(f'user: {query}')
click.echo(f'[user]: {query}')
content = types.Content(role='user', parts=[types.Part(text=query)])
async for event in runner.run_async(
user_id=session.user_id, session_id=session.id, new_message=content
@@ -65,23 +67,23 @@ async def run_input_file(
if event.content and event.content.parts:
if text := ''.join(part.text or '' for part in event.content.parts):
click.echo(f'[{event.author}]: {text}')
return session
async def run_interactively(
app_name: str,
root_agent: LlmAgent,
artifact_service: BaseArtifactService,
session: Session,
session_service: BaseSessionService,
) -> None:
runner = Runner(
app_name=app_name,
app_name=session.app_name,
agent=root_agent,
artifact_service=artifact_service,
session_service=session_service,
)
while True:
query = input('user: ')
query = input('[user]: ')
if not query or not query.strip():
continue
if query == 'exit':
@@ -100,7 +102,8 @@ async def run_cli(
*,
agent_parent_dir: str,
agent_folder_name: str,
json_file_path: Optional[str] = None,
input_file: Optional[str] = None,
saved_session_file: Optional[str] = None,
save_session: bool,
) -> None:
"""Runs an interactive CLI for a certain agent.
@@ -109,8 +112,11 @@ async def run_cli(
agent_parent_dir: str, the absolute path of the parent folder of the agent
folder.
agent_folder_name: str, the name of the agent folder.
json_file_path: Optional[str], the absolute path to the json file, either
*.input.json or *.session.json.
input_file: Optional[str], the absolute path to the json file that contains
the initial session state and user queries, exclusive with
saved_session_file.
saved_session_file: Optional[str], the absolute path to the json file that
contains a previously saved session, exclusive with input_file.
save_session: bool, whether to save the session on exit.
"""
if agent_parent_dir not in sys.path:
@@ -118,46 +124,50 @@ async def run_cli(
artifact_service = InMemoryArtifactService()
session_service = InMemorySessionService()
session = session_service.create_session(
app_name=agent_folder_name, user_id='test_user'
)
agent_module_path = os.path.join(agent_parent_dir, agent_folder_name)
agent_module = importlib.import_module(agent_folder_name)
user_id = 'test_user'
session = session_service.create_session(
app_name=agent_folder_name, user_id=user_id
)
root_agent = agent_module.agent.root_agent
envs.load_dotenv_for_agent(agent_folder_name, agent_parent_dir)
if json_file_path:
if json_file_path.endswith('.input.json'):
await run_input_file(
app_name=agent_folder_name,
root_agent=root_agent,
artifact_service=artifact_service,
session=session,
session_service=session_service,
input_path=json_file_path,
)
elif json_file_path.endswith('.session.json'):
with open(json_file_path, 'r') as f:
session = Session.model_validate_json(f.read())
for content in session.get_contents():
if content.role == 'user':
print('user: ', content.parts[0].text)
if input_file:
session = await run_input_file(
app_name=agent_folder_name,
user_id=user_id,
root_agent=root_agent,
artifact_service=artifact_service,
session_service=session_service,
input_path=input_file,
)
elif saved_session_file:
loaded_session = None
with open(saved_session_file, 'r') as f:
loaded_session = Session.model_validate_json(f.read())
if loaded_session:
for event in loaded_session.events:
session_service.append_event(session, event)
content = event.content
if not content or not content.parts or not content.parts[0].text:
continue
if event.author == 'user':
click.echo(f'[user]: {content.parts[0].text}')
else:
print(content.parts[0].text)
await run_interactively(
agent_folder_name,
root_agent,
artifact_service,
session,
session_service,
)
else:
print(f'Unsupported file type: {json_file_path}')
exit(1)
click.echo(f'[{event.author}]: {content.parts[0].text}')
await run_interactively(
root_agent,
artifact_service,
session,
session_service,
)
else:
print(f'Running agent {root_agent.name}, type exit to exit.')
click.echo(f'Running agent {root_agent.name}, type exit to exit.')
await run_interactively(
agent_folder_name,
root_agent,
artifact_service,
session,
@@ -165,11 +175,8 @@ async def run_cli(
)
if save_session:
if json_file_path:
session_path = json_file_path.replace('.input.json', '.session.json')
else:
session_id = input('Session ID to save: ')
session_path = f'{agent_module_path}/{session_id}.session.json'
session_id = input('Session ID to save: ')
session_path = f'{agent_module_path}/{session_id}.session.json'
# Fetch the session again to get all the details.
session = session_service.get_session(
+6 -1
View File
@@ -54,7 +54,7 @@ COPY "agents/{app_name}/" "/app/agents/{app_name}/"
EXPOSE {port}
CMD adk {command} --port={port} {trace_to_cloud_option} "/app/agents"
CMD adk {command} --port={port} {session_db_option} {trace_to_cloud_option} "/app/agents"
"""
@@ -85,6 +85,7 @@ def to_cloud_run(
trace_to_cloud: bool,
with_ui: bool,
verbosity: str,
session_db_url: str,
):
"""Deploys an agent to Google Cloud Run.
@@ -112,6 +113,7 @@ def to_cloud_run(
trace_to_cloud: Whether to enable Cloud Trace.
with_ui: Whether to deploy with UI.
verbosity: The verbosity level of the CLI.
session_db_url: The database URL to connect the session.
"""
app_name = app_name or os.path.basename(agent_folder)
@@ -144,6 +146,9 @@ def to_cloud_run(
port=port,
command='web' if with_ui else 'api_server',
install_agent_deps=install_agent_deps,
session_db_option=f'--session_db_url={session_db_url}'
if session_db_url
else '',
trace_to_cloud_option='--trace_to_cloud' if trace_to_cloud else '',
)
dockerfile_path = os.path.join(temp_folder, 'Dockerfile')
+1 -1
View File
@@ -256,7 +256,7 @@ def run_evals(
)
if final_eval_status == EvalStatus.PASSED:
result = "âś… Passsed"
result = "âś… Passed"
else:
result = "❌ Failed"
+78 -13
View File
@@ -96,6 +96,23 @@ def cli_create_cmd(
)
def validate_exclusive(ctx, param, value):
# Store the validated parameters in the context
if not hasattr(ctx, "exclusive_opts"):
ctx.exclusive_opts = {}
# If this option has a value and we've already seen another exclusive option
if value is not None and any(ctx.exclusive_opts.values()):
exclusive_opt = next(key for key, val in ctx.exclusive_opts.items() if val)
raise click.UsageError(
f"Options '{param.name}' and '{exclusive_opt}' cannot be set together."
)
# Record this option's value
ctx.exclusive_opts[param.name] = value is not None
return value
@main.command("run")
@click.option(
"--save_session",
@@ -105,13 +122,43 @@ def cli_create_cmd(
default=False,
help="Optional. Whether to save the session to a json file on exit.",
)
@click.option(
"--replay",
type=click.Path(
exists=True, dir_okay=False, file_okay=True, resolve_path=True
),
help=(
"The json file that contains the initial state of the session and user"
" queries. A new session will be created using this state. And user"
" queries are run againt the newly created session. Users cannot"
" continue to interact with the agent."
),
callback=validate_exclusive,
)
@click.option(
"--resume",
type=click.Path(
exists=True, dir_okay=False, file_okay=True, resolve_path=True
),
help=(
"The json file that contains a previously saved session (by"
"--save_session option). The previous session will be re-displayed. And"
" user can continue to interact with the agent."
),
callback=validate_exclusive,
)
@click.argument(
"agent",
type=click.Path(
exists=True, dir_okay=True, file_okay=False, resolve_path=True
),
)
def cli_run(agent: str, save_session: bool):
def cli_run(
agent: str,
save_session: bool,
replay: Optional[str],
resume: Optional[str],
):
"""Runs an interactive CLI for a certain agent.
AGENT: The path to the agent source code folder.
@@ -129,6 +176,8 @@ def cli_run(agent: str, save_session: bool):
run_cli(
agent_parent_dir=agent_parent_folder,
agent_folder_name=agent_folder_name,
input_file=replay,
saved_session_file=resume,
save_session=save_session,
)
)
@@ -245,12 +294,13 @@ def cli_eval(
@click.option(
"--session_db_url",
help=(
"Optional. The database URL to store the session.\n\n - Use"
" 'agentengine://<agent_engine_resource_id>' to connect to Vertex"
" managed session service.\n\n - Use 'sqlite://<path_to_sqlite_file>'"
" to connect to a SQLite DB.\n\n - See"
" https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls"
" for more details on supported DB URLs."
"""Optional. The database URL to store the session.
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
),
)
@click.option(
@@ -366,12 +416,13 @@ def cli_web(
@click.option(
"--session_db_url",
help=(
"Optional. The database URL to store the session.\n\n - Use"
" 'agentengine://<agent_engine_resource_id>' to connect to Vertex"
" managed session service.\n\n - Use 'sqlite://<path_to_sqlite_file>'"
" to connect to a SQLite DB.\n\n - See"
" https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls"
" for more details on supported DB URLs."
"""Optional. The database URL to store the session.
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
),
)
@click.option(
@@ -541,6 +592,18 @@ def cli_api_server(
default="WARNING",
help="Optional. Override the default verbosity level.",
)
@click.option(
"--session_db_url",
help=(
"""Optional. The database URL to store the session.
- Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
- Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
- See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
),
)
@click.argument(
"agent",
type=click.Path(
@@ -558,6 +621,7 @@ def cli_deploy_cloud_run(
trace_to_cloud: bool,
with_ui: bool,
verbosity: str,
session_db_url: str,
):
"""Deploys an agent to Cloud Run.
@@ -579,6 +643,7 @@ def cli_deploy_cloud_run(
trace_to_cloud=trace_to_cloud,
with_ui=with_ui,
verbosity=verbosity,
session_db_url=session_db_url,
)
except Exception as e:
click.secho(f"Deploy failed: {e}", fg="red", err=True)
+6
View File
@@ -756,6 +756,12 @@ def get_fast_api_app(
except Exception as e:
logger.exception("Error during live websocket communication: %s", e)
traceback.print_exc()
WEBSOCKET_INTERNAL_ERROR_CODE = 1011
WEBSOCKET_MAX_BYTES_FOR_REASON = 123
await websocket.close(
code=WEBSOCKET_INTERNAL_ERROR_CODE,
reason=str(e)[:WEBSOCKET_MAX_BYTES_FOR_REASON],
)
finally:
for task in pending:
task.cancel()

Some files were not shown because too many files have changed in this diff Show More