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,87 @@
|
|
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 enum import Enum
|
16
|
+
import logging
|
17
|
+
import sys
|
18
|
+
from typing import Optional
|
19
|
+
|
20
|
+
from google.genai import types
|
21
|
+
from pydantic import BaseModel
|
22
|
+
from pydantic import ConfigDict
|
23
|
+
from pydantic import field_validator
|
24
|
+
|
25
|
+
logger = logging.getLogger(__name__)
|
26
|
+
|
27
|
+
|
28
|
+
class StreamingMode(Enum):
|
29
|
+
NONE = None
|
30
|
+
SSE = 'sse'
|
31
|
+
BIDI = 'bidi'
|
32
|
+
|
33
|
+
|
34
|
+
class RunConfig(BaseModel):
|
35
|
+
"""Configs for runtime behavior of agents."""
|
36
|
+
|
37
|
+
model_config = ConfigDict(
|
38
|
+
extra='forbid',
|
39
|
+
)
|
40
|
+
|
41
|
+
speech_config: Optional[types.SpeechConfig] = None
|
42
|
+
"""Speech configuration for the live agent."""
|
43
|
+
|
44
|
+
response_modalities: Optional[list[str]] = None
|
45
|
+
"""The output modalities. If not set, its default to AUDIO."""
|
46
|
+
|
47
|
+
save_input_blobs_as_artifacts: bool = False
|
48
|
+
"""Whether or not to save the input blobs as artifacts."""
|
49
|
+
|
50
|
+
support_cfc: bool = False
|
51
|
+
"""
|
52
|
+
Whether to support CFC (Compositional Function Calling). Only applicable for
|
53
|
+
StreamingMode.SSE. If it's true. the LIVE API will be invoked. Since only LIVE
|
54
|
+
API supports CFC
|
55
|
+
"""
|
56
|
+
|
57
|
+
streaming_mode: StreamingMode = StreamingMode.NONE
|
58
|
+
"""Streaming mode, None or StreamingMode.SSE or StreamingMode.BIDI."""
|
59
|
+
|
60
|
+
output_audio_transcription: Optional[types.AudioTranscriptionConfig] = None
|
61
|
+
"""Output transcription for live agents with audio response."""
|
62
|
+
|
63
|
+
max_llm_calls: int = 500
|
64
|
+
"""
|
65
|
+
A limit on the total number of llm calls for a given run.
|
66
|
+
|
67
|
+
Valid Values:
|
68
|
+
- More than 0 and less than sys.maxsize: The bound on the number of llm
|
69
|
+
calls is enforced, if the value is set in this range.
|
70
|
+
- Less than or equal to 0: This allows for unbounded number of llm calls.
|
71
|
+
"""
|
72
|
+
|
73
|
+
@field_validator('max_llm_calls', mode='after')
|
74
|
+
@classmethod
|
75
|
+
def validate_max_llm_calls(cls, value: int) -> int:
|
76
|
+
if value == sys.maxsize:
|
77
|
+
raise ValueError(f'max_llm_calls should be less than {sys.maxsize}.')
|
78
|
+
elif value <= 0:
|
79
|
+
logger.warning(
|
80
|
+
'max_llm_calls is less than or equal to 0. This will result in'
|
81
|
+
' no enforcement on total number of llm calls that will be made for a'
|
82
|
+
' run. This may not be ideal, as this could result in a never'
|
83
|
+
' ending communication between the model and the agent in certain'
|
84
|
+
' cases.',
|
85
|
+
)
|
86
|
+
|
87
|
+
return value
|
@@ -0,0 +1,45 @@
|
|
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
|
+
"""Sequential agent implementation."""
|
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 .base_agent import BaseAgent
|
26
|
+
|
27
|
+
|
28
|
+
class SequentialAgent(BaseAgent):
|
29
|
+
"""A shell agent that run its sub-agents in sequence."""
|
30
|
+
|
31
|
+
@override
|
32
|
+
async def _run_async_impl(
|
33
|
+
self, ctx: InvocationContext
|
34
|
+
) -> AsyncGenerator[Event, None]:
|
35
|
+
for sub_agent in self.sub_agents:
|
36
|
+
async for event in sub_agent.run_async(ctx):
|
37
|
+
yield event
|
38
|
+
|
39
|
+
@override
|
40
|
+
async def _run_live_impl(
|
41
|
+
self, ctx: InvocationContext
|
42
|
+
) -> AsyncGenerator[Event, None]:
|
43
|
+
for sub_agent in self.sub_agents:
|
44
|
+
async for event in sub_agent.run_live(ctx):
|
45
|
+
yield event
|
@@ -0,0 +1,34 @@
|
|
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 Union
|
16
|
+
|
17
|
+
from google.genai import types
|
18
|
+
from pydantic import BaseModel
|
19
|
+
from pydantic import ConfigDict
|
20
|
+
|
21
|
+
|
22
|
+
class TranscriptionEntry(BaseModel):
|
23
|
+
"""Store the data that can be used for transcription."""
|
24
|
+
|
25
|
+
model_config = ConfigDict(
|
26
|
+
arbitrary_types_allowed=True,
|
27
|
+
extra='forbid',
|
28
|
+
)
|
29
|
+
|
30
|
+
role: str
|
31
|
+
"""The role that created this data, typically "user" or "model"""
|
32
|
+
|
33
|
+
data: Union[types.Blob, types.Content]
|
34
|
+
"""The data that can be used for transcription"""
|
@@ -0,0 +1,23 @@
|
|
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
|
+
]
|
@@ -0,0 +1,128 @@
|
|
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
|
+
"""Abstract base class for artifact services."""
|
16
|
+
|
17
|
+
from abc import ABC
|
18
|
+
from abc import abstractmethod
|
19
|
+
from typing import Optional
|
20
|
+
|
21
|
+
from google.genai import types
|
22
|
+
|
23
|
+
|
24
|
+
class BaseArtifactService(ABC):
|
25
|
+
"""Abstract base class for artifact services."""
|
26
|
+
|
27
|
+
@abstractmethod
|
28
|
+
def save_artifact(
|
29
|
+
self,
|
30
|
+
*,
|
31
|
+
app_name: str,
|
32
|
+
user_id: str,
|
33
|
+
session_id: str,
|
34
|
+
filename: str,
|
35
|
+
artifact: types.Part,
|
36
|
+
) -> int:
|
37
|
+
"""Saves an artifact to the artifact service storage.
|
38
|
+
|
39
|
+
The artifact is a file identified by the app name, user ID, session ID, and
|
40
|
+
filename. After saving the artifact, a revision ID is returned to identify
|
41
|
+
the artifact version.
|
42
|
+
|
43
|
+
Args:
|
44
|
+
app_name: The app name.
|
45
|
+
user_id: The user ID.
|
46
|
+
session_id: The session ID.
|
47
|
+
filename: The filename of the artifact.
|
48
|
+
artifact: The artifact to save.
|
49
|
+
|
50
|
+
Returns:
|
51
|
+
The revision ID. The first version of the artifact has a revision ID of 0.
|
52
|
+
This is incremented by 1 after each successful save.
|
53
|
+
"""
|
54
|
+
|
55
|
+
@abstractmethod
|
56
|
+
def load_artifact(
|
57
|
+
self,
|
58
|
+
*,
|
59
|
+
app_name: str,
|
60
|
+
user_id: str,
|
61
|
+
session_id: str,
|
62
|
+
filename: str,
|
63
|
+
version: Optional[int] = None,
|
64
|
+
) -> Optional[types.Part]:
|
65
|
+
"""Gets an artifact from the artifact service storage.
|
66
|
+
|
67
|
+
The artifact is a file identified by the app name, user ID, session ID, and
|
68
|
+
filename.
|
69
|
+
|
70
|
+
Args:
|
71
|
+
app_name: The app name.
|
72
|
+
user_id: The user ID.
|
73
|
+
session_id: The session ID.
|
74
|
+
filename: The filename of the artifact.
|
75
|
+
version: The version of the artifact. If None, the latest version will be
|
76
|
+
returned.
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
The artifact or None if not found.
|
80
|
+
"""
|
81
|
+
pass
|
82
|
+
|
83
|
+
@abstractmethod
|
84
|
+
def list_artifact_keys(
|
85
|
+
self, *, app_name: str, user_id: str, session_id: str
|
86
|
+
) -> list[str]:
|
87
|
+
"""Lists all the artifact filenames within a session.
|
88
|
+
|
89
|
+
Args:
|
90
|
+
app_name: The name of the application.
|
91
|
+
user_id: The ID of the user.
|
92
|
+
session_id: The ID of the session.
|
93
|
+
|
94
|
+
Returns:
|
95
|
+
A list of all artifact filenames within a session.
|
96
|
+
"""
|
97
|
+
pass
|
98
|
+
|
99
|
+
@abstractmethod
|
100
|
+
def delete_artifact(
|
101
|
+
self, *, app_name: str, user_id: str, session_id: str, filename: str
|
102
|
+
) -> None:
|
103
|
+
"""Deletes an artifact.
|
104
|
+
|
105
|
+
Args:
|
106
|
+
app_name: The name of the application.
|
107
|
+
user_id: The ID of the user.
|
108
|
+
session_id: The ID of the session.
|
109
|
+
filename: The name of the artifact file.
|
110
|
+
"""
|
111
|
+
pass
|
112
|
+
|
113
|
+
@abstractmethod
|
114
|
+
def list_versions(
|
115
|
+
self, *, app_name: str, user_id: str, session_id: str, filename: str
|
116
|
+
) -> list[int]:
|
117
|
+
"""Lists all versions of an artifact.
|
118
|
+
|
119
|
+
Args:
|
120
|
+
app_name: The name of the application.
|
121
|
+
user_id: The ID of the user.
|
122
|
+
session_id: The ID of the session.
|
123
|
+
filename: The name of the artifact file.
|
124
|
+
|
125
|
+
Returns:
|
126
|
+
A list of all available versions of the artifact.
|
127
|
+
"""
|
128
|
+
pass
|
@@ -0,0 +1,195 @@
|
|
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
|
+
"""An artifact service implementation using Google Cloud Storage (GCS)."""
|
16
|
+
|
17
|
+
import logging
|
18
|
+
from typing import Optional
|
19
|
+
|
20
|
+
from google.cloud import storage
|
21
|
+
from google.genai import types
|
22
|
+
from typing_extensions import override
|
23
|
+
|
24
|
+
from .base_artifact_service import BaseArtifactService
|
25
|
+
|
26
|
+
logger = logging.getLogger(__name__)
|
27
|
+
|
28
|
+
|
29
|
+
class GcsArtifactService(BaseArtifactService):
|
30
|
+
"""An artifact service implementation using Google Cloud Storage (GCS)."""
|
31
|
+
|
32
|
+
def __init__(self, bucket_name: str, **kwargs):
|
33
|
+
"""Initializes the GcsArtifactService.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
bucket_name: The name of the bucket to use.
|
37
|
+
**kwargs: Keyword arguments to pass to the Google Cloud Storage client.
|
38
|
+
"""
|
39
|
+
self.bucket_name = bucket_name
|
40
|
+
self.storage_client = storage.Client(**kwargs)
|
41
|
+
self.bucket = self.storage_client.bucket(self.bucket_name)
|
42
|
+
|
43
|
+
def _file_has_user_namespace(self, filename: str) -> bool:
|
44
|
+
"""Checks if the filename has a user namespace.
|
45
|
+
|
46
|
+
Args:
|
47
|
+
filename: The filename to check.
|
48
|
+
|
49
|
+
Returns:
|
50
|
+
True if the filename has a user namespace (starts with "user:"),
|
51
|
+
False otherwise.
|
52
|
+
"""
|
53
|
+
return filename.startswith("user:")
|
54
|
+
|
55
|
+
def _get_blob_name(
|
56
|
+
self,
|
57
|
+
app_name: str,
|
58
|
+
user_id: str,
|
59
|
+
session_id: str,
|
60
|
+
filename: str,
|
61
|
+
version: int,
|
62
|
+
) -> str:
|
63
|
+
"""Constructs the blob name in GCS.
|
64
|
+
|
65
|
+
Args:
|
66
|
+
app_name: The name of the application.
|
67
|
+
user_id: The ID of the user.
|
68
|
+
session_id: The ID of the session.
|
69
|
+
filename: The name of the artifact file.
|
70
|
+
version: The version of the artifact.
|
71
|
+
|
72
|
+
Returns:
|
73
|
+
The constructed blob name in GCS.
|
74
|
+
"""
|
75
|
+
if self._file_has_user_namespace(filename):
|
76
|
+
return f"{app_name}/{user_id}/user/{filename}/{version}"
|
77
|
+
return f"{app_name}/{user_id}/{session_id}/{filename}/{version}"
|
78
|
+
|
79
|
+
@override
|
80
|
+
def save_artifact(
|
81
|
+
self,
|
82
|
+
*,
|
83
|
+
app_name: str,
|
84
|
+
user_id: str,
|
85
|
+
session_id: str,
|
86
|
+
filename: str,
|
87
|
+
artifact: types.Part,
|
88
|
+
) -> int:
|
89
|
+
versions = self.list_versions(
|
90
|
+
app_name=app_name,
|
91
|
+
user_id=user_id,
|
92
|
+
session_id=session_id,
|
93
|
+
filename=filename,
|
94
|
+
)
|
95
|
+
version = 0 if not versions else max(versions) + 1
|
96
|
+
|
97
|
+
blob_name = self._get_blob_name(
|
98
|
+
app_name, user_id, session_id, filename, version
|
99
|
+
)
|
100
|
+
blob = self.bucket.blob(blob_name)
|
101
|
+
|
102
|
+
blob.upload_from_string(
|
103
|
+
data=artifact.inline_data.data,
|
104
|
+
content_type=artifact.inline_data.mime_type,
|
105
|
+
)
|
106
|
+
|
107
|
+
return version
|
108
|
+
|
109
|
+
@override
|
110
|
+
def load_artifact(
|
111
|
+
self,
|
112
|
+
*,
|
113
|
+
app_name: str,
|
114
|
+
user_id: str,
|
115
|
+
session_id: str,
|
116
|
+
filename: str,
|
117
|
+
version: Optional[int] = None,
|
118
|
+
) -> Optional[types.Part]:
|
119
|
+
if version is None:
|
120
|
+
versions = self.list_versions(
|
121
|
+
app_name=app_name,
|
122
|
+
user_id=user_id,
|
123
|
+
session_id=session_id,
|
124
|
+
filename=filename,
|
125
|
+
)
|
126
|
+
if not versions:
|
127
|
+
return None
|
128
|
+
version = max(versions)
|
129
|
+
|
130
|
+
blob_name = self._get_blob_name(
|
131
|
+
app_name, user_id, session_id, filename, version
|
132
|
+
)
|
133
|
+
blob = self.bucket.blob(blob_name)
|
134
|
+
|
135
|
+
artifact_bytes = blob.download_as_bytes()
|
136
|
+
if not artifact_bytes:
|
137
|
+
return None
|
138
|
+
artifact = types.Part.from_bytes(
|
139
|
+
data=artifact_bytes, mime_type=blob.content_type
|
140
|
+
)
|
141
|
+
return artifact
|
142
|
+
|
143
|
+
@override
|
144
|
+
def list_artifact_keys(
|
145
|
+
self, *, app_name: str, user_id: str, session_id: str
|
146
|
+
) -> list[str]:
|
147
|
+
filenames = set()
|
148
|
+
|
149
|
+
session_prefix = f"{app_name}/{user_id}/{session_id}/"
|
150
|
+
session_blobs = self.storage_client.list_blobs(
|
151
|
+
self.bucket, prefix=session_prefix
|
152
|
+
)
|
153
|
+
for blob in session_blobs:
|
154
|
+
_, _, _, filename, _ = blob.name.split("/")
|
155
|
+
filenames.add(filename)
|
156
|
+
|
157
|
+
user_namespace_prefix = f"{app_name}/{user_id}/user/"
|
158
|
+
user_namespace_blobs = self.storage_client.list_blobs(
|
159
|
+
self.bucket, prefix=user_namespace_prefix
|
160
|
+
)
|
161
|
+
for blob in user_namespace_blobs:
|
162
|
+
_, _, _, filename, _ = blob.name.split("/")
|
163
|
+
filenames.add(filename)
|
164
|
+
|
165
|
+
return sorted(list(filenames))
|
166
|
+
|
167
|
+
@override
|
168
|
+
def delete_artifact(
|
169
|
+
self, *, app_name: str, user_id: str, session_id: str, filename: str
|
170
|
+
) -> None:
|
171
|
+
versions = self.list_versions(
|
172
|
+
app_name=app_name,
|
173
|
+
user_id=user_id,
|
174
|
+
session_id=session_id,
|
175
|
+
filename=filename,
|
176
|
+
)
|
177
|
+
for version in versions:
|
178
|
+
blob_name = self._get_blob_name(
|
179
|
+
app_name, user_id, session_id, filename, version
|
180
|
+
)
|
181
|
+
blob = self.bucket.blob(blob_name)
|
182
|
+
blob.delete()
|
183
|
+
return
|
184
|
+
|
185
|
+
@override
|
186
|
+
def list_versions(
|
187
|
+
self, *, app_name: str, user_id: str, session_id: str, filename: str
|
188
|
+
) -> list[int]:
|
189
|
+
prefix = self._get_blob_name(app_name, user_id, session_id, filename, "")
|
190
|
+
blobs = self.storage_client.list_blobs(self.bucket, prefix=prefix)
|
191
|
+
versions = []
|
192
|
+
for blob in blobs:
|
193
|
+
_, _, _, _, version = blob.name.split("/")
|
194
|
+
versions.append(int(version))
|
195
|
+
return versions
|
@@ -0,0 +1,133 @@
|
|
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
|
+
"""An in-memory implementation of the artifact service."""
|
16
|
+
|
17
|
+
import logging
|
18
|
+
from typing import Optional
|
19
|
+
|
20
|
+
from google.genai import types
|
21
|
+
from pydantic import BaseModel
|
22
|
+
from pydantic import Field
|
23
|
+
from typing_extensions import override
|
24
|
+
|
25
|
+
from .base_artifact_service import BaseArtifactService
|
26
|
+
|
27
|
+
logger = logging.getLogger(__name__)
|
28
|
+
|
29
|
+
|
30
|
+
class InMemoryArtifactService(BaseArtifactService, BaseModel):
|
31
|
+
"""An in-memory implementation of the artifact service."""
|
32
|
+
|
33
|
+
artifacts: dict[str, list[types.Part]] = Field(default_factory=dict)
|
34
|
+
|
35
|
+
def _file_has_user_namespace(self, filename: str) -> bool:
|
36
|
+
"""Checks if the filename has a user namespace.
|
37
|
+
|
38
|
+
Args:
|
39
|
+
filename: The filename to check.
|
40
|
+
|
41
|
+
Returns:
|
42
|
+
True if the filename has a user namespace (starts with "user:"),
|
43
|
+
False otherwise.
|
44
|
+
"""
|
45
|
+
return filename.startswith("user:")
|
46
|
+
|
47
|
+
def _artifact_path(
|
48
|
+
self, app_name: str, user_id: str, session_id: str, filename: str
|
49
|
+
) -> str:
|
50
|
+
"""Constructs the artifact path.
|
51
|
+
|
52
|
+
Args:
|
53
|
+
app_name: The name of the application.
|
54
|
+
user_id: The ID of the user.
|
55
|
+
session_id: The ID of the session.
|
56
|
+
filename: The name of the artifact file.
|
57
|
+
|
58
|
+
Returns:
|
59
|
+
The constructed artifact path.
|
60
|
+
"""
|
61
|
+
if self._file_has_user_namespace(filename):
|
62
|
+
return f"{app_name}/{user_id}/user/{filename}"
|
63
|
+
return f"{app_name}/{user_id}/{session_id}/{filename}"
|
64
|
+
|
65
|
+
@override
|
66
|
+
def save_artifact(
|
67
|
+
self,
|
68
|
+
*,
|
69
|
+
app_name: str,
|
70
|
+
user_id: str,
|
71
|
+
session_id: str,
|
72
|
+
filename: str,
|
73
|
+
artifact: types.Part,
|
74
|
+
) -> int:
|
75
|
+
path = self._artifact_path(app_name, user_id, session_id, filename)
|
76
|
+
if path not in self.artifacts:
|
77
|
+
self.artifacts[path] = []
|
78
|
+
version = len(self.artifacts[path])
|
79
|
+
self.artifacts[path].append(artifact)
|
80
|
+
return version
|
81
|
+
|
82
|
+
@override
|
83
|
+
def load_artifact(
|
84
|
+
self,
|
85
|
+
*,
|
86
|
+
app_name: str,
|
87
|
+
user_id: str,
|
88
|
+
session_id: str,
|
89
|
+
filename: str,
|
90
|
+
version: Optional[int] = None,
|
91
|
+
) -> Optional[types.Part]:
|
92
|
+
path = self._artifact_path(app_name, user_id, session_id, filename)
|
93
|
+
versions = self.artifacts.get(path)
|
94
|
+
if not versions:
|
95
|
+
return None
|
96
|
+
if version is None:
|
97
|
+
version = -1
|
98
|
+
return versions[version]
|
99
|
+
|
100
|
+
@override
|
101
|
+
def list_artifact_keys(
|
102
|
+
self, *, app_name: str, user_id: str, session_id: str
|
103
|
+
) -> list[str]:
|
104
|
+
session_prefix = f"{app_name}/{user_id}/{session_id}/"
|
105
|
+
usernamespace_prefix = f"{app_name}/{user_id}/user/"
|
106
|
+
filenames = []
|
107
|
+
for path in self.artifacts:
|
108
|
+
if path.startswith(session_prefix):
|
109
|
+
filename = path.removeprefix(session_prefix)
|
110
|
+
filenames.append(filename)
|
111
|
+
elif path.startswith(usernamespace_prefix):
|
112
|
+
filename = path.removeprefix(usernamespace_prefix)
|
113
|
+
filenames.append(filename)
|
114
|
+
return sorted(filenames)
|
115
|
+
|
116
|
+
@override
|
117
|
+
def delete_artifact(
|
118
|
+
self, *, app_name: str, user_id: str, session_id: str, filename: str
|
119
|
+
) -> None:
|
120
|
+
path = self._artifact_path(app_name, user_id, session_id, filename)
|
121
|
+
if not self.artifacts.get(path):
|
122
|
+
return None
|
123
|
+
self.artifacts.pop(path, None)
|
124
|
+
|
125
|
+
@override
|
126
|
+
def list_versions(
|
127
|
+
self, *, app_name: str, user_id: str, session_id: str, filename: str
|
128
|
+
) -> list[int]:
|
129
|
+
path = self._artifact_path(app_name, user_id, session_id, filename)
|
130
|
+
versions = self.artifacts.get(path)
|
131
|
+
if not versions:
|
132
|
+
return []
|
133
|
+
return list(range(len(versions)))
|
@@ -0,0 +1,22 @@
|
|
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
|