@botpress/adk 1.18.3 → 1.19.0-beta.11

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 (299) hide show
  1. package/dist/agent-init/agent-project-generator.d.ts +10 -7
  2. package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
  3. package/dist/agent-project/agent-project.d.ts +1 -1
  4. package/dist/agent-project/agent-project.d.ts.map +1 -1
  5. package/dist/agent-project/component-files.d.ts +10 -0
  6. package/dist/agent-project/component-files.d.ts.map +1 -0
  7. package/dist/agent-project/component-index-writer.d.ts +22 -0
  8. package/dist/agent-project/component-index-writer.d.ts.map +1 -0
  9. package/dist/agent-project/config-writer.d.ts +5 -0
  10. package/dist/agent-project/config-writer.d.ts.map +1 -1
  11. package/dist/agent-project/dependencies-parser.d.ts.map +1 -1
  12. package/dist/agent-project/file-watcher.d.ts.map +1 -1
  13. package/dist/agent-project/index.d.ts +3 -0
  14. package/dist/agent-project/index.d.ts.map +1 -1
  15. package/dist/agent-project/lock-to-dependencies.d.ts +11 -0
  16. package/dist/agent-project/lock-to-dependencies.d.ts.map +1 -0
  17. package/dist/agent-project/types.d.ts +1 -0
  18. package/dist/agent-project/types.d.ts.map +1 -1
  19. package/dist/agent-project/validation-errors.d.ts +1 -0
  20. package/dist/agent-project/validation-errors.d.ts.map +1 -1
  21. package/dist/agent0/capabilities/commands/adk-build.md +39 -0
  22. package/dist/agent0/capabilities/commands/adk-debug.md +23 -0
  23. package/dist/agent0/capabilities/commands/adk-dev-console.md +17 -0
  24. package/dist/agent0/capabilities/commands/adk-document.md +68 -0
  25. package/dist/agent0/capabilities/commands/adk-eval.md +17 -0
  26. package/dist/agent0/capabilities/commands/adk-explain.md +22 -0
  27. package/dist/agent0/capabilities/commands/adk-init.md +30 -0
  28. package/dist/agent0/capabilities/commands/adk-ship.md +29 -0
  29. package/dist/agent0/capabilities/commands/adk-test.md +27 -0
  30. package/dist/agent0/capabilities/commands/adk-validate.md +31 -0
  31. package/dist/agent0/capabilities/skills/adk/SKILL.md +548 -0
  32. package/dist/agent0/capabilities/skills/adk/references/actions.md +823 -0
  33. package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +669 -0
  34. package/dist/agent0/capabilities/skills/adk/references/agent-config.md +450 -0
  35. package/dist/agent0/capabilities/skills/adk/references/assets.md +237 -0
  36. package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +747 -0
  37. package/dist/agent0/capabilities/skills/adk/references/cli.md +1334 -0
  38. package/dist/agent0/capabilities/skills/adk/references/context-api.md +461 -0
  39. package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +311 -0
  40. package/dist/agent0/capabilities/skills/adk/references/conversations.md +1111 -0
  41. package/dist/agent0/capabilities/skills/adk/references/custom-components.md +167 -0
  42. package/dist/agent0/capabilities/skills/adk/references/desk.md +852 -0
  43. package/dist/agent0/capabilities/skills/adk/references/evals.md +11 -0
  44. package/dist/agent0/capabilities/skills/adk/references/explain-config.md +424 -0
  45. package/dist/agent0/capabilities/skills/adk/references/files.md +918 -0
  46. package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +659 -0
  47. package/dist/agent0/capabilities/skills/adk/references/integrations.md +266 -0
  48. package/dist/agent0/capabilities/skills/adk/references/interfaces.md +97 -0
  49. package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +456 -0
  50. package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +112 -0
  51. package/dist/agent0/capabilities/skills/adk/references/messages.md +769 -0
  52. package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +201 -0
  53. package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +469 -0
  54. package/dist/agent0/capabilities/skills/adk/references/plugins.md +280 -0
  55. package/dist/agent0/capabilities/skills/adk/references/tables.md +1136 -0
  56. package/dist/agent0/capabilities/skills/adk/references/tags.md +516 -0
  57. package/dist/agent0/capabilities/skills/adk/references/tools.md +581 -0
  58. package/dist/agent0/capabilities/skills/adk/references/triggers.md +719 -0
  59. package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +851 -0
  60. package/dist/agent0/capabilities/skills/adk/references/workflows.md +1408 -0
  61. package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +454 -0
  62. package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +1408 -0
  63. package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +257 -0
  64. package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +231 -0
  65. package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +420 -0
  66. package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +239 -0
  67. package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +209 -0
  68. package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +313 -0
  69. package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +203 -0
  70. package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +111 -0
  71. package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +115 -0
  72. package/dist/agent0/capabilities/skills/adk-dev-console/references/component-registry.md +43 -0
  73. package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +70 -0
  74. package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +273 -0
  75. package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +114 -0
  76. package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +124 -0
  77. package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +244 -0
  78. package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +354 -0
  79. package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +355 -0
  80. package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +225 -0
  81. package/dist/agent0/config/index.d.ts +5 -0
  82. package/dist/agent0/config/index.d.ts.map +1 -0
  83. package/dist/agent0/config/paths.d.ts +12 -0
  84. package/dist/agent0/config/paths.d.ts.map +1 -0
  85. package/dist/agent0/config/schema.d.ts +171 -0
  86. package/dist/agent0/config/schema.d.ts.map +1 -0
  87. package/dist/agent0/config/secrets.d.ts +4 -0
  88. package/dist/agent0/config/secrets.d.ts.map +1 -0
  89. package/dist/agent0/config/store.d.ts +26 -0
  90. package/dist/agent0/config/store.d.ts.map +1 -0
  91. package/dist/agent0/index.d.ts +6 -0
  92. package/dist/agent0/index.d.ts.map +1 -0
  93. package/dist/agent0/index.js +3381 -0
  94. package/dist/agent0/index.js.map +29 -0
  95. package/dist/agent0/providers/catalog.d.ts +189 -0
  96. package/dist/agent0/providers/catalog.d.ts.map +1 -0
  97. package/dist/agent0/providers/index.d.ts +4 -0
  98. package/dist/agent0/providers/index.d.ts.map +1 -0
  99. package/dist/agent0/providers/registry.d.ts +32 -0
  100. package/dist/agent0/providers/registry.d.ts.map +1 -0
  101. package/dist/agent0/providers/source.d.ts +105 -0
  102. package/dist/agent0/providers/source.d.ts.map +1 -0
  103. package/dist/agent0/runtime/client.d.ts +49 -0
  104. package/dist/agent0/runtime/client.d.ts.map +1 -0
  105. package/dist/agent0/runtime/engine.d.ts +79 -0
  106. package/dist/agent0/runtime/engine.d.ts.map +1 -0
  107. package/dist/agent0/runtime/index.d.ts +7 -0
  108. package/dist/agent0/runtime/index.d.ts.map +1 -0
  109. package/dist/agent0/runtime/manager.d.ts +81 -0
  110. package/dist/agent0/runtime/manager.d.ts.map +1 -0
  111. package/dist/agent0/runtime/permissions.d.ts +6 -0
  112. package/dist/agent0/runtime/permissions.d.ts.map +1 -0
  113. package/dist/agent0/runtime/process.d.ts +52 -0
  114. package/dist/agent0/runtime/process.d.ts.map +1 -0
  115. package/dist/agent0/runtime/project-discovery.d.ts +5 -0
  116. package/dist/agent0/runtime/project-discovery.d.ts.map +1 -0
  117. package/dist/agent0/types.d.ts +447 -0
  118. package/dist/agent0/types.d.ts.map +1 -0
  119. package/dist/assets/manager.d.ts +0 -2
  120. package/dist/assets/manager.d.ts.map +1 -1
  121. package/dist/assets/types.d.ts +3 -1
  122. package/dist/assets/types.d.ts.map +1 -1
  123. package/dist/auth/credentials.d.ts.map +1 -1
  124. package/dist/auth/index.d.ts +30 -0
  125. package/dist/auth/index.d.ts.map +1 -1
  126. package/dist/auth/service.d.ts.map +1 -1
  127. package/dist/bot-generator/dev-id-manager.d.ts.map +1 -1
  128. package/dist/bot-generator/generator.d.ts +5 -1
  129. package/dist/bot-generator/generator.d.ts.map +1 -1
  130. package/dist/bot-generator/integration-sync.d.ts +2 -0
  131. package/dist/bot-generator/integration-sync.d.ts.map +1 -1
  132. package/dist/bot-generator/interface-sync.d.ts +2 -0
  133. package/dist/bot-generator/interface-sync.d.ts.map +1 -1
  134. package/dist/bot-generator/plugin-sync.d.ts +2 -0
  135. package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
  136. package/dist/bot-generator/table-validation.d.ts +17 -0
  137. package/dist/bot-generator/table-validation.d.ts.map +1 -0
  138. package/dist/chat-bundle.cjs +31 -0
  139. package/dist/cognitive/models.d.ts +32 -0
  140. package/dist/cognitive/models.d.ts.map +1 -0
  141. package/dist/commands/base-command.d.ts +1 -0
  142. package/dist/commands/base-command.d.ts.map +1 -1
  143. package/dist/commands/bp-add-command.d.ts.map +1 -1
  144. package/dist/commands/bp-build-command.d.ts.map +1 -1
  145. package/dist/commands/bp-chat-command.d.ts.map +1 -1
  146. package/dist/commands/bp-cli.d.ts +1 -0
  147. package/dist/commands/bp-cli.d.ts.map +1 -1
  148. package/dist/commands/bp-cli.js +147 -0
  149. package/dist/commands/bp-cli.js.map +12 -0
  150. package/dist/commands/bp-deploy-command.d.ts.map +1 -1
  151. package/dist/commands/bp-dev-command.d.ts +7 -0
  152. package/dist/commands/bp-dev-command.d.ts.map +1 -1
  153. package/dist/commands/bp-dev-stderr.d.ts +21 -0
  154. package/dist/commands/bp-dev-stderr.d.ts.map +1 -0
  155. package/dist/commands/bp-dev-worker-env.d.ts +7 -0
  156. package/dist/commands/bp-dev-worker-env.d.ts.map +1 -0
  157. package/dist/commands/index.d.ts +0 -5
  158. package/dist/commands/index.d.ts.map +1 -1
  159. package/dist/config/manager.d.ts +9 -1
  160. package/dist/config/manager.d.ts.map +1 -1
  161. package/dist/constants.d.ts +1 -0
  162. package/dist/constants.d.ts.map +1 -1
  163. package/dist/dependencies/alias-utils.d.ts +13 -0
  164. package/dist/dependencies/alias-utils.d.ts.map +1 -0
  165. package/dist/dependencies/dependency-manager.d.ts +89 -0
  166. package/dist/dependencies/dependency-manager.d.ts.map +1 -0
  167. package/dist/dependencies/errors.d.ts +19 -0
  168. package/dist/dependencies/errors.d.ts.map +1 -0
  169. package/dist/dependencies/index.d.ts +17 -0
  170. package/dist/dependencies/index.d.ts.map +1 -0
  171. package/dist/dependencies/index.js +6233 -0
  172. package/dist/dependencies/index.js.map +61 -0
  173. package/dist/dependencies/json-utils.d.ts +3 -0
  174. package/dist/dependencies/json-utils.d.ts.map +1 -0
  175. package/dist/dependencies/lock-file.d.ts +15 -0
  176. package/dist/dependencies/lock-file.d.ts.map +1 -0
  177. package/dist/dependencies/migration.d.ts +8 -0
  178. package/dist/dependencies/migration.d.ts.map +1 -0
  179. package/dist/dependencies/registry/integration-registry.d.ts +17 -0
  180. package/dist/dependencies/registry/integration-registry.d.ts.map +1 -0
  181. package/dist/dependencies/registry/interface-registry.d.ts +11 -0
  182. package/dist/dependencies/registry/interface-registry.d.ts.map +1 -0
  183. package/dist/dependencies/registry/plugin-registry.d.ts +16 -0
  184. package/dist/dependencies/registry/plugin-registry.d.ts.map +1 -0
  185. package/dist/dependencies/resolvers/integration-resolver.d.ts +30 -0
  186. package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -0
  187. package/dist/dependencies/resolvers/plugin-resolver.d.ts +38 -0
  188. package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -0
  189. package/dist/dependencies/types.d.ts +254 -0
  190. package/dist/dependencies/types.d.ts.map +1 -0
  191. package/dist/deploy-manifest/index.d.ts +608 -0
  192. package/dist/deploy-manifest/index.d.ts.map +1 -0
  193. package/dist/file-watcher/watcher.d.ts +21 -5
  194. package/dist/file-watcher/watcher.d.ts.map +1 -1
  195. package/dist/generators/action-types.d.ts.map +1 -1
  196. package/dist/generators/assets.d.ts +2 -2
  197. package/dist/generators/assets.d.ts.map +1 -1
  198. package/dist/generators/client-wrapper.d.ts.map +1 -1
  199. package/dist/generators/tests.d.ts +6 -6
  200. package/dist/generators/tests.d.ts.map +1 -1
  201. package/dist/generators/utils.d.ts.map +1 -1
  202. package/dist/index.d.ts +15 -12
  203. package/dist/index.d.ts.map +1 -1
  204. package/dist/index.js +17614 -5514
  205. package/dist/index.js.map +83 -66
  206. package/dist/integrations/config-utils.d.ts.map +1 -1
  207. package/dist/integrations/hub-cache.d.ts.map +1 -1
  208. package/dist/integrations/index.d.ts +0 -6
  209. package/dist/integrations/index.d.ts.map +1 -1
  210. package/dist/integrations/manager.d.ts +17 -1
  211. package/dist/integrations/manager.d.ts.map +1 -1
  212. package/dist/interfaces/index.d.ts +0 -2
  213. package/dist/interfaces/index.d.ts.map +1 -1
  214. package/dist/interfaces/manager.d.ts +3 -1
  215. package/dist/interfaces/manager.d.ts.map +1 -1
  216. package/dist/interfaces/parser.d.ts.map +1 -1
  217. package/dist/knowledge/manager.d.ts +3 -1
  218. package/dist/knowledge/manager.d.ts.map +1 -1
  219. package/dist/knowledge/types.d.ts +2 -2
  220. package/dist/knowledge/types.d.ts.map +1 -1
  221. package/dist/plugins/manager.d.ts +34 -1
  222. package/dist/plugins/manager.d.ts.map +1 -1
  223. package/dist/preflight/checker.d.ts +5 -6
  224. package/dist/preflight/checker.d.ts.map +1 -1
  225. package/dist/preflight/index.d.ts +2 -2
  226. package/dist/preflight/index.d.ts.map +1 -1
  227. package/dist/preflight/types.d.ts +30 -32
  228. package/dist/preflight/types.d.ts.map +1 -1
  229. package/dist/runner/script-runner.d.ts +2 -0
  230. package/dist/runner/script-runner.d.ts.map +1 -1
  231. package/dist/runner/supervise-child.d.ts +24 -0
  232. package/dist/runner/supervise-child.d.ts.map +1 -0
  233. package/dist/secrets/manager.d.ts.map +1 -1
  234. package/dist/tables/table-manager.d.ts.map +1 -1
  235. package/dist/tables/types.d.ts +3 -2
  236. package/dist/tables/types.d.ts.map +1 -1
  237. package/dist/templates/README.md +14 -13
  238. package/dist/templates/blank/agent.config.ts +0 -3
  239. package/dist/templates/blank/evals/index.eval.ts +30 -0
  240. package/dist/templates/blank/src/conversations/index.ts +16 -16
  241. package/dist/templates/blank/tsconfig.json +1 -1
  242. package/dist/templates/botpress-desk/README.md +87 -0
  243. package/dist/templates/botpress-desk/agent.config.ts +19 -0
  244. package/dist/templates/botpress-desk/evals/index.eval.ts +30 -0
  245. package/dist/templates/botpress-desk/package.json +17 -0
  246. package/dist/templates/botpress-desk/src/actions/index.ts +19 -0
  247. package/dist/templates/botpress-desk/src/conversations/index.ts +16 -0
  248. package/dist/templates/botpress-desk/src/knowledge/index.ts +20 -0
  249. package/dist/templates/botpress-desk/src/tables/index.ts +16 -0
  250. package/dist/templates/botpress-desk/src/tools/handToSupport.ts +23 -0
  251. package/dist/templates/botpress-desk/src/triggers/index.ts +17 -0
  252. package/dist/templates/botpress-desk/src/workflows/index.ts +21 -0
  253. package/dist/templates/crm-enrichment/agent.config.ts +0 -3
  254. package/dist/templates/crm-enrichment/evals/example.eval.ts +29 -0
  255. package/dist/templates/crm-enrichment/package.json +1 -0
  256. package/dist/templates/crm-enrichment/tsconfig.json +1 -1
  257. package/dist/templates/hello-world/agent.config.ts +0 -3
  258. package/dist/templates/hello-world/evals/context-retention.eval.ts +37 -0
  259. package/dist/templates/hello-world/evals/greeting.eval.ts +43 -0
  260. package/dist/templates/hello-world/package.json +1 -0
  261. package/dist/templates/hello-world/tsconfig.json +1 -1
  262. package/dist/templates/knowledge-assistant/agent.config.ts +0 -3
  263. package/dist/templates/knowledge-assistant/evals/engineering-practices.eval.ts +45 -0
  264. package/dist/templates/knowledge-assistant/evals/out-of-scope.eval.ts +33 -0
  265. package/dist/templates/knowledge-assistant/evals/pto-policy.eval.ts +44 -0
  266. package/dist/templates/knowledge-assistant/package.json +1 -0
  267. package/dist/templates/knowledge-assistant/tsconfig.json +1 -1
  268. package/dist/templates/slack-triage/agent.config.ts +0 -8
  269. package/dist/templates/slack-triage/evals/triage-basic.eval.ts +9 -39
  270. package/dist/templates/slack-triage/package.json +1 -0
  271. package/dist/templates/slack-triage/src/conversations/slack-dm.ts +4 -1
  272. package/dist/templates/slack-triage/tsconfig.json +1 -1
  273. package/dist/templates/template.config.json +16 -16
  274. package/dist/test-utils/mock-module.d.ts +29 -0
  275. package/dist/test-utils/mock-module.d.ts.map +1 -0
  276. package/dist/utils/require-chat.d.ts +3 -24
  277. package/dist/utils/require-chat.d.ts.map +1 -1
  278. package/dist/utils/search-ranking.d.ts +15 -0
  279. package/dist/utils/search-ranking.d.ts.map +1 -0
  280. package/dist/utils/source-map-optimizer.d.ts +10 -11
  281. package/dist/utils/source-map-optimizer.d.ts.map +1 -1
  282. package/dist/workspace/workspace-cache.d.ts.map +1 -1
  283. package/package.json +23 -11
  284. package/dist/commands/copilot-config-reader.d.ts +0 -12
  285. package/dist/commands/copilot-config-reader.d.ts.map +0 -1
  286. package/dist/commands/copilot-server.d.ts +0 -26
  287. package/dist/commands/copilot-server.d.ts.map +0 -1
  288. package/dist/commands/opencode-config.d.ts +0 -29
  289. package/dist/commands/opencode-config.d.ts.map +0 -1
  290. package/dist/integrations/checker.d.ts +0 -41
  291. package/dist/integrations/checker.d.ts.map +0 -1
  292. package/dist/integrations/operations.d.ts +0 -140
  293. package/dist/integrations/operations.d.ts.map +0 -1
  294. package/dist/integrations/sync-manager.d.ts +0 -19
  295. package/dist/integrations/sync-manager.d.ts.map +0 -1
  296. package/dist/interfaces/operations.d.ts +0 -48
  297. package/dist/interfaces/operations.d.ts.map +0 -1
  298. package/dist/preflight/formatter.d.ts +0 -12
  299. package/dist/preflight/formatter.d.ts.map +0 -1
