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.
Files changed (345) hide show
  1. google/adk/._version.py +0 -0
  2. google/adk/__init__.py +20 -0
  3. google/adk/agents/__init__.py +32 -0
  4. google/adk/agents/active_streaming_tool.py +38 -0
  5. google/adk/agents/base_agent.py +345 -0
  6. google/adk/agents/callback_context.py +112 -0
  7. google/adk/agents/invocation_context.py +181 -0
  8. google/adk/agents/langgraph_agent.py +140 -0
  9. google/adk/agents/live_request_queue.py +64 -0
  10. google/adk/agents/llm_agent.py +376 -0
  11. google/adk/agents/loop_agent.py +62 -0
  12. google/adk/agents/parallel_agent.py +96 -0
  13. google/adk/agents/readonly_context.py +46 -0
  14. google/adk/agents/remote_agent.py +50 -0
  15. google/adk/agents/run_config.py +87 -0
  16. google/adk/agents/sequential_agent.py +45 -0
  17. google/adk/agents/transcription_entry.py +34 -0
  18. google/adk/artifacts/__init__.py +23 -0
  19. google/adk/artifacts/base_artifact_service.py +128 -0
  20. google/adk/artifacts/gcs_artifact_service.py +195 -0
  21. google/adk/artifacts/in_memory_artifact_service.py +133 -0
  22. google/adk/auth/__init__.py +22 -0
  23. google/adk/auth/auth_credential.py +220 -0
  24. google/adk/auth/auth_handler.py +268 -0
  25. google/adk/auth/auth_preprocessor.py +116 -0
  26. google/adk/auth/auth_schemes.py +67 -0
  27. google/adk/auth/auth_tool.py +55 -0
  28. google/adk/cli/__init__.py +15 -0
  29. google/adk/cli/__main__.py +18 -0
  30. google/adk/cli/agent_graph.py +148 -0
  31. google/adk/cli/browser/adk_favicon.svg +17 -0
  32. google/adk/cli/browser/assets/audio-processor.js +51 -0
  33. google/adk/cli/browser/assets/config/runtime-config.json +3 -0
  34. google/adk/cli/browser/index.html +33 -0
  35. google/adk/cli/browser/main-SY2WYYGV.js +75 -0
  36. google/adk/cli/browser/polyfills-FFHMD2TL.js +18 -0
  37. google/adk/cli/browser/styles-4VDSPQ37.css +17 -0
  38. google/adk/cli/cli.py +181 -0
  39. google/adk/cli/cli_deploy.py +181 -0
  40. google/adk/cli/cli_eval.py +282 -0
  41. google/adk/cli/cli_tools_click.py +524 -0
  42. google/adk/cli/fast_api.py +784 -0
  43. google/adk/cli/utils/__init__.py +49 -0
  44. google/adk/cli/utils/envs.py +57 -0
  45. google/adk/cli/utils/evals.py +93 -0
  46. google/adk/cli/utils/logs.py +72 -0
  47. google/adk/code_executors/__init__.py +49 -0
  48. google/adk/code_executors/base_code_executor.py +97 -0
  49. google/adk/code_executors/code_execution_utils.py +256 -0
  50. google/adk/code_executors/code_executor_context.py +202 -0
  51. google/adk/code_executors/container_code_executor.py +196 -0
  52. google/adk/code_executors/unsafe_local_code_executor.py +71 -0
  53. google/adk/code_executors/vertex_ai_code_executor.py +234 -0
  54. google/adk/docs/Makefile +20 -0
  55. google/adk/docs/build/doctrees/google-adk.doctree +0 -0
  56. google/adk/docs/build/html/_sources/google-adk.rst.txt +98 -0
  57. google/adk/docs/build/html/_sources/index.rst.txt +7 -0
  58. google/adk/docs/build/html/_static/autodoc_pydantic.css +27 -0
  59. google/adk/docs/build/html/_static/basic.css +925 -0
  60. google/adk/docs/build/html/_static/debug.css +85 -0
  61. google/adk/docs/build/html/_static/doctools.js +156 -0
  62. google/adk/docs/build/html/_static/documentation_options.js +29 -0
  63. google/adk/docs/build/html/_static/file.png +0 -0
  64. google/adk/docs/build/html/_static/language_data.js +199 -0
  65. google/adk/docs/build/html/_static/minus.png +0 -0
  66. google/adk/docs/build/html/_static/plus.png +0 -0
  67. google/adk/docs/build/html/_static/pygments.css +274 -0
  68. google/adk/docs/build/html/_static/scripts/furo-extensions.js +16 -0
  69. google/adk/docs/build/html/_static/scripts/furo.js +19 -0
  70. google/adk/docs/build/html/_static/scripts/furo.js.LICENSE.txt +7 -0
  71. google/adk/docs/build/html/_static/scripts/furo.js.map +1 -0
  72. google/adk/docs/build/html/_static/searchtools.js +620 -0
  73. google/adk/docs/build/html/_static/skeleton.css +312 -0
  74. google/adk/docs/build/html/_static/sphinx_highlight.js +170 -0
  75. google/adk/docs/build/html/_static/styles/furo-extensions.css +18 -0
  76. google/adk/docs/build/html/_static/styles/furo-extensions.css.map +1 -0
  77. google/adk/docs/build/html/_static/styles/furo.css +18 -0
  78. google/adk/docs/build/html/_static/styles/furo.css.map +1 -0
  79. google/adk/docs/build/html/genindex.html +861 -0
  80. google/adk/docs/build/html/google-adk.html +5461 -0
  81. google/adk/docs/build/html/index.html +567 -0
  82. google/adk/docs/build/html/objects.inv +0 -0
  83. google/adk/docs/build/html/py-modindex.html +373 -0
  84. google/adk/docs/build/html/search.html +333 -0
  85. google/adk/docs/build/html/searchindex.js +17 -0
  86. google/adk/docs/source/conf.py +133 -0
  87. google/adk/docs/source/google-adk.rst +98 -0
  88. google/adk/docs/source/index.rst +7 -0
  89. google/adk/evaluation/__init__.py +31 -0
  90. google/adk/evaluation/agent_evaluator.py +329 -0
  91. google/adk/evaluation/evaluation_constants.py +24 -0
  92. google/adk/evaluation/evaluation_generator.py +270 -0
  93. google/adk/evaluation/response_evaluator.py +135 -0
  94. google/adk/evaluation/trajectory_evaluator.py +184 -0
  95. google/adk/events/__init__.py +21 -0
  96. google/adk/events/event.py +130 -0
  97. google/adk/events/event_actions.py +55 -0
  98. google/adk/examples/__init__.py +28 -0
  99. google/adk/examples/base_example_provider.py +35 -0
  100. google/adk/examples/example.py +27 -0
  101. google/adk/examples/example_util.py +123 -0
  102. google/adk/examples/vertex_ai_example_store.py +104 -0
  103. google/adk/flows/__init__.py +14 -0
  104. google/adk/flows/llm_flows/__init__.py +20 -0
  105. google/adk/flows/llm_flows/_base_llm_processor.py +52 -0
  106. google/adk/flows/llm_flows/_code_execution.py +458 -0
  107. google/adk/flows/llm_flows/_nl_planning.py +129 -0
  108. google/adk/flows/llm_flows/agent_transfer.py +132 -0
  109. google/adk/flows/llm_flows/audio_transcriber.py +109 -0
  110. google/adk/flows/llm_flows/auto_flow.py +49 -0
  111. google/adk/flows/llm_flows/base_llm_flow.py +559 -0
  112. google/adk/flows/llm_flows/basic.py +72 -0
  113. google/adk/flows/llm_flows/contents.py +370 -0
  114. google/adk/flows/llm_flows/functions.py +486 -0
  115. google/adk/flows/llm_flows/identity.py +47 -0
  116. google/adk/flows/llm_flows/instructions.py +137 -0
  117. google/adk/flows/llm_flows/single_flow.py +57 -0
  118. google/adk/memory/__init__.py +35 -0
  119. google/adk/memory/base_memory_service.py +74 -0
  120. google/adk/memory/in_memory_memory_service.py +62 -0
  121. google/adk/memory/vertex_ai_rag_memory_service.py +177 -0
  122. google/adk/models/__init__.py +31 -0
  123. google/adk/models/anthropic_llm.py +243 -0
  124. google/adk/models/base_llm.py +87 -0
  125. google/adk/models/base_llm_connection.py +76 -0
  126. google/adk/models/gemini_llm_connection.py +200 -0
  127. google/adk/models/google_llm.py +331 -0
  128. google/adk/models/lite_llm.py +673 -0
  129. google/adk/models/llm_request.py +98 -0
  130. google/adk/models/llm_response.py +111 -0
  131. google/adk/models/registry.py +102 -0
  132. google/adk/planners/__init__.py +23 -0
  133. google/adk/planners/base_planner.py +66 -0
  134. google/adk/planners/built_in_planner.py +75 -0
  135. google/adk/planners/plan_re_act_planner.py +208 -0
  136. google/adk/runners.py +456 -0
  137. google/adk/sessions/__init__.py +41 -0
  138. google/adk/sessions/base_session_service.py +133 -0
  139. google/adk/sessions/database_session_service.py +522 -0
  140. google/adk/sessions/in_memory_session_service.py +206 -0
  141. google/adk/sessions/session.py +54 -0
  142. google/adk/sessions/state.py +71 -0
  143. google/adk/sessions/vertex_ai_session_service.py +356 -0
  144. google/adk/telemetry.py +189 -0
  145. google/adk/tests/__init__.py +14 -0
  146. google/adk/tests/integration/.env.example +10 -0
  147. google/adk/tests/integration/__init__.py +18 -0
  148. google/adk/tests/integration/conftest.py +119 -0
  149. google/adk/tests/integration/fixture/__init__.py +14 -0
  150. google/adk/tests/integration/fixture/agent_with_config/__init__.py +15 -0
  151. google/adk/tests/integration/fixture/agent_with_config/agent.py +88 -0
  152. google/adk/tests/integration/fixture/callback_agent/__init__.py +15 -0
  153. google/adk/tests/integration/fixture/callback_agent/agent.py +105 -0
  154. google/adk/tests/integration/fixture/context_update_test/OWNERS +1 -0
  155. google/adk/tests/integration/fixture/context_update_test/__init__.py +15 -0
  156. google/adk/tests/integration/fixture/context_update_test/agent.py +43 -0
  157. google/adk/tests/integration/fixture/context_update_test/successful_test.session.json +582 -0
  158. google/adk/tests/integration/fixture/context_variable_agent/__init__.py +15 -0
  159. google/adk/tests/integration/fixture/context_variable_agent/agent.py +115 -0
  160. google/adk/tests/integration/fixture/customer_support_ma/__init__.py +15 -0
  161. google/adk/tests/integration/fixture/customer_support_ma/agent.py +172 -0
  162. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/__init__.py +15 -0
  163. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/agent.py +338 -0
  164. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/order_query.test.json +69 -0
  165. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/test_config.json +6 -0
  166. google/adk/tests/integration/fixture/flow_complex_spark/__init__.py +15 -0
  167. google/adk/tests/integration/fixture/flow_complex_spark/agent.py +182 -0
  168. google/adk/tests/integration/fixture/flow_complex_spark/sample.session.json +190 -0
  169. google/adk/tests/integration/fixture/hello_world_agent/__init__.py +15 -0
  170. google/adk/tests/integration/fixture/hello_world_agent/agent.py +95 -0
  171. google/adk/tests/integration/fixture/hello_world_agent/roll_die.test.json +24 -0
  172. google/adk/tests/integration/fixture/hello_world_agent/test_config.json +6 -0
  173. google/adk/tests/integration/fixture/home_automation_agent/__init__.py +15 -0
  174. google/adk/tests/integration/fixture/home_automation_agent/agent.py +304 -0
  175. google/adk/tests/integration/fixture/home_automation_agent/simple_test.test.json +5 -0
  176. google/adk/tests/integration/fixture/home_automation_agent/simple_test2.test.json +5 -0
  177. google/adk/tests/integration/fixture/home_automation_agent/test_config.json +5 -0
  178. google/adk/tests/integration/fixture/home_automation_agent/test_files/dependent_tool_calls.test.json +18 -0
  179. google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/eval_data.test.json +17 -0
  180. google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/test_config.json +6 -0
  181. google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_multi_turn_conversation.test.json +18 -0
  182. google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test.test.json +17 -0
  183. google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test2.test.json +5 -0
  184. google/adk/tests/integration/fixture/home_automation_agent/test_files/test_config.json +5 -0
  185. google/adk/tests/integration/fixture/tool_agent/__init__.py +15 -0
  186. google/adk/tests/integration/fixture/tool_agent/agent.py +218 -0
  187. google/adk/tests/integration/fixture/tool_agent/files/Agent_test_plan.pdf +0 -0
  188. google/adk/tests/integration/fixture/trip_planner_agent/__init__.py +15 -0
  189. google/adk/tests/integration/fixture/trip_planner_agent/agent.py +110 -0
  190. google/adk/tests/integration/fixture/trip_planner_agent/initial.session.json +13 -0
  191. google/adk/tests/integration/fixture/trip_planner_agent/test_config.json +5 -0
  192. google/adk/tests/integration/fixture/trip_planner_agent/test_files/initial.session.json +13 -0
  193. google/adk/tests/integration/fixture/trip_planner_agent/test_files/test_config.json +5 -0
  194. google/adk/tests/integration/fixture/trip_planner_agent/test_files/trip_inquiry_sub_agent.test.json +7 -0
  195. google/adk/tests/integration/fixture/trip_planner_agent/trip_inquiry.test.json +19 -0
  196. google/adk/tests/integration/models/__init__.py +14 -0
  197. google/adk/tests/integration/models/test_google_llm.py +65 -0
  198. google/adk/tests/integration/test_callback.py +70 -0
  199. google/adk/tests/integration/test_context_variable.py +67 -0
  200. google/adk/tests/integration/test_evalute_agent_in_fixture.py +76 -0
  201. google/adk/tests/integration/test_multi_agent.py +28 -0
  202. google/adk/tests/integration/test_multi_turn.py +42 -0
  203. google/adk/tests/integration/test_single_agent.py +23 -0
  204. google/adk/tests/integration/test_sub_agent.py +26 -0
  205. google/adk/tests/integration/test_system_instruction.py +177 -0
  206. google/adk/tests/integration/test_tools.py +287 -0
  207. google/adk/tests/integration/test_with_test_file.py +34 -0
  208. google/adk/tests/integration/tools/__init__.py +14 -0
  209. google/adk/tests/integration/utils/__init__.py +16 -0
  210. google/adk/tests/integration/utils/asserts.py +75 -0
  211. google/adk/tests/integration/utils/test_runner.py +97 -0
  212. google/adk/tests/unittests/__init__.py +14 -0
  213. google/adk/tests/unittests/agents/__init__.py +14 -0
  214. google/adk/tests/unittests/agents/test_base_agent.py +407 -0
  215. google/adk/tests/unittests/agents/test_langgraph_agent.py +191 -0
  216. google/adk/tests/unittests/agents/test_llm_agent_callbacks.py +138 -0
  217. google/adk/tests/unittests/agents/test_llm_agent_fields.py +231 -0
  218. google/adk/tests/unittests/agents/test_loop_agent.py +136 -0
  219. google/adk/tests/unittests/agents/test_parallel_agent.py +92 -0
  220. google/adk/tests/unittests/agents/test_sequential_agent.py +114 -0
  221. google/adk/tests/unittests/artifacts/__init__.py +14 -0
  222. google/adk/tests/unittests/artifacts/test_artifact_service.py +276 -0
  223. google/adk/tests/unittests/auth/test_auth_handler.py +575 -0
  224. google/adk/tests/unittests/conftest.py +73 -0
  225. google/adk/tests/unittests/fast_api/__init__.py +14 -0
  226. google/adk/tests/unittests/fast_api/test_fast_api.py +269 -0
  227. google/adk/tests/unittests/flows/__init__.py +14 -0
  228. google/adk/tests/unittests/flows/llm_flows/__init__.py +14 -0
  229. google/adk/tests/unittests/flows/llm_flows/_test_examples.py +142 -0
  230. google/adk/tests/unittests/flows/llm_flows/test_agent_transfer.py +311 -0
  231. google/adk/tests/unittests/flows/llm_flows/test_functions_long_running.py +244 -0
  232. google/adk/tests/unittests/flows/llm_flows/test_functions_request_euc.py +346 -0
  233. google/adk/tests/unittests/flows/llm_flows/test_functions_sequential.py +93 -0
  234. google/adk/tests/unittests/flows/llm_flows/test_functions_simple.py +258 -0
  235. google/adk/tests/unittests/flows/llm_flows/test_identity.py +66 -0
  236. google/adk/tests/unittests/flows/llm_flows/test_instructions.py +164 -0
  237. google/adk/tests/unittests/flows/llm_flows/test_model_callbacks.py +142 -0
  238. google/adk/tests/unittests/flows/llm_flows/test_other_configs.py +46 -0
  239. google/adk/tests/unittests/flows/llm_flows/test_tool_callbacks.py +269 -0
  240. google/adk/tests/unittests/models/__init__.py +14 -0
  241. google/adk/tests/unittests/models/test_google_llm.py +224 -0
  242. google/adk/tests/unittests/models/test_litellm.py +804 -0
  243. google/adk/tests/unittests/models/test_models.py +60 -0
  244. google/adk/tests/unittests/sessions/__init__.py +14 -0
  245. google/adk/tests/unittests/sessions/test_session_service.py +227 -0
  246. google/adk/tests/unittests/sessions/test_vertex_ai_session_service.py +246 -0
  247. google/adk/tests/unittests/streaming/__init__.py +14 -0
  248. google/adk/tests/unittests/streaming/test_streaming.py +50 -0
  249. google/adk/tests/unittests/tools/__init__.py +14 -0
  250. google/adk/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py +499 -0
  251. google/adk/tests/unittests/tools/apihub_tool/test_apihub_toolset.py +204 -0
  252. google/adk/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py +600 -0
  253. google/adk/tests/unittests/tools/application_integration_tool/clients/test_integration_client.py +630 -0
  254. google/adk/tests/unittests/tools/application_integration_tool/test_application_integration_toolset.py +345 -0
  255. google/adk/tests/unittests/tools/google_api_tool/__init__.py +13 -0
  256. google/adk/tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py +657 -0
  257. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_auto_auth_credential_exchanger.py +145 -0
  258. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_base_auth_credential_exchanger.py +68 -0
  259. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_oauth2_exchanger.py +153 -0
  260. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_service_account_exchanger.py +196 -0
  261. google/adk/tests/unittests/tools/openapi_tool/auth/test_auth_helper.py +573 -0
  262. google/adk/tests/unittests/tools/openapi_tool/common/test_common.py +436 -0
  263. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test.yaml +1367 -0
  264. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py +628 -0
  265. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_toolset.py +139 -0
  266. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py +406 -0
  267. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py +966 -0
  268. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_tool_auth_handler.py +201 -0
  269. google/adk/tests/unittests/tools/retrieval/__init__.py +14 -0
  270. google/adk/tests/unittests/tools/retrieval/test_vertex_ai_rag_retrieval.py +147 -0
  271. google/adk/tests/unittests/tools/test_agent_tool.py +167 -0
  272. google/adk/tests/unittests/tools/test_base_tool.py +141 -0
  273. google/adk/tests/unittests/tools/test_build_function_declaration.py +277 -0
  274. google/adk/tests/unittests/utils.py +304 -0
  275. google/adk/tools/__init__.py +51 -0
  276. google/adk/tools/_automatic_function_calling_util.py +346 -0
  277. google/adk/tools/agent_tool.py +176 -0
  278. google/adk/tools/apihub_tool/__init__.py +19 -0
  279. google/adk/tools/apihub_tool/apihub_toolset.py +209 -0
  280. google/adk/tools/apihub_tool/clients/__init__.py +13 -0
  281. google/adk/tools/apihub_tool/clients/apihub_client.py +332 -0
  282. google/adk/tools/apihub_tool/clients/secret_client.py +115 -0
  283. google/adk/tools/application_integration_tool/__init__.py +19 -0
  284. google/adk/tools/application_integration_tool/application_integration_toolset.py +230 -0
  285. google/adk/tools/application_integration_tool/clients/connections_client.py +903 -0
  286. google/adk/tools/application_integration_tool/clients/integration_client.py +253 -0
  287. google/adk/tools/base_tool.py +144 -0
  288. google/adk/tools/built_in_code_execution_tool.py +59 -0
  289. google/adk/tools/crewai_tool.py +72 -0
  290. google/adk/tools/example_tool.py +62 -0
  291. google/adk/tools/exit_loop_tool.py +23 -0
  292. google/adk/tools/function_parameter_parse_util.py +307 -0
  293. google/adk/tools/function_tool.py +87 -0
  294. google/adk/tools/get_user_choice_tool.py +28 -0
  295. google/adk/tools/google_api_tool/__init__.py +14 -0
  296. google/adk/tools/google_api_tool/google_api_tool.py +59 -0
  297. google/adk/tools/google_api_tool/google_api_tool_set.py +107 -0
  298. google/adk/tools/google_api_tool/google_api_tool_sets.py +55 -0
  299. google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py +521 -0
  300. google/adk/tools/google_search_tool.py +68 -0
  301. google/adk/tools/langchain_tool.py +86 -0
  302. google/adk/tools/load_artifacts_tool.py +113 -0
  303. google/adk/tools/load_memory_tool.py +58 -0
  304. google/adk/tools/load_web_page.py +41 -0
  305. google/adk/tools/long_running_tool.py +39 -0
  306. google/adk/tools/mcp_tool/__init__.py +42 -0
  307. google/adk/tools/mcp_tool/conversion_utils.py +161 -0
  308. google/adk/tools/mcp_tool/mcp_tool.py +113 -0
  309. google/adk/tools/mcp_tool/mcp_toolset.py +272 -0
  310. google/adk/tools/openapi_tool/__init__.py +21 -0
  311. google/adk/tools/openapi_tool/auth/__init__.py +19 -0
  312. google/adk/tools/openapi_tool/auth/auth_helpers.py +498 -0
  313. google/adk/tools/openapi_tool/auth/credential_exchangers/__init__.py +25 -0
  314. google/adk/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.py +105 -0
  315. google/adk/tools/openapi_tool/auth/credential_exchangers/base_credential_exchanger.py +55 -0
  316. google/adk/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.py +117 -0
  317. google/adk/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.py +97 -0
  318. google/adk/tools/openapi_tool/common/__init__.py +19 -0
  319. google/adk/tools/openapi_tool/common/common.py +300 -0
  320. google/adk/tools/openapi_tool/openapi_spec_parser/__init__.py +32 -0
  321. google/adk/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.py +231 -0
  322. google/adk/tools/openapi_tool/openapi_spec_parser/openapi_toolset.py +144 -0
  323. google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py +260 -0
  324. google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py +496 -0
  325. google/adk/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.py +268 -0
  326. google/adk/tools/preload_memory_tool.py +72 -0
  327. google/adk/tools/retrieval/__init__.py +36 -0
  328. google/adk/tools/retrieval/base_retrieval_tool.py +37 -0
  329. google/adk/tools/retrieval/files_retrieval.py +33 -0
  330. google/adk/tools/retrieval/llama_index_retrieval.py +41 -0
  331. google/adk/tools/retrieval/vertex_ai_rag_retrieval.py +107 -0
  332. google/adk/tools/tool_context.py +90 -0
  333. google/adk/tools/toolbox_tool.py +46 -0
  334. google/adk/tools/transfer_to_agent_tool.py +21 -0
  335. google/adk/tools/vertex_ai_search_tool.py +96 -0
  336. google/adk/version.py +16 -0
  337. google_adk-0.0.3.dist-info/METADATA +73 -0
  338. google_adk-0.0.3.dist-info/RECORD +340 -0
  339. {google_adk-0.0.1.dist-info → google_adk-0.0.3.dist-info}/WHEEL +1 -2
  340. google_adk-0.0.3.dist-info/entry_points.txt +3 -0
  341. agent_kit/__init__.py +0 -0
  342. google_adk-0.0.1.dist-info/LICENSE.txt +0 -170
  343. google_adk-0.0.1.dist-info/METADATA +0 -15
  344. google_adk-0.0.1.dist-info/RECORD +0 -6
  345. google_adk-0.0.1.dist-info/top_level.txt +0 -1
