aip-agents-binary 0.0.0__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 (447) hide show
  1. aip_agents/__init__.py +66 -0
  2. aip_agents/a2a/__init__.py +19 -0
  3. aip_agents/a2a/server/__init__.py +10 -0
  4. aip_agents/a2a/server/base_executor.py +1125 -0
  5. aip_agents/a2a/server/google_adk_executor.py +198 -0
  6. aip_agents/a2a/server/langflow_executor.py +180 -0
  7. aip_agents/a2a/server/langgraph_executor.py +270 -0
  8. aip_agents/a2a/types.py +232 -0
  9. aip_agents/a2ui/__init__.py +26 -0
  10. aip_agents/a2ui/catalog_provider.py +109 -0
  11. aip_agents/a2ui/examples/0.8/booking_form.json +1 -0
  12. aip_agents/a2ui/examples/0.8/confirmation.json +1 -0
  13. aip_agents/a2ui/examples/0.8/single_column_list.json +1 -0
  14. aip_agents/a2ui/examples/0.9/booking_form.json +1 -0
  15. aip_agents/a2ui/examples/0.9/confirmation.json +1 -0
  16. aip_agents/a2ui/examples/0.9/single_column_list.json +1 -0
  17. aip_agents/a2ui/middleware.py +754 -0
  18. aip_agents/a2ui/models.py +153 -0
  19. aip_agents/a2ui/public_url.py +138 -0
  20. aip_agents/a2ui/stream_filter.py +67 -0
  21. aip_agents/agent/__init__.py +72 -0
  22. aip_agents/agent/base_agent.py +1437 -0
  23. aip_agents/agent/base_langgraph_agent.py +4048 -0
  24. aip_agents/agent/google_adk_agent.py +932 -0
  25. aip_agents/agent/google_adk_constants.py +11 -0
  26. aip_agents/agent/graph_runtime.py +185 -0
  27. aip_agents/agent/hitl/__init__.py +24 -0
  28. aip_agents/agent/hitl/config.py +28 -0
  29. aip_agents/agent/hitl/langgraph_hitl_mixin.py +515 -0
  30. aip_agents/agent/hitl/manager.py +532 -0
  31. aip_agents/agent/hitl/models.py +18 -0
  32. aip_agents/agent/hitl/prompt/__init__.py +9 -0
  33. aip_agents/agent/hitl/prompt/base.py +42 -0
  34. aip_agents/agent/hitl/prompt/deferred.py +73 -0
  35. aip_agents/agent/hitl/registry.py +149 -0
  36. aip_agents/agent/interface.py +138 -0
  37. aip_agents/agent/interfaces.py +65 -0
  38. aip_agents/agent/langflow_agent.py +464 -0
  39. aip_agents/agent/langgraph_react_agent.py +3741 -0
  40. aip_agents/agent/model_invocation_adapter.py +346 -0
  41. aip_agents/agent/system_instruction_context.py +34 -0
  42. aip_agents/agent/tool_execution_engine.py +587 -0
  43. aip_agents/audio_interface/__init__.py +30 -0
  44. aip_agents/audio_interface/audio_agent_adapter.py +254 -0
  45. aip_agents/audio_interface/config.py +146 -0
  46. aip_agents/audio_interface/errors.py +15 -0
  47. aip_agents/audio_interface/livekit_audio_session.py +504 -0
  48. aip_agents/audio_interface/livekit_realtime_audio_session.py +142 -0
  49. aip_agents/audio_interface/session_factory.py +40 -0
  50. aip_agents/clients/__init__.py +10 -0
  51. aip_agents/clients/langflow/__init__.py +10 -0
  52. aip_agents/clients/langflow/client.py +477 -0
  53. aip_agents/clients/langflow/types.py +18 -0
  54. aip_agents/common/__init__.py +5 -0
  55. aip_agents/common/callable_introspection.py +17 -0
  56. aip_agents/constants.py +23 -0
  57. aip_agents/context/__init__.py +5 -0
  58. aip_agents/context/budget.py +237 -0
  59. aip_agents/context/compaction.py +339 -0
  60. aip_agents/context/metadata.py +169 -0
  61. aip_agents/context/offload.py +449 -0
  62. aip_agents/context/preparation.py +196 -0
  63. aip_agents/context/prompt.py +61 -0
  64. aip_agents/context/runtime.py +149 -0
  65. aip_agents/context/session_recall.py +69 -0
  66. aip_agents/context/state.py +48 -0
  67. aip_agents/context/utils.py +44 -0
  68. aip_agents/credentials/manager.py +132 -0
  69. aip_agents/examples/__init__.py +5 -0
  70. aip_agents/examples/audio_livekit_session.py +116 -0
  71. aip_agents/examples/compare_streaming_client.py +783 -0
  72. aip_agents/examples/compare_streaming_server.py +141 -0
  73. aip_agents/examples/gl_connectors_smoke.py +148 -0
  74. aip_agents/examples/hello_world_a2a_google_adk_client.py +49 -0
  75. aip_agents/examples/hello_world_a2a_google_adk_client_agent.py +48 -0
  76. aip_agents/examples/hello_world_a2a_google_adk_client_streaming.py +60 -0
  77. aip_agents/examples/hello_world_a2a_google_adk_server.py +78 -0
  78. aip_agents/examples/hello_world_a2a_langchain_client.py +39 -0
  79. aip_agents/examples/hello_world_a2a_langchain_client_agent.py +39 -0
  80. aip_agents/examples/hello_world_a2a_langchain_client_lm_invoker.py +37 -0
  81. aip_agents/examples/hello_world_a2a_langchain_client_streaming.py +41 -0
  82. aip_agents/examples/hello_world_a2a_langchain_reference_client_streaming.py +60 -0
  83. aip_agents/examples/hello_world_a2a_langchain_reference_server.py +104 -0
  84. aip_agents/examples/hello_world_a2a_langchain_server.py +78 -0
  85. aip_agents/examples/hello_world_a2a_langchain_server_lm_invoker.py +77 -0
  86. aip_agents/examples/hello_world_a2a_langflow_client.py +83 -0
  87. aip_agents/examples/hello_world_a2a_langflow_server.py +80 -0
  88. aip_agents/examples/hello_world_a2a_langgraph_artifact_client.py +73 -0
  89. aip_agents/examples/hello_world_a2a_langgraph_artifact_client_streaming.py +76 -0
  90. aip_agents/examples/hello_world_a2a_langgraph_artifact_server.py +91 -0
  91. aip_agents/examples/hello_world_a2a_langgraph_client.py +54 -0
  92. aip_agents/examples/hello_world_a2a_langgraph_client_agent.py +54 -0
  93. aip_agents/examples/hello_world_a2a_langgraph_client_agent_lm_invoker.py +32 -0
  94. aip_agents/examples/hello_world_a2a_langgraph_client_streaming.py +50 -0
  95. aip_agents/examples/hello_world_a2a_langgraph_client_streaming_lm_invoker.py +44 -0
  96. aip_agents/examples/hello_world_a2a_langgraph_client_streaming_tool_streaming.py +92 -0
  97. aip_agents/examples/hello_world_a2a_langgraph_server.py +83 -0
  98. aip_agents/examples/hello_world_a2a_langgraph_server_lm_invoker.py +78 -0
  99. aip_agents/examples/hello_world_a2a_langgraph_server_tool_streaming.py +131 -0
  100. aip_agents/examples/hello_world_a2a_mcp_langgraph.py +196 -0
  101. aip_agents/examples/hello_world_a2a_three_level_agent_hierarchy_client.py +244 -0
  102. aip_agents/examples/hello_world_a2a_three_level_agent_hierarchy_server.py +250 -0
  103. aip_agents/examples/hello_world_a2a_with_metadata_langchain_client.py +57 -0
  104. aip_agents/examples/hello_world_a2a_with_metadata_langchain_server_lm_invoker.py +79 -0
  105. aip_agents/examples/hello_world_filesystem.py +162 -0
  106. aip_agents/examples/hello_world_google_adk.py +41 -0
  107. aip_agents/examples/hello_world_google_adk_mcp_http.py +34 -0
  108. aip_agents/examples/hello_world_google_adk_mcp_http_stream.py +40 -0
  109. aip_agents/examples/hello_world_google_adk_mcp_sse.py +44 -0
  110. aip_agents/examples/hello_world_google_adk_mcp_sse_stream.py +48 -0
  111. aip_agents/examples/hello_world_google_adk_mcp_stdio.py +44 -0
  112. aip_agents/examples/hello_world_google_adk_mcp_stdio_stream.py +48 -0
  113. aip_agents/examples/hello_world_google_adk_stream.py +44 -0
  114. aip_agents/examples/hello_world_langchain.py +28 -0
  115. aip_agents/examples/hello_world_langchain_lm_invoker.py +15 -0
  116. aip_agents/examples/hello_world_langchain_mcp_http.py +34 -0
  117. aip_agents/examples/hello_world_langchain_mcp_http_interactive.py +130 -0
  118. aip_agents/examples/hello_world_langchain_mcp_http_stream.py +42 -0
  119. aip_agents/examples/hello_world_langchain_mcp_multi_server.py +155 -0
  120. aip_agents/examples/hello_world_langchain_mcp_sse.py +34 -0
  121. aip_agents/examples/hello_world_langchain_mcp_sse_stream.py +40 -0
  122. aip_agents/examples/hello_world_langchain_mcp_stdio.py +30 -0
  123. aip_agents/examples/hello_world_langchain_mcp_stdio_stream.py +41 -0
  124. aip_agents/examples/hello_world_langchain_stream.py +36 -0
  125. aip_agents/examples/hello_world_langchain_stream_lm_invoker.py +39 -0
  126. aip_agents/examples/hello_world_langflow_agent.py +163 -0
  127. aip_agents/examples/hello_world_langgraph.py +39 -0
  128. aip_agents/examples/hello_world_langgraph_gl_connector_twitter.py +44 -0
  129. aip_agents/examples/hello_world_langgraph_mcp_http.py +31 -0
  130. aip_agents/examples/hello_world_langgraph_mcp_http_stream.py +34 -0
  131. aip_agents/examples/hello_world_langgraph_mcp_sse.py +35 -0
  132. aip_agents/examples/hello_world_langgraph_mcp_sse_stream.py +50 -0
  133. aip_agents/examples/hello_world_langgraph_mcp_stdio.py +35 -0
  134. aip_agents/examples/hello_world_langgraph_mcp_stdio_stream.py +50 -0
  135. aip_agents/examples/hello_world_langgraph_skills.py +62 -0
  136. aip_agents/examples/hello_world_langgraph_stream.py +43 -0
  137. aip_agents/examples/hello_world_langgraph_stream_lm_invoker.py +37 -0
  138. aip_agents/examples/hello_world_model_switch_cli.py +210 -0
  139. aip_agents/examples/hello_world_multi_agent_adk.py +75 -0
  140. aip_agents/examples/hello_world_multi_agent_langchain.py +54 -0
  141. aip_agents/examples/hello_world_multi_agent_langgraph.py +66 -0
  142. aip_agents/examples/hello_world_multi_agent_langgraph_lm_invoker.py +69 -0
  143. aip_agents/examples/hello_world_multi_agent_tool_output_client.py +57 -0
  144. aip_agents/examples/hello_world_multi_agent_tool_output_server.py +131 -0
  145. aip_agents/examples/hello_world_pii_logger.py +21 -0
  146. aip_agents/examples/hello_world_ptc.py +49 -0
  147. aip_agents/examples/hello_world_ptc_custom_tools.py +83 -0
  148. aip_agents/examples/hello_world_sentry.py +133 -0
  149. aip_agents/examples/hello_world_step_limits.py +273 -0
  150. aip_agents/examples/hello_world_stock_a2a_server.py +100 -0
  151. aip_agents/examples/hello_world_tool_output_client.py +55 -0
  152. aip_agents/examples/hello_world_tool_output_server.py +113 -0
  153. aip_agents/examples/hitl_demo.py +724 -0
  154. aip_agents/examples/mcp_configs/configs.py +63 -0
  155. aip_agents/examples/mcp_servers/common.py +76 -0
  156. aip_agents/examples/mcp_servers/mcp_name.py +29 -0
  157. aip_agents/examples/mcp_servers/mcp_server_http.py +19 -0
  158. aip_agents/examples/mcp_servers/mcp_server_sse.py +19 -0
  159. aip_agents/examples/mcp_servers/mcp_server_stdio.py +19 -0
  160. aip_agents/examples/mcp_servers/mcp_time.py +10 -0
  161. aip_agents/examples/pii_demo_langgraph_client.py +69 -0
  162. aip_agents/examples/pii_demo_langgraph_server.py +125 -0
  163. aip_agents/examples/pii_demo_multi_agent_client.py +80 -0
  164. aip_agents/examples/pii_demo_multi_agent_server.py +246 -0
  165. aip_agents/examples/todolist_planning_a2a_langchain_client.py +70 -0
  166. aip_agents/examples/todolist_planning_a2a_langgraph_server.py +87 -0
  167. aip_agents/examples/tools/__init__.py +27 -0
  168. aip_agents/examples/tools/adk_arithmetic_tools.py +36 -0
  169. aip_agents/examples/tools/adk_weather_tool.py +60 -0
  170. aip_agents/examples/tools/data_generator_tool.py +103 -0
  171. aip_agents/examples/tools/data_visualization_tool.py +312 -0
  172. aip_agents/examples/tools/image_artifact_tool.py +136 -0
  173. aip_agents/examples/tools/langchain_arithmetic_tools.py +26 -0
  174. aip_agents/examples/tools/langchain_currency_exchange_tool.py +88 -0
  175. aip_agents/examples/tools/langchain_graph_artifact_tool.py +172 -0
  176. aip_agents/examples/tools/langchain_weather_tool.py +48 -0
  177. aip_agents/examples/tools/langgraph_streaming_tool.py +130 -0
  178. aip_agents/examples/tools/mock_retrieval_tool.py +56 -0
  179. aip_agents/examples/tools/multiply_tool.py +43 -0
  180. aip_agents/examples/tools/pii_demo_tools.py +189 -0
  181. aip_agents/examples/tools/random_chart_tool.py +142 -0
  182. aip_agents/examples/tools/serper_tool.py +202 -0
  183. aip_agents/examples/tools/stock_tools.py +82 -0
  184. aip_agents/examples/tools/table_generator_tool.py +167 -0
  185. aip_agents/examples/tools/time_tool.py +82 -0
  186. aip_agents/examples/tools/weather_forecast_tool.py +38 -0
  187. aip_agents/guardrails/__init__.py +83 -0
  188. aip_agents/guardrails/engines/__init__.py +69 -0
  189. aip_agents/guardrails/engines/base.py +90 -0
  190. aip_agents/guardrails/engines/nemo.py +101 -0
  191. aip_agents/guardrails/engines/phrase_matcher.py +113 -0
  192. aip_agents/guardrails/exceptions.py +39 -0
  193. aip_agents/guardrails/manager.py +163 -0
  194. aip_agents/guardrails/middleware.py +199 -0
  195. aip_agents/guardrails/schemas.py +63 -0
  196. aip_agents/guardrails/utils.py +45 -0
  197. aip_agents/integration/__init__.py +43 -0
  198. aip_agents/integration/agent.py +58 -0
  199. aip_agents/integration/guardrails.py +52 -0
  200. aip_agents/integration/hitl.py +71 -0
  201. aip_agents/integration/ptc.py +95 -0
  202. aip_agents/integration/skills.py +37 -0
  203. aip_agents/integration/storage.py +81 -0
  204. aip_agents/integration/version.py +103 -0
  205. aip_agents/mcp/__init__.py +1 -0
  206. aip_agents/mcp/client/__init__.py +60 -0
  207. aip_agents/mcp/client/base_mcp_client.py +377 -0
  208. aip_agents/mcp/client/connection_manager.py +231 -0
  209. aip_agents/mcp/client/errors.py +119 -0
  210. aip_agents/mcp/client/google_adk/__init__.py +45 -0
  211. aip_agents/mcp/client/google_adk/client.py +383 -0
  212. aip_agents/mcp/client/langchain/__init__.py +11 -0
  213. aip_agents/mcp/client/langchain/client.py +265 -0
  214. aip_agents/mcp/client/persistent_session.py +704 -0
  215. aip_agents/mcp/client/session_pool.py +358 -0
  216. aip_agents/mcp/client/transports.py +288 -0
  217. aip_agents/mcp/utils/__init__.py +7 -0
  218. aip_agents/mcp/utils/config_validator.py +139 -0
  219. aip_agents/memory/__init__.py +14 -0
  220. aip_agents/memory/adapters/__init__.py +10 -0
  221. aip_agents/memory/adapters/base_adapter.py +815 -0
  222. aip_agents/memory/adapters/mem0.py +286 -0
  223. aip_agents/memory/base.py +84 -0
  224. aip_agents/memory/constants.py +49 -0
  225. aip_agents/memory/factory.py +86 -0
  226. aip_agents/memory/guidance.py +20 -0
  227. aip_agents/memory/simple_memory.py +47 -0
  228. aip_agents/middleware/__init__.py +65 -0
  229. aip_agents/middleware/backends/__init__.py +72 -0
  230. aip_agents/middleware/backends/in_memory.py +578 -0
  231. aip_agents/middleware/backends/local_disk.py +1203 -0
  232. aip_agents/middleware/backends/protocol.py +353 -0
  233. aip_agents/middleware/backends/sandbox.py +1431 -0
  234. aip_agents/middleware/backends/sandbox_files.py +113 -0
  235. aip_agents/middleware/backends/utils.py +293 -0
  236. aip_agents/middleware/base.py +239 -0
  237. aip_agents/middleware/filesystem.py +690 -0
  238. aip_agents/middleware/manager.py +291 -0
  239. aip_agents/middleware/memory.py +532 -0
  240. aip_agents/middleware/pii_middleware.py +192 -0
  241. aip_agents/middleware/schema.py +19 -0
  242. aip_agents/middleware/skills.py +872 -0
  243. aip_agents/middleware/task_delegation.py +1656 -0
  244. aip_agents/middleware/todolist.py +276 -0
  245. aip_agents/middleware/tools/__init__.py +23 -0
  246. aip_agents/middleware/tools/edit_file.py +70 -0
  247. aip_agents/middleware/tools/execute.py +428 -0
  248. aip_agents/middleware/tools/grep_file.py +79 -0
  249. aip_agents/middleware/tools/ls.py +71 -0
  250. aip_agents/middleware/tools/read_file.py +239 -0
  251. aip_agents/middleware/tools/skill_load.py +193 -0
  252. aip_agents/middleware/tools/skill_resource.py +338 -0
  253. aip_agents/middleware/tools/write_file.py +114 -0
  254. aip_agents/middleware/vision.py +322 -0
  255. aip_agents/ptc/__init__.py +87 -0
  256. aip_agents/ptc/custom_tools.py +511 -0
  257. aip_agents/ptc/custom_tools_payload.py +499 -0
  258. aip_agents/ptc/custom_tools_templates/__init__.py +1 -0
  259. aip_agents/ptc/custom_tools_templates/custom_build_function.py.template +24 -0
  260. aip_agents/ptc/custom_tools_templates/custom_init.py.template +26 -0
  261. aip_agents/ptc/custom_tools_templates/custom_invoke.py.template +149 -0
  262. aip_agents/ptc/custom_tools_templates/custom_registry.py.template +112 -0
  263. aip_agents/ptc/custom_tools_templates/custom_sources_init.py.template +7 -0
  264. aip_agents/ptc/custom_tools_templates/custom_wrapper.py.template +87 -0
  265. aip_agents/ptc/doc_gen.py +122 -0
  266. aip_agents/ptc/exceptions.py +57 -0
  267. aip_agents/ptc/executor.py +627 -0
  268. aip_agents/ptc/mcp/__init__.py +45 -0
  269. aip_agents/ptc/mcp/sandbox_bridge.py +679 -0
  270. aip_agents/ptc/mcp/templates/__init__.py +1 -0
  271. aip_agents/ptc/mcp/templates/mcp_client.py.template +240 -0
  272. aip_agents/ptc/naming.py +430 -0
  273. aip_agents/ptc/payload.py +26 -0
  274. aip_agents/ptc/prompt_builder.py +674 -0
  275. aip_agents/ptc/ptc_helper.py +16 -0
  276. aip_agents/ptc/sandbox_bridge.py +297 -0
  277. aip_agents/ptc/template_utils.py +33 -0
  278. aip_agents/ptc/templates/__init__.py +1 -0
  279. aip_agents/ptc/templates/ptc_helper.py.template +134 -0
  280. aip_agents/ptc/tool_def_helpers.py +101 -0
  281. aip_agents/ptc/tool_enrichment.py +163 -0
  282. aip_agents/resilience/__init__.py +10 -0
  283. aip_agents/resilience/base.py +46 -0
  284. aip_agents/resilience/tool.py +1661 -0
  285. aip_agents/sandbox/__init__.py +62 -0
  286. aip_agents/sandbox/defaults.py +220 -0
  287. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-1-datasaur.Dockerfile +120 -0
  288. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-1.Dockerfile +100 -0
  289. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-2-datasaur.Dockerfile +143 -0
  290. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-2.Dockerfile +119 -0
  291. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-3-datasaur.Dockerfile +173 -0
  292. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-3.Dockerfile +130 -0
  293. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-4-runner-managed.Dockerfile +164 -0
  294. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-4-runner-managed.patch_js_context.py +41 -0
  295. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2-4-runner-managed.requirements.txt +29 -0
  296. aip_agents/sandbox/dockerfiles/aip-agents-sandbox-v2.Dockerfile +87 -0
  297. aip_agents/sandbox/e2b_runtime.py +27 -0
  298. aip_agents/sandbox/image_registry.py +98 -0
  299. aip_agents/sandbox/providers/__init__.py +76 -0
  300. aip_agents/sandbox/providers/base.py +392 -0
  301. aip_agents/sandbox/providers/bedrock.py +28 -0
  302. aip_agents/sandbox/providers/e2b.py +230 -0
  303. aip_agents/sandbox/providers/opensandbox.py +163 -0
  304. aip_agents/sandbox/sandbox_runtime.py +967 -0
  305. aip_agents/sandbox/template_builder.py +240 -0
  306. aip_agents/sandbox/types.py +141 -0
  307. aip_agents/sandbox/validation.py +50 -0
  308. aip_agents/schema/__init__.py +106 -0
  309. aip_agents/schema/a2a.py +58 -0
  310. aip_agents/schema/agent.py +117 -0
  311. aip_agents/schema/artifacts.py +75 -0
  312. aip_agents/schema/attachments.py +425 -0
  313. aip_agents/schema/hitl.py +157 -0
  314. aip_agents/schema/langgraph.py +47 -0
  315. aip_agents/schema/model_id.py +103 -0
  316. aip_agents/schema/model_usage.py +50 -0
  317. aip_agents/schema/runtime_metadata.py +78 -0
  318. aip_agents/schema/step_limit.py +108 -0
  319. aip_agents/schema/storage.py +40 -0
  320. aip_agents/schema/tool_payloads.py +68 -0
  321. aip_agents/sentry/__init__.py +11 -0
  322. aip_agents/sentry/sentry.py +267 -0
  323. aip_agents/skills/__init__.py +30 -0
  324. aip_agents/skills/errors.py +110 -0
  325. aip_agents/skills/installer.py +479 -0
  326. aip_agents/skills/models.py +769 -0
  327. aip_agents/skills/stager.py +224 -0
  328. aip_agents/skills/validation.py +53 -0
  329. aip_agents/storage/__init__.py +41 -0
  330. aip_agents/storage/base.py +85 -0
  331. aip_agents/storage/clients/__init__.py +12 -0
  332. aip_agents/storage/clients/minio_client.py +318 -0
  333. aip_agents/storage/config.py +62 -0
  334. aip_agents/storage/providers/__init__.py +15 -0
  335. aip_agents/storage/providers/base.py +106 -0
  336. aip_agents/storage/providers/memory.py +114 -0
  337. aip_agents/storage/providers/object_storage.py +214 -0
  338. aip_agents/tools/__init__.py +65 -0
  339. aip_agents/tools/agent_schedule_tool.py +392 -0
  340. aip_agents/tools/browser_use/__init__.py +83 -0
  341. aip_agents/tools/browser_use/action_parser.py +104 -0
  342. aip_agents/tools/browser_use/browser_use_tool.py +1118 -0
  343. aip_agents/tools/browser_use/llm_config.py +120 -0
  344. aip_agents/tools/browser_use/minio_storage.py +203 -0
  345. aip_agents/tools/browser_use/schemas.py +121 -0
  346. aip_agents/tools/browser_use/session.py +13 -0
  347. aip_agents/tools/browser_use/session_errors.py +132 -0
  348. aip_agents/tools/browser_use/steel_session_recording.py +321 -0
  349. aip_agents/tools/browser_use/streaming.py +263 -0
  350. aip_agents/tools/browser_use/structured_data_parser.py +257 -0
  351. aip_agents/tools/browser_use/structured_data_recovery.py +204 -0
  352. aip_agents/tools/browser_use/types.py +37 -0
  353. aip_agents/tools/code_sandbox/__init__.py +48 -0
  354. aip_agents/tools/code_sandbox/code_sandbox_tool.py +350 -0
  355. aip_agents/tools/code_sandbox/constant.py +13 -0
  356. aip_agents/tools/code_sandbox/e2b_cloud_sandbox_extended.py +346 -0
  357. aip_agents/tools/code_sandbox/e2b_sandbox_tool.py +65 -0
  358. aip_agents/tools/computer_use/__init__.py +75 -0
  359. aip_agents/tools/computer_use/computer_use_tool.py +910 -0
  360. aip_agents/tools/computer_use/schemas.py +78 -0
  361. aip_agents/tools/computer_use/streaming.py +198 -0
  362. aip_agents/tools/computer_use/types.py +32 -0
  363. aip_agents/tools/constants.py +177 -0
  364. aip_agents/tools/date_range_tool.py +554 -0
  365. aip_agents/tools/document_loader/__init__.py +44 -0
  366. aip_agents/tools/document_loader/base_reader.py +302 -0
  367. aip_agents/tools/document_loader/docx_reader_tool.py +68 -0
  368. aip_agents/tools/document_loader/excel_reader_tool.py +171 -0
  369. aip_agents/tools/document_loader/pdf_reader_tool.py +79 -0
  370. aip_agents/tools/document_loader/pdf_splitter.py +169 -0
  371. aip_agents/tools/execute_ptc_code.py +582 -0
  372. aip_agents/tools/gl_connector/__init__.py +5 -0
  373. aip_agents/tools/gl_connector/tool.py +518 -0
  374. aip_agents/tools/gl_connector_tools.py +170 -0
  375. aip_agents/tools/memory_search/__init__.py +29 -0
  376. aip_agents/tools/memory_search/base.py +213 -0
  377. aip_agents/tools/memory_search/mem0.py +424 -0
  378. aip_agents/tools/memory_search/schema.py +81 -0
  379. aip_agents/tools/memory_search_tool.py +34 -0
  380. aip_agents/tools/streaming_common.py +577 -0
  381. aip_agents/tools/time_tool.py +117 -0
  382. aip_agents/tools/tool_config_injector.py +300 -0
  383. aip_agents/tools/web_search/__init__.py +15 -0
  384. aip_agents/tools/web_search/serper_tool.py +187 -0
  385. aip_agents/types/__init__.py +73 -0
  386. aip_agents/types/a2a_events.py +13 -0
  387. aip_agents/utils/__init__.py +91 -0
  388. aip_agents/utils/a2a_connector.py +1758 -0
  389. aip_agents/utils/artifact_helpers.py +542 -0
  390. aip_agents/utils/artifacts/__init__.py +20 -0
  391. aip_agents/utils/artifacts/tracker.py +367 -0
  392. aip_agents/utils/attachment_helpers.py +178 -0
  393. aip_agents/utils/constants.py +22 -0
  394. aip_agents/utils/datetime/__init__.py +34 -0
  395. aip_agents/utils/datetime/normalization.py +231 -0
  396. aip_agents/utils/datetime/timezone.py +206 -0
  397. aip_agents/utils/env_loader.py +27 -0
  398. aip_agents/utils/event_handler_registry.py +58 -0
  399. aip_agents/utils/file_prompt_utils.py +276 -0
  400. aip_agents/utils/file_watchers/__init__.py +33 -0
  401. aip_agents/utils/file_watchers/base.py +46 -0
  402. aip_agents/utils/file_watchers/e2b.py +128 -0
  403. aip_agents/utils/file_watchers/factory.py +39 -0
  404. aip_agents/utils/file_watchers/ls_diff.py +88 -0
  405. aip_agents/utils/file_watchers/sandbox.py +66 -0
  406. aip_agents/utils/file_watchers/watchdog.py +97 -0
  407. aip_agents/utils/final_response_builder.py +211 -0
  408. aip_agents/utils/formatter_llm_client.py +258 -0
  409. aip_agents/utils/langgraph/__init__.py +19 -0
  410. aip_agents/utils/langgraph/converter.py +399 -0
  411. aip_agents/utils/langgraph/delegation_context.py +22 -0
  412. aip_agents/utils/langgraph/tool_managers/__init__.py +15 -0
  413. aip_agents/utils/langgraph/tool_managers/a2a_tool_manager.py +99 -0
  414. aip_agents/utils/langgraph/tool_managers/base_tool_manager.py +66 -0
  415. aip_agents/utils/langgraph/tool_managers/delegation_tool_manager.py +1329 -0
  416. aip_agents/utils/langgraph/tool_output_management.py +1047 -0
  417. aip_agents/utils/logger.py +195 -0
  418. aip_agents/utils/metadata/__init__.py +27 -0
  419. aip_agents/utils/metadata/activity_metadata_helper.py +407 -0
  420. aip_agents/utils/metadata/activity_narrative/__init__.py +35 -0
  421. aip_agents/utils/metadata/activity_narrative/builder.py +822 -0
  422. aip_agents/utils/metadata/activity_narrative/constants.py +51 -0
  423. aip_agents/utils/metadata/activity_narrative/context.py +49 -0
  424. aip_agents/utils/metadata/activity_narrative/formatters.py +230 -0
  425. aip_agents/utils/metadata/activity_narrative/utils.py +35 -0
  426. aip_agents/utils/metadata/schemas/__init__.py +16 -0
  427. aip_agents/utils/metadata/schemas/activity_schema.py +29 -0
  428. aip_agents/utils/metadata/schemas/thinking_schema.py +31 -0
  429. aip_agents/utils/metadata/thinking_metadata_helper.py +38 -0
  430. aip_agents/utils/metadata_helper.py +363 -0
  431. aip_agents/utils/name_preprocessor/__init__.py +17 -0
  432. aip_agents/utils/name_preprocessor/base_name_preprocessor.py +73 -0
  433. aip_agents/utils/name_preprocessor/google_name_preprocessor.py +100 -0
  434. aip_agents/utils/name_preprocessor/name_preprocessor.py +87 -0
  435. aip_agents/utils/name_preprocessor/openai_name_preprocessor.py +48 -0
  436. aip_agents/utils/pii/__init__.py +29 -0
  437. aip_agents/utils/pii/pii_handler.py +555 -0
  438. aip_agents/utils/pii/pii_helper.py +225 -0
  439. aip_agents/utils/pii/uuid_deanonymizer_mapping.py +195 -0
  440. aip_agents/utils/reference_helper.py +273 -0
  441. aip_agents/utils/sse_chunk_transformer.py +836 -0
  442. aip_agents/utils/step_limit_manager.py +265 -0
  443. aip_agents/utils/token_usage_helper.py +531 -0
  444. aip_agents_binary-0.0.0.dist-info/METADATA +825 -0
  445. aip_agents_binary-0.0.0.dist-info/RECORD +447 -0
  446. aip_agents_binary-0.0.0.dist-info/WHEEL +5 -0
  447. aip_agents_binary-0.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,542 @@
