google-adk 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/adk/._version.py +0 -0
- google/adk/__init__.py +20 -0
- google/adk/agents/__init__.py +32 -0
- google/adk/agents/active_streaming_tool.py +38 -0
- google/adk/agents/base_agent.py +345 -0
- google/adk/agents/callback_context.py +112 -0
- google/adk/agents/invocation_context.py +181 -0
- google/adk/agents/langgraph_agent.py +140 -0
- google/adk/agents/live_request_queue.py +64 -0
- google/adk/agents/llm_agent.py +376 -0
- google/adk/agents/loop_agent.py +62 -0
- google/adk/agents/parallel_agent.py +96 -0
- google/adk/agents/readonly_context.py +46 -0
- google/adk/agents/remote_agent.py +50 -0
- google/adk/agents/run_config.py +87 -0
- google/adk/agents/sequential_agent.py +45 -0
- google/adk/agents/transcription_entry.py +34 -0
- google/adk/artifacts/__init__.py +23 -0
- google/adk/artifacts/base_artifact_service.py +128 -0
- google/adk/artifacts/gcs_artifact_service.py +195 -0
- google/adk/artifacts/in_memory_artifact_service.py +133 -0
- google/adk/auth/__init__.py +22 -0
- google/adk/auth/auth_credential.py +220 -0
- google/adk/auth/auth_handler.py +268 -0
- google/adk/auth/auth_preprocessor.py +116 -0
- google/adk/auth/auth_schemes.py +67 -0
- google/adk/auth/auth_tool.py +55 -0
- google/adk/cli/__init__.py +15 -0
- google/adk/cli/__main__.py +18 -0
- google/adk/cli/agent_graph.py +148 -0
- google/adk/cli/browser/adk_favicon.svg +17 -0
- google/adk/cli/browser/assets/audio-processor.js +51 -0
- google/adk/cli/browser/assets/config/runtime-config.json +3 -0
- google/adk/cli/browser/index.html +33 -0
- google/adk/cli/browser/main-SY2WYYGV.js +75 -0
- google/adk/cli/browser/polyfills-FFHMD2TL.js +18 -0
- google/adk/cli/browser/styles-4VDSPQ37.css +17 -0
- google/adk/cli/cli.py +181 -0
- google/adk/cli/cli_deploy.py +181 -0
- google/adk/cli/cli_eval.py +282 -0
- google/adk/cli/cli_tools_click.py +524 -0
- google/adk/cli/fast_api.py +784 -0
- google/adk/cli/utils/__init__.py +49 -0
- google/adk/cli/utils/envs.py +57 -0
- google/adk/cli/utils/evals.py +93 -0
- google/adk/cli/utils/logs.py +72 -0
- google/adk/code_executors/__init__.py +49 -0
- google/adk/code_executors/base_code_executor.py +97 -0
- google/adk/code_executors/code_execution_utils.py +256 -0
- google/adk/code_executors/code_executor_context.py +202 -0
- google/adk/code_executors/container_code_executor.py +196 -0
- google/adk/code_executors/unsafe_local_code_executor.py +71 -0
- google/adk/code_executors/vertex_ai_code_executor.py +234 -0
- google/adk/docs/Makefile +20 -0
- google/adk/docs/build/doctrees/google-adk.doctree +0 -0
- google/adk/docs/build/html/_sources/google-adk.rst.txt +98 -0
- google/adk/docs/build/html/_sources/index.rst.txt +7 -0
- google/adk/docs/build/html/_static/autodoc_pydantic.css +27 -0
- google/adk/docs/build/html/_static/basic.css +925 -0
- google/adk/docs/build/html/_static/debug.css +85 -0
- google/adk/docs/build/html/_static/doctools.js +156 -0
- google/adk/docs/build/html/_static/documentation_options.js +29 -0
- google/adk/docs/build/html/_static/file.png +0 -0
- google/adk/docs/build/html/_static/language_data.js +199 -0
- google/adk/docs/build/html/_static/minus.png +0 -0
- google/adk/docs/build/html/_static/plus.png +0 -0
- google/adk/docs/build/html/_static/pygments.css +274 -0
- google/adk/docs/build/html/_static/scripts/furo-extensions.js +16 -0
- google/adk/docs/build/html/_static/scripts/furo.js +19 -0
- google/adk/docs/build/html/_static/scripts/furo.js.LICENSE.txt +7 -0
- google/adk/docs/build/html/_static/scripts/furo.js.map +1 -0
- google/adk/docs/build/html/_static/searchtools.js +620 -0
- google/adk/docs/build/html/_static/skeleton.css +312 -0
- google/adk/docs/build/html/_static/sphinx_highlight.js +170 -0
- google/adk/docs/build/html/_static/styles/furo-extensions.css +18 -0
- google/adk/docs/build/html/_static/styles/furo-extensions.css.map +1 -0
- google/adk/docs/build/html/_static/styles/furo.css +18 -0
- google/adk/docs/build/html/_static/styles/furo.css.map +1 -0
- google/adk/docs/build/html/genindex.html +861 -0
- google/adk/docs/build/html/google-adk.html +5461 -0
- google/adk/docs/build/html/index.html +567 -0
- google/adk/docs/build/html/objects.inv +0 -0
- google/adk/docs/build/html/py-modindex.html +373 -0
- google/adk/docs/build/html/search.html +333 -0
- google/adk/docs/build/html/searchindex.js +17 -0
- google/adk/docs/source/conf.py +133 -0
- google/adk/docs/source/google-adk.rst +98 -0
- google/adk/docs/source/index.rst +7 -0
- google/adk/evaluation/__init__.py +31 -0
- google/adk/evaluation/agent_evaluator.py +329 -0
- google/adk/evaluation/evaluation_constants.py +24 -0
- google/adk/evaluation/evaluation_generator.py +270 -0
- google/adk/evaluation/response_evaluator.py +135 -0
- google/adk/evaluation/trajectory_evaluator.py +184 -0
- google/adk/events/__init__.py +21 -0
- google/adk/events/event.py +130 -0
- google/adk/events/event_actions.py +55 -0
- google/adk/examples/__init__.py +28 -0
- google/adk/examples/base_example_provider.py +35 -0
- google/adk/examples/example.py +27 -0
- google/adk/examples/example_util.py +123 -0
- google/adk/examples/vertex_ai_example_store.py +104 -0
- google/adk/flows/__init__.py +14 -0
- google/adk/flows/llm_flows/__init__.py +20 -0
- google/adk/flows/llm_flows/_base_llm_processor.py +52 -0
- google/adk/flows/llm_flows/_code_execution.py +458 -0
- google/adk/flows/llm_flows/_nl_planning.py +129 -0
- google/adk/flows/llm_flows/agent_transfer.py +132 -0
- google/adk/flows/llm_flows/audio_transcriber.py +109 -0
- google/adk/flows/llm_flows/auto_flow.py +49 -0
- google/adk/flows/llm_flows/base_llm_flow.py +559 -0
- google/adk/flows/llm_flows/basic.py +72 -0
- google/adk/flows/llm_flows/contents.py +370 -0
- google/adk/flows/llm_flows/functions.py +486 -0
- google/adk/flows/llm_flows/identity.py +47 -0
- google/adk/flows/llm_flows/instructions.py +137 -0
- google/adk/flows/llm_flows/single_flow.py +57 -0
- google/adk/memory/__init__.py +35 -0
- google/adk/memory/base_memory_service.py +74 -0
- google/adk/memory/in_memory_memory_service.py +62 -0
- google/adk/memory/vertex_ai_rag_memory_service.py +177 -0
- google/adk/models/__init__.py +31 -0
- google/adk/models/anthropic_llm.py +243 -0
- google/adk/models/base_llm.py +87 -0
- google/adk/models/base_llm_connection.py +76 -0
- google/adk/models/gemini_llm_connection.py +200 -0
- google/adk/models/google_llm.py +331 -0
- google/adk/models/lite_llm.py +673 -0
- google/adk/models/llm_request.py +98 -0
- google/adk/models/llm_response.py +111 -0
- google/adk/models/registry.py +102 -0
- google/adk/planners/__init__.py +23 -0
- google/adk/planners/base_planner.py +66 -0
- google/adk/planners/built_in_planner.py +75 -0
- google/adk/planners/plan_re_act_planner.py +208 -0
- google/adk/runners.py +456 -0
- google/adk/sessions/__init__.py +41 -0
- google/adk/sessions/base_session_service.py +133 -0
- google/adk/sessions/database_session_service.py +522 -0
- google/adk/sessions/in_memory_session_service.py +206 -0
- google/adk/sessions/session.py +54 -0
- google/adk/sessions/state.py +71 -0
- google/adk/sessions/vertex_ai_session_service.py +356 -0
- google/adk/telemetry.py +189 -0
- google/adk/tests/__init__.py +14 -0
- google/adk/tests/integration/.env.example +10 -0
- google/adk/tests/integration/__init__.py +18 -0
- google/adk/tests/integration/conftest.py +119 -0
- google/adk/tests/integration/fixture/__init__.py +14 -0
- google/adk/tests/integration/fixture/agent_with_config/__init__.py +15 -0
- google/adk/tests/integration/fixture/agent_with_config/agent.py +88 -0
- google/adk/tests/integration/fixture/callback_agent/__init__.py +15 -0
- google/adk/tests/integration/fixture/callback_agent/agent.py +105 -0
- google/adk/tests/integration/fixture/context_update_test/OWNERS +1 -0
- google/adk/tests/integration/fixture/context_update_test/__init__.py +15 -0
- google/adk/tests/integration/fixture/context_update_test/agent.py +43 -0
- google/adk/tests/integration/fixture/context_update_test/successful_test.session.json +582 -0
- google/adk/tests/integration/fixture/context_variable_agent/__init__.py +15 -0
- google/adk/tests/integration/fixture/context_variable_agent/agent.py +115 -0
- google/adk/tests/integration/fixture/customer_support_ma/__init__.py +15 -0
- google/adk/tests/integration/fixture/customer_support_ma/agent.py +172 -0
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/__init__.py +15 -0
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/agent.py +338 -0
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/order_query.test.json +69 -0
- google/adk/tests/integration/fixture/ecommerce_customer_service_agent/test_config.json +6 -0
- google/adk/tests/integration/fixture/flow_complex_spark/__init__.py +15 -0
- google/adk/tests/integration/fixture/flow_complex_spark/agent.py +182 -0
- google/adk/tests/integration/fixture/flow_complex_spark/sample.session.json +190 -0
- google/adk/tests/integration/fixture/hello_world_agent/__init__.py +15 -0
- google/adk/tests/integration/fixture/hello_world_agent/agent.py +95 -0
- google/adk/tests/integration/fixture/hello_world_agent/roll_die.test.json +24 -0
- google/adk/tests/integration/fixture/hello_world_agent/test_config.json +6 -0
- google/adk/tests/integration/fixture/home_automation_agent/__init__.py +15 -0
- google/adk/tests/integration/fixture/home_automation_agent/agent.py +304 -0
- google/adk/tests/integration/fixture/home_automation_agent/simple_test.test.json +5 -0
- google/adk/tests/integration/fixture/home_automation_agent/simple_test2.test.json +5 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_config.json +5 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_files/dependent_tool_calls.test.json +18 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/eval_data.test.json +17 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/test_config.json +6 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_multi_turn_conversation.test.json +18 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test.test.json +17 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test2.test.json +5 -0
- google/adk/tests/integration/fixture/home_automation_agent/test_files/test_config.json +5 -0
- google/adk/tests/integration/fixture/tool_agent/__init__.py +15 -0
- google/adk/tests/integration/fixture/tool_agent/agent.py +218 -0
- google/adk/tests/integration/fixture/tool_agent/files/Agent_test_plan.pdf +0 -0
- google/adk/tests/integration/fixture/trip_planner_agent/__init__.py +15 -0
- google/adk/tests/integration/fixture/trip_planner_agent/agent.py +110 -0
- google/adk/tests/integration/fixture/trip_planner_agent/initial.session.json +13 -0
- google/adk/tests/integration/fixture/trip_planner_agent/test_config.json +5 -0
- google/adk/tests/integration/fixture/trip_planner_agent/test_files/initial.session.json +13 -0
- google/adk/tests/integration/fixture/trip_planner_agent/test_files/test_config.json +5 -0
- google/adk/tests/integration/fixture/trip_planner_agent/test_files/trip_inquiry_sub_agent.test.json +7 -0
- google/adk/tests/integration/fixture/trip_planner_agent/trip_inquiry.test.json +19 -0
- google/adk/tests/integration/models/__init__.py +14 -0
- google/adk/tests/integration/models/test_google_llm.py +65 -0
- google/adk/tests/integration/test_callback.py +70 -0
- google/adk/tests/integration/test_context_variable.py +67 -0
- google/adk/tests/integration/test_evalute_agent_in_fixture.py +76 -0
- google/adk/tests/integration/test_multi_agent.py +28 -0
- google/adk/tests/integration/test_multi_turn.py +42 -0
- google/adk/tests/integration/test_single_agent.py +23 -0
- google/adk/tests/integration/test_sub_agent.py +26 -0
- google/adk/tests/integration/test_system_instruction.py +177 -0
- google/adk/tests/integration/test_tools.py +287 -0
- google/adk/tests/integration/test_with_test_file.py +34 -0
- google/adk/tests/integration/tools/__init__.py +14 -0
- google/adk/tests/integration/utils/__init__.py +16 -0
- google/adk/tests/integration/utils/asserts.py +75 -0
- google/adk/tests/integration/utils/test_runner.py +97 -0
- google/adk/tests/unittests/__init__.py +14 -0
- google/adk/tests/unittests/agents/__init__.py +14 -0
- google/adk/tests/unittests/agents/test_base_agent.py +407 -0
- google/adk/tests/unittests/agents/test_langgraph_agent.py +191 -0
- google/adk/tests/unittests/agents/test_llm_agent_callbacks.py +138 -0
- google/adk/tests/unittests/agents/test_llm_agent_fields.py +231 -0
- google/adk/tests/unittests/agents/test_loop_agent.py +136 -0
- google/adk/tests/unittests/agents/test_parallel_agent.py +92 -0
- google/adk/tests/unittests/agents/test_sequential_agent.py +114 -0
- google/adk/tests/unittests/artifacts/__init__.py +14 -0
- google/adk/tests/unittests/artifacts/test_artifact_service.py +276 -0
- google/adk/tests/unittests/auth/test_auth_handler.py +575 -0
- google/adk/tests/unittests/conftest.py +73 -0
- google/adk/tests/unittests/fast_api/__init__.py +14 -0
- google/adk/tests/unittests/fast_api/test_fast_api.py +269 -0
- google/adk/tests/unittests/flows/__init__.py +14 -0
- google/adk/tests/unittests/flows/llm_flows/__init__.py +14 -0
- google/adk/tests/unittests/flows/llm_flows/_test_examples.py +142 -0
- google/adk/tests/unittests/flows/llm_flows/test_agent_transfer.py +311 -0
- google/adk/tests/unittests/flows/llm_flows/test_functions_long_running.py +244 -0
- google/adk/tests/unittests/flows/llm_flows/test_functions_request_euc.py +346 -0
- google/adk/tests/unittests/flows/llm_flows/test_functions_sequential.py +93 -0
- google/adk/tests/unittests/flows/llm_flows/test_functions_simple.py +258 -0
- google/adk/tests/unittests/flows/llm_flows/test_identity.py +66 -0
- google/adk/tests/unittests/flows/llm_flows/test_instructions.py +164 -0
- google/adk/tests/unittests/flows/llm_flows/test_model_callbacks.py +142 -0
- google/adk/tests/unittests/flows/llm_flows/test_other_configs.py +46 -0
- google/adk/tests/unittests/flows/llm_flows/test_tool_callbacks.py +269 -0
- google/adk/tests/unittests/models/__init__.py +14 -0
- google/adk/tests/unittests/models/test_google_llm.py +224 -0
- google/adk/tests/unittests/models/test_litellm.py +804 -0
- google/adk/tests/unittests/models/test_models.py +60 -0
- google/adk/tests/unittests/sessions/__init__.py +14 -0
- google/adk/tests/unittests/sessions/test_session_service.py +227 -0
- google/adk/tests/unittests/sessions/test_vertex_ai_session_service.py +246 -0
- google/adk/tests/unittests/streaming/__init__.py +14 -0
- google/adk/tests/unittests/streaming/test_streaming.py +50 -0
- google/adk/tests/unittests/tools/__init__.py +14 -0
- google/adk/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py +499 -0
- google/adk/tests/unittests/tools/apihub_tool/test_apihub_toolset.py +204 -0
- google/adk/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py +600 -0
- google/adk/tests/unittests/tools/application_integration_tool/clients/test_integration_client.py +630 -0
- google/adk/tests/unittests/tools/application_integration_tool/test_application_integration_toolset.py +345 -0
- google/adk/tests/unittests/tools/google_api_tool/__init__.py +13 -0
- google/adk/tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py +657 -0
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_auto_auth_credential_exchanger.py +145 -0
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_base_auth_credential_exchanger.py +68 -0
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_oauth2_exchanger.py +153 -0
- google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_service_account_exchanger.py +196 -0
- google/adk/tests/unittests/tools/openapi_tool/auth/test_auth_helper.py +573 -0
- google/adk/tests/unittests/tools/openapi_tool/common/test_common.py +436 -0
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test.yaml +1367 -0
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py +628 -0
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_toolset.py +139 -0
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py +406 -0
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py +966 -0
- google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_tool_auth_handler.py +201 -0
- google/adk/tests/unittests/tools/retrieval/__init__.py +14 -0
- google/adk/tests/unittests/tools/retrieval/test_vertex_ai_rag_retrieval.py +147 -0
- google/adk/tests/unittests/tools/test_agent_tool.py +167 -0
- google/adk/tests/unittests/tools/test_base_tool.py +141 -0
- google/adk/tests/unittests/tools/test_build_function_declaration.py +277 -0
- google/adk/tests/unittests/utils.py +304 -0
- google/adk/tools/__init__.py +51 -0
- google/adk/tools/_automatic_function_calling_util.py +346 -0
- google/adk/tools/agent_tool.py +176 -0
- google/adk/tools/apihub_tool/__init__.py +19 -0
- google/adk/tools/apihub_tool/apihub_toolset.py +209 -0
- google/adk/tools/apihub_tool/clients/__init__.py +13 -0
- google/adk/tools/apihub_tool/clients/apihub_client.py +332 -0
- google/adk/tools/apihub_tool/clients/secret_client.py +115 -0
- google/adk/tools/application_integration_tool/__init__.py +19 -0
- google/adk/tools/application_integration_tool/application_integration_toolset.py +230 -0
- google/adk/tools/application_integration_tool/clients/connections_client.py +903 -0
- google/adk/tools/application_integration_tool/clients/integration_client.py +253 -0
- google/adk/tools/base_tool.py +144 -0
- google/adk/tools/built_in_code_execution_tool.py +59 -0
- google/adk/tools/crewai_tool.py +72 -0
- google/adk/tools/example_tool.py +62 -0
- google/adk/tools/exit_loop_tool.py +23 -0
- google/adk/tools/function_parameter_parse_util.py +307 -0
- google/adk/tools/function_tool.py +87 -0
- google/adk/tools/get_user_choice_tool.py +28 -0
- google/adk/tools/google_api_tool/__init__.py +14 -0
- google/adk/tools/google_api_tool/google_api_tool.py +59 -0
- google/adk/tools/google_api_tool/google_api_tool_set.py +107 -0
- google/adk/tools/google_api_tool/google_api_tool_sets.py +55 -0
- google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py +521 -0
- google/adk/tools/google_search_tool.py +68 -0
- google/adk/tools/langchain_tool.py +86 -0
- google/adk/tools/load_artifacts_tool.py +113 -0
- google/adk/tools/load_memory_tool.py +58 -0
- google/adk/tools/load_web_page.py +41 -0
- google/adk/tools/long_running_tool.py +39 -0
- google/adk/tools/mcp_tool/__init__.py +42 -0
- google/adk/tools/mcp_tool/conversion_utils.py +161 -0
- google/adk/tools/mcp_tool/mcp_tool.py +113 -0
- google/adk/tools/mcp_tool/mcp_toolset.py +272 -0
- google/adk/tools/openapi_tool/__init__.py +21 -0
- google/adk/tools/openapi_tool/auth/__init__.py +19 -0
- google/adk/tools/openapi_tool/auth/auth_helpers.py +498 -0
- google/adk/tools/openapi_tool/auth/credential_exchangers/__init__.py +25 -0
- google/adk/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.py +105 -0
- google/adk/tools/openapi_tool/auth/credential_exchangers/base_credential_exchanger.py +55 -0
- google/adk/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.py +117 -0
- google/adk/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.py +97 -0
- google/adk/tools/openapi_tool/common/__init__.py +19 -0
- google/adk/tools/openapi_tool/common/common.py +300 -0
- google/adk/tools/openapi_tool/openapi_spec_parser/__init__.py +32 -0
- google/adk/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.py +231 -0
- google/adk/tools/openapi_tool/openapi_spec_parser/openapi_toolset.py +144 -0
- google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py +260 -0
- google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py +496 -0
- google/adk/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.py +268 -0
- google/adk/tools/preload_memory_tool.py +72 -0
- google/adk/tools/retrieval/__init__.py +36 -0
- google/adk/tools/retrieval/base_retrieval_tool.py +37 -0
- google/adk/tools/retrieval/files_retrieval.py +33 -0
- google/adk/tools/retrieval/llama_index_retrieval.py +41 -0
- google/adk/tools/retrieval/vertex_ai_rag_retrieval.py +107 -0
- google/adk/tools/tool_context.py +90 -0
- google/adk/tools/toolbox_tool.py +46 -0
- google/adk/tools/transfer_to_agent_tool.py +21 -0
- google/adk/tools/vertex_ai_search_tool.py +96 -0
- google/adk/version.py +16 -0
- google_adk-0.0.3.dist-info/METADATA +73 -0
- google_adk-0.0.3.dist-info/RECORD +340 -0
- {google_adk-0.0.1.dist-info → google_adk-0.0.3.dist-info}/WHEEL +1 -2
- google_adk-0.0.3.dist-info/entry_points.txt +3 -0
- agent_kit/__init__.py +0 -0
- google_adk-0.0.1.dist-info/LICENSE.txt +0 -170
- google_adk-0.0.1.dist-info/METADATA +0 -15
- google_adk-0.0.1.dist-info/RECORD +0 -6
- google_adk-0.0.1.dist-info/top_level.txt +0 -1
@@ -0,0 +1,376 @@
|
|
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 logging
|
18
|
+
from typing import Any
|
19
|
+
from typing import AsyncGenerator
|
20
|
+
from typing import Callable
|
21
|
+
from typing import Literal
|
22
|
+
from typing import Optional
|
23
|
+
from typing import Union
|
24
|
+
|
25
|
+
from google.genai import types
|
26
|
+
from pydantic import BaseModel
|
27
|
+
from pydantic import Field
|
28
|
+
from pydantic import field_validator
|
29
|
+
from pydantic import model_validator
|
30
|
+
from typing_extensions import override
|
31
|
+
from typing_extensions import TypeAlias
|
32
|
+
|
33
|
+
from ..code_executors.base_code_executor import BaseCodeExecutor
|
34
|
+
from ..events.event import Event
|
35
|
+
from ..examples.base_example_provider import BaseExampleProvider
|
36
|
+
from ..examples.example import Example
|
37
|
+
from ..flows.llm_flows.auto_flow import AutoFlow
|
38
|
+
from ..flows.llm_flows.base_llm_flow import BaseLlmFlow
|
39
|
+
from ..flows.llm_flows.single_flow import SingleFlow
|
40
|
+
from ..models.base_llm import BaseLlm
|
41
|
+
from ..models.llm_request import LlmRequest
|
42
|
+
from ..models.llm_response import LlmResponse
|
43
|
+
from ..models.registry import LLMRegistry
|
44
|
+
from ..planners.base_planner import BasePlanner
|
45
|
+
from ..tools.base_tool import BaseTool
|
46
|
+
from ..tools.function_tool import FunctionTool
|
47
|
+
from ..tools.tool_context import ToolContext
|
48
|
+
from .base_agent import BaseAgent
|
49
|
+
from .callback_context import CallbackContext
|
50
|
+
from .invocation_context import InvocationContext
|
51
|
+
from .readonly_context import ReadonlyContext
|
52
|
+
|
53
|
+
logger = logging.getLogger(__name__)
|
54
|
+
|
55
|
+
|
56
|
+
BeforeModelCallback: TypeAlias = Callable[
|
57
|
+
[CallbackContext, LlmRequest], Optional[LlmResponse]
|
58
|
+
]
|
59
|
+
AfterModelCallback: TypeAlias = Callable[
|
60
|
+
[CallbackContext, LlmResponse],
|
61
|
+
Optional[LlmResponse],
|
62
|
+
]
|
63
|
+
BeforeToolCallback: TypeAlias = Callable[
|
64
|
+
[BaseTool, dict[str, Any], ToolContext],
|
65
|
+
Optional[dict],
|
66
|
+
]
|
67
|
+
AfterToolCallback: TypeAlias = Callable[
|
68
|
+
[BaseTool, dict[str, Any], ToolContext, dict],
|
69
|
+
Optional[dict],
|
70
|
+
]
|
71
|
+
|
72
|
+
InstructionProvider: TypeAlias = Callable[[ReadonlyContext], str]
|
73
|
+
|
74
|
+
ToolUnion: TypeAlias = Union[Callable, BaseTool]
|
75
|
+
ExamplesUnion = Union[list[Example], BaseExampleProvider]
|
76
|
+
|
77
|
+
|
78
|
+
def _convert_tool_union_to_tool(
|
79
|
+
tool_union: ToolUnion,
|
80
|
+
) -> BaseTool:
|
81
|
+
return (
|
82
|
+
tool_union
|
83
|
+
if isinstance(tool_union, BaseTool)
|
84
|
+
else FunctionTool(tool_union)
|
85
|
+
)
|
86
|
+
|
87
|
+
|
88
|
+
class LlmAgent(BaseAgent):
|
89
|
+
"""LLM-based Agent."""
|
90
|
+
|
91
|
+
model: Union[str, BaseLlm] = ''
|
92
|
+
"""The model to use for the agent.
|
93
|
+
|
94
|
+
When not set, the agent will inherit the model from its ancestor.
|
95
|
+
"""
|
96
|
+
|
97
|
+
instruction: Union[str, InstructionProvider] = ''
|
98
|
+
"""Instructions for the LLM model, guiding the agent's behavior."""
|
99
|
+
|
100
|
+
global_instruction: Union[str, InstructionProvider] = ''
|
101
|
+
"""Instructions for all the agents in the entire agent tree.
|
102
|
+
|
103
|
+
global_instruction ONLY takes effect in root agent.
|
104
|
+
|
105
|
+
For example: use global_instruction to make all agents have a stable identity
|
106
|
+
or personality.
|
107
|
+
"""
|
108
|
+
|
109
|
+
tools: list[ToolUnion] = Field(default_factory=list)
|
110
|
+
"""Tools available to this agent."""
|
111
|
+
|
112
|
+
generate_content_config: Optional[types.GenerateContentConfig] = None
|
113
|
+
"""The additional content generation configurations.
|
114
|
+
|
115
|
+
NOTE: not all fields are usable, e.g. tools must be configured via `tools`,
|
116
|
+
thinking_config must be configured via `planner` in LlmAgent.
|
117
|
+
|
118
|
+
For example: use this config to adjust model temperature, configure safety
|
119
|
+
settings, etc.
|
120
|
+
"""
|
121
|
+
|
122
|
+
# LLM-based agent transfer configs - Start
|
123
|
+
disallow_transfer_to_parent: bool = False
|
124
|
+
"""Disallows LLM-controlled transferring to the parent agent."""
|
125
|
+
disallow_transfer_to_peers: bool = False
|
126
|
+
"""Disallows LLM-controlled transferring to the peer agents."""
|
127
|
+
# LLM-based agent transfer configs - End
|
128
|
+
|
129
|
+
include_contents: Literal['default', 'none'] = 'default'
|
130
|
+
"""Whether to include contents in the model request.
|
131
|
+
|
132
|
+
When set to 'none', the model request will not include any contents, such as
|
133
|
+
user messages, tool results, etc.
|
134
|
+
"""
|
135
|
+
|
136
|
+
# Controlled input/output configurations - Start
|
137
|
+
input_schema: Optional[type[BaseModel]] = None
|
138
|
+
"""The input schema when agent is used as a tool."""
|
139
|
+
output_schema: Optional[type[BaseModel]] = None
|
140
|
+
"""The output schema when agent replies.
|
141
|
+
|
142
|
+
NOTE: when this is set, agent can ONLY reply and CANNOT use any tools, such as
|
143
|
+
function tools, RAGs, agent transfer, etc.
|
144
|
+
"""
|
145
|
+
output_key: Optional[str] = None
|
146
|
+
"""The key in session state to store the output of the agent.
|
147
|
+
|
148
|
+
Typically use cases:
|
149
|
+
- Extracts agent reply for later use, such as in tools, callbacks, etc.
|
150
|
+
- Connects agents to coordinate with each other.
|
151
|
+
"""
|
152
|
+
# Controlled input/output configurations - End
|
153
|
+
|
154
|
+
# Advance features - Start
|
155
|
+
planner: Optional[BasePlanner] = None
|
156
|
+
"""Instructs the agent to make a plan and execute it step by step.
|
157
|
+
|
158
|
+
NOTE: to use model's built-in thinking features, set the `thinking_config`
|
159
|
+
field in `google.adk.planners.built_in_planner`.
|
160
|
+
|
161
|
+
"""
|
162
|
+
|
163
|
+
code_executor: Optional[BaseCodeExecutor] = None
|
164
|
+
"""Allow agent to execute code blocks from model responses using the provided
|
165
|
+
CodeExecutor.
|
166
|
+
|
167
|
+
Check out available code executions in `google.adk.code_executor` package.
|
168
|
+
|
169
|
+
NOTE: to use model's built-in code executor, don't set this field, add
|
170
|
+
`google.adk.tools.built_in_code_execution` to tools instead.
|
171
|
+
"""
|
172
|
+
# Advance features - End
|
173
|
+
|
174
|
+
# TODO: remove below fields after migration. - Start
|
175
|
+
# These fields are added back for easier migration.
|
176
|
+
examples: Optional[ExamplesUnion] = None
|
177
|
+
# TODO: remove above fields after migration. - End
|
178
|
+
|
179
|
+
# Callbacks - Start
|
180
|
+
before_model_callback: Optional[BeforeModelCallback] = None
|
181
|
+
"""Called before calling the LLM.
|
182
|
+
Args:
|
183
|
+
callback_context: CallbackContext,
|
184
|
+
llm_request: LlmRequest, The raw model request. Callback can mutate the
|
185
|
+
request.
|
186
|
+
|
187
|
+
Returns:
|
188
|
+
The content to return to the user. When present, the model call will be
|
189
|
+
skipped and the provided content will be returned to user.
|
190
|
+
"""
|
191
|
+
after_model_callback: Optional[AfterModelCallback] = None
|
192
|
+
"""Called after calling LLM.
|
193
|
+
|
194
|
+
Args:
|
195
|
+
callback_context: CallbackContext,
|
196
|
+
llm_response: LlmResponse, the actual model response.
|
197
|
+
|
198
|
+
Returns:
|
199
|
+
The content to return to the user. When present, the actual model response
|
200
|
+
will be ignored and the provided content will be returned to user.
|
201
|
+
"""
|
202
|
+
before_tool_callback: Optional[BeforeToolCallback] = None
|
203
|
+
"""Called before the tool is called.
|
204
|
+
|
205
|
+
Args:
|
206
|
+
tool: The tool to be called.
|
207
|
+
args: The arguments to the tool.
|
208
|
+
tool_context: ToolContext,
|
209
|
+
|
210
|
+
Returns:
|
211
|
+
The tool response. When present, the returned tool response will be used and
|
212
|
+
the framework will skip calling the actual tool.
|
213
|
+
"""
|
214
|
+
after_tool_callback: Optional[AfterToolCallback] = None
|
215
|
+
"""Called after the tool is called.
|
216
|
+
|
217
|
+
Args:
|
218
|
+
tool: The tool to be called.
|
219
|
+
args: The arguments to the tool.
|
220
|
+
tool_context: ToolContext,
|
221
|
+
tool_response: The response from the tool.
|
222
|
+
|
223
|
+
Returns:
|
224
|
+
When present, the returned dict will be used as tool result.
|
225
|
+
"""
|
226
|
+
# Callbacks - End
|
227
|
+
|
228
|
+
@override
|
229
|
+
async def _run_async_impl(
|
230
|
+
self, ctx: InvocationContext
|
231
|
+
) -> AsyncGenerator[Event, None]:
|
232
|
+
async for event in self._llm_flow.run_async(ctx):
|
233
|
+
self.__maybe_save_output_to_state(event)
|
234
|
+
yield event
|
235
|
+
|
236
|
+
@override
|
237
|
+
async def _run_live_impl(
|
238
|
+
self, ctx: InvocationContext
|
239
|
+
) -> AsyncGenerator[Event, None]:
|
240
|
+
async for event in self._llm_flow.run_live(ctx):
|
241
|
+
self.__maybe_save_output_to_state(event)
|
242
|
+
yield event
|
243
|
+
if ctx.end_invocation:
|
244
|
+
return
|
245
|
+
|
246
|
+
@property
|
247
|
+
def canonical_model(self) -> BaseLlm:
|
248
|
+
"""The resolved self.model field as BaseLlm.
|
249
|
+
|
250
|
+
This method is only for use by Agent Development Kit.
|
251
|
+
"""
|
252
|
+
if isinstance(self.model, BaseLlm):
|
253
|
+
return self.model
|
254
|
+
elif self.model: # model is non-empty str
|
255
|
+
return LLMRegistry.new_llm(self.model)
|
256
|
+
else: # find model from ancestors.
|
257
|
+
ancestor_agent = self.parent_agent
|
258
|
+
while ancestor_agent is not None:
|
259
|
+
if isinstance(ancestor_agent, LlmAgent):
|
260
|
+
return ancestor_agent.canonical_model
|
261
|
+
ancestor_agent = ancestor_agent.parent_agent
|
262
|
+
raise ValueError(f'No model found for {self.name}.')
|
263
|
+
|
264
|
+
def canonical_instruction(self, ctx: ReadonlyContext) -> str:
|
265
|
+
"""The resolved self.instruction field to construct instruction for this agent.
|
266
|
+
|
267
|
+
This method is only for use by Agent Development Kit.
|
268
|
+
"""
|
269
|
+
if isinstance(self.instruction, str):
|
270
|
+
return self.instruction
|
271
|
+
else:
|
272
|
+
return self.instruction(ctx)
|
273
|
+
|
274
|
+
def canonical_global_instruction(self, ctx: ReadonlyContext) -> str:
|
275
|
+
"""The resolved self.instruction field to construct global instruction.
|
276
|
+
|
277
|
+
This method is only for use by Agent Development Kit.
|
278
|
+
"""
|
279
|
+
if isinstance(self.global_instruction, str):
|
280
|
+
return self.global_instruction
|
281
|
+
else:
|
282
|
+
return self.global_instruction(ctx)
|
283
|
+
|
284
|
+
@property
|
285
|
+
def canonical_tools(self) -> list[BaseTool]:
|
286
|
+
"""The resolved self.tools field as a list of BaseTool.
|
287
|
+
|
288
|
+
This method is only for use by Agent Development Kit.
|
289
|
+
"""
|
290
|
+
return [_convert_tool_union_to_tool(tool) for tool in self.tools]
|
291
|
+
|
292
|
+
@property
|
293
|
+
def _llm_flow(self) -> BaseLlmFlow:
|
294
|
+
if (
|
295
|
+
self.disallow_transfer_to_parent
|
296
|
+
and self.disallow_transfer_to_peers
|
297
|
+
and not self.sub_agents
|
298
|
+
):
|
299
|
+
return SingleFlow()
|
300
|
+
else:
|
301
|
+
return AutoFlow()
|
302
|
+
|
303
|
+
def __maybe_save_output_to_state(self, event: Event):
|
304
|
+
"""Saves the model output to state if needed."""
|
305
|
+
if (
|
306
|
+
self.output_key
|
307
|
+
and event.is_final_response()
|
308
|
+
and event.content
|
309
|
+
and event.content.parts
|
310
|
+
):
|
311
|
+
result = ''.join(
|
312
|
+
[part.text if part.text else '' for part in event.content.parts]
|
313
|
+
)
|
314
|
+
if self.output_schema:
|
315
|
+
result = self.output_schema.model_validate_json(result).model_dump(
|
316
|
+
exclude_none=True
|
317
|
+
)
|
318
|
+
event.actions.state_delta[self.output_key] = result
|
319
|
+
|
320
|
+
@model_validator(mode='after')
|
321
|
+
def __model_validator_after(self) -> LlmAgent:
|
322
|
+
self.__check_output_schema()
|
323
|
+
return self
|
324
|
+
|
325
|
+
def __check_output_schema(self):
|
326
|
+
if not self.output_schema:
|
327
|
+
return
|
328
|
+
|
329
|
+
if (
|
330
|
+
not self.disallow_transfer_to_parent
|
331
|
+
or not self.disallow_transfer_to_peers
|
332
|
+
):
|
333
|
+
logger.warning(
|
334
|
+
'Invalid config for agent %s: output_schema cannot co-exist with'
|
335
|
+
' agent transfer configurations. Setting'
|
336
|
+
' disallow_transfer_to_parent=True, disallow_transfer_to_peers=True',
|
337
|
+
self.name,
|
338
|
+
)
|
339
|
+
self.disallow_transfer_to_parent = True
|
340
|
+
self.disallow_transfer_to_peers = True
|
341
|
+
|
342
|
+
if self.sub_agents:
|
343
|
+
raise ValueError(
|
344
|
+
f'Invalid config for agent {self.name}: if output_schema is set,'
|
345
|
+
' sub_agents must be empty to disable agent transfer.'
|
346
|
+
)
|
347
|
+
|
348
|
+
if self.tools:
|
349
|
+
raise ValueError(
|
350
|
+
f'Invalid config for agent {self.name}: if output_schema is set,'
|
351
|
+
' tools must be empty'
|
352
|
+
)
|
353
|
+
|
354
|
+
@field_validator('generate_content_config', mode='after')
|
355
|
+
@classmethod
|
356
|
+
def __validate_generate_content_config(
|
357
|
+
cls, generate_content_config: Optional[types.GenerateContentConfig]
|
358
|
+
) -> types.GenerateContentConfig:
|
359
|
+
if not generate_content_config:
|
360
|
+
return types.GenerateContentConfig()
|
361
|
+
if generate_content_config.thinking_config:
|
362
|
+
raise ValueError('Thinking config should be set via LlmAgent.planner.')
|
363
|
+
if generate_content_config.tools:
|
364
|
+
raise ValueError('All tools must be set via LlmAgent.tools.')
|
365
|
+
if generate_content_config.system_instruction:
|
366
|
+
raise ValueError(
|
367
|
+
'System instruction must be set via LlmAgent.instruction.'
|
368
|
+
)
|
369
|
+
if generate_content_config.response_schema:
|
370
|
+
raise ValueError(
|
371
|
+
'Response schema must be set via LlmAgent.output_schema.'
|
372
|
+
)
|
373
|
+
return generate_content_config
|
374
|
+
|
375
|
+
|
376
|
+
Agent: TypeAlias = LlmAgent
|
@@ -0,0 +1,62 @@
|
|
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('The behavior for run_live is not defined yet.')
|
62
|
+
yield # AsyncGenerator requires having at least one yield statement
|
@@ -0,0 +1,96 @@
|
|
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
|
+
"""Parallel agent implementation."""
|
16
|
+
|
17
|
+
from __future__ import annotations
|
18
|
+
|
19
|
+
import asyncio
|
20
|
+
from typing import AsyncGenerator
|
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
|
+
def _set_branch_for_current_agent(
|
30
|
+
current_agent: BaseAgent, invocation_context: InvocationContext
|
31
|
+
):
|
32
|
+
invocation_context.branch = (
|
33
|
+
f"{invocation_context.branch}.{current_agent.name}"
|
34
|
+
if invocation_context.branch
|
35
|
+
else current_agent.name
|
36
|
+
)
|
37
|
+
|
38
|
+
|
39
|
+
async def _merge_agent_run(
|
40
|
+
agent_runs: list[AsyncGenerator[Event, None]],
|
41
|
+
) -> AsyncGenerator[Event, None]:
|
42
|
+
"""Merges the agent run event generator.
|
43
|
+
|
44
|
+
This implementation guarantees for each agent, it won't move on until the
|
45
|
+
generated event is processed by upstream runner.
|
46
|
+
|
47
|
+
Args:
|
48
|
+
agent_runs: A list of async generators that yield events from each agent.
|
49
|
+
|
50
|
+
Yields:
|
51
|
+
Event: The next event from the merged generator.
|
52
|
+
"""
|
53
|
+
tasks = [
|
54
|
+
asyncio.create_task(events_for_one_agent.__anext__())
|
55
|
+
for events_for_one_agent in agent_runs
|
56
|
+
]
|
57
|
+
pending_tasks = set(tasks)
|
58
|
+
|
59
|
+
while pending_tasks:
|
60
|
+
done, pending_tasks = await asyncio.wait(
|
61
|
+
pending_tasks, return_when=asyncio.FIRST_COMPLETED
|
62
|
+
)
|
63
|
+
for task in done:
|
64
|
+
try:
|
65
|
+
yield task.result()
|
66
|
+
|
67
|
+
# Find the generator that produced this event and move it on.
|
68
|
+
for i, original_task in enumerate(tasks):
|
69
|
+
if task == original_task:
|
70
|
+
new_task = asyncio.create_task(agent_runs[i].__anext__())
|
71
|
+
tasks[i] = new_task
|
72
|
+
pending_tasks.add(new_task)
|
73
|
+
break # stop iterating once found
|
74
|
+
|
75
|
+
except StopAsyncIteration:
|
76
|
+
continue
|
77
|
+
|
78
|
+
|
79
|
+
class ParallelAgent(BaseAgent):
|
80
|
+
"""A shell agent that run its sub-agents in parallel in isolated manner.
|
81
|
+
|
82
|
+
This approach is beneficial for scenarios requiring multiple perspectives or
|
83
|
+
attempts on a single task, such as:
|
84
|
+
|
85
|
+
- Running different algorithms simultaneously.
|
86
|
+
- Generating multiple responses for review by a subsequent evaluation agent.
|
87
|
+
"""
|
88
|
+
|
89
|
+
@override
|
90
|
+
async def _run_async_impl(
|
91
|
+
self, ctx: InvocationContext
|
92
|
+
) -> AsyncGenerator[Event, None]:
|
93
|
+
_set_branch_for_current_agent(self, ctx)
|
94
|
+
agent_runs = [agent.run_async(ctx) for agent in self.sub_agents]
|
95
|
+
async for event in _merge_agent_run(agent_runs):
|
96
|
+
yield event
|
@@ -0,0 +1,46 @@
|
|
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 TYPE_CHECKING
|
20
|
+
|
21
|
+
if TYPE_CHECKING:
|
22
|
+
from .invocation_context import InvocationContext
|
23
|
+
|
24
|
+
|
25
|
+
class ReadonlyContext:
|
26
|
+
|
27
|
+
def __init__(
|
28
|
+
self,
|
29
|
+
invocation_context: InvocationContext,
|
30
|
+
) -> None:
|
31
|
+
self._invocation_context = invocation_context
|
32
|
+
|
33
|
+
@property
|
34
|
+
def invocation_id(self) -> str:
|
35
|
+
"""The current invocation id."""
|
36
|
+
return self._invocation_context.invocation_id
|
37
|
+
|
38
|
+
@property
|
39
|
+
def agent_name(self) -> str:
|
40
|
+
"""The name of the agent that is currently running."""
|
41
|
+
return self._invocation_context.agent.name
|
42
|
+
|
43
|
+
@property
|
44
|
+
def state(self) -> MappingProxyType[str, Any]:
|
45
|
+
"""The state of the current session. READONLY field."""
|
46
|
+
return MappingProxyType(self._invocation_context.session.state)
|
@@ -0,0 +1,50 @@
|
|
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
|
+
from typing import AsyncGenerator
|
17
|
+
|
18
|
+
from pydantic import Field
|
19
|
+
import requests
|
20
|
+
from typing_extensions import override
|
21
|
+
|
22
|
+
from ..events.event import Event
|
23
|
+
from .base_agent import BaseAgent
|
24
|
+
from .invocation_context import InvocationContext
|
25
|
+
|
26
|
+
|
27
|
+
class RemoteAgent(BaseAgent):
|
28
|
+
"""Experimental, do not use."""
|
29
|
+
|
30
|
+
url: str
|
31
|
+
|
32
|
+
sub_agents: list[BaseAgent] = Field(
|
33
|
+
default_factory=list, init=False, frozen=True
|
34
|
+
)
|
35
|
+
"""Sub-agent is dsiabled in RemoteAgent."""
|
36
|
+
|
37
|
+
@override
|
38
|
+
async def _run_async_impl(
|
39
|
+
self, ctx: InvocationContext
|
40
|
+
) -> AsyncGenerator[Event, None]:
|
41
|
+
data = {
|
42
|
+
'invocation_id': ctx.invocation_id,
|
43
|
+
'session': ctx.session.model_dump(exclude_none=True),
|
44
|
+
}
|
45
|
+
events = requests.post(self.url, data=json.dumps(data), timeout=120)
|
46
|
+
events.raise_for_status()
|
47
|
+
for event in events.json():
|
48
|
+
e = Event.model_validate(event)
|
49
|
+
e.author = self.name
|
50
|
+
yield e
|