@@ -0,0 +1,115 @@
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.agents.invocation_context import InvocationContext
20
+ from google.adk.planners import PlanReActPlanner
21
+ from google.adk.tools import ToolContext
22
+
23
+
24
+ def update_fc(
25
+ data_one: str,
26
+ data_two: Union[int, float, str],
27
+ data_three: list[str],
28
+ data_four: List[Union[int, float, str]],
29
+ tool_context: ToolContext,
30
+ ) -> str:
31
+ """Simply ask to update these variables in the context"""
32
+ tool_context.actions.update_state('data_one', data_one)
33
+ tool_context.actions.update_state('data_two', data_two)
34
+ tool_context.actions.update_state('data_three', data_three)
35
+ tool_context.actions.update_state('data_four', data_four)
36
+ return 'The function `update_fc` executed successfully'
37
+
38
+
39
+ def echo_info(customer_id: str) -> str:
40
+ """Echo the context variable"""
41
+ return customer_id
42
+
43
+
44
+ def build_global_instruction(invocation_context: InvocationContext) -> str:
45
+ return (
46
+ 'This is the gloabl agent instruction for invocation:'
47
+ f' {invocation_context.invocation_id}.'
48
+ )
49
+
50
+
51
+ def build_sub_agent_instruction(invocation_context: InvocationContext) -> str:
52
+ return 'This is the plain text sub agent instruction.'
53
+
54
+
55
+ context_variable_echo_agent = Agent(
56
+ model='gemini-1.5-flash',
57
+ name='context_variable_echo_agent',
58
+ instruction=(
59
+ 'Use the echo_info tool to echo {customerId}, {customerInt},'
60
+ ' {customerFloat}, and {customerJson}. Ask for it if you need to.'
61
+ ),
62
+ flow='auto',
63
+ tools=[echo_info],
64
+ )
65
+
66
+ context_variable_with_complicated_format_agent = Agent(
67
+ model='gemini-1.5-flash',
68
+ name='context_variable_echo_agent',
69
+ instruction=(
70
+ 'Use the echo_info tool to echo { customerId }, {{customer_int }, { '
71
+ " non-identifier-float}}, {artifact.fileName}, {'key1': 'value1'} and"
72
+ " {{'key2': 'value2'}}. Ask for it if you need to."
73
+ ),
74
+ flow='auto',
75
+ tools=[echo_info],
76
+ )
77
+
78
+ context_variable_with_nl_planner_agent = Agent(
79
+ model='gemini-1.5-flash',
80
+ name='context_variable_with_nl_planner_agent',
81
+ instruction=(
82
+ 'Use the echo_info tool to echo {customerId}. Ask for it if you'
83
+ ' need to.'
84
+ ),
85
+ flow='auto',
86
+ planner=PlanReActPlanner(),
87
+ tools=[echo_info],
88
+ )
89
+
90
+ context_variable_with_function_instruction_agent = Agent(
91
+ model='gemini-1.5-flash',
92
+ name='context_variable_with_function_instruction_agent',
93
+ instruction=build_sub_agent_instruction,
94
+ flow='auto',
95
+ )
96
+
97
+ context_variable_update_agent = Agent(
98
+ model='gemini-1.5-flash',
99
+ name='context_variable_update_agent',
100
+ instruction='Call tools',
101
+ flow='auto',
102
+ tools=[update_fc],
103
+ )
104
+
105
+ root_agent = Agent(
106
+ model='gemini-1.5-flash',
107
+ name='root_agent',
108
+ description='The root agent.',
109
+ flow='auto',
110
+ global_instruction=build_global_instruction,
111
+ sub_agents=[
112
+ context_variable_with_nl_planner_agent,
113
+ context_variable_update_agent,
114
+ ],
115
+ )
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,172 @@
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
+ import sys
17
+
18
+ from google.adk import Agent
19
+ from google.adk.agents import RemoteAgent
20
+ from google.adk.examples import Example
21
+ from google.adk.sessions import Session
22
+ from google.genai import types
23
+
24
+
25
+ def reset_data():
26
+ pass
27
+
28
+
29
+ def fetch_user_flight_information(customer_email: str) -> str:
30
+ """Fetch user flight information."""
31
+ return """
32
+ [{"ticket_no": "7240005432906569", "book_ref": "C46E9F", "flight_id": 19250, "flight_no": "LX0112", "departure_airport": "CDG", "arrival_airport": "BSL", "scheduled_departure": "2024-12-30 12:09:03.561731-04:00", "scheduled_arrival": "2024-12-30 13:39:03.561731-04:00", "seat_no": "18E", "fare_conditions": "Economy"}]
33
+ """
34
+
35
+
36
+ def list_customer_flights(customer_email: str) -> str:
37
+ return "{'flights': [{'book_ref': 'C46E9F'}]}"
38
+
39
+
40
+ def update_ticket_to_new_flight(ticket_no: str, new_flight_id: str) -> str:
41
+ return 'OK, your ticket has been updated.'
42
+
43
+
44
+ def lookup_company_policy(topic: str) -> str:
45
+ """Lookup policies for flight cancelation and rebooking."""
46
+ return """
47
+ 1. How can I change my booking?
48
+ * The ticket number must start with 724 (SWISS ticket no./plate).
49
+ * The ticket was not paid for by barter or voucher (there are exceptions to voucher payments; if the ticket was paid for in full by voucher, then it may be possible to rebook online under certain circumstances. If it is not possible to rebook online because of the payment method, then you will be informed accordingly during the rebooking process).
50
+ * There must be an active flight booking for your ticket. It is not possible to rebook open tickets or tickets without the corresponding flight segments online at the moment.
51
+ * It is currently only possible to rebook outbound (one-way) tickets or return tickets with single flight routes (point-to-point).
52
+ """
53
+
54
+
55
+ def search_flights(
56
+ departure_airport: str = None,
57
+ arrival_airport: str = None,
58
+ start_time: str = None,
59
+ end_time: str = None,
60
+ ) -> list[dict]:
61
+ return """
62
+ [{"flight_id": 19238, "flight_no": "LX0112", "scheduled_departure": "2024-05-08 12:09:03.561731-04:00", "scheduled_arrival": "2024-05-08 13:39:03.561731-04:00", "departure_airport": "CDG", "arrival_airport": "BSL", "status": "Scheduled", "aircraft_code": "SU9", "actual_departure": null, "actual_arrival": null}, {"flight_id": 19242, "flight_no": "LX0112", "scheduled_departure": "2024-05-09 12:09:03.561731-04:00", "scheduled_arrival": "2024-05-09 13:39:03.561731-04:00", "departure_airport": "CDG", "arrival_airport": "BSL", "status": "Scheduled", "aircraft_code": "SU9", "actual_departure": null, "actual_arrival": null}]"""
63
+
64
+
65
+ def search_hotels(
66
+ location: str = None,
67
+ price_tier: str = None,
68
+ checkin_date: str = None,
69
+ checkout_date: str = None,
70
+ ) -> list[dict]:
71
+ return """
72
+ [{"id": 1, "name": "Hilton Basel", "location": "Basel", "price_tier": "Luxury"}, {"id": 3, "name": "Hyatt Regency Basel", "location": "Basel", "price_tier": "Upper Upscale"}, {"id": 8, "name": "Holiday Inn Basel", "location": "Basel", "price_tier": "Upper Midscale"}]
73
+ """
74
+
75
+
76
+ def book_hotel(hotel_name: str) -> str:
77
+ return 'OK, your hotel has been booked.'
78
+
79
+
80
+ def before_model_call(agent: Agent, session: Session, user_message):
81
+ if 'expedia' in user_message.lower():
82
+ response = types.Content(
83
+ role='model',
84
+ parts=[types.Part(text="Sorry, I can't answer this question.")],
85
+ )
86
+ return response
87
+ return None
88
+
89
+
90
+ def after_model_call(
91
+ agent: Agent, session: Session, content: types.Content
92
+ ) -> bool:
93
+ model_message = content.parts[0].text
94
+ if 'expedia' in model_message.lower():
95
+ response = types.Content(
96
+ role='model',
97
+ parts=[types.Part(text="Sorry, I can't answer this question.")],
98
+ )
99
+ return response
100
+ return None
101
+
102
+
103
+ flight_agent = Agent(
104
+ model='gemini-1.5-pro',
105
+ name='flight_agent',
106
+ description='Handles flight information, policy and updates',
107
+ instruction="""
108
+ You are a specialized assistant for handling flight updates.
109
+ The primary assistant delegates work to you whenever the user needs help updating their bookings.
110
+ Confirm the updated flight details with the customer and inform them of any additional fees.
111
+ When searching, be persistent. Expand your query bounds if the first search returns no results.
112
+ Remember that a booking isn't completed until after the relevant tool has successfully been used.
113
+ Do not waste the user's time. Do not make up invalid tools or functions.
114
+ """,
115
+ tools=[
116
+ list_customer_flights,
117
+ lookup_company_policy,
118
+ fetch_user_flight_information,
119
+ search_flights,
120
+ update_ticket_to_new_flight,
121
+ ],
122
+ )
123
+
124
+ hotel_agent = Agent(
125
+ model='gemini-1.5-pro',
126
+ name='hotel_agent',
127
+ description='Handles hotel information and booking',
128
+ instruction="""
129
+ You are a specialized assistant for handling hotel bookings.
130
+ The primary assistant delegates work to you whenever the user needs help booking a hotel.
131
+ Search for available hotels based on the user's preferences and confirm the booking details with the customer.
132
+ When searching, be persistent. Expand your query bounds if the first search returns no results.
133
+ """,
134
+ tools=[search_hotels, book_hotel],
135
+ )
136
+
137
+
138
+ idea_agent = RemoteAgent(
139
+ model='gemini-1.5-pro',
140
+ name='idea_agent',
141
+ description='Provide travel ideas base on the destination.',
142
+ url='http://localhost:8000/agent/run',
143
+ )
144
+
145
+
146
+ root_agent = Agent(
147
+ model='gemini-1.5-pro',
148
+ name='root_agent',
149
+ instruction="""
150
+ You are a helpful customer support assistant for Swiss Airlines.
151
+ """,
152
+ sub_agents=[flight_agent, hotel_agent, idea_agent],
153
+ flow='auto',
154
+ examples=[
155
+ Example(
156
+ input=types.Content(
157
+ role='user',
158
+ parts=[types.Part(text='How were you built?')],
159
+ ),
160
+ output=[
161
+ types.Content(
162
+ role='model',
163
+ parts=[
164
+ types.Part(
165
+ text='I was built with the best agent framework.'
166
+ )
167
+ ],
168
+ )
169
+ ],
170
+ ),
171
+ ],
172
+ )
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,338 @@
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
+
17
+ # A lightweight in-memory mock database
18
+ ORDER_DB = {
19
+ "1": "FINISHED",
20
+ "2": "CANCELED",
21
+ "3": "PENDING",
22
+ "4": "PENDING",
23
+ } # Order id to status mapping. Available states: 'FINISHED', 'PENDING', and 'CANCELED'
24
+ USER_TO_ORDER_DB = {
25
+ "user_a": ["1", "4"],
26
+ "user_b": ["2"],
27
+ "user_c": ["3"],
28
+ } # User id to Order id mapping
29
+ TICKET_DB = [{
30
+ "ticket_id": "1",
31
+ "user_id": "user_a",
32
+ "issue_type": "LOGIN_ISSUE",
33
+ "status": "OPEN",
34
+ }] # Available states: 'OPEN', 'CLOSED', 'ESCALATED'
35
+ USER_INFO_DB = {
36
+ "user_a": {"name": "Alice", "email": "alice@example.com"},
37
+ "user_b": {"name": "Bob", "email": "bob@example.com"},
38
+ }
39
+
40
+
41
+ def reset_data():
42
+ global ORDER_DB
43
+ global USER_TO_ORDER_DB
44
+ global TICKET_DB
45
+ global USER_INFO_DB
46
+ ORDER_DB = {
47
+ "1": "FINISHED",
48
+ "2": "CANCELED",
49
+ "3": "PENDING",
50
+ "4": "PENDING",
51
+ }
52
+ USER_TO_ORDER_DB = {
53
+ "user_a": ["1", "4"],
54
+ "user_b": ["2"],
55
+ "user_c": ["3"],
56
+ }
57
+ TICKET_DB = [{
58
+ "ticket_id": "1",
59
+ "user_id": "user_a",
60
+ "issue_type": "LOGIN_ISSUE",
61
+ "status": "OPEN",
62
+ }]
63
+ USER_INFO_DB = {
64
+ "user_a": {"name": "Alice", "email": "alice@example.com"},
65
+ "user_b": {"name": "Bob", "email": "bob@example.com"},
66
+ }
67
+
68
+
69
+ def get_order_status(order_id: str) -> str:
70
+ """Get the status of an order.
71
+
72
+ Args:
73
+ order_id (str): The unique identifier of the order.
74
+
75
+ Returns:
76
+ str: The status of the order (e.g., 'FINISHED', 'CANCELED', 'PENDING'),
77
+ or 'Order not found' if the order_id does not exist.
78
+ """
79
+ return ORDER_DB.get(order_id, "Order not found")
80
+
81
+
82
+ def get_order_ids_for_user(user_id: str) -> list:
83
+ """Get the list of order IDs assigned to a specific transaction associated with a user.
84
+
85
+ Args:
86
+ user_id (str): The unique identifier of the user.
87
+
88
+ Returns:
89
+ List[str]: A list of order IDs associated with the user, or an empty list
90
+ if no orders are found.
91
+ """
92
+ return USER_TO_ORDER_DB.get(user_id, [])
93
+
94
+
95
+ def cancel_order(order_id: str) -> str:
96
+ """Cancel an order if it is in a 'PENDING' state.
97
+
98
+ You should call "get_order_status" to check the status first, before calling
99
+ this tool.
100
+
101
+ Args:
102
+ order_id (str): The unique identifier of the order to be canceled.
103
+
104
+ Returns:
105
+ str: A message indicating whether the order was successfully canceled or
106
+ not.
107
+ """
108
+ if order_id in ORDER_DB and ORDER_DB[order_id] == "PENDING":
109
+ ORDER_DB[order_id] = "CANCELED"
110
+ return f"Order {order_id} has been canceled."
111
+ return f"Order {order_id} cannot be canceled."
112
+
113
+
114
+ def refund_order(order_id: str) -> str:
115
+ """Process a refund for an order if it is in a 'CANCELED' state.
116
+
117
+ You should call "get_order_status" to check if status first, before calling
118
+ this tool.
119
+
120
+ Args:
121
+ order_id (str): The unique identifier of the order to be refunded.
122
+
123
+ Returns:
124
+ str: A message indicating whether the order was successfully refunded or
125
+ not.
126
+ """
127
+ if order_id in ORDER_DB and ORDER_DB[order_id] == "CANCELED":
128
+ return f"Order {order_id} has been refunded."
129
+ return f"Order {order_id} cannot be refunded."
130
+
131
+
132
+ def create_ticket(user_id: str, issue_type: str) -> str:
133
+ """Create a new support ticket for a user.
134
+
135
+ Args:
136
+ user_id (str): The unique identifier of the user creating the ticket.
137
+ issue_type (str): An issue type the user is facing. Available types:
138
+ 'LOGIN_ISSUE', 'ORDER_ISSUE', 'OTHER'.
139
+
140
+ Returns:
141
+ str: A message indicating that the ticket was created successfully,
142
+ including the ticket ID.
143
+ """
144
+ ticket_id = str(len(TICKET_DB) + 1)
145
+ TICKET_DB.append({
146
+ "ticket_id": ticket_id,
147
+ "user_id": user_id,
148
+ "issue_type": issue_type,
149
+ "status": "OPEN",
150
+ })
151
+ return f"Ticket {ticket_id} created successfully."
152
+
153
+
154
+ def get_ticket_info(ticket_id: str) -> str:
155
+ """Retrieve the information of a support ticket.
156
+
157
+ current status of a support ticket.
158
+
159
+ Args:
160
+ ticket_id (str): The unique identifier of the ticket.
161
+
162
+ Returns:
163
+ A dictionary contains the following fields, or 'Ticket not found' if the
164
+ ticket_id does not exist:
165
+ - "ticket_id": str, the current ticket id
166
+ - "user_id": str, the associated user id
167
+ - "issue": str, the issue type
168
+ - "status": The current status of the ticket (e.g., 'OPEN', 'CLOSED',
169
+ 'ESCALATED')
170
+
171
+ Example: {"ticket_id": "1", "user_id": "user_a", "issue": "Login issue",
172
+ "status": "OPEN"}
173
+ """
174
+ for ticket in TICKET_DB:
175
+ if ticket["ticket_id"] == ticket_id:
176
+ return ticket
177
+ return "Ticket not found"
178
+
179
+
180
+ def get_tickets_for_user(user_id: str) -> list:
181
+ """Get all the ticket IDs associated with a user.
182
+
183
+ Args:
184
+ user_id (str): The unique identifier of the user.
185
+
186
+ Returns:
187
+ List[str]: A list of ticket IDs associated with the user.
188
+ If no tickets are found, returns an empty list.
189
+ """
190
+ return [
191
+ ticket["ticket_id"]
192
+ for ticket in TICKET_DB
193
+ if ticket["user_id"] == user_id
194
+ ]
195
+
196
+
197
+ def update_ticket_status(ticket_id: str, status: str) -> str:
198
+ """Update the status of a support ticket.
199
+
200
+ Args:
201
+ ticket_id (str): The unique identifier of the ticket.
202
+ status (str): The new status to assign to the ticket (e.g., 'OPEN',
203
+ 'CLOSED', 'ESCALATED').
204
+
205
+ Returns:
206
+ str: A message indicating whether the ticket status was successfully
207
+ updated.
208
+ """
209
+ for ticket in TICKET_DB:
210
+ if ticket["ticket_id"] == ticket_id:
211
+ ticket["status"] = status
212
+ return f"Ticket {ticket_id} status updated to {status}."
213
+ return "Ticket not found"
214
+
215
+
216
+ def get_user_info(user_id: str) -> dict:
217
+ """Retrieve information (name, email) about a user.
218
+
219
+ Args:
220
+ user_id (str): The unique identifier of the user.
221
+
222
+ Returns:
223
+ dict or str: A dictionary containing user information of the following
224
+ fields, or 'User not found' if the user_id does not exist:
225
+
226
+ - name: The name of the user
227
+ - email: The email address of the user
228
+
229
+ For example, {"name": "Chelsea", "email": "123@example.com"}
230
+ """
231
+ return USER_INFO_DB.get(user_id, "User not found")
232
+
233
+
234
+ def send_email(user_id: str, email: str) -> list:
235
+ """Send email to user for notification.
236
+
237
+ Args:
238
+ user_id (str): The unique identifier of the user.
239
+ email (str): The email address of the user.
240
+
241
+ Returns:
242
+ str: A message indicating whether the email was successfully sent.
243
+ """
244
+ if user_id in USER_INFO_DB:
245
+ return f"Email sent to {email} for user id {user_id}"
246
+ return "Cannot find this user"
247
+
248
+
249
+ # def update_user_info(user_id: str, new_info: dict[str, str]) -> str:
250
+ def update_user_info(user_id: str, email: str, name: str) -> str:
251
+ """Update a user's information.
252
+
253
+ Args:
254
+ user_id (str): The unique identifier of the user.
255
+ new_info (dict): A dictionary containing the fields to be updated (e.g.,
256
+ {'email': 'new_email@example.com'}). Available field keys: 'email' and
257
+ 'name'.
258
+
259
+ Returns:
260
+ str: A message indicating whether the user's information was successfully
261
+ updated or not.
262
+ """
263
+ if user_id in USER_INFO_DB:
264
+ # USER_INFO_DB[user_id].update(new_info)
265
+ if email and name:
266
+ USER_INFO_DB[user_id].update({"email": email, "name": name})
267
+ elif email:
268
+ USER_INFO_DB[user_id].update({"email": email})
269
+ elif name:
270
+ USER_INFO_DB[user_id].update({"name": name})
271
+ else:
272
+ raise ValueError("this should not happen.")
273
+ return f"User {user_id} information updated."
274
+ return "User not found"
275
+
276
+
277
+ def get_user_id_from_cookie() -> str:
278
+ """Get user ID(username) from the cookie.
279
+
280
+ Only use this function when you do not know user ID(username).
281
+
282
+ Args: None
283
+
284
+ Returns:
285
+ str: The user ID.
286
+ """
287
+ return "user_a"
288
+
289
+
290
+ root_agent = Agent(
291
+ model="gemini-2.0-flash-001",
292
+ name="Ecommerce_Customer_Service",
293
+ instruction="""
294
+ You are an intelligent customer service assistant for an e-commerce platform. Your goal is to accurately understand user queries and use the appropriate tools to fulfill requests. Follow these guidelines:
295
+
296
+ 1. **Understand the Query**:
297
+ - Identify actions and conditions (e.g., create a ticket only for pending orders).
298
+ - Extract necessary details (e.g., user ID, order ID) from the query or infer them from the context.
299
+
300
+ 2. **Plan Multi-Step Workflows**:
301
+ - Break down complex queries into sequential steps. For example
302
+ - typical workflow:
303
+ - Retrieve IDs or references first (e.g., orders for a user).
304
+ - Evaluate conditions (e.g., check order status).
305
+ - Perform actions (e.g., create a ticket) only when conditions are met.
306
+ - another typical workflows - order cancellation and refund:
307
+ - Retrieve all orders for the user (`get_order_ids_for_user`).
308
+ - Cancel pending orders (`cancel_order`).
309
+ - Refund canceled orders (`refund_order`).
310
+ - Notify the user (`send_email`).
311
+ - another typical workflows - send user report:
312
+ - Get user id.
313
+ - Get user info(like emails)
314
+ - Send email to user.
315
+
316
+ 3. **Avoid Skipping Steps**:
317
+ - Ensure each intermediate step is completed before moving to the next.
318
+ - Do not create tickets or take other actions without verifying the conditions specified in the query.
319
+
320
+ 4. **Provide Clear Responses**:
321
+ - Confirm the actions performed, including details like ticket ID or pending orders.
322
+ - Ensure the response aligns with the steps taken and query intent.
323
+ """,
324
+ tools=[
325
+ get_order_status,
326
+ cancel_order,
327
+ get_order_ids_for_user,
328
+ refund_order,
329
+ create_ticket,
330
+ update_ticket_status,
331
+ get_tickets_for_user,
332
+ get_ticket_info,
333
+ get_user_info,
334
+ send_email,
335
+ update_user_info,
336
+ get_user_id_from_cookie,
337
+ ],
338
+ )