1
+ """Utility functions for artifact handling in agent tools.
2
+
3
+ This module provides standardized functions for creating artifact responses
4
+ that are compatible with the A2A protocol and the agent's artifact handling system.
5
+
6
+ Authors:
7
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
8
+ """
9
+
10
+ import base64
11
+ import hashlib
12
+ from typing import Any
13
+
14
+ from deprecated import deprecated
15
+ from langgraph.types import Command
16
+ from pydantic import ValidationError
17
+
18
+ from aip_agents.a2a.types import Artifact, ArtifactType, MimeType, get_mime_type_from_filename
19
+ from aip_agents.schema.attachments import (
20
+ create_generated_document_attachment,
21
+ create_generated_image_attachment,
22
+ is_supported_document_mime,
23
+ is_supported_image_mime,
24
+ )
25
+
26
+
27
+ class ArtifactHandler:
28
+ """Handler class for creating and managing artifacts in agent tools.
29
+
30
+ This class provides a clean, object-oriented interface for artifact creation
31
+ with built-in validation, deduplication, and standardized formatting.
32
+ """
33
+
34
+ def __init__(self):
35
+ """Initialize the ArtifactHandler."""
36
+ self._artifact_cache: dict[str, dict[str, Any]] = {}
37
+
38
+ @deprecated(version="0.5.0", reason="Use create_artifact(...) which handles text and binary.")
39
+ def create_file_artifact( # noqa: PLR0913
40
+ self,
41
+ result: str,
42
+ artifact_data: bytes | str,
43
+ artifact_name: str,
44
+ artifact_description: str = "",
45
+ mime_type: str | None = None,
46
+ enable_deduplication: bool = True,
47
+ ) -> dict[str, Any]:
48
+ """Deprecated. Use create_artifact instead.
49
+
50
+ Args:
51
+ result (str): The message/result to show to the agent.
52
+ artifact_data (bytes | str): The binary data for the artifact.
53
+ artifact_name (str): The name for the artifact file.
54
+ artifact_description (str, optional): Description of the artifact. Defaults to "".
55
+ mime_type (str | None, optional): MIME type of the artifact. If None, will be auto-detected.
56
+ enable_deduplication (bool, optional): Whether to deduplicate by content hash. Defaults to True.
57
+
58
+ Returns:
59
+ dict[str, Any]: Dictionary with 'result' and 'artifact' keys.
60
+ """
61
+ return self.create_artifact(
62
+ result=result,
63
+ data=artifact_data,
64
+ artifact_name=artifact_name,
65
+ artifact_description=artifact_description,
66
+ mime_type=mime_type,
67
+ enable_deduplication=enable_deduplication,
68
+ )
69
+
70
+ @deprecated(version="0.5.0", reason="Use create_artifact(...) which handles text and binary.")
71
+ def create_text_artifact( # noqa: PLR0913
72
+ self,
73
+ result: str,
74
+ artifact_text: str,
75
+ artifact_name: str,
76
+ artifact_description: str = "",
77
+ mime_type: str | None = None,
78
+ enable_deduplication: bool = True,
79
+ ) -> dict[str, Any]:
80
+ """Deprecated. Use create_artifact instead.
81
+
82
+ Args:
83
+ result (str): The message/result to show to the agent.
84
+ artifact_text (str): The text content for the artifact.
85
+ artifact_name (str): The name for the artifact file.
86
+ artifact_description (str, optional): Description of the artifact. Defaults to "".
87
+ mime_type (str | None, optional): MIME type of the artifact. If None, will be auto-detected.
88
+ enable_deduplication (bool, optional): Whether to deduplicate by content hash. Defaults to True.
89
+
90
+ Returns:
91
+ dict[str, Any]: Dictionary with 'result' and 'artifact' keys.
92
+ """
93
+ return self.create_artifact(
94
+ result=result,
95
+ data=artifact_text,
96
+ artifact_name=artifact_name,
97
+ artifact_description=artifact_description,
98
+ mime_type=mime_type,
99
+ enable_deduplication=enable_deduplication,
100
+ )
101
+
102
+ def create_artifact( # noqa: PLR0913
103
+ self,
104
+ result: str,
105
+ data: bytes | str,
106
+ artifact_name: str,
107
+ artifact_description: str = "",
108
+ mime_type: str | None = None,
109
+ enable_deduplication: bool = True,
110
+ ) -> dict[str, Any]:
111
+ """Create an artifact with automatic text/binary handling.
112
+
113
+ Args:
114
+ result: The message/result to show to the agent.
115
+ data: The data for the artifact. Bytes for binary; str for text or base64.
116
+ artifact_name: The filename to present to users.
117
+ artifact_description: Description of the artifact.
118
+ mime_type: Optional MIME type. If None, inferred from filename.
119
+ enable_deduplication: Whether to deduplicate by content hash.
120
+
121
+ Returns:
122
+ Dictionary with 'result' and 'artifact' keys.
123
+ """
124
+ inferred_mime = self._infer_mime_type(artifact_name, mime_type)
125
+ is_text_like = self._is_text_mime(inferred_mime)
126
+
127
+ artifact_b64 = self._encode_to_base64(data, treat_as_text=is_text_like)
128
+ effective_mime = (
129
+ inferred_mime
130
+ if not is_text_like or inferred_mime != MimeType.APPLICATION_OCTET_STREAM
131
+ else MimeType.TEXT_PLAIN
132
+ )
133
+
134
+ # Deduplication check
135
+ if enable_deduplication:
136
+ artifact_hash = self.generate_artifact_hash(artifact_b64, artifact_name, effective_mime)
137
+ cached = self._artifact_cache.get(artifact_hash)
138
+ if cached:
139
+ return {
140
+ "result": f"Using cached artifact: {cached['artifact']['name']}",
141
+ "artifact": cached["artifact"],
142
+ }
143
+
144
+ artifact_payload = self._build_artifact_payload(
145
+ b64_data=artifact_b64,
146
+ name=artifact_name,
147
+ description=artifact_description,
148
+ mime=effective_mime,
149
+ )
150
+
151
+ response = {"result": result, "artifact": artifact_payload}
152
+
153
+ if enable_deduplication:
154
+ artifact_hash = self.generate_artifact_hash(artifact_b64, artifact_name, effective_mime)
155
+ self._artifact_cache[artifact_hash] = response
156
+
157
+ return response
158
+
159
+ def _infer_mime_type(self, artifact_name: str, override_mime_type: str | None) -> str:
160
+ """Return explicit MIME if provided; otherwise infer from filename.
161
+
162
+ Args:
163
+ artifact_name (str): The name of the artifact.
164
+ override_mime_type (str | None): The MIME type to override.
165
+
166
+ Returns:
167
+ str: The inferred MIME type.
168
+ """
169
+ return override_mime_type or get_mime_type_from_filename(artifact_name)
170
+
171
+ def _is_text_mime(self, mime: str) -> bool:
172
+ """Check whether a MIME type should be treated as text content.
173
+
174
+ Args:
175
+ mime (str): The MIME type to check.
176
+
177
+ Returns:
178
+ bool: True if the MIME type should be treated as text content, False otherwise.
179
+ """
180
+ return mime.startswith("text/") or mime == MimeType.APPLICATION_JSON
181
+
182
+ def _encode_to_base64(self, data: bytes | str, treat_as_text: bool) -> str:
183
+ """Encode data to base64 according to handling rules for text/binary.
184
+
185
+ - For text: always base64-encode UTF-8 bytes
186
+ - For binary: bytes are base64-encoded; str is assumed already base64
187
+
188
+ Args:
189
+ data (bytes | str): The data to encode.
190
+ treat_as_text (bool): Whether to treat the data as text.
191
+
192
+ Returns:
193
+ str: The base64 encoded data.
194
+ """
195
+ if treat_as_text:
196
+ if isinstance(data, str):
197
+ raw = data.encode("utf-8")
198
+ elif isinstance(data, bytes):
199
+ raw = data
200
+ else:
201
+ raise TypeError("data must be bytes or str")
202
+ return base64.b64encode(raw).decode("utf-8")
203
+
204
+ # binary path
205
+ if isinstance(data, bytes):
206
+ return base64.b64encode(data).decode("utf-8")
207
+ if isinstance(data, str):
208
+ return data
209
+ raise TypeError("data must be bytes or str")
210
+
211
+ def _build_artifact_payload(self, b64_data: str, name: str, description: str, mime: str) -> dict[str, Any]:
212
+ """Construct a validated artifact payload as a dict via the Artifact model.
213
+
214
+ Args:
215
+ b64_data (str): Base64 encoded data.
216
+ name (str): Artifact name.
217
+ description (str): Artifact description.
218
+ mime (str): MIME type.
219
+
220
+ Returns:
221
+ dict[str, Any]: Dictionary with 'artifact_type', 'data', 'name', 'description', and 'mime_type' keys.
222
+ """
223
+ metadata = None
224
+ if is_supported_image_mime(mime):
225
+ attachment = create_generated_image_attachment(
226
+ artifact_name=name,
227
+ mime_type=mime,
228
+ artifact_data=b64_data,
229
+ ).model_dump()
230
+ metadata = {
231
+ "attachment": attachment,
232
+ "attachment_registry": {attachment["id"]: attachment},
233
+ }
234
+ elif is_supported_document_mime(mime):
235
+ attachment = create_generated_document_attachment(
236
+ artifact_name=name,
237
+ mime_type=mime,
238
+ artifact_data=b64_data,
239
+ ).model_dump()
240
+ metadata = {
241
+ "attachment": attachment,
242
+ "attachment_registry": {attachment["id"]: attachment},
243
+ }
244
+
245
+ return Artifact(
246
+ artifact_type=ArtifactType.FILE,
247
+ data=b64_data,
248
+ name=name,
249
+ description=description,
250
+ mime_type=mime,
251
+ metadata=metadata,
252
+ ).model_dump()
253
+
254
+ def create_error_response(self, error_message: str) -> str:
255
+ """Create a standardized error response for tools.
256
+
257
+ Args:
258
+ error_message: The error message to return.
259
+
260
+ Returns:
261
+ String with error information.
262
+ """
263
+ return f"Error: {error_message}"
264
+
265
+ def clear_cache(self) -> None:
266
+ """Clear the artifact cache."""
267
+ self._artifact_cache.clear()
268
+
269
+ def get_cache_size(self) -> int:
270
+ """Get the number of cached artifacts.
271
+
272
+ Returns:
273
+ Number of artifacts in cache.
274
+ """
275
+ return len(self._artifact_cache)
276
+
277
+ @staticmethod
278
+ def generate_artifact_hash(artifact_data: str, name: str, mime_type: str) -> str:
279
+ """Generate a hash for artifact deduplication.
280
+
281
+ Args:
282
+ artifact_data: Base64 encoded artifact data.
283
+ name: Artifact name.
284
+ mime_type: MIME type.
285
+
286
+ Returns:
287
+ Hash string for deduplication.
288
+ """
289
+ content = f"{artifact_data}:{name}:{mime_type}"
290
+ return hashlib.sha256(content.encode()).hexdigest()
291
+
292
+
293
+ # Global instance for convenience
294
+ _default_handler = ArtifactHandler()
295
+
296
+
297
+ @deprecated(version="0.5.0", reason="Use create_artifact_command(...) which returns a Command update.")
298
+ def create_artifact_response( # noqa: PLR0913
299
+ result: str,
300
+ artifact_data: bytes | str,
301
+ artifact_name: str,
302
+ artifact_description: str = "",
303
+ mime_type: str | None = None,
304
+ ) -> dict[str, Any]:
305
+ r"""Create a standardized artifact response for tools.
306
+
307
+ This function creates a response that separates the agent-facing result
308
+ from the user-facing artifact, following the established pattern for
309
+ artifact generation in the agent system.
310
+
311
+ Args:
312
+ result: The message/result to show to the agent (clean, no file data).
313
+ artifact_data: The binary data or base64 string for the artifact.
314
+ artifact_name: The name for the artifact file.
315
+ artifact_description: Description of the artifact. Defaults to "".
316
+ mime_type: MIME type of the artifact. If None, will be auto-detected from filename.
317
+
318
+ Returns:
319
+ Dictionary with 'result' and 'artifacts' keys (artifacts is always a list).
320
+
321
+ Example:
322
+ >>> import io
323
+ >>> csv_data = "Name,Age\\nAlice,30\\nBob,25"
324
+ >>> response = create_artifact_response(
325
+ ... result="Generated a 2-row CSV table",
326
+ ... artifact_data=csv_data.encode('utf-8'),
327
+ ... artifact_name="data.csv",
328
+ ... artifact_description="Sample data table",
329
+ ... mime_type="text/csv"
330
+ ... )
331
+ >>> assert "result" in response
332
+ >>> assert "artifacts" in response
333
+ >>> assert isinstance(response["artifacts"], list)
334
+ """
335
+ single_artifact = _default_handler.create_artifact(
336
+ result=result,
337
+ data=artifact_data,
338
+ artifact_name=artifact_name,
339
+ artifact_description=artifact_description,
340
+ mime_type=mime_type,
341
+ enable_deduplication=False,
342
+ )
343
+
344
+ # Convert single artifact to list format
345
+ return {"result": single_artifact["result"], "artifacts": [single_artifact["artifact"]]}
346
+
347
+
348
+ @deprecated(version="0.5.0", reason="Use create_artifact_command(...) which handles text and binary.")
349
+ def create_text_artifact_response(
350
+ result: str,
351
+ artifact_text: str,
352
+ artifact_name: str,
353
+ artifact_description: str = "",
354
+ mime_type: str | None = None,
355
+ ) -> dict[str, Any]:
356
+ """Create a standardized artifact response for tools.
357
+
358
+ Args:
359
+ result: The message/result to show to the agent.
360
+ artifact_text: The text content for the artifact.
361
+ artifact_name: The name for the artifact file.
362
+ artifact_description: Description of the artifact.
363
+ mime_type: MIME type of the artifact. If None, will be auto-detected from filename.
364
+
365
+ Returns:
366
+ Dictionary with 'result' and 'artifacts' keys (artifacts is always a list).
367
+ """
368
+ return _default_handler.create_artifact(
369
+ result=result,
370
+ data=artifact_text,
371
+ artifact_name=artifact_name,
372
+ artifact_description=artifact_description,
373
+ mime_type=mime_type,
374
+ enable_deduplication=False,
375
+ )
376
+
377
+
378
+ @deprecated(version="0.5.0", reason="Use create_artifact_command(...) and compose updates instead of dict responses.")
379
+ def create_multiple_artifacts_response(result: str, artifacts: list[dict[str, Any]]) -> dict[str, Any]:
380
+ """Create a standardized response for multiple artifacts.
381
+
382
+ Args:
383
+ result: The message/result to show to the agent.
384
+ artifacts: List of artifact dictionaries.
385
+
386
+ Returns:
387
+ Dictionary with 'result' and 'artifacts' keys.
388
+ """
389
+ return {"result": result, "artifacts": artifacts}
390
+
391
+
392
+ def create_artifact_command( # noqa: PLR0913
393
+ result: str,
394
+ artifact_data: bytes | str,
395
+ artifact_name: str,
396
+ artifact_description: str = "",
397
+ mime_type: str | None = None,
398
+ metadata_update: dict[str, Any] | None = None,
399
+ ) -> Command:
400
+ """Create a Command that updates artifacts (and optional metadata).
401
+
402
+ Args:
403
+ result: Message/result to show to the agent (for ToolMessage content).
404
+ artifact_data: The binary data or base64 string for the artifact.
405
+ artifact_name: The name for the artifact file.
406
+ artifact_description: Description of the artifact.
407
+ mime_type: MIME type of the artifact. If None, auto-detected from filename.
408
+ metadata_update: Optional metadata delta to merge into state metadata.
409
+
410
+ Returns:
411
+ Command: A LangGraph Command with update containing 'result', 'artifacts', and optional 'metadata'.
412
+ """
413
+ single = _default_handler.create_artifact(
414
+ result=result,
415
+ data=artifact_data,
416
+ artifact_name=artifact_name,
417
+ artifact_description=artifact_description,
418
+ mime_type=mime_type,
419
+ enable_deduplication=False,
420
+ )
421
+ update: dict[str, Any] = {
422
+ "result": single["result"],
423
+ "artifacts": [single["artifact"]],
424
+ }
425
+ if metadata_update:
426
+ update["metadata"] = metadata_update
427
+ return Command(update=update)
428
+
429
+
430
+ def create_multiple_artifacts_command(
431
+ result: str,
432
+ artifacts: list[Artifact | dict[str, Any]] | None = None,
433
+ metadata_update: dict[str, Any] | None = None,
434
+ ) -> Command:
435
+ """Create a Command that updates multiple artifacts (and optional metadata).
436
+
437
+ The 'artifacts' list accepts mixed item types:
438
+ - Artifact: a typed artifact model (preferred). Will be converted via model_dump().
439
+ - dict: a prebuilt artifact dict ready for A2A.
440
+ - DataSpec dict: raw spec to build an artifact with keys:
441
+ {'data': bytes|str, 'artifact_name': str, 'artifact_description'?: str, 'mime_type'?: str}
442
+
443
+ Args:
444
+ result: Message/result to show to the agent.
445
+ artifacts: List of items (Artifact | dict) to attach or build.
446
+ metadata_update: Optional metadata delta to merge into state metadata.
447
+
448
+ Returns:
449
+ Command: A LangGraph Command with update containing 'result', 'artifacts', and optional 'metadata'.
450
+ """
451
+ built_artifacts: list[dict[str, Any]] = []
452
+ if not artifacts:
453
+ raise ValueError("At least one of 'artifacts' must be provided and non-empty")
454
+
455
+ for art in artifacts or []:
456
+ if isinstance(art, Artifact):
457
+ built_artifacts.append(art.model_dump())
458
+ elif isinstance(art, dict):
459
+ try:
460
+ validated = Artifact.model_validate(art)
461
+ except ValidationError as e:
462
+ raise ValueError(f"Invalid artifact dict: {e}") from e
463
+ built_artifacts.append(validated.model_dump())
464
+ else:
465
+ raise TypeError("artifacts items must be Artifact or dict")
466
+
467
+ update: dict[str, Any] = {"result": result, "artifacts": built_artifacts}
468
+ if metadata_update:
469
+ update["metadata"] = metadata_update
470
+ return Command(update=update)
471
+
472
+
473
+ def create_error_response(error_message: str) -> str:
474
+ """Create a standardized error response for tools.
475
+
476
+ For error cases, we return a simple string that will be passed directly
477
+ to the agent without any artifact processing.
478
+
479
+ Args:
480
+ error_message: The error message to return.
481
+
482
+ Returns:
483
+ String with error information.
484
+ """
485
+ return _default_handler.create_error_response(error_message)
486
+
487
+
488
+ def extract_artifacts_from_agent_response(result: Any) -> tuple[str, list[dict[str, Any]]]:
489
+ """Extract artifacts from agent response for delegation tools.
490
+
491
+ Args:
492
+ result: The result returned by the delegated agent.
493
+
494
+ Returns:
495
+ Tuple of (text_response, artifacts_list) where:
496
+ - text_response: The text content for the agent
497
+ - artifacts_list: List of artifacts to be passed through
498
+ """
499
+ if not isinstance(result, dict):
500
+ return str(result), []
501
+
502
+ text_response = result.get("output", str(result))
503
+ artifacts = result.get("full_final_state", {}).get("artifacts", [])
504
+
505
+ # Ensure artifacts is a list before returning
506
+ if not isinstance(artifacts, list):
507
+ artifacts = []
508
+
509
+ return str(text_response), artifacts
510
+
511
+
512
+ def create_delegation_response_with_artifacts(
513
+ result: str, artifacts: list[dict[str, Any]], agent_name: str = ""
514
+ ) -> Command:
515
+ """Create a delegation response that includes artifacts only when needed.
516
+
517
+ Args:
518
+ result: The text result from the delegated agent.
519
+ artifacts: List of artifacts from the delegated agent (always a list).
520
+ agent_name: Deprecated compatibility argument. Accepted but ignored;
521
+ delegation attribution is carried by structured metadata, not by
522
+ prefixing the result text.
523
+
524
+ Returns:
525
+ Command containing 'result' and optional 'artifacts'.
526
+ """
527
+ if agent_name:
528
+ import warnings
529
+
530
+ warnings.warn(
531
+ "agent_name is accepted for backward compatibility and ignored; "
532
+ "delegation attribution is no longer prefixed into result text.",
533
+ DeprecationWarning,
534
+ stacklevel=2,
535
+ )
536
+
537
+ formatted_result = result
538
+
539
+ update: dict[str, Any] = {"result": formatted_result}
540
+ if artifacts:
541
+ update["artifacts"] = artifacts
542
+ return Command(update=update)
@@ -0,0 +1,20 @@
1
+ """Artifact tracking and building utilities.
2
+
3
+ This module provides ArtifactTracker which uses the Strategy Pattern to
4
+ support different file watching mechanisms across backends (LocalDisk, E2B, etc.).
5
+
6
+ Authors:
7
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
8
+ """
9
+
10
+ from aip_agents.utils.artifacts.tracker import (
11
+ DEFAULT_ARTIFACT_EXTENSIONS,
12
+ DEFAULT_EXCLUDED_ARTIFACT_DIRS,
13
+ ArtifactTracker,
14
+ )
15
+
16
+ __all__ = [
17
+ "ArtifactTracker",
18
+ "DEFAULT_ARTIFACT_EXTENSIONS",
19
+ "DEFAULT_EXCLUDED_ARTIFACT_DIRS",
20
+ ]