@nhtio/adk 0.1.0-master-f0aa531d
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.
- package/LICENSE.md +9 -0
- package/README.md +3 -0
- package/batteries/index.d.ts +28 -0
- package/batteries/llm/index.d.ts +11 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs +916 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/adapter.d.ts +101 -0
- package/batteries/llm/openai_chat_completions/adapter.mjs +914 -0
- package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/exceptions.cjs +89 -0
- package/batteries/llm/openai_chat_completions/exceptions.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/exceptions.d.ts +97 -0
- package/batteries/llm/openai_chat_completions/exceptions.mjs +81 -0
- package/batteries/llm/openai_chat_completions/exceptions.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/helpers.cjs +819 -0
- package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/helpers.d.ts +233 -0
- package/batteries/llm/openai_chat_completions/helpers.mjs +783 -0
- package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/index.d.ts +27 -0
- package/batteries/llm/openai_chat_completions/types.cjs +1 -0
- package/batteries/llm/openai_chat_completions/types.d.ts +524 -0
- package/batteries/llm/openai_chat_completions/types.mjs +0 -0
- package/batteries/llm/openai_chat_completions/validation.cjs +190 -0
- package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/validation.d.ts +31 -0
- package/batteries/llm/openai_chat_completions/validation.mjs +187 -0
- package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions.cjs +51 -0
- package/batteries/llm/openai_chat_completions.mjs +5 -0
- package/batteries/llm/webllm_chat_completions/adapter.cjs +658 -0
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/adapter.d.ts +103 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs +656 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/exceptions.cjs +70 -0
- package/batteries/llm/webllm_chat_completions/exceptions.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/exceptions.d.ts +74 -0
- package/batteries/llm/webllm_chat_completions/exceptions.mjs +65 -0
- package/batteries/llm/webllm_chat_completions/exceptions.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/helpers.cjs +38 -0
- package/batteries/llm/webllm_chat_completions/helpers.d.ts +6 -0
- package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -0
- package/batteries/llm/webllm_chat_completions/index.d.ts +25 -0
- package/batteries/llm/webllm_chat_completions/types.d.ts +31 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs +115 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/validation.d.ts +8 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs +112 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions.cjs +50 -0
- package/batteries/llm/webllm_chat_completions.mjs +6 -0
- package/batteries/llm.cjs +63 -0
- package/batteries/llm.mjs +10 -0
- package/batteries/storage/flydrive/index.d.ts +167 -0
- package/batteries/storage/flydrive.cjs +249 -0
- package/batteries/storage/flydrive.cjs.map +1 -0
- package/batteries/storage/flydrive.mjs +249 -0
- package/batteries/storage/flydrive.mjs.map +1 -0
- package/batteries/storage/in_memory/index.d.ts +106 -0
- package/batteries/storage/in_memory.cjs +121 -0
- package/batteries/storage/in_memory.cjs.map +1 -0
- package/batteries/storage/in_memory.mjs +119 -0
- package/batteries/storage/in_memory.mjs.map +1 -0
- package/batteries/storage/index.d.ts +18 -0
- package/batteries/storage/opfs/index.d.ts +299 -0
- package/batteries/storage/opfs.cjs +368 -0
- package/batteries/storage/opfs.cjs.map +1 -0
- package/batteries/storage/opfs.mjs +366 -0
- package/batteries/storage/opfs.mjs.map +1 -0
- package/batteries/storage.cjs +4 -0
- package/batteries/storage.mjs +2 -0
- package/batteries/tools/color/index.d.ts +37 -0
- package/batteries/tools/color.cjs +659 -0
- package/batteries/tools/color.cjs.map +1 -0
- package/batteries/tools/color.mjs +655 -0
- package/batteries/tools/color.mjs.map +1 -0
- package/batteries/tools/comparison/index.d.ts +29 -0
- package/batteries/tools/comparison.cjs +171 -0
- package/batteries/tools/comparison.cjs.map +1 -0
- package/batteries/tools/comparison.mjs +168 -0
- package/batteries/tools/comparison.mjs.map +1 -0
- package/batteries/tools/data_structure/index.d.ts +30 -0
- package/batteries/tools/data_structure.cjs +270 -0
- package/batteries/tools/data_structure.cjs.map +1 -0
- package/batteries/tools/data_structure.mjs +267 -0
- package/batteries/tools/data_structure.mjs.map +1 -0
- package/batteries/tools/datetime_extended/index.d.ts +51 -0
- package/batteries/tools/datetime_extended.cjs +309 -0
- package/batteries/tools/datetime_extended.cjs.map +1 -0
- package/batteries/tools/datetime_extended.mjs +302 -0
- package/batteries/tools/datetime_extended.mjs.map +1 -0
- package/batteries/tools/datetime_math/index.d.ts +36 -0
- package/batteries/tools/datetime_math.cjs +175 -0
- package/batteries/tools/datetime_math.cjs.map +1 -0
- package/batteries/tools/datetime_math.mjs +171 -0
- package/batteries/tools/datetime_math.mjs.map +1 -0
- package/batteries/tools/encoding/index.d.ts +36 -0
- package/batteries/tools/encoding.cjs +156 -0
- package/batteries/tools/encoding.cjs.map +1 -0
- package/batteries/tools/encoding.mjs +152 -0
- package/batteries/tools/encoding.mjs.map +1 -0
- package/batteries/tools/formatting/index.d.ts +28 -0
- package/batteries/tools/formatting.cjs +120 -0
- package/batteries/tools/formatting.cjs.map +1 -0
- package/batteries/tools/formatting.mjs +117 -0
- package/batteries/tools/formatting.mjs.map +1 -0
- package/batteries/tools/geo_basics/index.d.ts +33 -0
- package/batteries/tools/geo_basics.cjs +136 -0
- package/batteries/tools/geo_basics.cjs.map +1 -0
- package/batteries/tools/geo_basics.mjs +132 -0
- package/batteries/tools/geo_basics.mjs.map +1 -0
- package/batteries/tools/index.d.ts +32 -0
- package/batteries/tools/math/index.d.ts +37 -0
- package/batteries/tools/math.cjs +136 -0
- package/batteries/tools/math.cjs.map +1 -0
- package/batteries/tools/math.mjs +133 -0
- package/batteries/tools/math.mjs.map +1 -0
- package/batteries/tools/memory/index.d.ts +73 -0
- package/batteries/tools/memory.cjs +193 -0
- package/batteries/tools/memory.cjs.map +1 -0
- package/batteries/tools/memory.mjs +187 -0
- package/batteries/tools/memory.mjs.map +1 -0
- package/batteries/tools/parsing/index.d.ts +47 -0
- package/batteries/tools/parsing.cjs +191 -0
- package/batteries/tools/parsing.cjs.map +1 -0
- package/batteries/tools/parsing.mjs +185 -0
- package/batteries/tools/parsing.mjs.map +1 -0
- package/batteries/tools/retrievables/index.d.ts +81 -0
- package/batteries/tools/retrievables.cjs +215 -0
- package/batteries/tools/retrievables.cjs.map +1 -0
- package/batteries/tools/retrievables.mjs +209 -0
- package/batteries/tools/retrievables.mjs.map +1 -0
- package/batteries/tools/standing_instructions/index.d.ts +64 -0
- package/batteries/tools/standing_instructions.cjs +126 -0
- package/batteries/tools/standing_instructions.cjs.map +1 -0
- package/batteries/tools/standing_instructions.mjs +121 -0
- package/batteries/tools/standing_instructions.mjs.map +1 -0
- package/batteries/tools/statistics/index.d.ts +46 -0
- package/batteries/tools/statistics.cjs +253 -0
- package/batteries/tools/statistics.cjs.map +1 -0
- package/batteries/tools/statistics.mjs +248 -0
- package/batteries/tools/statistics.mjs.map +1 -0
- package/batteries/tools/string_processing/index.d.ts +29 -0
- package/batteries/tools/string_processing.cjs +154 -0
- package/batteries/tools/string_processing.cjs.map +1 -0
- package/batteries/tools/string_processing.mjs +151 -0
- package/batteries/tools/string_processing.mjs.map +1 -0
- package/batteries/tools/structured_data/index.d.ts +34 -0
- package/batteries/tools/structured_data.cjs +189 -0
- package/batteries/tools/structured_data.cjs.map +1 -0
- package/batteries/tools/structured_data.mjs +185 -0
- package/batteries/tools/structured_data.mjs.map +1 -0
- package/batteries/tools/text_analysis/index.d.ts +31 -0
- package/batteries/tools/text_analysis.cjs +120 -0
- package/batteries/tools/text_analysis.cjs.map +1 -0
- package/batteries/tools/text_analysis.mjs +117 -0
- package/batteries/tools/text_analysis.mjs.map +1 -0
- package/batteries/tools/text_comparison/index.d.ts +28 -0
- package/batteries/tools/text_comparison.cjs +96 -0
- package/batteries/tools/text_comparison.cjs.map +1 -0
- package/batteries/tools/text_comparison.mjs +93 -0
- package/batteries/tools/text_comparison.mjs.map +1 -0
- package/batteries/tools/time/index.d.ts +27 -0
- package/batteries/tools/time.cjs +63 -0
- package/batteries/tools/time.cjs.map +1 -0
- package/batteries/tools/time.mjs +60 -0
- package/batteries/tools/time.mjs.map +1 -0
- package/batteries/tools/unit_conversion/index.d.ts +19 -0
- package/batteries/tools/unit_conversion.cjs +452 -0
- package/batteries/tools/unit_conversion.cjs.map +1 -0
- package/batteries/tools/unit_conversion.mjs +450 -0
- package/batteries/tools/unit_conversion.mjs.map +1 -0
- package/batteries/tools.cjs +80 -0
- package/batteries/tools.mjs +21 -0
- package/batteries.cjs +142 -0
- package/batteries.mjs +30 -0
- package/chunk-KmRHZBOW.js +35 -0
- package/common-DeZaonK1.mjs +208 -0
- package/common-DeZaonK1.mjs.map +1 -0
- package/common-Od8edUXU.js +232 -0
- package/common-Od8edUXU.js.map +1 -0
- package/common.cjs +31 -0
- package/common.d.ts +108 -0
- package/common.mjs +8 -0
- package/dispatch_runner-9j6bXHL3.mjs +1609 -0
- package/dispatch_runner-9j6bXHL3.mjs.map +1 -0
- package/dispatch_runner-CsoH0nld.js +1627 -0
- package/dispatch_runner-CsoH0nld.js.map +1 -0
- package/dispatch_runner.cjs +3 -0
- package/dispatch_runner.d.ts +17 -0
- package/dispatch_runner.mjs +2 -0
- package/exceptions-D5YrO9Vm.js +280 -0
- package/exceptions-D5YrO9Vm.js.map +1 -0
- package/exceptions-NrzIHw_R.mjs +244 -0
- package/exceptions-NrzIHw_R.mjs.map +1 -0
- package/exceptions.cjs +33 -0
- package/exceptions.d.ts +52 -0
- package/exceptions.mjs +3 -0
- package/factories.cjs +4 -0
- package/factories.d.ts +39 -0
- package/factories.mjs +2 -0
- package/forge.cjs +9 -0
- package/forge.d.ts +49 -0
- package/forge.mjs +5 -0
- package/guards.cjs +96 -0
- package/guards.cjs.map +1 -0
- package/guards.d.ts +83 -0
- package/guards.mjs +72 -0
- package/guards.mjs.map +1 -0
- package/index.cjs +107 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +18 -0
- package/index.mjs +31 -0
- package/index.mjs.map +1 -0
- package/lib/classes/artifact_tool.d.ts +129 -0
- package/lib/classes/base_exception.d.ts +83 -0
- package/lib/classes/identity.d.ts +71 -0
- package/lib/classes/media.d.ts +326 -0
- package/lib/classes/memory.d.ts +72 -0
- package/lib/classes/message.d.ts +137 -0
- package/lib/classes/registry.d.ts +79 -0
- package/lib/classes/retrievable.d.ts +100 -0
- package/lib/classes/spooled_artifact.d.ts +296 -0
- package/lib/classes/spooled_json_artifact.d.ts +158 -0
- package/lib/classes/spooled_markdown_artifact.d.ts +202 -0
- package/lib/classes/thought.d.ts +142 -0
- package/lib/classes/tokenizable.d.ts +124 -0
- package/lib/classes/tool.d.ts +228 -0
- package/lib/classes/tool_call.d.ts +190 -0
- package/lib/classes/tool_registry.d.ts +159 -0
- package/lib/classes/turn_gate.d.ts +109 -0
- package/lib/contracts/dispatch_context.d.ts +345 -0
- package/lib/contracts/media_reader.d.ts +60 -0
- package/lib/contracts/spool_reader.d.ts +80 -0
- package/lib/contracts/spooled_artifact_constructor.d.ts +38 -0
- package/lib/contracts/turn_runner_config.d.ts +101 -0
- package/lib/contracts/turn_runner_context.d.ts +267 -0
- package/lib/dispatch_runner.d.ts +98 -0
- package/lib/exceptions/runtime.d.ts +370 -0
- package/lib/helpers/media_readers.d.ts +39 -0
- package/lib/turn_runner.d.ts +144 -0
- package/lib/types/dispatch_context.d.ts +233 -0
- package/lib/types/dispatch_runner.d.ts +387 -0
- package/lib/types/turn_runner.d.ts +322 -0
- package/lib/utils/canonical_json.d.ts +18 -0
- package/lib/utils/exceptions.d.ts +78 -0
- package/lib/utils/guards.d.ts +32 -0
- package/lib/utils/validation.d.ts +77 -0
- package/package.json +334 -0
- package/runtime-BJVkrGQe.js +519 -0
- package/runtime-BJVkrGQe.js.map +1 -0
- package/runtime-CrEPIFgr.mjs +346 -0
- package/runtime-CrEPIFgr.mjs.map +1 -0
- package/skills/adk-assembly/SKILL.md +109 -0
- package/skills/adk-assembly/references/assembly-contract.md +66 -0
- package/skills/adk-assembly/references/executors-tools-pipelines-events.md +113 -0
- package/skills/adk-assembly/references/first-integration.md +93 -0
- package/skills/adk-assembly/references/storage-and-context.md +102 -0
- package/spooled_artifact-C5ZtGxuJ.mjs +544 -0
- package/spooled_artifact-C5ZtGxuJ.mjs.map +1 -0
- package/spooled_artifact-Cm9Te22K.js +568 -0
- package/spooled_artifact-Cm9Te22K.js.map +1 -0
- package/spooled_artifact.cjs +7 -0
- package/spooled_artifact.d.ts +40 -0
- package/spooled_artifact.mjs +3 -0
- package/spooled_markdown_artifact-BpUJol0W.mjs +771 -0
- package/spooled_markdown_artifact-BpUJol0W.mjs.map +1 -0
- package/spooled_markdown_artifact-RRB113sy.js +786 -0
- package/spooled_markdown_artifact-RRB113sy.js.map +1 -0
- package/thought-CDb457b4.mjs +470 -0
- package/thought-CDb457b4.mjs.map +1 -0
- package/thought-DuN2PgdO.js +494 -0
- package/thought-DuN2PgdO.js.map +1 -0
- package/tool-COSeH8I6.js +302 -0
- package/tool-COSeH8I6.js.map +1 -0
- package/tool-D2WB1EA1.mjs +296 -0
- package/tool-D2WB1EA1.mjs.map +1 -0
- package/tool_call-BKyyxGaZ.mjs +578 -0
- package/tool_call-BKyyxGaZ.mjs.map +1 -0
- package/tool_call-DFgzcVcU.js +608 -0
- package/tool_call-DFgzcVcU.js.map +1 -0
- package/tool_registry-Dkfprsck.js +641 -0
- package/tool_registry-Dkfprsck.js.map +1 -0
- package/tool_registry-DqLOyGyG.mjs +592 -0
- package/tool_registry-DqLOyGyG.mjs.map +1 -0
- package/turn_runner-CMm2BHdX.js +615 -0
- package/turn_runner-CMm2BHdX.js.map +1 -0
- package/turn_runner-y7eyEcJH.mjs +603 -0
- package/turn_runner-y7eyEcJH.mjs.map +1 -0
- package/turn_runner.cjs +3 -0
- package/turn_runner.d.ts +21 -0
- package/turn_runner.mjs +2 -0
- package/types.cjs +1 -0
- package/types.d.ts +56 -0
- package/types.mjs +0 -0
- package/vite-env.d.ts +23 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Executors, Tools, Pipelines, and Events
|
|
2
|
+
|
|
3
|
+
The executor is the only primary reasoning loop. Pipelines prepare or inspect context. Events deliver output and telemetry.
|
|
4
|
+
|
|
5
|
+
## Executor Contract
|
|
6
|
+
|
|
7
|
+
`executorCallback` implements `DispatchExecutorFn`:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const executor = async (ctx, helpers) => {
|
|
11
|
+
try {
|
|
12
|
+
// call model, stream output, execute tools, persist state
|
|
13
|
+
ctx.ack()
|
|
14
|
+
} catch (error) {
|
|
15
|
+
ctx.nack(error instanceof Error ? error : new Error(String(error)))
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The executor must eventually call exactly one terminal signal per invocation:
|
|
21
|
+
|
|
22
|
+
- `ctx.ack()` for successful completion.
|
|
23
|
+
- `ctx.nack(error)` for failure.
|
|
24
|
+
|
|
25
|
+
Failing to signal can leave the dispatch loop running until an abort or middleware intervention. Double signaling throws.
|
|
26
|
+
|
|
27
|
+
For battery executors, use `autoAck: true` for simple one-shot turns that should finish after a tool-call-free response. Omit it only when the application owns a later quality gate or terminal signal.
|
|
28
|
+
|
|
29
|
+
## Executor Responsibilities
|
|
30
|
+
|
|
31
|
+
A custom executor owns:
|
|
32
|
+
|
|
33
|
+
1. Formatting ADK primitives into provider requests.
|
|
34
|
+
2. Calling the model/provider or custom decision runtime.
|
|
35
|
+
3. Streaming functional output through `helpers.reportMessage`, `helpers.reportThought`, and `helpers.reportToolCall`.
|
|
36
|
+
4. Executing requested tools inline with `tool.executor(ctx)(args)`.
|
|
37
|
+
5. Persisting messages, thoughts, and tool calls through `ctx.store*` / `ctx.mutate*`.
|
|
38
|
+
6. Enforcing provider retry, timeout, and loop policies.
|
|
39
|
+
7. Finalizing with `ack()` or `nack()`.
|
|
40
|
+
|
|
41
|
+
Reporting is not persistence. Use both `helpers.report*` for live output and `ctx.store*` for durable state.
|
|
42
|
+
|
|
43
|
+
## Tool Wiring
|
|
44
|
+
|
|
45
|
+
Define tools with `Tool`. The `inputSchema` is both runtime argument validation and the model-visible schema.
|
|
46
|
+
|
|
47
|
+
Register tools through:
|
|
48
|
+
|
|
49
|
+
- `tools: [toolA, toolB]` for baseline tools available each turn.
|
|
50
|
+
- `fetchToolsCallback` plus middleware registration for dynamic tools.
|
|
51
|
+
- `new ToolRegistry([...])` or `ToolRegistry.merge(...)` when manually combining registries.
|
|
52
|
+
|
|
53
|
+
Do not look for `ToolRegistry.fromTools`; construct a registry directly.
|
|
54
|
+
|
|
55
|
+
Trust rules:
|
|
56
|
+
|
|
57
|
+
- `trusted: false` is the safe default for inline textual/spooled tool results.
|
|
58
|
+
- Set `trusted: true` only for developer-controlled or explicitly user-authorized output.
|
|
59
|
+
- `Media.trustTier` controls media trust, not `Tool.trusted`.
|
|
60
|
+
|
|
61
|
+
Tool handler returns are raw. Executors or batteries decide whether to wrap strings/bytes in `SpooledArtifact`, spool bytes, or persist `Media` handles directly.
|
|
62
|
+
|
|
63
|
+
## Pipeline Placement
|
|
64
|
+
|
|
65
|
+
ADK has four optional middleware arrays:
|
|
66
|
+
|
|
67
|
+
- `turnInputPipeline`: once before dispatch. Use for hydration, retrieval, memory loading, rate limits, standing-instruction refresh, and stash setup.
|
|
68
|
+
- `turnOutputPipeline`: once after successful dispatch. Use for memory extraction, analytics, webhooks, and success-only cleanup.
|
|
69
|
+
- `dispatchInputPipeline`: before every executor call. Use for iteration caps, loop detection, and corrective intervention.
|
|
70
|
+
- `dispatchOutputPipeline`: after every executor call. Use for per-iteration logging and inspection.
|
|
71
|
+
|
|
72
|
+
Middleware must call `next()` to continue. Not calling `next()` short-circuits intentionally.
|
|
73
|
+
|
|
74
|
+
Hard rules:
|
|
75
|
+
|
|
76
|
+
- No primary reasoning models in pipelines.
|
|
77
|
+
- Put secondary preprocessing model calls in pipelines only as an explicit cost/security exception.
|
|
78
|
+
- Use `ctx.stash.get()` and `ctx.stash.set()` for cross-middleware data.
|
|
79
|
+
- Do not put critical failure cleanup in `turnOutputPipeline`; it does not run after input or dispatch failures.
|
|
80
|
+
|
|
81
|
+
## Iteration Guards
|
|
82
|
+
|
|
83
|
+
Core ADK does not impose iteration limits. Add a dispatch input guard for runaway loops:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
const iterationCap = async (ctx, next) => {
|
|
87
|
+
if (ctx.iteration >= 10) {
|
|
88
|
+
ctx.nack(new Error('Max iterations exceeded'))
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
await next()
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
For repeated tool calls, use the same checksum convention stored on the tool call and inspect `ctx.toolCallCount(checksum)`.
|
|
96
|
+
|
|
97
|
+
## Events
|
|
98
|
+
|
|
99
|
+
`runner.run()` returns no assistant data. Output and telemetry leave through two buses.
|
|
100
|
+
|
|
101
|
+
Functional bus:
|
|
102
|
+
|
|
103
|
+
- API: `runner.on`, `runner.off`, `runner.once`.
|
|
104
|
+
- Events: `message`, `thought`, `toolCall`.
|
|
105
|
+
- Use for product output: terminal streaming, SSE, WebSocket messages, tool progress UI.
|
|
106
|
+
|
|
107
|
+
Observability bus:
|
|
108
|
+
|
|
109
|
+
- API: `runner.observe`, `runner.unobserve`, `runner.observeOnce`.
|
|
110
|
+
- Events include `turnStart`, `turnEnd`, `dispatchStart`, `dispatchEnd`, `iterationStart`, `iterationEnd`, `toolExecutionStart`, `toolExecutionEnd`, `log`, and `error`.
|
|
111
|
+
- Use for tracing, metrics, structured logs, and error reporting only.
|
|
112
|
+
|
|
113
|
+
Register listeners before `runner.run()`. If removing a listener changes product behavior, it belongs on the functional bus; if removing it only changes telemetry, it belongs on the observability bus.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# First Integration Workflow
|
|
2
|
+
|
|
3
|
+
Use this reference when the user asks to add ADK to an existing project, create a first agent, scaffold a runnable example, or get from zero to one working turn.
|
|
4
|
+
|
|
5
|
+
## Choose the Integration Path
|
|
6
|
+
|
|
7
|
+
Ask only when the answer is not inferable from the project:
|
|
8
|
+
|
|
9
|
+
1. Runtime: Node, browser, worker, CLI, server, or test harness.
|
|
10
|
+
2. Package manager: npm, pnpm, yarn, or bun.
|
|
11
|
+
3. Executor mode:
|
|
12
|
+
- Mock executor: no key, no network, best first smoke test.
|
|
13
|
+
- OpenAI battery: Node/server real-model path.
|
|
14
|
+
- WebLLM battery: browser-local model path.
|
|
15
|
+
- BYO executor: custom provider, custom prompt rendering, custom retry/tool loop.
|
|
16
|
+
4. Storage mode:
|
|
17
|
+
- No-op callbacks for first scaffold/tests.
|
|
18
|
+
- Real callbacks for production conversation continuity.
|
|
19
|
+
|
|
20
|
+
Default to the mock executor when the user wants a safe local scaffold and has not provided provider credentials.
|
|
21
|
+
|
|
22
|
+
## Scaffold Shape
|
|
23
|
+
|
|
24
|
+
For a first integration, create the smallest explicit assembly rather than hiding ADK behind an abstraction:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
src/
|
|
28
|
+
noop-storage.ts
|
|
29
|
+
hydrate-messages.ts
|
|
30
|
+
agent.ts
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
If the project already has a convention such as `app/`, `lib/`, `server/`, or `packages/*/src`, adapt the directory names but keep the same separation:
|
|
34
|
+
|
|
35
|
+
- `noop-storage.ts`: all 25 callbacks with correct arity.
|
|
36
|
+
- `hydrate-messages.ts`: `turnInputPipeline` middleware that calls `ctx.fetchMessages()` and adds results to `ctx.turnMessages`.
|
|
37
|
+
- `agent.ts`: `Message`, `TurnRunner`, executor or battery, event listeners, and `runner.run(rawCtx)`.
|
|
38
|
+
|
|
39
|
+
Do not invent a `noopStorageAdapter` import from `@nhtio/adk`; it is a local snippet copied into the user's project.
|
|
40
|
+
|
|
41
|
+
## Dependency Step
|
|
42
|
+
|
|
43
|
+
Add `@nhtio/adk` only if the target project does not already depend on it. For TypeScript examples that run directly from source, add `tsx`, `typescript`, and `@types/node` as dev dependencies when absent.
|
|
44
|
+
|
|
45
|
+
Use the detected package manager. For pnpm projects:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
pnpm add @nhtio/adk
|
|
49
|
+
pnpm add -D tsx typescript @types/node
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Mock Executor First
|
|
53
|
+
|
|
54
|
+
Prefer the Quickstart mock executor for a first smoke test. It should:
|
|
55
|
+
|
|
56
|
+
1. Create an assistant `Message`.
|
|
57
|
+
2. Stream text with `helpers.reportMessage(id, reply, { isComplete: true })`.
|
|
58
|
+
3. Persist the message with `ctx.storeMessage(...)`.
|
|
59
|
+
4. Call `ctx.ack()` exactly once.
|
|
60
|
+
|
|
61
|
+
This proves the runner, storage callbacks, hydration middleware, event listener, and raw turn context are wired before introducing provider credentials.
|
|
62
|
+
|
|
63
|
+
## Real Model Upgrade
|
|
64
|
+
|
|
65
|
+
When the user asks for a real model and the runtime supports it, replace only the executor slot:
|
|
66
|
+
|
|
67
|
+
- Use `OpenAIChatCompletionsAdapter` from `@nhtio/adk/batteries/llm` for OpenAI-compatible Chat Completions.
|
|
68
|
+
- Set `autoAck: true` for simple tool-call-free first turns.
|
|
69
|
+
- Require `OPENAI_API_KEY` or the user's configured provider secret at runtime; never hard-code credentials.
|
|
70
|
+
- Keep `noop-storage.ts` and `hydrate-messages.ts` unchanged from the mock scaffold unless the user is also adding persistence.
|
|
71
|
+
|
|
72
|
+
## Smoke Test Expectations
|
|
73
|
+
|
|
74
|
+
A minimal smoke run is successful when:
|
|
75
|
+
|
|
76
|
+
- `runner.on('message', ...)` is registered before `runner.run(...)`.
|
|
77
|
+
- The process prints at least one assistant message chunk.
|
|
78
|
+
- An observability listener sees `turnEnd`.
|
|
79
|
+
- `runner.run(...)` is awaited but not used as the source of assistant text.
|
|
80
|
+
|
|
81
|
+
If the user has tests, add the narrowest test that observes the `message` event and asserts the expected text. If no test harness exists, provide a runnable script command such as `pnpm exec tsx src/agent.ts`.
|
|
82
|
+
|
|
83
|
+
## Upgrade Sequence
|
|
84
|
+
|
|
85
|
+
After the first turn works, add production capabilities one at a time:
|
|
86
|
+
|
|
87
|
+
1. Replace no-op message and tool-call callbacks with real persistence.
|
|
88
|
+
2. Add tools and ensure tool calls are reported and persisted.
|
|
89
|
+
3. Add retrieval and memory hydration in `turnInputPipeline`.
|
|
90
|
+
4. Add iteration guards in `dispatchInputPipeline`.
|
|
91
|
+
5. Add telemetry through `runner.observe`, not business behavior.
|
|
92
|
+
|
|
93
|
+
Do not introduce retrieval, memory, tools, and production persistence in the same first scaffold unless the user explicitly asks for a full integration.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Storage and Context
|
|
2
|
+
|
|
3
|
+
ADK does not persist or hydrate state by default. A complete `TurnRunner` assembly provides 25 callbacks, and the application decides when to call fetch callbacks and where to place returned primitives.
|
|
4
|
+
|
|
5
|
+
## The 25 Required Callbacks
|
|
6
|
+
|
|
7
|
+
Retrieval callbacks require exactly one declared parameter, usually `ctx`:
|
|
8
|
+
|
|
9
|
+
- `fetchMemoriesCallback`
|
|
10
|
+
- `fetchMessagesCallback`
|
|
11
|
+
- `fetchThoughtsCallback`
|
|
12
|
+
- `fetchToolCallsCallback`
|
|
13
|
+
- `fetchToolsCallback`
|
|
14
|
+
- `fetchRetrievablesCallback`
|
|
15
|
+
- `refreshStandingInstructionsCallback`
|
|
16
|
+
|
|
17
|
+
Persistence callbacks require exactly two declared parameters, usually `ctx` and the value or id:
|
|
18
|
+
|
|
19
|
+
- Store: `storeMemoryCallback`, `storeMessageCallback`, `storeThoughtCallback`, `storeToolCallCallback`, `storeRetrievableCallback`, `storeStandingInstructionCallback`
|
|
20
|
+
- Mutate: `mutateMemoryCallback`, `mutateMessageCallback`, `mutateThoughtCallback`, `mutateToolCallCallback`, `mutateRetrievableCallback`, `mutateStandingInstructionCallback`
|
|
21
|
+
- Delete: `deleteMemoryCallback`, `deleteMessageCallback`, `deleteThoughtCallback`, `deleteToolCallCallback`, `deleteRetrievableCallback`, `deleteStandingInstructionCallback`
|
|
22
|
+
|
|
23
|
+
No-ops are valid, but omissions and wrong arity are invalid:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
fetchMessagesCallback: async (_ctx) => []
|
|
27
|
+
deleteMemoryCallback: async (_ctx, _id) => {}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Do not write arity-zero callbacks such as `async () => []` for fetch callbacks or `async () => {}` for write callbacks.
|
|
31
|
+
|
|
32
|
+
## Persistence Priorities
|
|
33
|
+
|
|
34
|
+
- `Message` persistence is required for real conversation continuity.
|
|
35
|
+
- `ToolCall` persistence is required for tool-using agents and multi-iteration loops.
|
|
36
|
+
- `Memory`, `Thought`, `Retrievable`, and standing-instruction callbacks can be no-op for early prototypes if the product does not use those features.
|
|
37
|
+
- Storage batteries do not implement these callbacks; they only store spooled artifact bytes.
|
|
38
|
+
|
|
39
|
+
## Context Hydration Pattern
|
|
40
|
+
|
|
41
|
+
New turn-scoped sets start empty. ADK exposes fetch methods, but it does not call them automatically.
|
|
42
|
+
|
|
43
|
+
Hydrate in `turnInputPipeline`:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const hydrateMessages = async (ctx, next) => {
|
|
47
|
+
const messages = await ctx.fetchMessages()
|
|
48
|
+
for (const message of messages) {
|
|
49
|
+
ctx.turnMessages.add(message)
|
|
50
|
+
}
|
|
51
|
+
await next()
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Use the same pattern for memories, thoughts, tool calls, retrievables, tools, and refreshed standing instructions. Put prerequisite hydration first in `turnInputPipeline` so later middleware and the executor see populated context.
|
|
56
|
+
|
|
57
|
+
## Messages
|
|
58
|
+
|
|
59
|
+
Messages represent conversation history. To seed the first user message, return a real `Message` instance from `fetchMessagesCallback` and hydrate it into `ctx.turnMessages`. `RawTurnContext` does not accept message history.
|
|
60
|
+
|
|
61
|
+
## Tools as Context
|
|
62
|
+
|
|
63
|
+
`fetchToolsCallback` is required but not automatic. Baseline tools can be supplied in `TurnRunnerConfig.tools`. Dynamic tools must be fetched manually and registered:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const dynamicToolsMiddleware = async (ctx, next) => {
|
|
67
|
+
const tools = await ctx.fetchTools()
|
|
68
|
+
for (const tool of tools) {
|
|
69
|
+
ctx.tools.register(tool)
|
|
70
|
+
}
|
|
71
|
+
await next()
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Retrieval
|
|
76
|
+
|
|
77
|
+
Use `Retrievable` for external documents and RAG chunks. Inject standard RAG results in `turnInputPipeline`, not in the executor, unless the task genuinely requires mid-loop search.
|
|
78
|
+
|
|
79
|
+
Trust tiers are security controls:
|
|
80
|
+
|
|
81
|
+
- `first-party`: controlled internal content.
|
|
82
|
+
- `third-party-public`: public web/API content.
|
|
83
|
+
- `third-party-private`: user uploads, private integrations, untrusted private content.
|
|
84
|
+
|
|
85
|
+
Never label user-supplied or public content as `first-party`. Rank, limit, and truncate retrieval results to fit the context budget.
|
|
86
|
+
|
|
87
|
+
## Memory
|
|
88
|
+
|
|
89
|
+
Memory is curated durable fact state, not conversation history and not RAG context.
|
|
90
|
+
|
|
91
|
+
Memory lifecycle:
|
|
92
|
+
|
|
93
|
+
1. Load ranked memories by explicitly calling `ctx.fetchMemories()` in `turnInputPipeline`.
|
|
94
|
+
2. Add returned `Memory` instances to `ctx.turnMemories`.
|
|
95
|
+
3. Write new memories in one audited path: executor, output middleware, or an external background process.
|
|
96
|
+
4. Persist lifecycle policy through `storeMemoryCallback`, `mutateMemoryCallback`, and `deleteMemoryCallback`.
|
|
97
|
+
|
|
98
|
+
Avoid storing raw user text as trusted memory. Store source/trust metadata in the application database because the ADK `Memory` primitive contains content, confidence, importance, and timestamps, not a trust tier.
|
|
99
|
+
|
|
100
|
+
## Standing Instructions
|
|
101
|
+
|
|
102
|
+
Standing instructions are `string | Tokenizable`, not instances of a `StandingInstruction` class. Refresh them explicitly with `ctx.refreshStandingInstructions()` when the assembly needs current operator or tenant instructions.
|