@@ -0,0 +1,209 @@
1
+ # LLM Behavior Debugging
2
+
3
+ When the bot's code runs fine but the LLM makes bad decisions — wrong tools, fabricated data, refusals, or loops. These issues live in the model's reasoning, not in your runtime code.
4
+
5
+ Always use `adk traces --format json` to inspect `think` and `tool_call` spans.
6
+
7
+ ---
8
+
9
+ ## 1. Wrong Tool Selected
10
+
11
+ **Symptom:** The model picks a different tool than expected for the user's request.
12
+
13
+ **How to diagnose:**
14
+
15
+ ```bash
16
+ adk traces --format json
17
+ ```
18
+
19
+ 1. Find the `think` span before the `tool_call` — this shows the model's reasoning
20
+ 2. Compare the tool it chose vs the tool you expected
21
+ 3. Read both tools' `description` fields — is the wrong tool's description a better match for the input?
22
+
23
+ **Common causes:**
24
+
25
+ - Tool descriptions are too similar or ambiguous
26
+ - The correct tool's description doesn't clearly cover the use case
27
+ - Too many tools available — the model gets confused with a large tool set
28
+
29
+ **Fixes:**
30
+
31
+ - **Sharpen descriptions:** Make each tool's purpose unambiguous. Include what the tool does NOT do.
32
+ - **Add negative examples:** "Do NOT use this tool for X — use Y instead."
33
+ - **Reduce tool count:** If tools are rarely used, consider consolidating or removing them
34
+ - **Last resort, use `confirm: true`:** Require user confirmation before executing, giving the user a chance to correct
35
+
36
+ ---
37
+
38
+ ## 2. Hallucinated Parameters
39
+
40
+ **Symptom:** The model invokes the right tool but fills in parameter values that the user never provided.
41
+
42
+ **How to diagnose:**
43
+
44
+ ```bash
45
+ adk traces --format json
46
+ ```
47
+
48
+ Check the `tool_call` span's `input` field against what the user actually said.
49
+
50
+ **Common causes:**
51
+
52
+ - Input schema is too loose (e.g., free-form `z.string()` where `z.enum()` would be better)
53
+ - No validation in the handler — the hallucinated value passes through
54
+ - The model infers values from context that don't exist
55
+
56
+ **Fixes:**
57
+
58
+ - **Tighten input schemas:** Use `z.enum()` for known values, add `.describe()` to clarify what each field expects
59
+ - **Add handler validation:** Check that input values make sense before using them
60
+ - **Last resort, require confirmation:** Set `confirm: true` on the tool so the user sees parameters before execution
61
+
62
+ ---
63
+
64
+ ## 3. Refusal
65
+
66
+ **Symptom:** The model refuses to perform an action, saying it can't or shouldn't do something.
67
+
68
+ **How to diagnose:**
69
+
70
+ ```bash
71
+ adk traces --format json
72
+ ```
73
+
74
+ Check `think` spans for safety-related reasoning. The model may cite content policy, uncertainty, or ethical concerns.
75
+
76
+ **Common causes:**
77
+
78
+ - The system prompt or instructions don't explicitly authorize the action
79
+ - The tool description sounds potentially harmful or sensitive
80
+ - The user's request is ambiguous and the model errs on the side of caution
81
+
82
+ **Fixes:**
83
+
84
+ - **Update instructions:** Explicitly authorize the actions in your conversation's `instructions` field
85
+ - **Soften tool descriptions:** Remove language that sounds risky (e.g., "delete all" → "remove selected")
86
+ - **Check `confirm` settings:** If `confirm: true` is set, the model knows the user will approve — make sure instructions reflect this
87
+
88
+ ---
89
+
90
+ ## 4. Token Limit Issues
91
+
92
+ **Symptom:** The model's responses are truncated, it loses context from earlier in the conversation, or it starts repeating itself.
93
+
94
+ **How to diagnose:**
95
+
96
+ - Long conversations with many turns
97
+ - Large tool outputs filling the context window
98
+ - `adk traces --format json` may show degraded reasoning in later `think` spans
99
+
100
+ **Common causes:**
101
+
102
+ - Conversation history is too long — no pruning or summarization
103
+ - Tool outputs are large (e.g., full database dumps, long API responses)
104
+ - Model configuration doesn't match the conversation's needs
105
+
106
+ **Fixes:**
107
+
108
+ - **Check model configuration:** Verify model settings in `agent.config.ts` — consider using a model with a larger context window
109
+ - **Trim tool outputs:** Return only what the model needs, not everything
110
+ - **Summarize long conversations:** Use Zai to summarize earlier turns before they fill the window
111
+ - **Use `maxIterations`:** Set a reasonable limit on agent iterations to prevent runaway conversations
112
+
113
+ ---
114
+
115
+ ## 5. Poor Extraction Quality
116
+
117
+ **Symptom:** Using `adk.zai.extract()` or similar `zai` operations returns incorrect or incomplete structured data.
118
+
119
+ **Common causes:**
120
+
121
+ - Schema descriptions are vague — the model doesn't know what each field means
122
+ - Input text is ambiguous or poorly formatted
123
+ - Wrong model for the task — some models extract better than others
124
+
125
+ **Fixes:**
126
+
127
+ - **Improve schema descriptions:** Add `.describe()` to every field with clear, specific descriptions
128
+ - **Provide examples:** Show the model what good output looks like
129
+ - **Try a different model:** Some models handle extraction better; check model configuration
130
+ - **Pre-process input:** Clean up or normalize the text before extraction
131
+ - See the **Edge Cases & Gotchas** section in [zai-agent-reference.md](../../adk/references/zai-agent-reference.md) for common pitfalls like hallucinated fields and chunk-window issues
132
+
133
+ ---
134
+
135
+ ## 6. Looping
136
+
137
+ **Symptom:** The model calls the same tool repeatedly, or cycles between tools without making progress.
138
+
139
+ **How to diagnose:**
140
+
141
+ ```bash
142
+ adk traces --format json
143
+ ```
144
+
145
+ Look for repeated `tool_call` spans with the same `tool_name` in sequence.
146
+
147
+ **Common causes:**
148
+
149
+ - Tool output doesn't clearly indicate success or completion — the model retries
150
+ - Instructions are ambiguous about when to stop
151
+ - The tool fails silently (returns empty/null) and the model keeps trying
152
+ - No iteration limit set
153
+
154
+ **Fixes:**
155
+
156
+ - **Improve tool output clarity:** Return clear success/failure messages that tell the model it's done
157
+ - **Add `onBeforeTool` guardrail:** Detect repeated calls and abort
158
+
159
+ ```typescript
160
+ // Create per-conversation to avoid leaking state across turns
161
+ const makeLoopGuard = () => {
162
+ const seen = new Set<string>();
163
+ const onBeforeTool: Autonomous.Hooks["onBeforeTool"] = async ({ tool, input, controller }) => {
164
+ const key = `${tool.name}:${JSON.stringify(input)}`;
165
+ if (seen.has(key)) {
166
+ controller.abort("Already called this tool with these parameters");
167
+ return;
168
+ }
169
+ seen.add(key);
170
+ };
171
+ return { onBeforeTool };
172
+ };
173
+ ```
174
+
175
+ - **Set `maxIterations`:** Limit how many tool calls the agent can make per turn
176
+ - **Check instructions:** Add explicit stopping criteria ("after completing X, respond to the user")
177
+
178
+ ---
179
+
180
+ ## 7. Reading Model Reasoning
181
+
182
+ The `think` span type captures the model's internal reasoning before it acts. This is the most valuable debugging tool for LLM behavior issues.
183
+
184
+ **How to access:**
185
+
186
+ ```bash
187
+ # Via CLI
188
+ adk traces --format json
189
+ # Look for spans with type "think" — the "content" field has the reasoning
190
+ ```
191
+
192
+ **Via `onTrace` hook in code:**
193
+
194
+ ```typescript
195
+ const onTrace: Autonomous.Hooks["onTrace"] = ({ trace }) => {
196
+ if (trace.type === "think") {
197
+ console.debug(`[MODEL REASONING] ${trace.content}`);
198
+ }
199
+ };
200
+ ```
201
+
202
+ **What to look for:**
203
+
204
+ - Does the model correctly understand the user's intent?
205
+ - Does it consider the right tools?
206
+ - Does it have accurate context about the conversation state?
207
+ - Is it making assumptions that aren't supported by the input?
208
+
209
+ If the reasoning is wrong, the fix is usually in the instructions, tool descriptions, or the information available to the model — not in the code.
@@ -0,0 +1,313 @@
1
+ # Trace Summarization
2
+
3
+ How to fetch a trace, walk its span tree, and produce a free-form natural-language summary of what happened. The goal is a synthesized narrative, not a raw dump of span data.
4
+
5
+ ---
6
+
7
+ ## Fetching Trace Data
8
+
9
+ Use the `adk traces` CLI with filters to get the raw data.
10
+
11
+ ```bash
12
+ # Full trace with LLM reasoning included
13
+ adk traces trace=<trace-id> --include-llm --format json
14
+
15
+ # All traces for a conversation
16
+ adk traces conversation=<id> --include-llm --format json
17
+
18
+ # Recent traces (start here if you don't have an ID)
19
+ adk traces --include-llm --format json
20
+ ```
21
+
22
+ **Always pass `--include-llm`** when summarizing. Without it, `think` spans are omitted and you lose the model's reasoning, which is essential for explaining *why* the agent did what it did.
23
+
24
+ **Always pass `--format json`** for structured, parseable output.
25
+
26
+ ---
27
+
28
+ ## Reading the Span Tree
29
+
30
+ Traces contain a flat list of spans, but spans form a parent-child hierarchy via `parentSpanId`. To summarize effectively, reconstruct the tree.
31
+
32
+ ### Span hierarchy (typical)
33
+
34
+ ```
35
+ handler.conversation (or handler.workflow, handler.action)
36
+ └─ autonomous.execution
37
+ └─ autonomous.iteration (one per LLM turn)
38
+ ├─ cognitive.request (the LLM call)
39
+ ├─ think (model reasoning)
40
+ ├─ tool_call (tool invocation)
41
+ │ └─ autonomous.tool (tool execution detail)
42
+ ├─ tool_call (another tool)
43
+ ├─ code_execution_exception (if something broke)
44
+ └─ end (turn complete)
45
+ ```
46
+
47
+ ### How to walk it
48
+
49
+ 1. **Find the root span** -- the span with no `parentSpanId`, or the handler span (`handler.conversation`, `handler.workflow`, `handler.action`). This tells you what triggered the trace.
50
+ 2. **Walk children in chronological order** by `startTime`. Each child span is a step in the agent's behavior.
51
+ 3. **Group by iteration** -- `autonomous.iteration` spans each represent one LLM turn. Within each iteration, look for the `think` -> `tool_call` -> `end` sequence.
52
+ 4. **Follow errors upward** -- if a `code_execution_exception` or failed `tool_call` appears, check its parent iteration and the subsequent iteration to see how the agent recovered (or didn't).
53
+
54
+ ### Key fields per span type
55
+
56
+ | Span Type | Fields to Read | What They Tell You |
57
+ |-----------|---------------|-------------------|
58
+ | `handler.conversation` | `context.conversationId`, `context.userId` | What triggered the trace (incoming message) |
59
+ | `handler.workflow` | `name`, `context` | Which workflow was invoked |
60
+ | `handler.action` | `name`, `context` | Which action was called |
61
+ | `autonomous.iteration` | `data.iterationIndex` | Which LLM turn this is (0-indexed) |
62
+ | `cognitive.request` | `data.model`, `data.tokens` | Which model was used, token counts |
63
+ | `think` | `data.content` | The LLM's reasoning -- why it chose an action |
64
+ | `tool_call` | `data.tool_name`, `data.input`, `data.output`, `status`, `data.error` | What tool was called, with what, and what happened |
65
+ | `code_execution_exception` | `data.message`, `data.stackTrace` | Runtime error in the LLMz sandbox |
66
+ | `end` | `data.response` | What the agent said back to the user |
67
+
68
+ ---
69
+
70
+ ## Producing a Summary
71
+
72
+ Do **not** use a fixed template. Write a natural-language narrative that reads like a concise incident report or activity log. Cover these aspects in whatever order makes the most sense for the specific trace:
73
+
74
+ ### What to cover
75
+
76
+ 1. **The trigger** -- What started this trace? An incoming user message? A workflow invocation? A scheduled trigger? Extract this from the root span type and context.
77
+
78
+ 2. **The LLM's plan** -- What did the model decide to do and why? Synthesize from `think` spans. Don't quote them verbatim unless a specific phrase is important -- paraphrase the reasoning.
79
+
80
+ 3. **Tool calls and their outcomes** -- Which tools were called, with what key inputs, and what happened? For successful calls, note what was returned if relevant. For failures, state the error clearly.
81
+
82
+ 4. **Errors and recovery** -- Were there exceptions? Did the agent retry or give up? What was the error message? If the agent recovered, explain how.
83
+
84
+ 5. **The outcome** -- What was the final result? What did the agent respond with? Did the conversation turn succeed or fail?
85
+
86
+ 6. **Performance** -- Only mention if relevant (e.g., unusually slow, many iterations, high token usage). Don't include timing details for normal traces.
87
+
88
+ ### Adapting depth to context
89
+
90
+ The summary depth should match what the developer is asking:
91
+
92
+ | Developer Question | Summary Depth |
93
+ |-------------------|---------------|
94
+ | "What happened?" / "Summarize this trace" | **Brief** -- 3-5 sentences covering trigger, actions taken, outcome |
95
+ | "Why did it do X?" / "Why did the bot call tool Y?" | **Focused** -- Zoom into the relevant `think` span and the tool call, explain the reasoning chain |
96
+ | "What went wrong?" / "Why did this fail?" | **Diagnostic** -- Focus on the error path: what led to the failure, what the error was, whether recovery was attempted |
97
+ | "Walk me through the whole trace" | **Detailed** -- Full chronological narrative covering every iteration and tool call |
98
+
99
+ ---
100
+
101
+ ## Examples
102
+
103
+ ### Sample trace data (abbreviated)
104
+
105
+ ```json
106
+ {
107
+ "traceId": "tr_01J5EXAMPLE",
108
+ "spans": [
109
+ {
110
+ "spanId": "sp_001",
111
+ "name": "handler.conversation",
112
+ "startTime": "2026-04-21T14:00:00.000Z",
113
+ "endTime": "2026-04-21T14:00:03.200Z",
114
+ "status": "ok",
115
+ "context": {
116
+ "conversationId": "conv_abc123",
117
+ "userId": "user_xyz"
118
+ }
119
+ },
120
+ {
121
+ "spanId": "sp_002",
122
+ "parentSpanId": "sp_001",
123
+ "name": "autonomous.execution",
124
+ "startTime": "2026-04-21T14:00:00.050Z",
125
+ "endTime": "2026-04-21T14:00:03.100Z",
126
+ "status": "ok"
127
+ },
128
+ {
129
+ "spanId": "sp_003",
130
+ "parentSpanId": "sp_002",
131
+ "name": "autonomous.iteration",
132
+ "startTime": "2026-04-21T14:00:00.100Z",
133
+ "endTime": "2026-04-21T14:00:02.800Z",
134
+ "status": "ok",
135
+ "data": { "iterationIndex": 0 }
136
+ },
137
+ {
138
+ "spanId": "sp_004",
139
+ "parentSpanId": "sp_003",
140
+ "name": "think",
141
+ "startTime": "2026-04-21T14:00:00.200Z",
142
+ "data": {
143
+ "content": "The user is asking for the status of order #4521. I should look this up using the lookupOrder tool with the order ID."
144
+ }
145
+ },
146
+ {
147
+ "spanId": "sp_005",
148
+ "parentSpanId": "sp_003",
149
+ "name": "tool_call",
150
+ "startTime": "2026-04-21T14:00:00.500Z",
151
+ "endTime": "2026-04-21T14:00:01.200Z",
152
+ "status": "ok",
153
+ "data": {
154
+ "tool_name": "lookupOrder",
155
+ "input": { "orderId": "4521" },
156
+ "output": { "status": "shipped", "trackingNumber": "1Z999AA10123456784", "estimatedDelivery": "2026-04-23" }
157
+ }
158
+ },
159
+ {
160
+ "spanId": "sp_006",
161
+ "parentSpanId": "sp_003",
162
+ "name": "end",
163
+ "startTime": "2026-04-21T14:00:02.800Z",
164
+ "data": {
165
+ "response": "Your order #4521 has been shipped! Tracking number: 1Z999AA10123456784. Estimated delivery: April 23rd."
166
+ }
167
+ }
168
+ ]
169
+ }
170
+ ```
171
+
172
+ ### Brief summary ("What happened?")
173
+
174
+ > The user asked about order #4521. The agent looked it up with `lookupOrder`, found it was shipped with tracking number 1Z999AA10123456784 and an estimated delivery of April 23rd, and relayed that information to the user. Completed in one iteration, ~3 seconds.
175
+
176
+ ### Sample trace with an error (abbreviated)
177
+
178
+ ```json
179
+ {
180
+ "traceId": "tr_01J5FAILURE",
181
+ "spans": [
182
+ {
183
+ "spanId": "sp_010",
184
+ "name": "handler.conversation",
185
+ "startTime": "2026-04-21T15:00:00.000Z",
186
+ "endTime": "2026-04-21T15:00:08.500Z",
187
+ "status": "error",
188
+ "context": {
189
+ "conversationId": "conv_def456",
190
+ "userId": "user_xyz"
191
+ }
192
+ },
193
+ {
194
+ "spanId": "sp_011",
195
+ "parentSpanId": "sp_010",
196
+ "name": "autonomous.execution",
197
+ "startTime": "2026-04-21T15:00:00.050Z",
198
+ "endTime": "2026-04-21T15:00:08.400Z",
199
+ "status": "error"
200
+ },
201
+ {
202
+ "spanId": "sp_012",
203
+ "parentSpanId": "sp_011",
204
+ "name": "autonomous.iteration",
205
+ "startTime": "2026-04-21T15:00:00.100Z",
206
+ "endTime": "2026-04-21T15:00:04.000Z",
207
+ "status": "error",
208
+ "data": { "iterationIndex": 0 }
209
+ },
210
+ {
211
+ "spanId": "sp_013",
212
+ "parentSpanId": "sp_012",
213
+ "name": "think",
214
+ "startTime": "2026-04-21T15:00:00.200Z",
215
+ "data": {
216
+ "content": "The user wants to cancel order #7890. I'll use the cancelOrder tool."
217
+ }
218
+ },
219
+ {
220
+ "spanId": "sp_014",
221
+ "parentSpanId": "sp_012",
222
+ "name": "tool_call",
223
+ "startTime": "2026-04-21T15:00:00.500Z",
224
+ "endTime": "2026-04-21T15:00:02.000Z",
225
+ "status": "error",
226
+ "data": {
227
+ "tool_name": "cancelOrder",
228
+ "input": { "orderId": "7890" },
229
+ "error": "OrderService: Cannot cancel order in 'shipped' status"
230
+ }
231
+ },
232
+ {
233
+ "spanId": "sp_015",
234
+ "parentSpanId": "sp_011",
235
+ "name": "autonomous.iteration",
236
+ "startTime": "2026-04-21T15:00:04.100Z",
237
+ "endTime": "2026-04-21T15:00:08.000Z",
238
+ "status": "ok",
239
+ "data": { "iterationIndex": 1 }
240
+ },
241
+ {
242
+ "spanId": "sp_016",
243
+ "parentSpanId": "sp_015",
244
+ "name": "think",
245
+ "startTime": "2026-04-21T15:00:04.200Z",
246
+ "data": {
247
+ "content": "The cancelOrder tool failed because the order is already shipped. I should inform the user that shipped orders cannot be cancelled and suggest they initiate a return instead."
248
+ }
249
+ },
250
+ {
251
+ "spanId": "sp_017",
252
+ "parentSpanId": "sp_015",
253
+ "name": "end",
254
+ "startTime": "2026-04-21T15:00:07.900Z",
255
+ "data": {
256
+ "response": "I wasn't able to cancel order #7890 because it has already shipped. You can initiate a return once it arrives — would you like me to help with that?"
257
+ }
258
+ }
259
+ ]
260
+ }
261
+ ```
262
+
263
+ ### Diagnostic summary ("What went wrong?")
264
+
265
+ > The user asked to cancel order #7890. The agent called `cancelOrder` but it failed with "Cannot cancel order in 'shipped' status" -- the order was already shipped. In the second iteration, the agent recognized the failure, informed the user that shipped orders can't be cancelled, and suggested initiating a return instead. The agent handled the error gracefully; this is expected behavior for an already-shipped order, not a bug.
266
+
267
+ ### Focused summary ("Why did it suggest a return?")
268
+
269
+ > After `cancelOrder` failed with a "shipped" status error, the agent's reasoning (iteration 1 `think` span) explicitly noted that shipped orders can't be cancelled and decided to suggest a return as an alternative. This came from the model's own reasoning, not from the tool output or instructions -- it inferred the next-best action based on the error context.
270
+
271
+ ---
272
+
273
+ ## Patterns
274
+
275
+ ✅ **Synthesize, don't transcribe**
276
+
277
+ ```
278
+ Good: "The agent looked up the order, found it was shipped, and told the user."
279
+ Bad: "Span sp_004 is a think span with content 'The user is asking...' then span sp_005 is a tool_call to lookupOrder with input orderId=4521..."
280
+ ```
281
+
282
+ ✅ **Name tools and key values**
283
+
284
+ ```
285
+ Good: "Called `lookupOrder` with orderId '4521', got status 'shipped'."
286
+ Bad: "A tool was called and it returned some data."
287
+ ```
288
+
289
+ ✅ **Explain causation, not just sequence**
290
+
291
+ ```
292
+ Good: "The cancelOrder call failed because the order was already shipped, so the agent suggested a return instead."
293
+ Bad: "cancelOrder failed. Then the agent said to try a return."
294
+ ```
295
+
296
+ ✅ **Flag what matters for the developer's question**
297
+
298
+ ```
299
+ Good (for "why did it fail?"): "The root cause is that cancelOrder doesn't handle shipped orders -- it throws instead of returning an error object."
300
+ Bad: Giving a full trace walkthrough when the developer only asked about the failure.
301
+ ```
302
+
303
+ ❌ **Don't dump raw JSON or span IDs in the summary**
304
+
305
+ Span IDs and raw field values are debugging artifacts. The summary is for understanding, not for grep. Reference tool names, error messages, and key data values instead.
306
+
307
+ ❌ **Don't speculate beyond the trace data**
308
+
309
+ If the trace doesn't show why something happened, say so. Don't invent explanations.
310
+
311
+ ❌ **Don't include timing unless it's notable**
312
+
313
+ A 3-second conversation turn is normal. A 45-second turn with 12 iterations is worth calling out.