├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── release-please.yml ├── release-trigger.yml └── workflows │ ├── check-file-contents.yml │ ├── isort.yml │ ├── pyink.yml │ └── python-unit-tests.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets ├── adk-web-dev-ui-function-call.png └── agent-development-kit.png ├── autoformat.sh ├── contributing └── samples │ ├── README.md │ ├── adk_triaging_agent │ └── agent.py │ ├── application_integration_agent │ ├── README.md │ ├── __init__.py │ └── agent.py │ ├── artifact_save_text │ ├── __init__.py │ └── agent.py │ ├── bigquery │ ├── README.md │ ├── __init__.py │ └── agent.py │ ├── bigquery_agent │ ├── README.md │ ├── __init__.py │ └── agent.py │ ├── callbacks │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── code_execution │ ├── __init__.py │ └── agent.py │ ├── fields_output_schema │ ├── __init__.py │ └── agent.py │ ├── fields_planner │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── generate_image │ ├── __init__.py │ ├── agent.py │ └── sample.session.json │ ├── google_search_agent │ ├── __init__.py │ └── agent.py │ ├── hello_world │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── hello_world_anthropic │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── hello_world_litellm │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── hello_world_ma │ ├── __init__.py │ └── agent.py │ ├── hello_world_ollama │ ├── README.md │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── human_in_loop │ ├── README.md │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── integration_connector_euc_agent │ ├── README.md │ ├── __init__.py │ └── agent.py │ ├── jira_agent │ ├── README.md │ ├── __init__.py │ ├── agent.py │ ├── image-app-intg-editor.png │ ├── image-application-integration.png │ ├── image-connection-tool.png │ └── tools.py │ ├── langchain_structured_tool_agent │ ├── __init__.py │ └── agent.py │ ├── langchain_youtube_search_agent │ ├── README.md │ ├── __init__.py │ ├── agent.py │ └── requirements.txt │ ├── mcp_sse_agent │ ├── README.md │ ├── __init__.py │ ├── agent.py │ └── filesystem_server.py │ ├── mcp_stdio_notion_agent │ ├── README.md │ ├── __init__.py │ └── agent.py │ ├── mcp_stdio_server_agent │ ├── __init__.py │ └── agent.py │ ├── mcp_streamablehttp_agent │ ├── README.md │ ├── __init__.py │ ├── agent.py │ └── filesystem_server.py │ ├── memory │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── non_llm_sequential │ ├── __init__.py │ └── agent.py │ ├── oauth_calendar_agent │ ├── README.md │ ├── __init__.py │ └── agent.py │ ├── quickstart │ ├── __init__.py │ └── agent.py │ ├── session_state_agent │ ├── README.md │ ├── __init__.py │ ├── agent.py │ └── input.json │ ├── simple_sequential_agent │ ├── __init__.py │ └── agent.py │ ├── telemetry │ ├── agent.py │ └── main.py │ ├── token_usage │ ├── __init__.py │ ├── agent.py │ └── main.py │ ├── toolbox_agent │ ├── README.md │ ├── __init__.py │ ├── agent.py │ ├── tool_box.db │ └── tools.yaml │ └── workflow_agent_seq │ ├── README.md │ ├── __init__.py │ ├── agent.py │ ├── main.py │ └── sample.output ├── pylintrc ├── pyproject.toml ├── src └── google │ └── adk │ ├── __init__.py │ ├── agents │ ├── __init__.py │ ├── active_streaming_tool.py │ ├── base_agent.py │ ├── callback_context.py │ ├── invocation_context.py │ ├── langgraph_agent.py │ ├── live_request_queue.py │ ├── llm_agent.py │ ├── loop_agent.py │ ├── parallel_agent.py │ ├── readonly_context.py │ ├── run_config.py │ ├── sequential_agent.py │ └── transcription_entry.py │ ├── artifacts │ ├── __init__.py │ ├── base_artifact_service.py │ ├── gcs_artifact_service.py │ └── in_memory_artifact_service.py │ ├── auth │ ├── __init__.py │ ├── auth_credential.py │ ├── auth_handler.py │ ├── auth_preprocessor.py │ ├── auth_schemes.py │ └── auth_tool.py │ ├── cli │ ├── __init__.py │ ├── __main__.py │ ├── agent_graph.py │ ├── browser │ │ ├── adk_favicon.svg │ │ ├── assets │ │ │ ├── ADK-512-color.svg │ │ │ ├── audio-processor.js │ │ │ └── config │ │ │ │ └── runtime-config.json │ │ ├── index.html │ │ ├── main-VEXTCQ7U.js │ │ ├── polyfills-FFHMD2TL.js │ │ └── styles-4VDSPQ37.css │ ├── cli.py │ ├── cli_create.py │ ├── cli_deploy.py │ ├── cli_eval.py │ ├── cli_tools_click.py │ ├── fast_api.py │ └── utils │ │ ├── __init__.py │ │ ├── agent_loader.py │ │ ├── cleanup.py │ │ ├── common.py │ │ ├── envs.py │ │ ├── evals.py │ │ └── logs.py │ ├── code_executors │ ├── __init__.py │ ├── base_code_executor.py │ ├── built_in_code_executor.py │ ├── code_execution_utils.py │ ├── code_executor_context.py │ ├── container_code_executor.py │ ├── unsafe_local_code_executor.py │ └── vertex_ai_code_executor.py │ ├── errors │ ├── __init__.py │ └── not_found_error.py │ ├── evaluation │ ├── __init__.py │ ├── agent_evaluator.py │ ├── eval_case.py │ ├── eval_metrics.py │ ├── eval_result.py │ ├── eval_set.py │ ├── eval_set_results_manager.py │ ├── eval_sets_manager.py │ ├── evaluation_constants.py │ ├── evaluation_generator.py │ ├── evaluator.py │ ├── local_eval_set_results_manager.py │ ├── local_eval_sets_manager.py │ ├── response_evaluator.py │ └── trajectory_evaluator.py │ ├── events │ ├── __init__.py │ ├── event.py │ └── event_actions.py │ ├── examples │ ├── __init__.py │ ├── base_example_provider.py │ ├── example.py │ ├── example_util.py │ └── vertex_ai_example_store.py │ ├── flows │ ├── __init__.py │ └── llm_flows │ │ ├── __init__.py │ │ ├── _base_llm_processor.py │ │ ├── _code_execution.py │ │ ├── _nl_planning.py │ │ ├── agent_transfer.py │ │ ├── audio_transcriber.py │ │ ├── auto_flow.py │ │ ├── base_llm_flow.py │ │ ├── basic.py │ │ ├── contents.py │ │ ├── functions.py │ │ ├── identity.py │ │ ├── instructions.py │ │ └── single_flow.py │ ├── memory │ ├── __init__.py │ ├── _utils.py │ ├── base_memory_service.py │ ├── in_memory_memory_service.py │ ├── memory_entry.py │ └── vertex_ai_rag_memory_service.py │ ├── models │ ├── __init__.py │ ├── anthropic_llm.py │ ├── base_llm.py │ ├── base_llm_connection.py │ ├── gemini_llm_connection.py │ ├── google_llm.py │ ├── lite_llm.py │ ├── llm_request.py │ ├── llm_response.py │ └── registry.py │ ├── planners │ ├── __init__.py │ ├── base_planner.py │ ├── built_in_planner.py │ └── plan_re_act_planner.py │ ├── py.typed │ ├── runners.py │ ├── sessions │ ├── __init__.py │ ├── _session_util.py │ ├── base_session_service.py │ ├── database_session_service.py │ ├── in_memory_session_service.py │ ├── session.py │ ├── state.py │ └── vertex_ai_session_service.py │ ├── telemetry.py │ ├── tools │ ├── __init__.py │ ├── _automatic_function_calling_util.py │ ├── _forwarding_artifact_service.py │ ├── _function_parameter_parse_util.py │ ├── _gemini_schema_util.py │ ├── _memory_entry_utils.py │ ├── agent_tool.py │ ├── apihub_tool │ │ ├── __init__.py │ │ ├── apihub_toolset.py │ │ └── clients │ │ │ ├── __init__.py │ │ │ ├── apihub_client.py │ │ │ └── secret_client.py │ ├── application_integration_tool │ │ ├── __init__.py │ │ ├── application_integration_toolset.py │ │ ├── clients │ │ │ ├── connections_client.py │ │ │ └── integration_client.py │ │ └── integration_connector_tool.py │ ├── base_tool.py │ ├── base_toolset.py │ ├── bigquery │ │ ├── __init__.py │ │ ├── bigquery_credentials.py │ │ ├── bigquery_tool.py │ │ ├── bigquery_toolset.py │ │ ├── client.py │ │ ├── metadata_tool.py │ │ └── query_tool.py │ ├── crewai_tool.py │ ├── enterprise_search_tool.py │ ├── example_tool.py │ ├── exit_loop_tool.py │ ├── function_tool.py │ ├── get_user_choice_tool.py │ ├── google_api_tool │ │ ├── __init__.py │ │ ├── google_api_tool.py │ │ ├── google_api_toolset.py │ │ ├── google_api_toolsets.py │ │ └── googleapi_to_openapi_converter.py │ ├── google_search_tool.py │ ├── langchain_tool.py │ ├── load_artifacts_tool.py │ ├── load_memory_tool.py │ ├── load_web_page.py │ ├── long_running_tool.py │ ├── mcp_tool │ │ ├── __init__.py │ │ ├── conversion_utils.py │ │ ├── mcp_session_manager.py │ │ ├── mcp_tool.py │ │ └── mcp_toolset.py │ ├── openapi_tool │ │ ├── __init__.py │ │ ├── auth │ │ │ ├── __init__.py │ │ │ ├── auth_helpers.py │ │ │ └── credential_exchangers │ │ │ │ ├── __init__.py │ │ │ │ ├── auto_auth_credential_exchanger.py │ │ │ │ ├── base_credential_exchanger.py │ │ │ │ ├── oauth2_exchanger.py │ │ │ │ └── service_account_exchanger.py │ │ ├── common │ │ │ ├── __init__.py │ │ │ └── common.py │ │ └── openapi_spec_parser │ │ │ ├── __init__.py │ │ │ ├── openapi_spec_parser.py │ │ │ ├── openapi_toolset.py │ │ │ ├── operation_parser.py │ │ │ ├── rest_api_tool.py │ │ │ └── tool_auth_handler.py │ ├── preload_memory_tool.py │ ├── retrieval │ │ ├── __init__.py │ │ ├── base_retrieval_tool.py │ │ ├── files_retrieval.py │ │ ├── llama_index_retrieval.py │ │ └── vertex_ai_rag_retrieval.py │ ├── tool_context.py │ ├── toolbox_toolset.py │ ├── transfer_to_agent_tool.py │ ├── url_context_tool.py │ └── vertex_ai_search_tool.py │ ├── utils │ ├── __init__.py │ ├── instructions_utils.py │ └── variant_utils.py │ └── version.py └── tests ├── __init__.py ├── integration ├── .env.example ├── __init__.py ├── conftest.py ├── fixture │ ├── __init__.py │ ├── agent_with_config │ │ ├── __init__.py │ │ └── agent.py │ ├── callback_agent │ │ ├── __init__.py │ │ └── agent.py │ ├── context_update_test │ │ ├── OWNERS │ │ ├── __init__.py │ │ ├── agent.py │ │ └── successful_test.session.json │ ├── context_variable_agent │ │ ├── __init__.py │ │ └── agent.py │ ├── ecommerce_customer_service_agent │ │ ├── __init__.py │ │ ├── agent.py │ │ ├── order_query.test.json │ │ └── test_config.json │ ├── flow_complex_spark │ │ ├── __init__.py │ │ ├── agent.py │ │ └── sample.session.json │ ├── hello_world_agent │ │ ├── __init__.py │ │ ├── agent.py │ │ ├── roll_die.test.json │ │ └── test_config.json │ ├── home_automation_agent │ │ ├── __init__.py │ │ ├── agent.py │ │ ├── simple_test.test.json │ │ ├── simple_test2.test.json │ │ ├── test_config.json │ │ └── test_files │ │ │ ├── dependent_tool_calls.test.json │ │ │ ├── memorizing_past_events │ │ │ ├── eval_data.test.json │ │ │ └── test_config.json │ │ │ ├── simple_multi_turn_conversation.test.json │ │ │ ├── simple_test.test.json │ │ │ ├── simple_test2.test.json │ │ │ └── test_config.json │ ├── tool_agent │ │ ├── __init__.py │ │ ├── agent.py │ │ └── files │ │ │ └── Agent_test_plan.pdf │ └── trip_planner_agent │ │ ├── __init__.py │ │ ├── agent.py │ │ ├── initial.session.json │ │ ├── test_config.json │ │ ├── test_files │ │ ├── test_config.json │ │ └── trip_inquiry_sub_agent.test.json │ │ └── trip_inquiry.test.json ├── models │ ├── __init__.py │ └── test_google_llm.py ├── test_callback.py ├── test_context_variable.py ├── test_evalute_agent_in_fixture.py ├── test_multi_agent.py ├── test_multi_turn.py ├── test_single_agent.py ├── test_sub_agent.py ├── test_system_instruction.py ├── test_tools.py ├── test_with_test_file.py ├── tools │ └── __init__.py └── utils │ ├── __init__.py │ ├── asserts.py │ └── test_runner.py └── unittests ├── __init__.py ├── agents ├── __init__.py ├── test_base_agent.py ├── test_langgraph_agent.py ├── test_live_request_queue.py ├── test_llm_agent_callbacks.py ├── test_llm_agent_fields.py ├── test_loop_agent.py ├── test_model_callback_chain.py ├── test_parallel_agent.py ├── test_readonly_context.py ├── test_run_config.py └── test_sequential_agent.py ├── artifacts ├── __init__.py └── test_artifact_service.py ├── auth ├── test_auth_config.py └── test_auth_handler.py ├── cli ├── __init__.py ├── test_fast_api.py └── utils │ ├── __init__.py │ ├── test_agent_loader.py │ ├── test_cli.py │ ├── test_cli_create.py │ ├── test_cli_deploy.py │ ├── test_cli_tools_click.py │ └── test_evals.py ├── code_executors ├── __init__.py ├── test_built_in_code_executor.py ├── test_code_executor_context.py └── test_unsafe_local_code_executor.py ├── conftest.py ├── evaluation ├── __init__.py ├── test_local_eval_set_results_manager.py ├── test_local_eval_sets_manager.py ├── test_response_evaluator.py └── test_trajectory_evaluator.py ├── flows ├── __init__.py └── llm_flows │ ├── __init__.py │ ├── test_agent_transfer.py │ ├── test_async_tool_callbacks.py │ ├── test_functions_long_running.py │ ├── test_functions_request_euc.py │ ├── test_functions_sequential.py │ ├── test_functions_simple.py │ ├── test_identity.py │ ├── test_instructions.py │ ├── test_model_callbacks.py │ ├── test_other_configs.py │ ├── test_tool_callbacks.py │ └── test_tool_telemetry.py ├── models ├── __init__.py ├── test_anthropic_llm.py ├── test_google_llm.py ├── test_litellm.py └── test_models.py ├── sessions ├── __init__.py ├── test_session_service.py └── test_vertex_ai_session_service.py ├── streaming ├── __init__.py └── test_streaming.py ├── test_telemetry.py ├── testing_utils.py ├── tools ├── __init__.py ├── apihub_tool │ ├── clients │ │ └── test_apihub_client.py │ └── test_apihub_toolset.py ├── application_integration_tool │ ├── clients │ │ ├── test_connections_client.py │ │ └── test_integration_client.py │ ├── test_application_integration_toolset.py │ └── test_integration_connector_tool.py ├── bigquery │ ├── __init__ │ ├── test_bigquery_credentials.py │ ├── test_bigquery_credentials_manager.py │ └── test_bigquery_tool.py ├── bigquery_tool │ └── test_bigquery_toolset.py ├── google_api_tool │ ├── __init__.py │ └── test_googleapi_to_openapi_converter.py ├── openapi_tool │ ├── auth │ │ ├── credential_exchangers │ │ │ ├── test_auto_auth_credential_exchanger.py │ │ │ ├── test_base_auth_credential_exchanger.py │ │ │ ├── test_oauth2_exchanger.py │ │ │ └── test_service_account_exchanger.py │ │ └── test_auth_helper.py │ ├── common │ │ └── test_common.py │ └── openapi_spec_parser │ │ ├── test.yaml │ │ ├── test_openapi_spec_parser.py │ │ ├── test_openapi_toolset.py │ │ ├── test_operation_parser.py │ │ ├── test_rest_api_tool.py │ │ └── test_tool_auth_handler.py ├── retrieval │ ├── __init__.py │ └── test_vertex_ai_rag_retrieval.py ├── test_agent_tool.py ├── test_base_tool.py ├── test_build_function_declaration.py ├── test_function_tool.py └── test_gemini_schema_util.py └── utils ├── __init__.py └── test_instructions_utils.py /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ** Please make sure you read the contribution guide and file the issues in the right place. ** 11 | [Contribution guide.](https://google.github.io/adk-docs/contributing-guide/) 12 | 13 | **Describe the bug** 14 | A clear and concise description of what the bug is. 15 | 16 | **To Reproduce** 17 | Steps to reproduce the behavior: 18 | 1. Install '...' 19 | 2. Run '....' 20 | 3. Open '....' 21 | 4. See error 22 | 23 | **Expected behavior** 24 | A clear and concise description of what you expected to happen. 25 | 26 | **Screenshots** 27 | If applicable, add screenshots to help explain your problem. 28 | 29 | **Desktop (please complete the following information):** 30 | - OS: [e.g. iOS] 31 | - Python version(python -V): 32 | - ADK version(pip show google-adk): 33 | 34 | **Additional context** 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ** Please make sure you read the contribution guide and file the issues in the right place. ** 11 | [Contribution guide.](https://google.github.io/adk-docs/contributing-guide/) 12 | 13 | **Is your feature request related to a problem? Please describe.** 14 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 15 | 16 | **Describe the solution you'd like** 17 | A clear and concise description of what you want to happen. 18 | 19 | **Describe alternatives you've considered** 20 | A clear and concise description of any alternative solutions or features you've considered. 21 | 22 | **Additional context** 23 | Add any other context or screenshots about the feature request here. 24 | -------------------------------------------------------------------------------- /.github/release-please.yml: -------------------------------------------------------------------------------- 1 | releaseType: python 2 | handleGHRelease: true 3 | bumpMinorPreMajor: false 4 | extraFiles: 5 | - src/google/adk/version.py -------------------------------------------------------------------------------- /.github/release-trigger.yml: -------------------------------------------------------------------------------- 1 | enabled: true -------------------------------------------------------------------------------- /.github/workflows/python-unit-tests.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Python Unit Tests 16 | 17 | on: 18 | push: 19 | branches: [ main ] 20 | pull_request: 21 | branches: [ main ] 22 | 23 | jobs: 24 | test: 25 | runs-on: ubuntu-latest 26 | strategy: 27 | matrix: 28 | python-version: ["3.9", "3.10", "3.11"] 29 | 30 | steps: 31 | - name: Checkout code 32 | uses: actions/checkout@v4 33 | 34 | - name: Set up Python ${{ matrix.python-version }} 35 | uses: actions/setup-python@v5 36 | with: 37 | python-version: ${{ matrix.python-version }} 38 | 39 | - name: Install uv 40 | run: curl -LsSf https://astral.sh/uv/install.sh | sh 41 | 42 | - name: Install dependencies 43 | run: | 44 | uv venv .venv 45 | source .venv/bin/activate 46 | uv sync --extra test --extra eval 47 | 48 | - name: Run unit tests with pytest 49 | run: | 50 | source .venv/bin/activate 51 | pytest tests/unittests \ 52 | --ignore=tests/unittests/artifacts/test_artifact_service.py \ 53 | --ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Python 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | *.so 6 | .Python 7 | build/ 8 | develop-eggs/ 9 | dist/ 10 | downloads/ 11 | eggs/ 12 | .eggs/ 13 | lib/ 14 | lib64/ 15 | parts/ 16 | sdist/ 17 | var/ 18 | wheels/ 19 | *.egg-info/ 20 | .installed.cfg 21 | *.egg 22 | 23 | # Virtual Environment 24 | venv/ 25 | ENV/ 26 | env/ 27 | .env 28 | .venv 29 | env.bak/ 30 | venv.bak/ 31 | 32 | # IDE 33 | .idea/ 34 | .vscode/ 35 | *.swp 36 | *.swo 37 | .DS_Store 38 | 39 | # Testing 40 | .coverage 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .pytest_cache/ 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Distribution / packaging 55 | .Python 56 | build/ 57 | develop-eggs/ 58 | dist/ 59 | downloads/ 60 | eggs/ 61 | .eggs/ 62 | lib/ 63 | lib64/ 64 | parts/ 65 | sdist/ 66 | var/ 67 | wheels/ 68 | *.egg-info/ 69 | .installed.cfg 70 | *.egg 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # Logs 76 | *.log 77 | logs/ 78 | log/ 79 | 80 | # Local development settings 81 | .env.local 82 | .env.development.local 83 | .env.test.local 84 | .env.production.local 85 | 86 | # Google Cloud specific 87 | .gcloudignore 88 | .gcloudignore.local 89 | 90 | # Documentation 91 | docs/_build/ 92 | site/ 93 | 94 | # Misc 95 | .DS_Store 96 | Thumbs.db 97 | *.bak 98 | *.tmp 99 | *.temp 100 | -------------------------------------------------------------------------------- /assets/adk-web-dev-ui-function-call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/assets/adk-web-dev-ui-function-call.png -------------------------------------------------------------------------------- /assets/agent-development-kit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/assets/agent-development-kit.png -------------------------------------------------------------------------------- /contributing/samples/README.md: -------------------------------------------------------------------------------- 1 | # Contributing Resources 2 | 3 | This folder host resources for ADK contributors, for example, testing samples etc. 4 | 5 | # Samples 6 | 7 | Samples folder host samples to test different features. The samples are usually minimal and simplistic to test one or a few scenarios. 8 | 9 | **Note**: This is different from the [google/adk-samples](https://github.com/google/adk-samples) repo, which hosts more complex e2e samples for customers to use or modify directly. 10 | -------------------------------------------------------------------------------- /contributing/samples/application_integration_agent/README.md: -------------------------------------------------------------------------------- 1 | # Application Integration Agent Sample 2 | 3 | ## Introduction 4 | 5 | This sample demonstrates how to use the `ApplicationIntegrationToolset` within an ADK agent to interact with external applications, specifically Jira in this case. The agent (`agent.py`) is configured to manage Jira issues using a pre-configured Application Integration connection. 6 | 7 | ## Prerequisites 8 | 9 | 1. **Set up Integration Connection:** 10 | * You need an existing [Integration connection](https://cloud.google.com/integration-connectors/docs/overview) configured to interact with your Jira instance. Follow the [documentation](https://google.github.io/adk-docs/tools/google-cloud-tools/#use-integration-connectors) to provision the Integration Connector in Google Cloud and then use this [documentation](https://cloud.google.com/integration-connectors/docs/connectors/jiracloud/configure) to create an JIRA connection. Note the `Connection Name`, `Project ID`, and `Location` of your connection. 11 | * 12 | 13 | 2. **Configure Environment Variables:** 14 | * Create a `.env` file in the same directory as `agent.py` (or add to your existing one). 15 | * Add the following variables to the `.env` file, replacing the placeholder values with your actual connection details: 16 | 17 | ```dotenv 18 | CONNECTION_NAME= 19 | CONNECTION_PROJECT= 20 | CONNECTION_LOCATION= 21 | ``` 22 | 23 | ## How to Use 24 | 25 | 1. **Install Dependencies:** Ensure you have the necessary libraries installed (e.g., `google-adk`, `python-dotenv`). 26 | 2. **Run the Agent:** Execute the agent script from your terminal: 27 | ```bash 28 | python agent.py 29 | ``` 30 | 3. **Interact:** Once the agent starts, you can interact with it by typing prompts related to Jira issue management. 31 | 32 | ## Sample Prompts 33 | 34 | Here are some examples of how you can interact with the agent: 35 | 36 | * `Can you list me all the issues ?` 37 | * `Can you list me all the projects ?` 38 | * `Can you create an issue: "Bug in product XYZ" in project ABC ?` 39 | 40 | -------------------------------------------------------------------------------- /contributing/samples/application_integration_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/artifact_save_text/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/artifact_save_text/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from google.adk import Agent 17 | from google.adk.tools.tool_context import ToolContext 18 | from google.genai import types 19 | 20 | 21 | async def log_query(tool_context: ToolContext, query: str): 22 | """Saves the provided query string as a 'text/plain' artifact named 'query'.""" 23 | query_bytes = query.encode('utf-8') 24 | artifact_part = types.Part( 25 | inline_data=types.Blob(mime_type='text/plain', data=query_bytes) 26 | ) 27 | await tool_context.save_artifact('query', artifact_part) 28 | 29 | 30 | root_agent = Agent( 31 | model='gemini-2.0-flash', 32 | name='log_agent', 33 | description='Log user query.', 34 | instruction="""Always log the user query and reploy "kk, I've logged." 35 | """, 36 | tools=[log_query], 37 | generate_content_config=types.GenerateContentConfig( 38 | safety_settings=[ 39 | types.SafetySetting( # avoid false alarm about rolling dice. 40 | category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, 41 | threshold=types.HarmBlockThreshold.OFF, 42 | ), 43 | ] 44 | ), 45 | ) 46 | -------------------------------------------------------------------------------- /contributing/samples/bigquery/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/bigquery/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import os 16 | 17 | from google.adk.agents import llm_agent 18 | from google.adk.tools.bigquery import BigQueryCredentialsConfig 19 | from google.adk.tools.bigquery import BigQueryToolset 20 | import google.auth 21 | 22 | RUN_WITH_ADC = False 23 | 24 | 25 | if RUN_WITH_ADC: 26 | # Initialize the tools to use the application default credentials. 27 | application_default_credentials, _ = google.auth.default() 28 | credentials_config = BigQueryCredentialsConfig( 29 | credentials=application_default_credentials 30 | ) 31 | else: 32 | # Initiaze the tools to do interactive OAuth 33 | # The environment variables OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET 34 | # must be set 35 | credentials_config = BigQueryCredentialsConfig( 36 | client_id=os.getenv("OAUTH_CLIENT_ID"), 37 | client_secret=os.getenv("OAUTH_CLIENT_SECRET"), 38 | ) 39 | 40 | bigquery_toolset = BigQueryToolset(credentials_config=credentials_config) 41 | 42 | # The variable name `root_agent` determines what your root agent is for the 43 | # debug CLI 44 | root_agent = llm_agent.Agent( 45 | model="gemini-2.0-flash", 46 | name="hello_agent", 47 | description=( 48 | "Agent to answer questions about BigQuery data and models and execute" 49 | " SQL queries." 50 | ), 51 | instruction="""\ 52 | You are a data science agent with access to several BigQuery tools. 53 | Make use of those tools to answer the user's questions. 54 | """, 55 | tools=[bigquery_toolset], 56 | ) 57 | -------------------------------------------------------------------------------- /contributing/samples/bigquery_agent/README.md: -------------------------------------------------------------------------------- 1 | # BigQuery Sample 2 | 3 | ## Introduction 4 | 5 | This sample tests and demos the BigQuery support in ADK via two tools: 6 | 7 | * 1. bigquery_datasets_list: 8 | 9 | List user's datasets. 10 | 11 | * 2. bigquery_datasets_get: 12 | Get a dataset's details. 13 | 14 | * 3. bigquery_datasets_insert: 15 | Create a new dataset. 16 | 17 | * 4. bigquery_tables_list: 18 | List all tables in a dataset. 19 | 20 | * 5. bigquery_tables_get: 21 | Get a table's details. 22 | 23 | * 6. bigquery_tables_insert: 24 | Insert a new table into a dataset. 25 | 26 | ## How to use 27 | 28 | * 1. Follow https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name. to get your client id and client secret. 29 | Be sure to choose "web" as your client type. 30 | 31 | * 2. Configure your `.env` file to add two variables: 32 | 33 | * OAUTH_CLIENT_ID={your client id} 34 | * OAUTH_CLIENT_SECRET={your client secret} 35 | 36 | Note: don't create a separate `.env` file , instead put it to the same `.env` file that stores your Vertex AI or Dev ML credentials 37 | 38 | * 3. Follow https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred to add http://localhost/dev-ui/ to "Authorized redirect URIs". 39 | 40 | Note: localhost here is just a hostname that you use to access the dev ui, replace it with the actual hostname you use to access the dev ui. 41 | 42 | * 4. For 1st run, allow popup for localhost in Chrome. 43 | 44 | ## Sample prompt 45 | 46 | * `Do I have any datasets in project sean-dev-agent ?` 47 | * `Do I have any tables under it ?` 48 | * `could you get me the details of this table ?` 49 | * `Can you help to create a new dataset in the same project? id : sean_test , location: us` 50 | * `could you show me the details of this new dataset ?` 51 | * `could you create a new table under this dataset ? table name : sean_test_table. column1 : name is id , type is integer, required. column2 : name is info , type is string, required. column3 : name is backup , type is string, optional.` 52 | -------------------------------------------------------------------------------- /contributing/samples/bigquery_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/callbacks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/code_execution/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/fields_output_schema/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/fields_output_schema/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk import Agent 16 | from pydantic import BaseModel 17 | 18 | 19 | class WeahterData(BaseModel): 20 | temperature: str 21 | humidity: str 22 | wind_speed: str 23 | 24 | 25 | root_agent = Agent( 26 | name='root_agent', 27 | model='gemini-2.0-flash', 28 | instruction="""\ 29 | Answer user's questions based on the data you have. 30 | 31 | If you don't have the data, you can just say you don't know. 32 | 33 | Here are the data you have for San Jose 34 | 35 | * temperature: 26 C 36 | * humidity: 20% 37 | * wind_speed: 29 mph 38 | 39 | Here are the data you have for Cupertino 40 | 41 | * temperature: 16 C 42 | * humidity: 10% 43 | * wind_speed: 13 mph 44 | 45 | """, 46 | output_schema=WeahterData, 47 | output_key='weather_data', 48 | ) 49 | -------------------------------------------------------------------------------- /contributing/samples/fields_planner/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/generate_image/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/generate_image/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk import Agent 16 | from google.adk.tools import load_artifacts 17 | from google.adk.tools import ToolContext 18 | from google.genai import Client 19 | from google.genai import types 20 | 21 | # Only Vertex AI supports image generation for now. 22 | client = Client() 23 | 24 | 25 | async def generate_image(prompt: str, tool_context: 'ToolContext'): 26 | """Generates an image based on the prompt.""" 27 | response = client.models.generate_images( 28 | model='imagen-3.0-generate-002', 29 | prompt=prompt, 30 | config={'number_of_images': 1}, 31 | ) 32 | if not response.generated_images: 33 | return {'status': 'failed'} 34 | image_bytes = response.generated_images[0].image.image_bytes 35 | await tool_context.save_artifact( 36 | 'image.png', 37 | types.Part.from_bytes(data=image_bytes, mime_type='image/png'), 38 | ) 39 | return { 40 | 'status': 'success', 41 | 'detail': 'Image generated successfully and stored in artifacts.', 42 | 'filename': 'image.png', 43 | } 44 | 45 | 46 | root_agent = Agent( 47 | model='gemini-2.0-flash-001', 48 | name='root_agent', 49 | description="""An agent that generates images and answer questions about the images.""", 50 | instruction="""You are an agent whose job is to generate or edit an image based on the user's prompt. 51 | """, 52 | tools=[generate_image, load_artifacts], 53 | ) 54 | -------------------------------------------------------------------------------- /contributing/samples/google_search_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/google_search_agent/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk import Agent 16 | from google.adk.tools import google_search 17 | from google.genai import Client 18 | 19 | # Only Vertex AI supports image generation for now. 20 | client = Client() 21 | 22 | root_agent = Agent( 23 | model='gemini-2.0-flash-001', 24 | name='root_agent', 25 | description="""an agent whose job it is to perform Google search queries and answer questions about the results.""", 26 | instruction="""You are an agent whose job is to perform Google search queries and answer questions about the results. 27 | """, 28 | tools=[google_search], 29 | ) 30 | -------------------------------------------------------------------------------- /contributing/samples/hello_world/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/hello_world_anthropic/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from . import agent 17 | -------------------------------------------------------------------------------- /contributing/samples/hello_world_litellm/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from . import agent 17 | -------------------------------------------------------------------------------- /contributing/samples/hello_world_ma/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/hello_world_ollama/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/human_in_loop/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/human_in_loop/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import Any 16 | 17 | from google.adk import Agent 18 | from google.adk.tools import ToolContext 19 | from google.adk.tools.long_running_tool import LongRunningFunctionTool 20 | from google.genai import types 21 | 22 | 23 | def reimburse(purpose: str, amount: float) -> str: 24 | """Reimburse the amount of money to the employee.""" 25 | return { 26 | 'status': 'ok', 27 | } 28 | 29 | 30 | def ask_for_approval( 31 | purpose: str, amount: float, tool_context: ToolContext 32 | ) -> dict[str, Any]: 33 | """Ask for approval for the reimbursement.""" 34 | return { 35 | 'status': 'pending', 36 | 'amount': amount, 37 | 'ticketId': 'reimbursement-ticket-001', 38 | } 39 | 40 | 41 | root_agent = Agent( 42 | model='gemini-1.5-flash', 43 | name='reimbursement_agent', 44 | instruction=""" 45 | You are an agent whose job is to handle the reimbursement process for 46 | the employees. If the amount is less than $100, you will automatically 47 | approve the reimbursement. 48 | 49 | If the amount is greater than $100, you will 50 | ask for approval from the manager. If the manager approves, you will 51 | call reimburse() to reimburse the amount to the employee. If the manager 52 | rejects, you will inform the employee of the rejection. 53 | """, 54 | tools=[reimburse, LongRunningFunctionTool(func=ask_for_approval)], 55 | generate_content_config=types.GenerateContentConfig(temperature=0.1), 56 | ) 57 | -------------------------------------------------------------------------------- /contributing/samples/integration_connector_euc_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/jira_agent/README.md: -------------------------------------------------------------------------------- 1 | This agent connects to the Jira Cloud using Google Application Integration workflow and Integrations Connector 2 | 3 | **Instructions to connect to an agent:** 4 | 5 | **Use Integration Connectors** 6 | 7 | Connect your agent to enterprise applications using [Integration Connectors](https://cloud.google.com/integration-connectors/docs/overview). 8 | 9 | **Steps:** 10 | 11 | 1. To use a connector from Integration Connectors, you need to [provision](https://console.cloud.google.com/) Application Integration in the same region as your connection by clicking on "QUICK SETUP" button. 12 | Google Cloud Tools 13 | ![image_alt](https://github.com/karthidec/adk-python/blob/adk-samples-jira-agent/contributing/samples/jira_agent/image-application-integration.png?raw=true) 14 | 15 | 2. Go to [Connection Tool]((https://console.cloud.google.com/)) template from the template library and click on "USE TEMPLATE" button. 16 | ![image_alt](https://github.com/karthidec/adk-python/blob/adk-samples-jira-agent/contributing/samples/jira_agent/image-connection-tool.png?raw=true) 17 | 18 | 3. Fill the Integration Name as **ExecuteConnection** (It is mandatory to use this integration name only) and select the region same as the connection region. Click on "CREATE". 19 | 20 | 4. Publish the integration by using the "PUBLISH" button on the Application Integration Editor. 21 | ![image_alt](https://github.com/karthidec/adk-python/blob/adk-samples-jira-agent/contributing/samples/jira_agent/image-app-intg-editor.png?raw=true) 22 | 23 | **References:** 24 | 25 | https://google.github.io/adk-docs/tools/google-cloud-tools/#application-integration-tools 26 | -------------------------------------------------------------------------------- /contributing/samples/jira_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/jira_agent/image-app-intg-editor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/contributing/samples/jira_agent/image-app-intg-editor.png -------------------------------------------------------------------------------- /contributing/samples/jira_agent/image-application-integration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/contributing/samples/jira_agent/image-application-integration.png -------------------------------------------------------------------------------- /contributing/samples/jira_agent/image-connection-tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/contributing/samples/jira_agent/image-connection-tool.png -------------------------------------------------------------------------------- /contributing/samples/jira_agent/tools.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.tools.application_integration_tool.application_integration_toolset import ApplicationIntegrationToolset 16 | 17 | jira_tool = ApplicationIntegrationToolset( 18 | project="your-gcp-project-id", # replace with your GCP project ID 19 | location="your-regions", # replace your regions 20 | connection="your-integration-connection-name", # replace with your connection name 21 | entity_operations={ 22 | "Issues": ["GET", "LIST"], 23 | }, 24 | actions=[ 25 | "get_issue_by_key", 26 | ], 27 | tool_name="jira_conversation_tool", 28 | tool_instructions=""" 29 | 30 | This tool is to call an integration to search for issues in JIRA 31 | 32 | """, 33 | ) 34 | -------------------------------------------------------------------------------- /contributing/samples/langchain_structured_tool_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/langchain_structured_tool_agent/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """ 16 | This agent aims to test the Langchain tool with Langchain's StructuredTool 17 | """ 18 | from google.adk.agents import Agent 19 | from google.adk.tools.langchain_tool import LangchainTool 20 | from langchain_core.tools.structured import StructuredTool 21 | from pydantic import BaseModel 22 | 23 | 24 | def add(x, y) -> int: 25 | return x + y 26 | 27 | 28 | class AddSchema(BaseModel): 29 | x: int 30 | y: int 31 | 32 | 33 | test_langchain_tool = StructuredTool.from_function( 34 | add, 35 | name="add", 36 | description="Adds two numbers", 37 | args_schema=AddSchema, 38 | ) 39 | 40 | root_agent = Agent( 41 | model="gemini-2.0-flash-001", 42 | name="test_app", 43 | description="A helpful assistant for user questions.", 44 | instruction=( 45 | "You are a helpful assistant for user questions, you have access to a" 46 | " tool that adds two numbers." 47 | ), 48 | tools=[LangchainTool(tool=test_langchain_tool)], 49 | ) 50 | -------------------------------------------------------------------------------- /contributing/samples/langchain_youtube_search_agent/README.md: -------------------------------------------------------------------------------- 1 | # Langchain Youtube Search Agent 2 | 3 | This agent utilize the Lanchain YoutubeSearchTool to search youtubes. 4 | You need to install below dependencies: 5 | 6 | ```python 7 | uv pip install youtube_search 8 | ``` 9 | -------------------------------------------------------------------------------- /contributing/samples/langchain_youtube_search_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/langchain_youtube_search_agent/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.agents import LlmAgent 16 | from google.adk.tools.langchain_tool import LangchainTool 17 | from langchain_community.tools import YouTubeSearchTool 18 | 19 | # Instantiate the tool 20 | langchain_yt_tool = YouTubeSearchTool() 21 | 22 | # Wrap the tool in the LangchainTool class from ADK 23 | adk_yt_tool = LangchainTool( 24 | tool=langchain_yt_tool, 25 | ) 26 | 27 | root_agent = LlmAgent( 28 | name="youtube_search_agent", 29 | model="gemini-2.0-flash", # Replace with the actual model name 30 | instruction=""" 31 | Ask customer to provide singer name, and the number of videos to search. 32 | """, 33 | description="Help customer to search for a video on Youtube.", 34 | tools=[adk_yt_tool], 35 | output_key="youtube_search_output", 36 | ) 37 | -------------------------------------------------------------------------------- /contributing/samples/langchain_youtube_search_agent/requirements.txt: -------------------------------------------------------------------------------- 1 | youtube_search 2 | -------------------------------------------------------------------------------- /contributing/samples/mcp_sse_agent/README.md: -------------------------------------------------------------------------------- 1 | This agent connects to a local MCP server via sse. 2 | 3 | To run this agent, start the local MCP server first by : 4 | 5 | ```bash 6 | uv run filesystem_server.py 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /contributing/samples/mcp_sse_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/mcp_sse_agent/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | import os 17 | 18 | from google.adk.agents.llm_agent import LlmAgent 19 | from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset 20 | from google.adk.tools.mcp_tool.mcp_toolset import SseServerParams 21 | 22 | _allowed_path = os.path.dirname(os.path.abspath(__file__)) 23 | 24 | root_agent = LlmAgent( 25 | model='gemini-2.0-flash', 26 | name='enterprise_assistant', 27 | instruction=f"""\ 28 | Help user accessing their file systems. 29 | 30 | Allowed directory: {_allowed_path} 31 | """, 32 | tools=[ 33 | MCPToolset( 34 | connection_params=SseServerParams( 35 | url='http://localhost:3000/sse', 36 | headers={'Accept': 'text/event-stream'}, 37 | ), 38 | # don't want agent to do write operation 39 | # you can also do below 40 | # tool_filter=lambda tool, ctx=None: tool.name 41 | # not in [ 42 | # 'write_file', 43 | # 'edit_file', 44 | # 'create_directory', 45 | # 'move_file', 46 | # ], 47 | tool_filter=[ 48 | 'read_file', 49 | 'read_multiple_files', 50 | 'list_directory', 51 | 'directory_tree', 52 | 'search_files', 53 | 'get_file_info', 54 | 'list_allowed_directories', 55 | ], 56 | ) 57 | ], 58 | ) 59 | -------------------------------------------------------------------------------- /contributing/samples/mcp_stdio_notion_agent/README.md: -------------------------------------------------------------------------------- 1 | # Notion MCP Agent 2 | 3 | This is an agent that is using Notion MCP tool to call Notion API. And it demonstrate how to pass in the Notion API key. 4 | 5 | Follow below instruction to use it: 6 | 7 | * Follow the installation instruction in below page to get an API key for Notion API: 8 | https://www.npmjs.com/package/@notionhq/notion-mcp-server 9 | 10 | * Set the environment variable `NOTION_API_KEY` to the API key you obtained in the previous step. 11 | 12 | ```bash 13 | export NOTION_API_KEY= 14 | ``` 15 | 16 | * Run the agent in ADK Web UI 17 | 18 | * Send below queries: 19 | * What can you do for me ? 20 | * Seach `XXXX` in my pages. 21 | -------------------------------------------------------------------------------- /contributing/samples/mcp_stdio_notion_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/mcp_stdio_notion_agent/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import json 16 | import os 17 | 18 | from dotenv import load_dotenv 19 | from google.adk.agents.llm_agent import LlmAgent 20 | from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset 21 | from google.adk.tools.mcp_tool.mcp_toolset import StdioServerParameters 22 | 23 | load_dotenv() 24 | 25 | NOTION_API_KEY = os.getenv("NOTION_API_KEY") 26 | NOTION_HEADERS = json.dumps({ 27 | "Authorization": f"Bearer {NOTION_API_KEY}", 28 | "Notion-Version": "2022-06-28", 29 | }) 30 | 31 | root_agent = LlmAgent( 32 | model="gemini-2.0-flash", 33 | name="notion_agent", 34 | instruction=( 35 | "You are my workspace assistant. " 36 | "Use the provided tools to read, search, comment on, " 37 | "or create Notion pages. Ask clarifying questions when unsure." 38 | ), 39 | tools=[ 40 | MCPToolset( 41 | connection_params=StdioServerParameters( 42 | command="npx", 43 | args=["-y", "@notionhq/notion-mcp-server"], 44 | env={"OPENAPI_MCP_HEADERS": NOTION_HEADERS}, 45 | ) 46 | ) 47 | ], 48 | ) 49 | -------------------------------------------------------------------------------- /contributing/samples/mcp_stdio_server_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/mcp_streamablehttp_agent/README.md: -------------------------------------------------------------------------------- 1 | This agent connects to a local MCP server via sse. 2 | 3 | To run this agent, start the local MCP server first by : 4 | 5 | ```bash 6 | uv run filesystem_server.py 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /contributing/samples/mcp_streamablehttp_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/mcp_streamablehttp_agent/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | import os 17 | 18 | from google.adk.agents.llm_agent import LlmAgent 19 | from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams 20 | from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset 21 | from google.adk.tools.mcp_tool.mcp_toolset import SseServerParams 22 | 23 | _allowed_path = os.path.dirname(os.path.abspath(__file__)) 24 | 25 | root_agent = LlmAgent( 26 | model='gemini-2.0-flash', 27 | name='enterprise_assistant', 28 | instruction=f"""\ 29 | Help user accessing their file systems. 30 | 31 | Allowed directory: {_allowed_path} 32 | """, 33 | tools=[ 34 | MCPToolset( 35 | connection_params=StreamableHTTPServerParams( 36 | url='http://localhost:3000/mcp', 37 | ), 38 | # don't want agent to do write operation 39 | # you can also do below 40 | # tool_filter=lambda tool, ctx=None: tool.name 41 | # not in [ 42 | # 'write_file', 43 | # 'edit_file', 44 | # 'create_directory', 45 | # 'move_file', 46 | # ], 47 | tool_filter=[ 48 | 'read_file', 49 | 'read_multiple_files', 50 | 'list_directory', 51 | 'directory_tree', 52 | 'search_files', 53 | 'get_file_info', 54 | 'list_allowed_directories', 55 | ], 56 | ) 57 | ], 58 | ) 59 | -------------------------------------------------------------------------------- /contributing/samples/memory/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/memory/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from datetime import datetime 17 | 18 | from google.adk import Agent 19 | from google.adk.agents.callback_context import CallbackContext 20 | from google.adk.tools.load_memory_tool import load_memory_tool 21 | from google.adk.tools.preload_memory_tool import preload_memory_tool 22 | 23 | 24 | def update_current_time(callback_context: CallbackContext): 25 | callback_context.state['_time'] = datetime.now().isoformat() 26 | 27 | 28 | root_agent = Agent( 29 | model='gemini-2.0-flash-001', 30 | name='memory_agent', 31 | description='agent that have access to memory tools.', 32 | before_agent_callback=update_current_time, 33 | instruction="""\ 34 | You are an agent that help user answer questions. 35 | 36 | Current time: {_time} 37 | """, 38 | tools=[ 39 | load_memory_tool, 40 | preload_memory_tool, 41 | ], 42 | ) 43 | -------------------------------------------------------------------------------- /contributing/samples/non_llm_sequential/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/non_llm_sequential/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from google.adk.agents import Agent 17 | from google.adk.agents import SequentialAgent 18 | 19 | sub_agent_1 = Agent( 20 | name='sub_agent_1', 21 | description='No.1 sub agent.', 22 | model='gemini-2.0-flash-001', 23 | instruction='JUST SAY 1.', 24 | ) 25 | 26 | sub_agent_2 = Agent( 27 | name='sub_agent_2', 28 | description='No.2 sub agent.', 29 | model='gemini-2.0-flash-001', 30 | instruction='JUST SAY 2.', 31 | ) 32 | sequential_agent = SequentialAgent( 33 | name='sequential_agent', 34 | sub_agents=[sub_agent_1, sub_agent_2], 35 | ) 36 | 37 | root_agent = sequential_agent 38 | -------------------------------------------------------------------------------- /contributing/samples/oauth_calendar_agent/README.md: -------------------------------------------------------------------------------- 1 | # OAuth Sample 2 | 3 | ## Introduction 4 | 5 | This sample tests and demos the OAuth support in ADK via two tools: 6 | 7 | * 1. list_calendar_events 8 | 9 | This is a customized tool that calls Google Calendar API to list calendar events. 10 | It pass in the client id and client secrete to ADK and then get back the access token from ADK. 11 | And then it uses the access token to call calendar api. 12 | 13 | * 2. get_calendar_events 14 | 15 | This is an google calendar tool that calls Google Calendar API to get the details of a specific calendar. 16 | This tool is from the ADK built-in Google Calendar ToolSet. 17 | Everything is wrapped and the tool user just needs to pass in the client id and client secret. 18 | 19 | ## How to use 20 | 21 | * 1. Follow https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name. to get your client id and client secret. 22 | Be sure to choose "web" as your client type. 23 | 24 | * 2. Configure your `.env` file to add two variables: 25 | 26 | * OAUTH_CLIENT_ID={your client id} 27 | * OAUTH_CLIENT_SECRET={your client secret} 28 | 29 | Note: don't create a separate `.env` file , instead put it to the same `.env` file that stores your Vertex AI or Dev ML credentials 30 | 31 | * 3. Follow https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred to add http://localhost/dev-ui/ to "Authorized redirect URIs". 32 | 33 | Note: localhost here is just a hostname that you use to access the dev ui, replace it with the actual hostname you use to access the dev ui. 34 | 35 | * 4. For 1st run, allow popup for localhost in Chrome. 36 | 37 | ## Sample prompt 38 | 39 | * `List all my today's meeting from 7am to 7pm.` 40 | * `Get the details of the first event.` 41 | -------------------------------------------------------------------------------- /contributing/samples/oauth_calendar_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/quickstart/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/session_state_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/session_state_agent/input.json: -------------------------------------------------------------------------------- 1 | { 2 | "state": {}, 3 | "queries": ["hello world!"] 4 | } 5 | -------------------------------------------------------------------------------- /contributing/samples/simple_sequential_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/token_usage/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/toolbox_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /contributing/samples/toolbox_agent/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.agents import Agent 16 | from google.adk.tools.toolbox_toolset import ToolboxToolset 17 | 18 | root_agent = Agent( 19 | model="gemini-2.0-flash", 20 | name="root_agent", 21 | instruction="You are a helpful assistant", 22 | # Add Toolbox tools to ADK agent 23 | tools=[ 24 | ToolboxToolset( 25 | server_url="http://127.0.0.1:5000", toolset_name="my-toolset" 26 | ) 27 | ], 28 | ) 29 | -------------------------------------------------------------------------------- /contributing/samples/toolbox_agent/tool_box.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/contributing/samples/toolbox_agent/tool_box.db -------------------------------------------------------------------------------- /contributing/samples/workflow_agent_seq/README.md: -------------------------------------------------------------------------------- 1 | # Workflow Agent Sample - SequentialAgent 2 | 3 | Sample query: 4 | 5 | * Write a quicksort method in python. 6 | * Write a python function to do bubble sort. 7 | 8 | To run in cli (after installing `google-adk`): 9 | 10 | * `uv run main.py` (or `python main.py`) 11 | 12 | Check sample output in `sample.output` file in this folder. 13 | -------------------------------------------------------------------------------- /contributing/samples/workflow_agent_seq/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /src/google/adk/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import version 16 | from .agents.llm_agent import Agent 17 | from .runners import Runner 18 | 19 | __version__ = version.__version__ 20 | __all__ = ["Agent", "Runner"] 21 | -------------------------------------------------------------------------------- /src/google/adk/agents/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .base_agent import BaseAgent 16 | from .live_request_queue import LiveRequest 17 | from .live_request_queue import LiveRequestQueue 18 | from .llm_agent import Agent 19 | from .llm_agent import LlmAgent 20 | from .loop_agent import LoopAgent 21 | from .parallel_agent import ParallelAgent 22 | from .run_config import RunConfig 23 | from .sequential_agent import SequentialAgent 24 | 25 | __all__ = [ 26 | 'Agent', 27 | 'BaseAgent', 28 | 'LlmAgent', 29 | 'LoopAgent', 30 | 'ParallelAgent', 31 | 'SequentialAgent', 32 | ] 33 | -------------------------------------------------------------------------------- /src/google/adk/agents/active_streaming_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import annotations 16 | 17 | import asyncio 18 | from typing import Optional 19 | 20 | from pydantic import BaseModel 21 | from pydantic import ConfigDict 22 | 23 | from .live_request_queue import LiveRequestQueue 24 | 25 | 26 | class ActiveStreamingTool(BaseModel): 27 | """Manages streaming tool related resources during invocation.""" 28 | 29 | model_config = ConfigDict( 30 | arbitrary_types_allowed=True, 31 | extra='forbid', 32 | ) 33 | """The pydantic model config.""" 34 | 35 | task: Optional[asyncio.Task] = None 36 | """The active task of this streaming tool.""" 37 | 38 | stream: Optional[LiveRequestQueue] = None 39 | """The active (input) streams of this streaming tool.""" 40 | -------------------------------------------------------------------------------- /src/google/adk/agents/loop_agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Loop agent implementation.""" 16 | 17 | from __future__ import annotations 18 | 19 | from typing import AsyncGenerator 20 | from typing import Optional 21 | 22 | from typing_extensions import override 23 | 24 | from ..agents.invocation_context import InvocationContext 25 | from ..events.event import Event 26 | from .base_agent import BaseAgent 27 | 28 | 29 | class LoopAgent(BaseAgent): 30 | """A shell agent that run its sub-agents in a loop. 31 | 32 | When sub-agent generates an event with escalate or max_iterations are 33 | reached, the loop agent will stop. 34 | """ 35 | 36 | max_iterations: Optional[int] = None 37 | """The maximum number of iterations to run the loop agent. 38 | 39 | If not set, the loop agent will run indefinitely until a sub-agent 40 | escalates. 41 | """ 42 | 43 | @override 44 | async def _run_async_impl( 45 | self, ctx: InvocationContext 46 | ) -> AsyncGenerator[Event, None]: 47 | times_looped = 0 48 | while not self.max_iterations or times_looped < self.max_iterations: 49 | for sub_agent in self.sub_agents: 50 | async for event in sub_agent.run_async(ctx): 51 | yield event 52 | if event.actions.escalate: 53 | return 54 | times_looped += 1 55 | return 56 | 57 | @override 58 | async def _run_live_impl( 59 | self, ctx: InvocationContext 60 | ) -> AsyncGenerator[Event, None]: 61 | raise NotImplementedError('This is not supported yet for LoopAgent.') 62 | yield # AsyncGenerator requires having at least one yield statement 63 | -------------------------------------------------------------------------------- /src/google/adk/agents/readonly_context.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import annotations 16 | 17 | from types import MappingProxyType 18 | from typing import Any 19 | from typing import Optional 20 | from typing import TYPE_CHECKING 21 | 22 | if TYPE_CHECKING: 23 | from google.genai import types 24 | 25 | from .invocation_context import InvocationContext 26 | 27 | 28 | class ReadonlyContext: 29 | 30 | def __init__( 31 | self, 32 | invocation_context: InvocationContext, 33 | ) -> None: 34 | self._invocation_context = invocation_context 35 | 36 | @property 37 | def user_content(self) -> Optional[types.Content]: 38 | """The user content that started this invocation. READONLY field.""" 39 | return self._invocation_context.user_content 40 | 41 | @property 42 | def invocation_id(self) -> str: 43 | """The current invocation id.""" 44 | return self._invocation_context.invocation_id 45 | 46 | @property 47 | def agent_name(self) -> str: 48 | """The name of the agent that is currently running.""" 49 | return self._invocation_context.agent.name 50 | 51 | @property 52 | def state(self) -> MappingProxyType[str, Any]: 53 | """The state of the current session. READONLY field.""" 54 | return MappingProxyType(self._invocation_context.session.state) 55 | -------------------------------------------------------------------------------- /src/google/adk/agents/transcription_entry.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import Optional 16 | from typing import Union 17 | 18 | from google.genai import types 19 | from pydantic import BaseModel 20 | from pydantic import ConfigDict 21 | 22 | 23 | class TranscriptionEntry(BaseModel): 24 | """Store the data that can be used for transcription.""" 25 | 26 | model_config = ConfigDict( 27 | arbitrary_types_allowed=True, 28 | extra='forbid', 29 | ) 30 | """The pydantic model config.""" 31 | 32 | role: Optional[str] = None 33 | """The role that created this data, typically "user" or "model". For function 34 | call, this is None.""" 35 | 36 | data: Union[types.Blob, types.Content] 37 | """The data that can be used for transcription""" 38 | -------------------------------------------------------------------------------- /src/google/adk/artifacts/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .base_artifact_service import BaseArtifactService 16 | from .gcs_artifact_service import GcsArtifactService 17 | from .in_memory_artifact_service import InMemoryArtifactService 18 | 19 | __all__ = [ 20 | 'BaseArtifactService', 21 | 'GcsArtifactService', 22 | 'InMemoryArtifactService', 23 | ] 24 | -------------------------------------------------------------------------------- /src/google/adk/auth/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .auth_credential import AuthCredential 16 | from .auth_credential import AuthCredentialTypes 17 | from .auth_credential import OAuth2Auth 18 | from .auth_handler import AuthHandler 19 | from .auth_schemes import AuthScheme 20 | from .auth_schemes import AuthSchemeType 21 | from .auth_schemes import OpenIdConnectWithConfig 22 | from .auth_tool import AuthConfig 23 | -------------------------------------------------------------------------------- /src/google/adk/cli/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .cli_tools_click import main 16 | -------------------------------------------------------------------------------- /src/google/adk/cli/__main__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .cli_tools_click import main 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /src/google/adk/cli/browser/assets/audio-processor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | class AudioProcessor extends AudioWorkletProcessor { 18 | constructor() { 19 | super(); 20 | this.targetSampleRate = 22000; // Change to your desired rate 21 | this.originalSampleRate = sampleRate; // Browser's sample rate 22 | this.resampleRatio = this.originalSampleRate / this.targetSampleRate; 23 | } 24 | 25 | process(inputs, outputs, parameters) { 26 | const input = inputs[0]; 27 | if (input.length > 0) { 28 | let audioData = input[0]; // Get first channel's data 29 | 30 | if (this.resampleRatio !== 1) { 31 | audioData = this.resample(audioData); 32 | } 33 | 34 | this.port.postMessage(audioData); 35 | } 36 | return true; // Keep processor alive 37 | } 38 | 39 | resample(audioData) { 40 | const newLength = Math.round(audioData.length / this.resampleRatio); 41 | const resampled = new Float32Array(newLength); 42 | 43 | for (let i = 0; i < newLength; i++) { 44 | const srcIndex = Math.floor(i * this.resampleRatio); 45 | resampled[i] = audioData[srcIndex]; // Nearest neighbor resampling 46 | } 47 | return resampled; 48 | } 49 | } 50 | 51 | registerProcessor('audio-processor', AudioProcessor); 52 | -------------------------------------------------------------------------------- /src/google/adk/cli/browser/assets/config/runtime-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "backendUrl": "" 3 | } -------------------------------------------------------------------------------- /src/google/adk/cli/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import re 16 | from typing import Any 17 | from typing import Optional 18 | 19 | from ...agents.base_agent import BaseAgent 20 | from ...agents.llm_agent import LlmAgent 21 | 22 | __all__ = [ 23 | 'create_empty_state', 24 | ] 25 | 26 | 27 | def _create_empty_state(agent: BaseAgent, all_state: dict[str, Any]): 28 | for sub_agent in agent.sub_agents: 29 | _create_empty_state(sub_agent, all_state) 30 | 31 | if ( 32 | isinstance(agent, LlmAgent) 33 | and agent.instruction 34 | and isinstance(agent.instruction, str) 35 | ): 36 | for key in re.findall(r'{([\w]+)}', agent.instruction): 37 | all_state[key] = '' 38 | 39 | 40 | def create_empty_state( 41 | agent: BaseAgent, initialized_states: Optional[dict[str, Any]] = None 42 | ) -> dict[str, Any]: 43 | """Creates empty str for non-initialized states.""" 44 | non_initialized_states = {} 45 | _create_empty_state(agent, non_initialized_states) 46 | for key in initialized_states or {}: 47 | if key in non_initialized_states: 48 | del non_initialized_states[key] 49 | return non_initialized_states 50 | -------------------------------------------------------------------------------- /src/google/adk/cli/utils/cleanup.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import asyncio 16 | import logging 17 | from typing import List 18 | 19 | from ...runners import Runner 20 | 21 | logger = logging.getLogger("google_adk." + __name__) 22 | 23 | 24 | async def close_runners(runners: List[Runner]) -> None: 25 | cleanup_tasks = [asyncio.create_task(runner.close()) for runner in runners] 26 | if cleanup_tasks: 27 | # Wait for all cleanup tasks with timeout 28 | done, pending = await asyncio.wait( 29 | cleanup_tasks, 30 | timeout=30.0, # 30 second timeout for cleanup 31 | return_when=asyncio.ALL_COMPLETED, 32 | ) 33 | 34 | # If any tasks are still pending, log it 35 | if pending: 36 | logger.warning( 37 | "%s runner close tasks didn't complete in time", len(pending) 38 | ) 39 | for task in pending: 40 | task.cancel() 41 | -------------------------------------------------------------------------------- /src/google/adk/cli/utils/common.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import pydantic 16 | from pydantic import alias_generators 17 | 18 | 19 | class BaseModel(pydantic.BaseModel): 20 | model_config = pydantic.ConfigDict( 21 | alias_generator=alias_generators.to_camel, 22 | populate_by_name=True, 23 | ) 24 | -------------------------------------------------------------------------------- /src/google/adk/cli/utils/envs.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import logging 16 | import os 17 | 18 | from dotenv import load_dotenv 19 | 20 | logger = logging.getLogger(__file__) 21 | 22 | 23 | def _walk_to_root_until_found(folder, filename) -> str: 24 | checkpath = os.path.join(folder, filename) 25 | if os.path.exists(checkpath) and os.path.isfile(checkpath): 26 | return checkpath 27 | 28 | parent_folder = os.path.dirname(folder) 29 | if parent_folder == folder: # reached the root 30 | return '' 31 | 32 | return _walk_to_root_until_found(parent_folder, filename) 33 | 34 | 35 | def load_dotenv_for_agent( 36 | agent_name: str, agent_parent_folder: str, filename: str = '.env' 37 | ): 38 | """Loads the .env file for the agent module.""" 39 | 40 | # Gets the folder of agent_module as starting_folder 41 | starting_folder = os.path.abspath( 42 | os.path.join(agent_parent_folder, agent_name) 43 | ) 44 | dotenv_file_path = _walk_to_root_until_found(starting_folder, filename) 45 | if dotenv_file_path: 46 | load_dotenv(dotenv_file_path, override=True, verbose=True) 47 | logger.info( 48 | 'Loaded %s file for %s at %s', 49 | filename, 50 | agent_name, 51 | dotenv_file_path, 52 | ) 53 | else: 54 | logger.info('No %s file found for %s', filename, agent_name) 55 | -------------------------------------------------------------------------------- /src/google/adk/code_executors/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import logging 16 | 17 | from .base_code_executor import BaseCodeExecutor 18 | from .built_in_code_executor import BuiltInCodeExecutor 19 | from .code_executor_context import CodeExecutorContext 20 | from .unsafe_local_code_executor import UnsafeLocalCodeExecutor 21 | 22 | logger = logging.getLogger('google_adk.' + __name__) 23 | 24 | __all__ = [ 25 | 'BaseCodeExecutor', 26 | 'BuiltInCodeExecutor', 27 | 'CodeExecutorContext', 28 | 'UnsafeLocalCodeExecutor', 29 | ] 30 | 31 | try: 32 | from .vertex_ai_code_executor import VertexAiCodeExecutor 33 | 34 | __all__.append('VertexAiCodeExecutor') 35 | except ImportError: 36 | logger.debug( 37 | 'The Vertex sdk is not installed. If you want to use the Vertex Code' 38 | ' Interpreter with agents, please install it. If not, you can ignore this' 39 | ' warning.' 40 | ) 41 | 42 | try: 43 | from .container_code_executor import ContainerCodeExecutor 44 | 45 | __all__.append('ContainerCodeExecutor') 46 | except ImportError: 47 | logger.debug( 48 | 'The docker sdk is not installed. If you want to use the Container Code' 49 | ' Executor with agents, please install it. If not, you can ignore this' 50 | ' warning.' 51 | ) 52 | -------------------------------------------------------------------------------- /src/google/adk/code_executors/built_in_code_executor.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.genai import types 16 | from typing_extensions import override 17 | 18 | from ..agents.invocation_context import InvocationContext 19 | from ..models import LlmRequest 20 | from .base_code_executor import BaseCodeExecutor 21 | from .code_execution_utils import CodeExecutionInput 22 | from .code_execution_utils import CodeExecutionResult 23 | 24 | 25 | class BuiltInCodeExecutor(BaseCodeExecutor): 26 | """A code executor that uses the Model's built-in code executor. 27 | 28 | Currently only supports Gemini 2.0+ models, but will be expanded to 29 | other models. 30 | """ 31 | 32 | @override 33 | def execute_code( 34 | self, 35 | invocation_context: InvocationContext, 36 | code_execution_input: CodeExecutionInput, 37 | ) -> CodeExecutionResult: 38 | pass 39 | 40 | def process_llm_request(self, llm_request: LlmRequest) -> None: 41 | """Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool.""" 42 | if llm_request.model and llm_request.model.startswith("gemini-2"): 43 | llm_request.config = llm_request.config or types.GenerateContentConfig() 44 | llm_request.config.tools = llm_request.config.tools or [] 45 | llm_request.config.tools.append( 46 | types.Tool(code_execution=types.ToolCodeExecution()) 47 | ) 48 | return 49 | raise ValueError( 50 | "Gemini code execution tool is not supported for model" 51 | f" {llm_request.model}" 52 | ) 53 | -------------------------------------------------------------------------------- /src/google/adk/errors/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /src/google/adk/errors/not_found_error.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import annotations 16 | 17 | 18 | class NotFoundError(Exception): 19 | """Represents an error that occurs when an entity is not found.""" 20 | 21 | def __init__(self, message="The requested item was not found."): 22 | """Initializes the NotFoundError exception. 23 | 24 | Args: 25 | message (str): An optional custom message to describe the error. 26 | """ 27 | self.message = message 28 | super().__init__(self.message) 29 | -------------------------------------------------------------------------------- /src/google/adk/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import logging 16 | 17 | logger = logging.getLogger('google_adk.' + __name__) 18 | 19 | __all__ = [] 20 | 21 | try: 22 | from .agent_evaluator import AgentEvaluator 23 | 24 | __all__.append('AgentEvaluator') 25 | except ImportError: 26 | logger.debug( 27 | 'The Vertex[eval] sdk is not installed. If you want to use the Vertex' 28 | ' Evaluation with agents, please install it(pip install' 29 | ' "google-cloud-aiplatform[evaluation]). If not, you can ignore this' 30 | ' warning.' 31 | ) 32 | -------------------------------------------------------------------------------- /src/google/adk/evaluation/eval_metrics.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import annotations 16 | 17 | from typing import Optional 18 | 19 | from pydantic import alias_generators 20 | from pydantic import BaseModel 21 | from pydantic import ConfigDict 22 | 23 | from .eval_case import Invocation 24 | from .evaluator import EvalStatus 25 | 26 | 27 | class EvalMetric(BaseModel): 28 | """A metric used to evaluate a particular aspect of an eval case.""" 29 | 30 | model_config = ConfigDict( 31 | alias_generator=alias_generators.to_camel, 32 | populate_by_name=True, 33 | ) 34 | 35 | metric_name: str 36 | """The name of the metric.""" 37 | 38 | threshold: float 39 | """A threshold value. Each metric decides how to interpret this threshold.""" 40 | 41 | 42 | class EvalMetricResult(EvalMetric): 43 | """The actual computed score/value of a particular EvalMetric.""" 44 | 45 | model_config = ConfigDict( 46 | alias_generator=alias_generators.to_camel, 47 | populate_by_name=True, 48 | ) 49 | 50 | score: Optional[float] = None 51 | eval_status: EvalStatus 52 | 53 | 54 | class EvalMetricResultPerInvocation(BaseModel): 55 | """Eval metric results per invocation.""" 56 | 57 | model_config = ConfigDict( 58 | alias_generator=alias_generators.to_camel, 59 | populate_by_name=True, 60 | ) 61 | 62 | actual_invocation: Invocation 63 | """The actual invocation, usually obtained by inferencing the agent.""" 64 | 65 | expected_invocation: Invocation 66 | """The expected invocation, usually the reference or golden invocation.""" 67 | 68 | eval_metric_results: list[EvalMetricResult] = [] 69 | """Eval resutls for each applicable metric.""" 70 | -------------------------------------------------------------------------------- /src/google/adk/evaluation/eval_set.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import Optional 16 | 17 | from pydantic import BaseModel 18 | 19 | from .eval_case import EvalCase 20 | 21 | 22 | class EvalSet(BaseModel): 23 | """A set of eval cases.""" 24 | 25 | eval_set_id: str 26 | """Unique identifier for the eval set.""" 27 | 28 | name: Optional[str] = None 29 | """Name of the dataset.""" 30 | 31 | description: Optional[str] = None 32 | """Description of the dataset.""" 33 | 34 | eval_cases: list[EvalCase] 35 | """List of eval cases in the dataset. Each case represents a single 36 | interaction to be evaluated.""" 37 | 38 | creation_timestamp: float = 0.0 39 | """The time at which this eval set was created.""" 40 | -------------------------------------------------------------------------------- /src/google/adk/evaluation/eval_set_results_manager.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import annotations 16 | 17 | from abc import ABC 18 | from abc import abstractmethod 19 | 20 | from .eval_result import EvalCaseResult 21 | from .eval_result import EvalSetResult 22 | 23 | 24 | class EvalSetResultsManager(ABC): 25 | """An interface to manage Eval Set Results.""" 26 | 27 | @abstractmethod 28 | def save_eval_set_result( 29 | self, 30 | app_name: str, 31 | eval_set_id: str, 32 | eval_case_results: list[EvalCaseResult], 33 | ) -> None: 34 | """Creates and saves a new EvalSetResult given eval_case_results.""" 35 | raise NotImplementedError() 36 | 37 | @abstractmethod 38 | def get_eval_set_result( 39 | self, app_name: str, eval_set_result_id: str 40 | ) -> EvalSetResult: 41 | """Returns an EvalSetResult identified by app_name and eval_set_result_id.""" 42 | raise NotImplementedError() 43 | 44 | @abstractmethod 45 | def list_eval_set_results(self, app_name: str) -> list[str]: 46 | """Returns the eval result ids that belong to the given app_name.""" 47 | raise NotImplementedError() 48 | -------------------------------------------------------------------------------- /src/google/adk/evaluation/evaluation_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | class EvalConstants: 17 | """Holds constants for evaluation file constants.""" 18 | 19 | QUERY = "query" 20 | EXPECTED_TOOL_USE = "expected_tool_use" 21 | RESPONSE = "response" 22 | REFERENCE = "reference" 23 | TOOL_NAME = "tool_name" 24 | TOOL_INPUT = "tool_input" 25 | MOCK_TOOL_OUTPUT = "mock_tool_output" 26 | -------------------------------------------------------------------------------- /src/google/adk/evaluation/evaluator.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from abc import ABC 16 | from enum import Enum 17 | from typing import Optional 18 | 19 | from pydantic import BaseModel 20 | 21 | from .eval_case import Invocation 22 | 23 | 24 | class EvalStatus(Enum): 25 | PASSED = 1 26 | FAILED = 2 27 | NOT_EVALUATED = 3 28 | 29 | 30 | class PerInvocationResult(BaseModel): 31 | """Metric evaluation score per invocation.""" 32 | 33 | actual_invocation: Invocation 34 | expected_invocation: Invocation 35 | score: Optional[float] = None 36 | eval_status: EvalStatus = EvalStatus.NOT_EVALUATED 37 | 38 | 39 | class EvaluationResult(BaseModel): 40 | overall_score: Optional[float] = None 41 | """Overall score, based on each invocation.""" 42 | 43 | overall_eval_status: EvalStatus = EvalStatus.NOT_EVALUATED 44 | """Overall status, based on each invocation.""" 45 | 46 | per_invocation_results: list[PerInvocationResult] = [] 47 | 48 | 49 | class Evaluator(ABC): 50 | """A merics evaluator interface.""" 51 | 52 | def evaluate_invocations( 53 | self, 54 | actual_invocations: list[Invocation], 55 | expected_invocations: list[Invocation], 56 | ) -> EvaluationResult: 57 | """Returns EvaluationResult after performing evaluations using actual and expected invocations.""" 58 | raise NotImplementedError() 59 | -------------------------------------------------------------------------------- /src/google/adk/events/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .event import Event 16 | from .event_actions import EventActions 17 | 18 | __all__ = [ 19 | 'Event', 20 | 'EventActions', 21 | ] 22 | -------------------------------------------------------------------------------- /src/google/adk/examples/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .base_example_provider import BaseExampleProvider 16 | from .example import Example 17 | 18 | __all__ = [ 19 | 'BaseExampleProvider', 20 | 'Example', 21 | ] 22 | 23 | try: 24 | from .vertex_ai_example_store import VertexAiExampleStore 25 | 26 | __all__.append('VertexAiExampleStore') 27 | except ImportError: 28 | pass 29 | -------------------------------------------------------------------------------- /src/google/adk/examples/base_example_provider.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import abc 16 | 17 | from .example import Example 18 | 19 | 20 | # A class that provides examples for a given query. 21 | class BaseExampleProvider(abc.ABC): 22 | """Base class for example providers. 23 | 24 | This class defines the interface for providing examples for a given query. 25 | """ 26 | 27 | @abc.abstractmethod 28 | def get_examples(self, query: str) -> list[Example]: 29 | """Returns a list of examples for a given query. 30 | 31 | Args: 32 | query: The query to get examples for. 33 | 34 | Returns: 35 | A list of Example objects. 36 | """ 37 | -------------------------------------------------------------------------------- /src/google/adk/examples/example.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.genai import types 16 | from pydantic import BaseModel 17 | 18 | 19 | class Example(BaseModel): 20 | """A few-shot example. 21 | 22 | Attributes: 23 | input: The input content for the example. 24 | output: The expected output content for the example. 25 | """ 26 | 27 | input: types.Content 28 | output: list[types.Content] 29 | -------------------------------------------------------------------------------- /src/google/adk/flows/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /src/google/adk/flows/llm_flows/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import _code_execution 16 | from . import _nl_planning 17 | from . import contents 18 | from . import functions 19 | from . import identity 20 | from . import instructions 21 | -------------------------------------------------------------------------------- /src/google/adk/flows/llm_flows/_base_llm_processor.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Defines the processor interface used for BaseLlmFlow.""" 16 | from __future__ import annotations 17 | 18 | from abc import ABC 19 | from abc import abstractmethod 20 | from typing import AsyncGenerator 21 | from typing import TYPE_CHECKING 22 | 23 | from ...agents.invocation_context import InvocationContext 24 | from ...events.event import Event 25 | 26 | if TYPE_CHECKING: 27 | from ...models.llm_request import LlmRequest 28 | from ...models.llm_response import LlmResponse 29 | 30 | 31 | class BaseLlmRequestProcessor(ABC): 32 | """Base class for LLM request processor.""" 33 | 34 | @abstractmethod 35 | async def run_async( 36 | self, invocation_context: InvocationContext, llm_request: LlmRequest 37 | ) -> AsyncGenerator[Event, None]: 38 | """Runs the processor.""" 39 | raise NotImplementedError("Not implemented.") 40 | yield # AsyncGenerator requires a yield in function body. 41 | 42 | 43 | class BaseLlmResponseProcessor(ABC): 44 | """Base class for LLM response processor.""" 45 | 46 | @abstractmethod 47 | async def run_async( 48 | self, invocation_context: InvocationContext, llm_response: LlmResponse 49 | ) -> AsyncGenerator[Event, None]: 50 | """Processes the LLM response.""" 51 | raise NotImplementedError("Not implemented.") 52 | yield # AsyncGenerator requires a yield in function body. 53 | -------------------------------------------------------------------------------- /src/google/adk/flows/llm_flows/auto_flow.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Implementation of AutoFlow.""" 16 | 17 | from . import agent_transfer 18 | from .single_flow import SingleFlow 19 | 20 | 21 | class AutoFlow(SingleFlow): 22 | """AutoFlow is SingleFlow with agent transfer capability. 23 | 24 | Agent transfer is allowed in the following direction: 25 | 26 | 1. from parent to sub-agent; 27 | 2. from sub-agent to parent; 28 | 3. from sub-agent to its peer agents; 29 | 30 | For peer-agent transfers, it's only enabled when all below conditions are met: 31 | 32 | - The parent agent is also of AutoFlow; 33 | - `disallow_transfer_to_peer` option of this agent is False (default). 34 | 35 | Depending on the target agent flow type, the transfer may be automatically 36 | reversed. The condition is as below: 37 | 38 | - If the flow type of the tranferee agent is also auto, transfee agent will 39 | remain as the active agent. The transfee agent will respond to the user's 40 | next message directly. 41 | - If the flow type of the transfere agent is not auto, the active agent will 42 | be reversed back to previous agent. 43 | 44 | TODO: allow user to config auto-reverse function. 45 | """ 46 | 47 | def __init__(self): 48 | super().__init__() 49 | self.request_processors += [agent_transfer.request_processor] 50 | -------------------------------------------------------------------------------- /src/google/adk/flows/llm_flows/identity.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Gives the agent identity from the framework.""" 16 | 17 | from __future__ import annotations 18 | 19 | from typing import AsyncGenerator 20 | 21 | from typing_extensions import override 22 | 23 | from ...agents.invocation_context import InvocationContext 24 | from ...events.event import Event 25 | from ...models.llm_request import LlmRequest 26 | from ._base_llm_processor import BaseLlmRequestProcessor 27 | 28 | 29 | class _IdentityLlmRequestProcessor(BaseLlmRequestProcessor): 30 | """Gives the agent identity from the framework.""" 31 | 32 | @override 33 | async def run_async( 34 | self, invocation_context: InvocationContext, llm_request: LlmRequest 35 | ) -> AsyncGenerator[Event, None]: 36 | agent = invocation_context.agent 37 | si = [f'You are an agent. Your internal name is "{agent.name}".'] 38 | if agent.description: 39 | si.append(f' The description about you is "{agent.description}"') 40 | llm_request.append_instructions(si) 41 | 42 | # Maintain async generator behavior 43 | if False: # Ensures it behaves as a generator 44 | yield # This is a no-op but maintains generator structure 45 | 46 | 47 | request_processor = _IdentityLlmRequestProcessor() 48 | -------------------------------------------------------------------------------- /src/google/adk/flows/llm_flows/single_flow.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Implementation of single flow.""" 16 | 17 | import logging 18 | 19 | from . import _code_execution 20 | from . import _nl_planning 21 | from . import basic 22 | from . import contents 23 | from . import identity 24 | from . import instructions 25 | from ...auth import auth_preprocessor 26 | from .base_llm_flow import BaseLlmFlow 27 | 28 | logger = logging.getLogger('google_adk.' + __name__) 29 | 30 | 31 | class SingleFlow(BaseLlmFlow): 32 | """SingleFlow is the LLM flows that handles tools calls. 33 | 34 | A single flow only consider an agent itself and tools. 35 | No sub-agents are allowed for single flow. 36 | """ 37 | 38 | def __init__(self): 39 | super().__init__() 40 | self.request_processors += [ 41 | basic.request_processor, 42 | auth_preprocessor.request_processor, 43 | instructions.request_processor, 44 | identity.request_processor, 45 | contents.request_processor, 46 | # Some implementations of NL Planning mark planning contents as thoughts 47 | # in the post processor. Since these need to be unmarked, NL Planning 48 | # should be after contents. 49 | _nl_planning.request_processor, 50 | # Code execution should be after the contents as it mutates the contents 51 | # to optimize data files. 52 | _code_execution.request_processor, 53 | ] 54 | self.response_processors += [ 55 | _nl_planning.response_processor, 56 | _code_execution.response_processor, 57 | ] 58 | -------------------------------------------------------------------------------- /src/google/adk/memory/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | import logging 15 | 16 | from .base_memory_service import BaseMemoryService 17 | from .in_memory_memory_service import InMemoryMemoryService 18 | 19 | logger = logging.getLogger('google_adk.' + __name__) 20 | 21 | __all__ = [ 22 | 'BaseMemoryService', 23 | 'InMemoryMemoryService', 24 | ] 25 | 26 | try: 27 | from .vertex_ai_rag_memory_service import VertexAiRagMemoryService 28 | 29 | __all__.append('VertexAiRagMemoryService') 30 | except ImportError: 31 | logger.debug( 32 | 'The Vertex sdk is not installed. If you want to use the' 33 | ' VertexAiRagMemoryService please install it. If not, you can ignore this' 34 | ' warning.' 35 | ) 36 | -------------------------------------------------------------------------------- /src/google/adk/memory/_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from __future__ import annotations 17 | 18 | from datetime import datetime 19 | 20 | 21 | def format_timestamp(timestamp: float) -> str: 22 | """Formats the timestamp of the memory entry.""" 23 | return datetime.fromtimestamp(timestamp).isoformat() 24 | -------------------------------------------------------------------------------- /src/google/adk/memory/memory_entry.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from __future__ import annotations 17 | 18 | from typing import Optional 19 | 20 | from google.genai import types 21 | from pydantic import BaseModel 22 | 23 | 24 | class MemoryEntry(BaseModel): 25 | """Represent one memory entry.""" 26 | 27 | content: types.Content 28 | """The main content of the memory.""" 29 | 30 | author: Optional[str] = None 31 | """The author of the memory.""" 32 | 33 | timestamp: Optional[str] = None 34 | """The timestamp when the original content of this memory happened. 35 | 36 | This string will be forwarded to LLM. Preferred format is ISO 8601 format. 37 | """ 38 | -------------------------------------------------------------------------------- /src/google/adk/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Defines the interface to support a model.""" 16 | 17 | from .base_llm import BaseLlm 18 | from .google_llm import Gemini 19 | from .llm_request import LlmRequest 20 | from .llm_response import LlmResponse 21 | from .registry import LLMRegistry 22 | 23 | __all__ = [ 24 | 'BaseLlm', 25 | 'Gemini', 26 | 'LLMRegistry', 27 | ] 28 | 29 | 30 | for regex in Gemini.supported_models(): 31 | LLMRegistry.register(Gemini) 32 | -------------------------------------------------------------------------------- /src/google/adk/planners/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .base_planner import BasePlanner 16 | from .built_in_planner import BuiltInPlanner 17 | from .plan_re_act_planner import PlanReActPlanner 18 | 19 | __all__ = [ 20 | 'BasePlanner', 21 | 'BuiltInPlanner', 22 | 'PlanReActPlanner', 23 | ] 24 | -------------------------------------------------------------------------------- /src/google/adk/planners/base_planner.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import abc 16 | from abc import ABC 17 | from typing import List 18 | from typing import Optional 19 | 20 | from google.genai import types 21 | 22 | from ..agents.callback_context import CallbackContext 23 | from ..agents.readonly_context import ReadonlyContext 24 | from ..models.llm_request import LlmRequest 25 | 26 | 27 | class BasePlanner(ABC): 28 | """Abstract base class for all planners. 29 | 30 | The planner allows the agent to generate plans for the queries to guide its 31 | action. 32 | """ 33 | 34 | @abc.abstractmethod 35 | def build_planning_instruction( 36 | self, 37 | readonly_context: ReadonlyContext, 38 | llm_request: LlmRequest, 39 | ) -> Optional[str]: 40 | """Builds the system instruction to be appended to the LLM request for planning. 41 | 42 | Args: 43 | readonly_context: The readonly context of the invocation. 44 | llm_request: The LLM request. Readonly. 45 | 46 | Returns: 47 | The planning system instruction, or None if no instruction is needed. 48 | """ 49 | pass 50 | 51 | @abc.abstractmethod 52 | def process_planning_response( 53 | self, 54 | callback_context: CallbackContext, 55 | response_parts: List[types.Part], 56 | ) -> Optional[List[types.Part]]: 57 | """Processes the LLM response for planning. 58 | 59 | Args: 60 | callback_context: The callback context of the invocation. 61 | response_parts: The LLM response parts. Readonly. 62 | 63 | Returns: 64 | The processed response parts, or None if no processing is needed. 65 | """ 66 | pass 67 | -------------------------------------------------------------------------------- /src/google/adk/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/src/google/adk/py.typed -------------------------------------------------------------------------------- /src/google/adk/sessions/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | import logging 15 | 16 | from .base_session_service import BaseSessionService 17 | from .in_memory_session_service import InMemorySessionService 18 | from .session import Session 19 | from .state import State 20 | from .vertex_ai_session_service import VertexAiSessionService 21 | 22 | logger = logging.getLogger('google_adk.' + __name__) 23 | 24 | 25 | __all__ = [ 26 | 'BaseSessionService', 27 | 'InMemorySessionService', 28 | 'Session', 29 | 'State', 30 | 'VertexAiSessionService', 31 | ] 32 | 33 | try: 34 | from .database_session_service import DatabaseSessionService 35 | 36 | __all__.append('DatabaseSessionService') 37 | except ImportError: 38 | logger.debug( 39 | 'DatabaseSessionService require sqlalchemy>=2.0, please ensure it is' 40 | ' installed correctly.' 41 | ) 42 | -------------------------------------------------------------------------------- /src/google/adk/sessions/_session_util.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Utility functions for session service.""" 15 | from __future__ import annotations 16 | 17 | from typing import Any 18 | from typing import Optional 19 | 20 | from google.genai import types 21 | 22 | 23 | def decode_content( 24 | content: Optional[dict[str, Any]], 25 | ) -> Optional[types.Content]: 26 | """Decodes a content object from a JSON dictionary.""" 27 | if not content: 28 | return None 29 | return types.Content.model_validate(content) 30 | 31 | 32 | def decode_grounding_metadata( 33 | grounding_metadata: Optional[dict[str, Any]], 34 | ) -> Optional[types.GroundingMetadata]: 35 | """Decodes a grounding metadata object from a JSON dictionary.""" 36 | if not grounding_metadata: 37 | return None 38 | return types.GroundingMetadata.model_validate(grounding_metadata) 39 | -------------------------------------------------------------------------------- /src/google/adk/sessions/session.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import Any 16 | 17 | from pydantic import alias_generators 18 | from pydantic import BaseModel 19 | from pydantic import ConfigDict 20 | from pydantic import Field 21 | 22 | from ..events.event import Event 23 | 24 | 25 | class Session(BaseModel): 26 | """Represents a series of interactions between a user and agents. 27 | 28 | Attributes: 29 | id: The unique identifier of the session. 30 | app_name: The name of the app. 31 | user_id: The id of the user. 32 | state: The state of the session. 33 | events: The events of the session, e.g. user input, model response, function 34 | call/response, etc. 35 | last_update_time: The last update time of the session. 36 | """ 37 | 38 | model_config = ConfigDict( 39 | extra='forbid', 40 | arbitrary_types_allowed=True, 41 | alias_generator=alias_generators.to_camel, 42 | populate_by_name=True, 43 | ) 44 | """The pydantic model config.""" 45 | 46 | id: str 47 | """The unique identifier of the session.""" 48 | app_name: str 49 | """The name of the app.""" 50 | user_id: str 51 | """The id of the user.""" 52 | state: dict[str, Any] = Field(default_factory=dict) 53 | """The state of the session.""" 54 | events: list[Event] = Field(default_factory=list) 55 | """The events of the session, e.g. user input, model response, function 56 | call/response, etc.""" 57 | last_update_time: float = 0.0 58 | """The last update time of the session.""" 59 | -------------------------------------------------------------------------------- /src/google/adk/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from ..auth.auth_tool import AuthToolArguments 17 | from .apihub_tool.apihub_toolset import APIHubToolset 18 | from .base_tool import BaseTool 19 | from .example_tool import ExampleTool 20 | from .exit_loop_tool import exit_loop 21 | from .function_tool import FunctionTool 22 | from .get_user_choice_tool import get_user_choice_tool as get_user_choice 23 | from .google_search_tool import google_search 24 | from .load_artifacts_tool import load_artifacts_tool as load_artifacts 25 | from .load_memory_tool import load_memory_tool as load_memory 26 | from .long_running_tool import LongRunningFunctionTool 27 | from .preload_memory_tool import preload_memory_tool as preload_memory 28 | from .tool_context import ToolContext 29 | from .transfer_to_agent_tool import transfer_to_agent 30 | from .url_context_tool import url_context 31 | from .vertex_ai_search_tool import VertexAiSearchTool 32 | 33 | __all__ = [ 34 | 'APIHubToolset', 35 | 'AuthToolArguments', 36 | 'BaseTool', 37 | 'google_search', 38 | 'url_context', 39 | 'VertexAiSearchTool', 40 | 'ExampleTool', 41 | 'exit_loop', 42 | 'FunctionTool', 43 | 'get_user_choice', 44 | 'load_artifacts', 45 | 'load_memory', 46 | 'LongRunningFunctionTool', 47 | 'preload_memory', 48 | 'ToolContext', 49 | 'transfer_to_agent', 50 | ] 51 | -------------------------------------------------------------------------------- /src/google/adk/tools/_memory_entry_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from __future__ import annotations 17 | 18 | from typing import TYPE_CHECKING 19 | 20 | if TYPE_CHECKING: 21 | from ..memory.memory_entry import MemoryEntry 22 | 23 | 24 | def extract_text(memory: MemoryEntry, splitter: str = ' ') -> str: 25 | """Extracts the text from the memory entry.""" 26 | if not memory.content.parts: 27 | return '' 28 | return splitter.join( 29 | [part.text for part in memory.content.parts if part.text] 30 | ) 31 | -------------------------------------------------------------------------------- /src/google/adk/tools/apihub_tool/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .apihub_toolset import APIHubToolset 16 | 17 | __all__ = [ 18 | 'APIHubToolset', 19 | ] 20 | -------------------------------------------------------------------------------- /src/google/adk/tools/apihub_tool/clients/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /src/google/adk/tools/application_integration_tool/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .application_integration_toolset import ApplicationIntegrationToolset 16 | from .integration_connector_tool import IntegrationConnectorTool 17 | 18 | __all__ = [ 19 | 'ApplicationIntegrationToolset', 20 | 'IntegrationConnectorTool', 21 | ] 22 | -------------------------------------------------------------------------------- /src/google/adk/tools/bigquery/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """BigQuery Tools (Experimental). 16 | 17 | BigQuery Tools under this module are hand crafted and customized while the tools 18 | under google.adk.tools.google_api_tool are auto generated based on API 19 | definition. The rationales to have customized tool are: 20 | 21 | 1. BigQuery APIs have functions overlaps and LLM can't tell what tool to use 22 | 2. BigQuery APIs have a lot of parameters with some rarely used, which are not 23 | LLM-friendly 24 | 3. We want to provide more high-level tools like forecasting, RAG, segmentation, 25 | etc. 26 | 4. We want to provide extra access guardrails in those tools. For example, 27 | execute_sql can't arbitrarily mutate existing data. 28 | """ 29 | 30 | from .bigquery_credentials import BigQueryCredentialsConfig 31 | from .bigquery_tool import BigQueryTool 32 | from .bigquery_toolset import BigQueryToolset 33 | 34 | __all__ = [ 35 | "BigQueryTool", 36 | "BigQueryToolset", 37 | "BigQueryCredentialsConfig", 38 | ] 39 | -------------------------------------------------------------------------------- /src/google/adk/tools/bigquery/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import annotations 16 | 17 | import google.api_core.client_info 18 | from google.cloud import bigquery 19 | from google.oauth2.credentials import Credentials 20 | 21 | USER_AGENT = "adk-bigquery-tool" 22 | 23 | 24 | def get_bigquery_client(*, credentials: Credentials) -> bigquery.Client: 25 | """Get a BigQuery client.""" 26 | 27 | client_info = google.api_core.client_info.ClientInfo(user_agent=USER_AGENT) 28 | 29 | bigquery_client = bigquery.Client( 30 | credentials=credentials, client_info=client_info 31 | ) 32 | 33 | return bigquery_client 34 | -------------------------------------------------------------------------------- /src/google/adk/tools/example_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import annotations 16 | 17 | from typing import TYPE_CHECKING 18 | from typing import Union 19 | 20 | from pydantic import TypeAdapter 21 | from typing_extensions import override 22 | 23 | from ..examples import example_util 24 | from ..examples.base_example_provider import BaseExampleProvider 25 | from ..examples.example import Example 26 | from .base_tool import BaseTool 27 | from .tool_context import ToolContext 28 | 29 | if TYPE_CHECKING: 30 | from ..models.llm_request import LlmRequest 31 | 32 | 33 | class ExampleTool(BaseTool): 34 | """A tool that adds (few-shot) examples to the LLM request. 35 | 36 | Attributes: 37 | examples: The examples to add to the LLM request. 38 | """ 39 | 40 | def __init__(self, examples: Union[list[Example], BaseExampleProvider]): 41 | # Name and description are not used because this tool only changes 42 | # llm_request. 43 | super().__init__(name='example_tool', description='example tool') 44 | self.examples = ( 45 | TypeAdapter(list[Example]).validate_python(examples) 46 | if isinstance(examples, list) 47 | else examples 48 | ) 49 | 50 | @override 51 | async def process_llm_request( 52 | self, *, tool_context: ToolContext, llm_request: LlmRequest 53 | ) -> None: 54 | parts = tool_context.user_content.parts 55 | if not parts or not parts[0].text: 56 | return 57 | 58 | llm_request.append_instructions([ 59 | example_util.build_example_si( 60 | self.examples, parts[0].text, llm_request.model 61 | ) 62 | ]) 63 | -------------------------------------------------------------------------------- /src/google/adk/tools/exit_loop_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .tool_context import ToolContext 16 | 17 | 18 | def exit_loop(tool_context: ToolContext): 19 | """Exits the loop. 20 | 21 | Call this function only when you are instructed to do so. 22 | """ 23 | tool_context.actions.escalate = True 24 | -------------------------------------------------------------------------------- /src/google/adk/tools/get_user_choice_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import Optional 16 | 17 | from .long_running_tool import LongRunningFunctionTool 18 | from .tool_context import ToolContext 19 | 20 | 21 | def get_user_choice( 22 | options: list[str], tool_context: ToolContext 23 | ) -> Optional[str]: 24 | """Provides the options to the user and asks them to choose one.""" 25 | tool_context.actions.skip_summarization = True 26 | return None 27 | 28 | 29 | get_user_choice_tool = LongRunningFunctionTool(func=get_user_choice) 30 | -------------------------------------------------------------------------------- /src/google/adk/tools/google_api_tool/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Auto-generated tools and toolsets for Google APIs. 16 | 17 | These tools and toolsets are auto-generated based on the API specifications 18 | provided by the Google API Discovery API. 19 | """ 20 | 21 | from .google_api_tool import GoogleApiTool 22 | from .google_api_toolset import GoogleApiToolset 23 | from .google_api_toolsets import BigQueryToolset 24 | from .google_api_toolsets import CalendarToolset 25 | from .google_api_toolsets import DocsToolset 26 | from .google_api_toolsets import GmailToolset 27 | from .google_api_toolsets import SheetsToolset 28 | from .google_api_toolsets import SlidesToolset 29 | from .google_api_toolsets import YoutubeToolset 30 | 31 | __all__ = [ 32 | 'BigQueryToolset', 33 | 'CalendarToolset', 34 | 'GmailToolset', 35 | 'YoutubeToolset', 36 | 'SlidesToolset', 37 | 'SheetsToolset', 38 | 'DocsToolset', 39 | 'GoogleApiToolset', 40 | 'GoogleApiTool', 41 | ] 42 | -------------------------------------------------------------------------------- /src/google/adk/tools/load_web_page.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Tool for web browse.""" 16 | 17 | import requests 18 | 19 | 20 | def load_web_page(url: str) -> str: 21 | """Fetches the content in the url and returns the text in it. 22 | 23 | Args: 24 | url (str): The url to browse. 25 | 26 | Returns: 27 | str: The text content of the url. 28 | """ 29 | from bs4 import BeautifulSoup 30 | 31 | response = requests.get(url) 32 | 33 | if response.status_code == 200: 34 | soup = BeautifulSoup(response.content, 'lxml') 35 | text = soup.get_text(separator='\n', strip=True) 36 | else: 37 | text = f'Failed to fetch url: {url}' 38 | 39 | # Split the text into lines, filtering out very short lines 40 | # (e.g., single words or short subtitles) 41 | return '\n'.join(line for line in text.splitlines() if len(line.split()) > 3) 42 | -------------------------------------------------------------------------------- /src/google/adk/tools/long_running_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import Callable 16 | 17 | from .function_tool import FunctionTool 18 | 19 | 20 | class LongRunningFunctionTool(FunctionTool): 21 | """A function tool that returns the result asynchronously. 22 | 23 | This tool is used for long-running operations that may take a significant 24 | amount of time to complete. The framework will call the function. Once the 25 | function returns, the response will be returned asynchronously to the 26 | framework which is identified by the function_call_id. 27 | 28 | Example: 29 | ```python 30 | tool = LongRunningFunctionTool(a_long_running_function) 31 | ``` 32 | 33 | Attributes: 34 | is_long_running: Whether the tool is a long running operation. 35 | """ 36 | 37 | def __init__(self, func: Callable): 38 | super().__init__(func) 39 | self.is_long_running = True 40 | -------------------------------------------------------------------------------- /src/google/adk/tools/mcp_tool/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | __all__ = [] 16 | 17 | try: 18 | from .conversion_utils import adk_to_mcp_tool_type 19 | from .conversion_utils import gemini_to_json_schema 20 | from .mcp_session_manager import SseConnectionParams 21 | from .mcp_session_manager import StdioConnectionParams 22 | from .mcp_session_manager import StreamableHTTPConnectionParams 23 | from .mcp_tool import MCPTool 24 | from .mcp_toolset import MCPToolset 25 | 26 | __all__.extend([ 27 | 'adk_to_mcp_tool_type', 28 | 'gemini_to_json_schema', 29 | 'MCPTool', 30 | 'MCPToolset', 31 | 'StdioConnectionParams', 32 | 'SseConnectionParams', 33 | 'StreamableHTTPConnectionParams', 34 | ]) 35 | 36 | except ImportError as e: 37 | import logging 38 | import sys 39 | 40 | logger = logging.getLogger('google_adk.' + __name__) 41 | 42 | if sys.version_info < (3, 10): 43 | logger.warning( 44 | 'MCP Tool requires Python 3.10 or above. Please upgrade your Python' 45 | ' version.' 46 | ) 47 | else: 48 | logger.debug('MCP Tool is not installed') 49 | logger.debug(e) 50 | -------------------------------------------------------------------------------- /src/google/adk/tools/openapi_tool/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .openapi_spec_parser import OpenAPIToolset 16 | from .openapi_spec_parser import RestApiTool 17 | 18 | __all__ = [ 19 | 'OpenAPIToolset', 20 | 'RestApiTool', 21 | ] 22 | -------------------------------------------------------------------------------- /src/google/adk/tools/openapi_tool/auth/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import auth_helpers 16 | 17 | __all__ = [ 18 | 'auth_helpers', 19 | ] 20 | -------------------------------------------------------------------------------- /src/google/adk/tools/openapi_tool/auth/credential_exchangers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .auto_auth_credential_exchanger import AutoAuthCredentialExchanger 16 | from .base_credential_exchanger import BaseAuthCredentialExchanger 17 | from .oauth2_exchanger import OAuth2CredentialExchanger 18 | from .service_account_exchanger import ServiceAccountCredentialExchanger 19 | 20 | __all__ = [ 21 | 'AutoAuthCredentialExchanger', 22 | 'BaseAuthCredentialExchanger', 23 | 'OAuth2CredentialExchanger', 24 | 'ServiceAccountCredentialExchanger', 25 | ] 26 | -------------------------------------------------------------------------------- /src/google/adk/tools/openapi_tool/auth/credential_exchangers/base_credential_exchanger.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import abc 16 | from typing import Optional 17 | 18 | from .....auth.auth_credential import AuthCredential 19 | from .....auth.auth_schemes import AuthScheme 20 | 21 | 22 | class AuthCredentialMissingError(Exception): 23 | """Exception raised when required authentication credentials are missing.""" 24 | 25 | def __init__(self, message: str): 26 | super().__init__(message) 27 | self.message = message 28 | 29 | 30 | class BaseAuthCredentialExchanger: 31 | """Base class for authentication credential exchangers.""" 32 | 33 | @abc.abstractmethod 34 | def exchange_credential( 35 | self, 36 | auth_scheme: AuthScheme, 37 | auth_credential: Optional[AuthCredential] = None, 38 | ) -> AuthCredential: 39 | """Exchanges the provided authentication credential for a usable token/credential. 40 | 41 | Args: 42 | auth_scheme: The security scheme. 43 | auth_credential: The authentication credential. 44 | 45 | Returns: 46 | An updated AuthCredential object containing the fetched credential. 47 | For simple schemes like API key, it may return the original credential 48 | if no exchange is needed. 49 | 50 | Raises: 51 | NotImplementedError: If the method is not implemented by a subclass. 52 | """ 53 | raise NotImplementedError("Subclasses must implement exchange_credential.") 54 | -------------------------------------------------------------------------------- /src/google/adk/tools/openapi_tool/common/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import common 16 | 17 | __all__ = [ 18 | 'common', 19 | ] 20 | -------------------------------------------------------------------------------- /src/google/adk/tools/openapi_tool/openapi_spec_parser/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .openapi_spec_parser import OpenApiSpecParser 16 | from .openapi_spec_parser import OperationEndpoint 17 | from .openapi_spec_parser import ParsedOperation 18 | from .openapi_toolset import OpenAPIToolset 19 | from .operation_parser import OperationParser 20 | from .rest_api_tool import AuthPreparationState 21 | from .rest_api_tool import RestApiTool 22 | from .rest_api_tool import snake_to_lower_camel 23 | from .tool_auth_handler import ToolAuthHandler 24 | 25 | __all__ = [ 26 | 'OpenApiSpecParser', 27 | 'OperationEndpoint', 28 | 'ParsedOperation', 29 | 'OpenAPIToolset', 30 | 'OperationParser', 31 | 'RestApiTool', 32 | 'snake_to_lower_camel', 33 | 'AuthPreparationState', 34 | 'ToolAuthHandler', 35 | ] 36 | -------------------------------------------------------------------------------- /src/google/adk/tools/retrieval/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .base_retrieval_tool import BaseRetrievalTool 16 | from .files_retrieval import FilesRetrieval 17 | from .llama_index_retrieval import LlamaIndexRetrieval 18 | 19 | __all__ = [ 20 | 'BaseRetrievalTool', 21 | 'FilesRetrieval', 22 | 'LlamaIndexRetrieval', 23 | ] 24 | 25 | try: 26 | from .vertex_ai_rag_retrieval import VertexAiRagRetrieval 27 | 28 | __all__.append('VertexAiRagRetrieval') 29 | except ImportError: 30 | import logging 31 | 32 | logger = logging.getLogger('google_adk.' + __name__) 33 | logger.debug( 34 | 'The Vertex sdk is not installed. If you want to use the Vertex RAG with' 35 | ' agents, please install it. If not, you can ignore this warning.' 36 | ) 37 | -------------------------------------------------------------------------------- /src/google/adk/tools/retrieval/base_retrieval_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.genai import types 16 | from typing_extensions import override 17 | 18 | from ..base_tool import BaseTool 19 | 20 | 21 | class BaseRetrievalTool(BaseTool): 22 | 23 | @override 24 | def _get_declaration(self) -> types.FunctionDeclaration: 25 | return types.FunctionDeclaration( 26 | name=self.name, 27 | description=self.description, 28 | parameters=types.Schema( 29 | type=types.Type.OBJECT, 30 | properties={ 31 | 'query': types.Schema( 32 | type=types.Type.STRING, 33 | description='The query to retrieve.', 34 | ), 35 | }, 36 | ), 37 | ) 38 | -------------------------------------------------------------------------------- /src/google/adk/tools/retrieval/files_retrieval.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Provides data for the agent.""" 16 | 17 | from __future__ import annotations 18 | 19 | import logging 20 | 21 | from llama_index.core import SimpleDirectoryReader 22 | from llama_index.core import VectorStoreIndex 23 | 24 | from .llama_index_retrieval import LlamaIndexRetrieval 25 | 26 | logger = logging.getLogger("google_adk." + __name__) 27 | 28 | 29 | class FilesRetrieval(LlamaIndexRetrieval): 30 | 31 | def __init__(self, *, name: str, description: str, input_dir: str): 32 | 33 | self.input_dir = input_dir 34 | 35 | logger.info("Loading data from %s", input_dir) 36 | retriever = VectorStoreIndex.from_documents( 37 | SimpleDirectoryReader(input_dir).load_data() 38 | ).as_retriever() 39 | super().__init__(name=name, description=description, retriever=retriever) 40 | -------------------------------------------------------------------------------- /src/google/adk/tools/retrieval/llama_index_retrieval.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Provides data for the agent.""" 16 | 17 | from __future__ import annotations 18 | 19 | from typing import Any 20 | from typing import TYPE_CHECKING 21 | 22 | from typing_extensions import override 23 | 24 | from ..tool_context import ToolContext 25 | from .base_retrieval_tool import BaseRetrievalTool 26 | 27 | if TYPE_CHECKING: 28 | from llama_index.core.base.base_retriever import BaseRetriever 29 | 30 | 31 | class LlamaIndexRetrieval(BaseRetrievalTool): 32 | 33 | def __init__(self, *, name: str, description: str, retriever: BaseRetriever): 34 | super().__init__(name=name, description=description) 35 | self.retriever = retriever 36 | 37 | @override 38 | async def run_async( 39 | self, *, args: dict[str, Any], tool_context: ToolContext 40 | ) -> Any: 41 | return self.retriever.retrieve(args['query'])[0].text 42 | -------------------------------------------------------------------------------- /src/google/adk/tools/transfer_to_agent_tool.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .tool_context import ToolContext 16 | 17 | 18 | def transfer_to_agent(agent_name: str, tool_context: ToolContext): 19 | """Transfer the question to another agent. 20 | 21 | This tool hands off control to another agent when it's more suitable to 22 | answer the user's question according to the agent's description. 23 | 24 | Args: 25 | agent_name: the agent name to transfer to. 26 | """ 27 | tool_context.actions.transfer_to_agent = agent_name 28 | -------------------------------------------------------------------------------- /src/google/adk/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /src/google/adk/utils/variant_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Utilities for Google LLM variants. 16 | 17 | This module is for ADK internal use only. 18 | Please do not rely on the implementation details. 19 | """ 20 | 21 | from __future__ import annotations 22 | 23 | from enum import Enum 24 | import os 25 | 26 | _GOOGLE_LLM_VARIANT_VERTEX_AI = 'VERTEX_AI' 27 | _GOOGLE_LLM_VARIANT_GEMINI_API = 'GEMINI_API' 28 | 29 | 30 | class GoogleLLMVariant(Enum): 31 | """ 32 | The Google LLM variant to use. 33 | see https://google.github.io/adk-docs/get-started/quickstart/#set-up-the-model 34 | """ 35 | 36 | VERTEX_AI = _GOOGLE_LLM_VARIANT_VERTEX_AI 37 | """For using credentials from Google Vertex AI""" 38 | GEMINI_API = _GOOGLE_LLM_VARIANT_GEMINI_API 39 | """For using API Key from Google AI Studio""" 40 | 41 | 42 | def get_google_llm_variant() -> str: 43 | return ( 44 | GoogleLLMVariant.VERTEX_AI 45 | if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI', '0').lower() 46 | in [ 47 | 'true', 48 | '1', 49 | ] 50 | else GoogleLLMVariant.GEMINI_API 51 | ) 52 | -------------------------------------------------------------------------------- /src/google/adk/version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # version: major.minor.patch 16 | __version__ = "1.2.1" 17 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/integration/.env.example: -------------------------------------------------------------------------------- 1 | # Copy as .env file and fill your values below to run integration tests. 2 | 3 | # Choose Backend: GOOGLE_AI_ONLY | VERTEX_ONLY | BOTH (default) 4 | TEST_BACKEND=BOTH 5 | 6 | # ML Dev backend config 7 | GOOGLE_API_KEY=YOUR_VALUE_HERE 8 | # Vertex backend config 9 | GOOGLE_CLOUD_PROJECT=YOUR_VALUE_HERE 10 | GOOGLE_CLOUD_LOCATION=YOUR_VALUE_HERE 11 | -------------------------------------------------------------------------------- /tests/integration/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import pytest 16 | 17 | # This allows pytest to show the values of the asserts. 18 | pytest.register_assert_rewrite('tests.integration.utils') 19 | -------------------------------------------------------------------------------- /tests/integration/fixture/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/integration/fixture/agent_with_config/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/callback_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/context_update_test/OWNERS: -------------------------------------------------------------------------------- 1 | gkcng 2 | -------------------------------------------------------------------------------- /tests/integration/fixture/context_update_test/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/context_update_test/agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from typing import List 16 | from typing import Union 17 | 18 | from google.adk import Agent 19 | from google.adk.tools import ToolContext 20 | from pydantic import BaseModel 21 | 22 | 23 | def update_fc( 24 | data_one: str, 25 | data_two: Union[int, float, str], 26 | data_three: list[str], 27 | data_four: List[Union[int, float, str]], 28 | tool_context: ToolContext, 29 | ): 30 | """Simply ask to update these variables in the context""" 31 | tool_context.actions.update_state("data_one", data_one) 32 | tool_context.actions.update_state("data_two", data_two) 33 | tool_context.actions.update_state("data_three", data_three) 34 | tool_context.actions.update_state("data_four", data_four) 35 | 36 | 37 | root_agent = Agent( 38 | model="gemini-1.5-flash", 39 | name="root_agent", 40 | instruction="Call tools", 41 | flow="auto", 42 | tools=[update_fc], 43 | ) 44 | -------------------------------------------------------------------------------- /tests/integration/fixture/context_variable_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/ecommerce_customer_service_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/ecommerce_customer_service_agent/test_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "criteria": { 3 | "tool_trajectory_avg_score": 0.7, 4 | "response_match_score": 0.5 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/integration/fixture/flow_complex_spark/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/hello_world_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/hello_world_agent/test_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "criteria": { 3 | "tool_trajectory_avg_score": 1.0, 4 | "response_match_score": 0.5 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/integration/fixture/home_automation_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/home_automation_agent/simple_test.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "eval_set_id": "b305bd06-38c5-4796-b9c7-d9c7454338b9", 3 | "name": "b305bd06-38c5-4796-b9c7-d9c7454338b9", 4 | "description": null, 5 | "eval_cases": [ 6 | { 7 | "eval_id": "tests/integration/fixture/home_automation_agent/simple_test.test.json", 8 | "conversation": [ 9 | { 10 | "invocation_id": "b7982664-0ab6-47cc-ab13-326656afdf75", 11 | "user_content": { 12 | "parts": [ 13 | { 14 | "video_metadata": null, 15 | "thought": null, 16 | "code_execution_result": null, 17 | "executable_code": null, 18 | "file_data": null, 19 | "function_call": null, 20 | "function_response": null, 21 | "inline_data": null, 22 | "text": "Turn off device_2 in the Bedroom." 23 | } 24 | ], 25 | "role": "user" 26 | }, 27 | "final_response": { 28 | "parts": [ 29 | { 30 | "video_metadata": null, 31 | "thought": null, 32 | "code_execution_result": null, 33 | "executable_code": null, 34 | "file_data": null, 35 | "function_call": null, 36 | "function_response": null, 37 | "inline_data": null, 38 | "text": "I have set the device_2 status to off." 39 | } 40 | ], 41 | "role": "model" 42 | }, 43 | "intermediate_data": { 44 | "tool_uses": [ 45 | { 46 | "id": null, 47 | "args": { 48 | "location": "Bedroom", 49 | "device_id": "device_2", 50 | "status": "OFF" 51 | }, 52 | "name": "set_device_info" 53 | } 54 | ], 55 | "intermediate_responses": [] 56 | }, 57 | "creation_timestamp": 1747337309.2360144 58 | } 59 | ], 60 | "session_input": null, 61 | "creation_timestamp": 1747337309.2360282 62 | } 63 | ], 64 | "creation_timestamp": 1747337309.2360387 65 | } -------------------------------------------------------------------------------- /tests/integration/fixture/home_automation_agent/simple_test2.test.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "query": "Turn off device_3 in the Bedroom.", 3 | "expected_tool_use": [{"tool_name": "set_device_info", "tool_input": {"location": "Bedroom", "device_id": "device_3", "status": "OFF"}}], 4 | "reference": "I have set the device_3 status to off." 5 | }] 6 | -------------------------------------------------------------------------------- /tests/integration/fixture/home_automation_agent/test_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "criteria": { 3 | "tool_trajectory_avg_score": 1.0 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/test_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "criteria": { 3 | "tool_trajectory_avg_score": 1.0, 4 | "response_match_score": 0.5 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/integration/fixture/home_automation_agent/test_files/test_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "criteria": { 3 | "tool_trajectory_avg_score": 1.0 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/fixture/tool_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/tool_agent/files/Agent_test_plan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/adk-python/be7120831ae56d3735f081544eb59457cd103aa5/tests/integration/fixture/tool_agent/files/Agent_test_plan.pdf -------------------------------------------------------------------------------- /tests/integration/fixture/trip_planner_agent/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from . import agent 16 | -------------------------------------------------------------------------------- /tests/integration/fixture/trip_planner_agent/initial.session.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "test_id", 3 | "app_name": "trip_planner_agent", 4 | "user_id": "test_user", 5 | "state": { 6 | "origin": "San Francisco", 7 | "interests": "Food, Shopping, Museums", 8 | "range": "1000 miles", 9 | "cities": "" 10 | }, 11 | "events": [], 12 | "last_update_time": 1741218714.258285 13 | } 14 | -------------------------------------------------------------------------------- /tests/integration/fixture/trip_planner_agent/test_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "criteria": { 3 | "response_match_score": 0.5 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/fixture/trip_planner_agent/test_files/test_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "criteria": { 3 | "response_match_score": 0.5 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/fixture/trip_planner_agent/trip_inquiry.test.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "query": "Hi, who are you? What can you do?", 4 | "expected_tool_use": [], 5 | "reference": "I am trip_planner, and my goal is to plan the best trip ever. I can describe why a city was chosen, list its top attractions, and provide a detailed itinerary for each day of the trip.\n" 6 | }, 7 | { 8 | "query": "I want to travel from San Francisco to an European country in fall next year. I am considering London and Paris. What is your advice?", 9 | "expected_tool_use": [ 10 | { 11 | "tool_name": "transfer_to_agent", 12 | "tool_input": { 13 | "agent_name": "indentify_agent" 14 | } 15 | } 16 | ], 17 | "reference": "Okay, I can help you analyze London and Paris to determine which city is better for your trip next fall. I will consider weather patterns, seasonal events, travel costs (including flights from San Francisco), and your interests (food, shopping, and museums). After gathering this information, I'll provide a detailed report on my chosen city.\n" 18 | } 19 | ] 20 | -------------------------------------------------------------------------------- /tests/integration/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/integration/test_multi_agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.evaluation import AgentEvaluator 16 | import pytest 17 | 18 | 19 | @pytest.mark.asyncio 20 | async def test_eval_agent(): 21 | await AgentEvaluator.evaluate( 22 | agent_module="tests.integration.fixture.trip_planner_agent", 23 | eval_dataset_file_path_or_dir=( 24 | "tests/integration/fixture/trip_planner_agent/trip_inquiry.test.json" 25 | ), 26 | num_runs=4, 27 | ) 28 | -------------------------------------------------------------------------------- /tests/integration/test_multi_turn.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.evaluation import AgentEvaluator 16 | import pytest 17 | 18 | 19 | @pytest.mark.asyncio 20 | async def test_simple_multi_turn_conversation(): 21 | """Test a simple multi-turn conversation.""" 22 | await AgentEvaluator.evaluate( 23 | agent_module="tests.integration.fixture.home_automation_agent", 24 | eval_dataset_file_path_or_dir="tests/integration/fixture/home_automation_agent/test_files/simple_multi_turn_conversation.test.json", 25 | num_runs=4, 26 | ) 27 | 28 | 29 | @pytest.mark.asyncio 30 | async def test_dependent_tool_calls(): 31 | """Test subsequent tool calls that are dependent on previous tool calls.""" 32 | await AgentEvaluator.evaluate( 33 | agent_module="tests.integration.fixture.home_automation_agent", 34 | eval_dataset_file_path_or_dir="tests/integration/fixture/home_automation_agent/test_files/dependent_tool_calls.test.json", 35 | num_runs=4, 36 | ) 37 | 38 | 39 | @pytest.mark.asyncio 40 | async def test_memorizing_past_events(): 41 | """Test memorizing past events.""" 42 | await AgentEvaluator.evaluate( 43 | agent_module="tests.integration.fixture.home_automation_agent", 44 | eval_dataset_file_path_or_dir="tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/eval_data.test.json", 45 | num_runs=4, 46 | ) 47 | -------------------------------------------------------------------------------- /tests/integration/test_single_agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.evaluation import AgentEvaluator 16 | import pytest 17 | 18 | 19 | @pytest.mark.asyncio 20 | async def test_eval_agent(): 21 | await AgentEvaluator.evaluate( 22 | agent_module="tests.integration.fixture.home_automation_agent", 23 | eval_dataset_file_path_or_dir="tests/integration/fixture/home_automation_agent/simple_test.test.json", 24 | num_runs=4, 25 | ) 26 | -------------------------------------------------------------------------------- /tests/integration/test_sub_agent.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.evaluation import AgentEvaluator 16 | import pytest 17 | 18 | 19 | @pytest.mark.asyncio 20 | async def test_eval_agent(): 21 | """Test hotel sub agent in a multi-agent system.""" 22 | await AgentEvaluator.evaluate( 23 | agent_module="tests.integration.fixture.trip_planner_agent", 24 | eval_dataset_file_path_or_dir="tests/integration/fixture/trip_planner_agent/test_files/trip_inquiry_sub_agent.test.json", 25 | agent_name="identify_agent", 26 | num_runs=4, 27 | ) 28 | -------------------------------------------------------------------------------- /tests/integration/test_with_test_file.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.evaluation import AgentEvaluator 16 | import pytest 17 | 18 | 19 | @pytest.mark.asyncio 20 | async def test_with_single_test_file(): 21 | """Test the agent's basic ability via session file.""" 22 | await AgentEvaluator.evaluate( 23 | agent_module="tests.integration.fixture.home_automation_agent", 24 | eval_dataset_file_path_or_dir="tests/integration/fixture/home_automation_agent/simple_test.test.json", 25 | ) 26 | 27 | 28 | @pytest.mark.asyncio 29 | async def test_with_folder_of_test_files_long_running(): 30 | """Test the agent's basic ability via a folder of session files.""" 31 | await AgentEvaluator.evaluate( 32 | agent_module="tests.integration.fixture.home_automation_agent", 33 | eval_dataset_file_path_or_dir=( 34 | "tests/integration/fixture/home_automation_agent/test_files" 35 | ), 36 | num_runs=4, 37 | ) 38 | -------------------------------------------------------------------------------- /tests/integration/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/integration/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .asserts import * 16 | from .test_runner import TestRunner 17 | -------------------------------------------------------------------------------- /tests/unittests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/agents/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/agents/test_live_request_queue.py: -------------------------------------------------------------------------------- 1 | from unittest.mock import AsyncMock 2 | from unittest.mock import MagicMock 3 | from unittest.mock import patch 4 | 5 | from google.adk.agents.live_request_queue import LiveRequest 6 | from google.adk.agents.live_request_queue import LiveRequestQueue 7 | from google.genai import types 8 | import pytest 9 | 10 | 11 | @pytest.mark.asyncio 12 | async def test_close_queue(): 13 | queue = LiveRequestQueue() 14 | 15 | with patch.object(queue._queue, "put_nowait") as mock_put_nowait: 16 | queue.close() 17 | mock_put_nowait.assert_called_once_with(LiveRequest(close=True)) 18 | 19 | 20 | def test_send_content(): 21 | queue = LiveRequestQueue() 22 | content = MagicMock(spec=types.Content) 23 | 24 | with patch.object(queue._queue, "put_nowait") as mock_put_nowait: 25 | queue.send_content(content) 26 | mock_put_nowait.assert_called_once_with(LiveRequest(content=content)) 27 | 28 | 29 | def test_send_realtime(): 30 | queue = LiveRequestQueue() 31 | blob = MagicMock(spec=types.Blob) 32 | 33 | with patch.object(queue._queue, "put_nowait") as mock_put_nowait: 34 | queue.send_realtime(blob) 35 | mock_put_nowait.assert_called_once_with(LiveRequest(blob=blob)) 36 | 37 | 38 | def test_send(): 39 | queue = LiveRequestQueue() 40 | req = LiveRequest(content=MagicMock(spec=types.Content)) 41 | 42 | with patch.object(queue._queue, "put_nowait") as mock_put_nowait: 43 | queue.send(req) 44 | mock_put_nowait.assert_called_once_with(req) 45 | 46 | 47 | @pytest.mark.asyncio 48 | async def test_get(): 49 | queue = LiveRequestQueue() 50 | res = MagicMock(spec=types.Content) 51 | 52 | with patch.object(queue._queue, "get", return_value=res) as mock_get: 53 | result = await queue.get() 54 | 55 | assert result == res 56 | mock_get.assert_called_once() 57 | -------------------------------------------------------------------------------- /tests/unittests/agents/test_readonly_context.py: -------------------------------------------------------------------------------- 1 | from types import MappingProxyType 2 | from unittest.mock import MagicMock 3 | 4 | from google.adk.agents.readonly_context import ReadonlyContext 5 | import pytest 6 | 7 | 8 | @pytest.fixture 9 | def mock_invocation_context(): 10 | mock_context = MagicMock() 11 | mock_context.invocation_id = "test-invocation-id" 12 | mock_context.agent.name = "test-agent-name" 13 | mock_context.session.state = {"key1": "value1", "key2": "value2"} 14 | 15 | return mock_context 16 | 17 | 18 | def test_invocation_id(mock_invocation_context): 19 | readonly_context = ReadonlyContext(mock_invocation_context) 20 | assert readonly_context.invocation_id == "test-invocation-id" 21 | 22 | 23 | def test_agent_name(mock_invocation_context): 24 | readonly_context = ReadonlyContext(mock_invocation_context) 25 | assert readonly_context.agent_name == "test-agent-name" 26 | 27 | 28 | def test_state_content(mock_invocation_context): 29 | readonly_context = ReadonlyContext(mock_invocation_context) 30 | state = readonly_context.state 31 | 32 | assert isinstance(state, MappingProxyType) 33 | assert state["key1"] == "value1" 34 | assert state["key2"] == "value2" 35 | -------------------------------------------------------------------------------- /tests/unittests/agents/test_run_config.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import sys 3 | from unittest.mock import ANY 4 | from unittest.mock import patch 5 | 6 | from google.adk.agents.run_config import RunConfig 7 | import pytest 8 | 9 | 10 | def test_validate_max_llm_calls_valid(): 11 | value = RunConfig.validate_max_llm_calls(100) 12 | assert value == 100 13 | 14 | 15 | def test_validate_max_llm_calls_negative(): 16 | with patch("google.adk.agents.run_config.logger.warning") as mock_warning: 17 | value = RunConfig.validate_max_llm_calls(-1) 18 | mock_warning.assert_called_once_with(ANY) 19 | assert value == -1 20 | 21 | 22 | def test_validate_max_llm_calls_warns_on_zero(): 23 | with patch("google.adk.agents.run_config.logger.warning") as mock_warning: 24 | value = RunConfig.validate_max_llm_calls(0) 25 | mock_warning.assert_called_once_with(ANY) 26 | assert value == 0 27 | 28 | 29 | def test_validate_max_llm_calls_too_large(): 30 | with pytest.raises( 31 | ValueError, match=f"max_llm_calls should be less than {sys.maxsize}." 32 | ): 33 | RunConfig.validate_max_llm_calls(sys.maxsize) 34 | -------------------------------------------------------------------------------- /tests/unittests/artifacts/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/cli/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/cli/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/code_executors/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/flows/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/flows/llm_flows/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/flows/llm_flows/test_other_configs.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.agents import Agent 16 | from google.adk.tools import ToolContext 17 | from google.genai.types import Part 18 | from pydantic import BaseModel 19 | 20 | from ... import testing_utils 21 | 22 | 23 | def test_output_schema(): 24 | class CustomOutput(BaseModel): 25 | custom_field: str 26 | 27 | response = [ 28 | 'response1', 29 | ] 30 | mockModel = testing_utils.MockModel.create(responses=response) 31 | root_agent = Agent( 32 | name='root_agent', 33 | model=mockModel, 34 | output_schema=CustomOutput, 35 | disallow_transfer_to_parent=True, 36 | disallow_transfer_to_peers=True, 37 | ) 38 | 39 | runner = testing_utils.InMemoryRunner(root_agent) 40 | 41 | assert testing_utils.simplify_events(runner.run('test1')) == [ 42 | ('root_agent', 'response1'), 43 | ] 44 | assert len(mockModel.requests) == 1 45 | assert mockModel.requests[0].config.response_schema == CustomOutput 46 | assert mockModel.requests[0].config.response_mime_type == 'application/json' 47 | assert mockModel.requests[0].config.labels == {'adk_agent_name': 'root_agent'} 48 | -------------------------------------------------------------------------------- /tests/unittests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/sessions/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/streaming/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/streaming/test_streaming.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from google.adk.agents import Agent 16 | from google.adk.agents import LiveRequestQueue 17 | from google.adk.models import LlmResponse 18 | from google.genai import types 19 | import pytest 20 | 21 | from .. import testing_utils 22 | 23 | 24 | def test_streaming(): 25 | response1 = LlmResponse( 26 | turn_complete=True, 27 | ) 28 | 29 | mock_model = testing_utils.MockModel.create([response1]) 30 | 31 | root_agent = Agent( 32 | name='root_agent', 33 | model=mock_model, 34 | tools=[], 35 | ) 36 | 37 | runner = testing_utils.InMemoryRunner( 38 | root_agent=root_agent, response_modalities=['AUDIO'] 39 | ) 40 | live_request_queue = LiveRequestQueue() 41 | live_request_queue.send_realtime( 42 | blob=types.Blob(data=b'\x00\xFF', mime_type='audio/pcm') 43 | ) 44 | res_events = runner.run_live(live_request_queue) 45 | 46 | assert res_events is not None, 'Expected a list of events, got None.' 47 | assert ( 48 | len(res_events) > 0 49 | ), 'Expected at least one response, but got an empty list.' 50 | -------------------------------------------------------------------------------- /tests/unittests/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/tools/bigquery/__init__: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/tools/google_api_tool/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/tools/retrieval/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /tests/unittests/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | --------------------------------------------------------------------------------