melchizedek-agents 0.19.0 → 1.0.0

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 (242) hide show
  1. package/.env.example +4 -5
  2. package/AGENT_SETUP.md +3 -3
  3. package/CHANGELOG.md +492 -76
  4. package/DOCUMENTATION.md +153 -132
  5. package/QUICKSTART.md +14 -10
  6. package/README.md +12 -15
  7. package/config/agents/examples/image_production.yaml +2 -2
  8. package/config/agents/syndicateSchema.yaml +55 -26
  9. package/dist/lib/a2a/app.d.ts +17 -12
  10. package/dist/lib/a2a/app.js +16 -6
  11. package/dist/lib/a2a/executor.d.ts +10 -14
  12. package/dist/lib/a2a/executor.js +10 -18
  13. package/dist/lib/a2a/remoteAgent.d.ts +5 -12
  14. package/dist/lib/a2a/remoteAgent.js +5 -12
  15. package/dist/lib/adkPeer.d.ts +63 -0
  16. package/dist/lib/adkPeer.js +240 -0
  17. package/dist/lib/compile.d.ts +109 -81
  18. package/dist/lib/compile.js +163 -111
  19. package/dist/lib/compileAdk.d.ts +7 -4
  20. package/dist/lib/compileAdk.js +22 -12
  21. package/dist/lib/compileNative.d.ts +63 -49
  22. package/dist/lib/compileNative.js +136 -78
  23. package/dist/lib/config.d.ts +6 -6
  24. package/dist/lib/config.js +6 -6
  25. package/dist/lib/doctor.d.ts +22 -1
  26. package/dist/lib/doctor.js +27 -2
  27. package/dist/lib/index.d.ts +14 -7
  28. package/dist/lib/index.js +11 -7
  29. package/dist/lib/loadSyndicate.d.ts +3 -3
  30. package/dist/lib/loadSyndicate.js +2 -2
  31. package/dist/lib/memory/erase.d.ts +1 -1
  32. package/dist/lib/memory/erase.js +1 -1
  33. package/dist/lib/memory/namespace.d.ts +12 -14
  34. package/dist/lib/memory/namespace.js +13 -14
  35. package/dist/lib/memory/providers.d.ts +4 -5
  36. package/dist/lib/memory/providers.js +12 -6
  37. package/dist/lib/memory/supabaseMemoryService.d.ts +9 -30
  38. package/dist/lib/memory/supabaseMemoryService.js +8 -30
  39. package/dist/lib/model.d.ts +6 -12
  40. package/dist/lib/model.js +6 -12
  41. package/dist/lib/models/adapterResolver.d.ts +21 -38
  42. package/dist/lib/models/adapterResolver.js +33 -40
  43. package/dist/lib/models/adkGeminiAdapter.js +2 -0
  44. package/dist/lib/models/adkShim.d.ts +1 -1
  45. package/dist/lib/models/adkShim.js +1 -1
  46. package/dist/lib/models/capabilities.js +13 -10
  47. package/dist/lib/models/chatCompletionsAdapter.d.ts +12 -33
  48. package/dist/lib/models/chatCompletionsAdapter.js +13 -18
  49. package/dist/lib/models/circuitBreaker.d.ts +5 -5
  50. package/dist/lib/models/circuitBreaker.js +5 -5
  51. package/dist/lib/models/claudeAdapter.d.ts +9 -26
  52. package/dist/lib/models/claudeAdapter.js +11 -15
  53. package/dist/lib/models/claudeLlm.js +2 -2
  54. package/dist/lib/models/claudeModels.d.ts +4 -4
  55. package/dist/lib/models/claudeModels.js +4 -4
  56. package/dist/lib/models/contract.d.ts +11 -11
  57. package/dist/lib/models/contract.js +6 -6
  58. package/dist/lib/models/errorResponse.d.ts +13 -20
  59. package/dist/lib/models/errorResponse.js +0 -12
  60. package/dist/lib/models/fallback.d.ts +1 -1
  61. package/dist/lib/models/fallback.js +1 -1
  62. package/dist/lib/models/fallbackAdapter.d.ts +7 -8
  63. package/dist/lib/models/gatewayAdapter.d.ts +1 -1
  64. package/dist/lib/models/gatewayAdapter.js +1 -1
  65. package/dist/lib/models/gatewayLlm.js +2 -2
  66. package/dist/lib/models/geminiAdapter.d.ts +11 -10
  67. package/dist/lib/models/geminiAdapter.js +37 -15
  68. package/dist/lib/models/geminiState.d.ts +29 -8
  69. package/dist/lib/models/geminiState.js +34 -8
  70. package/dist/lib/models/genaiMapping.d.ts +104 -38
  71. package/dist/lib/models/genaiMapping.js +146 -43
  72. package/dist/lib/models/gptAdapter.d.ts +11 -11
  73. package/dist/lib/models/gptAdapter.js +13 -13
  74. package/dist/lib/models/gptLlm.js +2 -2
  75. package/dist/lib/models/grokLlm.js +2 -2
  76. package/dist/lib/models/kimiAdapter.d.ts +6 -7
  77. package/dist/lib/models/kimiAdapter.js +6 -9
  78. package/dist/lib/models/kimiLlm.js +2 -2
  79. package/dist/lib/models/ollamaAdapter.d.ts +3 -3
  80. package/dist/lib/models/ollamaAdapter.js +3 -3
  81. package/dist/lib/models/ollamaLlm.js +2 -2
  82. package/dist/lib/models/providerMap.d.ts +6 -5
  83. package/dist/lib/models/providerMap.js +6 -5
  84. package/dist/lib/models/providerState.d.ts +3 -2
  85. package/dist/lib/models/providerState.js +3 -2
  86. package/dist/lib/models/reasoning.d.ts +1 -1
  87. package/dist/lib/models/registry.d.ts +26 -69
  88. package/dist/lib/models/registry.js +32 -140
  89. package/dist/lib/models/retry.d.ts +2 -2
  90. package/dist/lib/models/retry.js +2 -2
  91. package/dist/lib/models/schemaNormalize.d.ts +25 -55
  92. package/dist/lib/models/schemaNormalize.js +30 -100
  93. package/dist/lib/models/tracedGemini.d.ts +1 -1
  94. package/dist/lib/models/tracedGemini.js +1 -1
  95. package/dist/lib/observability/lineage.d.ts +3 -3
  96. package/dist/lib/observability/lineage.js +10 -10
  97. package/dist/lib/observability/supabaseSpanExporter.js +1 -1
  98. package/dist/lib/observability/tracer.d.ts +25 -23
  99. package/dist/lib/observability/tracer.js +26 -63
  100. package/dist/lib/persistence/supabaseProvider.d.ts +4 -3
  101. package/dist/lib/runtime/adkSessionBridge.d.ts +1 -1
  102. package/dist/lib/runtime/adkSessionBridge.js +1 -1
  103. package/dist/lib/runtime/approvals.d.ts +6 -1
  104. package/dist/lib/runtime/approvals.js +39 -8
  105. package/dist/lib/runtime/credentials.d.ts +4 -2
  106. package/dist/lib/runtime/credentials.js +6 -1
  107. package/dist/lib/runtime/events.d.ts +3 -4
  108. package/dist/lib/runtime/events.js +3 -4
  109. package/dist/lib/runtime/logging.d.ts +3 -8
  110. package/dist/lib/runtime/logging.js +3 -8
  111. package/dist/lib/runtime/memoryService.d.ts +4 -6
  112. package/dist/lib/runtime/memoryService.js +3 -5
  113. package/dist/lib/runtime/native/agentLoop.d.ts +24 -16
  114. package/dist/lib/runtime/native/agentLoop.js +67 -37
  115. package/dist/lib/runtime/native/compaction.d.ts +10 -11
  116. package/dist/lib/runtime/native/compaction.js +10 -11
  117. package/dist/lib/runtime/native/delegate.d.ts +64 -12
  118. package/dist/lib/runtime/native/delegate.js +101 -25
  119. package/dist/lib/runtime/native/history.d.ts +5 -6
  120. package/dist/lib/runtime/native/history.js +5 -6
  121. package/dist/lib/runtime/native/interrupts.d.ts +12 -9
  122. package/dist/lib/runtime/native/interrupts.js +29 -10
  123. package/dist/lib/runtime/native/request.d.ts +25 -25
  124. package/dist/lib/runtime/native/request.js +36 -25
  125. package/dist/lib/runtime/native/selfCorrection.d.ts +75 -17
  126. package/dist/lib/runtime/native/selfCorrection.js +93 -19
  127. package/dist/lib/runtime/native/step.d.ts +34 -26
  128. package/dist/lib/runtime/native/step.js +78 -32
  129. package/dist/lib/runtime/native/taskMode.d.ts +8 -8
  130. package/dist/lib/runtime/native/taskMode.js +8 -8
  131. package/dist/lib/runtime/native/telemetry.d.ts +11 -11
  132. package/dist/lib/runtime/native/telemetry.js +11 -11
  133. package/dist/lib/runtime/native/tempState.d.ts +4 -4
  134. package/dist/lib/runtime/native/tempState.js +4 -4
  135. package/dist/lib/runtime/nativeTurn.d.ts +29 -32
  136. package/dist/lib/runtime/nativeTurn.js +30 -41
  137. package/dist/lib/runtime/questions.d.ts +8 -9
  138. package/dist/lib/runtime/questions.js +1 -2
  139. package/dist/lib/runtime/runtimeFlag.d.ts +35 -13
  140. package/dist/lib/runtime/runtimeFlag.js +46 -16
  141. package/dist/lib/runtime/sessions.d.ts +10 -12
  142. package/dist/lib/runtime/sessions.js +10 -12
  143. package/dist/lib/runtime/syndicateTurn.d.ts +46 -42
  144. package/dist/lib/runtime/syndicateTurn.js +182 -150
  145. package/dist/lib/runtime/turnControl.d.ts +8 -8
  146. package/dist/lib/runtime/turnControl.js +8 -8
  147. package/dist/lib/runtime/valueDepth.d.ts +23 -0
  148. package/dist/lib/runtime/valueDepth.js +41 -0
  149. package/dist/lib/session/supabaseSessionService.d.ts +7 -21
  150. package/dist/lib/session/supabaseSessionService.js +7 -43
  151. package/dist/lib/session/transcript.d.ts +16 -26
  152. package/dist/lib/session/transcript.js +17 -55
  153. package/dist/lib/storage/postgres/sessionService.d.ts +6 -20
  154. package/dist/lib/storage/postgres/sessionService.js +6 -39
  155. package/dist/lib/syndicateSchema.d.ts +2 -0
  156. package/dist/lib/syndicateSchema.js +32 -10
  157. package/dist/lib/toolRegistry.d.ts +20 -14
  158. package/dist/lib/toolRegistry.js +76 -33
  159. package/dist/lib/tools/adkTool.d.ts +1 -1
  160. package/dist/lib/tools/adkTool.js +1 -1
  161. package/dist/lib/tools/auth.d.ts +1 -1
  162. package/dist/lib/tools/auth.js +1 -1
  163. package/dist/lib/tools/collectionsSearchTool.d.ts +1 -1
  164. package/dist/lib/tools/collectionsSearchTool.js +1 -1
  165. package/dist/lib/tools/examples.d.ts +2 -4
  166. package/dist/lib/tools/examples.js +2 -4
  167. package/dist/lib/tools/generateImageTool.d.ts +3 -3
  168. package/dist/lib/tools/generateImageTool.js +4 -5
  169. package/dist/lib/tools/inspectImageTool.d.ts +2 -2
  170. package/dist/lib/tools/inspectImageTool.js +3 -4
  171. package/dist/lib/tools/mcpToolFactory.d.ts +4 -24
  172. package/dist/lib/tools/mcpToolFactory.js +19 -9
  173. package/dist/lib/tools/memoryTools.d.ts +5 -6
  174. package/dist/lib/tools/memoryTools.js +5 -6
  175. package/dist/lib/tools/nativeTools.d.ts +9 -14
  176. package/dist/lib/tools/nativeTools.js +9 -14
  177. package/dist/lib/tools/openapiTools.d.ts +5 -7
  178. package/dist/lib/tools/openapiTools.js +6 -13
  179. package/dist/lib/tools/scienceTools.d.ts +3 -3
  180. package/dist/lib/tools/scienceTools.js +8 -10
  181. package/dist/lib/tools/skillToolset.d.ts +1 -2
  182. package/dist/lib/tools/skillToolset.js +1 -2
  183. package/dist/lib/tools/skills/executor.d.ts +1 -1
  184. package/dist/lib/tools/skills/executor.js +1 -1
  185. package/dist/lib/tools/skills/frontmatter.d.ts +2 -2
  186. package/dist/lib/tools/skills/frontmatter.js +2 -2
  187. package/dist/lib/tools/skills/tools.d.ts +8 -10
  188. package/dist/lib/tools/skills/tools.js +9 -11
  189. package/dist/lib/tools/tool.d.ts +24 -40
  190. package/dist/lib/tools/tool.js +24 -56
  191. package/dist/lib/tools/toolContract.d.ts +8 -13
  192. package/dist/lib/tools/toolContract.js +6 -17
  193. package/dist/lib/tools/urlContextTool.d.ts +1 -1
  194. package/dist/lib/tools/urlContextTool.js +1 -1
  195. package/dist/lib/tools/webExtractTool.d.ts +2 -2
  196. package/dist/lib/tools/webExtractTool.js +3 -4
  197. package/dist/lib/tools/webSearchTool.d.ts +1 -1
  198. package/dist/lib/tools/webSearchTool.js +1 -1
  199. package/dist/lib/tools/wikiTools.d.ts +2 -2
  200. package/dist/lib/tools/wikiTools.js +5 -6
  201. package/dist/lib/tools/xApiSearchTool.d.ts +2 -2
  202. package/dist/lib/tools/xApiSearchTool.js +3 -4
  203. package/dist/lib/tools/xSearchTool.d.ts +1 -1
  204. package/dist/lib/tools/xSearchTool.js +1 -1
  205. package/dist/lib/tools/xaiSearchParams.d.ts +2 -5
  206. package/dist/lib/tools/xaiSearchParams.js +2 -5
  207. package/dist/lib/wiki/agentRun.d.ts +10 -11
  208. package/dist/lib/wiki/agentRun.js +24 -41
  209. package/dist/lib/workflow/agentNode.d.ts +31 -5
  210. package/dist/lib/workflow/agentNode.js +101 -8
  211. package/dist/lib/workflow/graph.d.ts +13 -13
  212. package/dist/lib/workflow/graph.js +25 -15
  213. package/dist/lib/workflow/nodeEvents.d.ts +5 -5
  214. package/dist/lib/workflow/nodeEvents.js +5 -5
  215. package/dist/lib/workflow/pause.d.ts +5 -4
  216. package/dist/lib/workflow/pause.js +5 -4
  217. package/dist/lib/workflow/resume.d.ts +14 -13
  218. package/dist/lib/workflow/resume.js +17 -16
  219. package/dist/lib/workflow/route.d.ts +7 -7
  220. package/dist/lib/workflow/route.js +8 -8
  221. package/dist/lib/workflow/scheduler.d.ts +54 -9
  222. package/dist/lib/workflow/scheduler.js +75 -8
  223. package/dist/lib/workflow/toolNode.d.ts +18 -29
  224. package/dist/lib/workflow/toolNode.js +29 -35
  225. package/dist/lib/workflow/turn.d.ts +29 -20
  226. package/dist/lib/workflow/turn.js +111 -24
  227. package/dist/lib/workflow.d.ts +38 -42
  228. package/dist/lib/workflow.js +38 -150
  229. package/dist/lib/workflowConfig.d.ts +6 -10
  230. package/dist/lib/workflowConfig.js +2 -27
  231. package/dist/scripts/a2a_server.js +1 -2
  232. package/dist/scripts/assistant_worker.d.ts +2 -2
  233. package/dist/scripts/assistant_worker.js +8 -7
  234. package/dist/scripts/doctor.d.ts +3 -1
  235. package/dist/scripts/doctor.js +4 -2
  236. package/dist/scripts/syndicate_chat.js +14 -24
  237. package/package.json +3 -6
  238. package/skills/briefs/_shared.md +2 -2
  239. package/skills/briefs/melchizedek-author.md +2 -2
  240. package/skills/briefs/melchizedek-models.md +6 -6
  241. package/skills/melchizedek-author/SKILL.md +2 -2
  242. package/skills/melchizedek-models/SKILL.md +5 -5
@@ -0,0 +1,63 @@
1
+ /**
2
+ * lib/adkPeer.ts — @google/adk as an optional peer (ADR 0102).
3
+ *
4
+ * WHY this file exists:
5
+ * From 0.20.0 the native runtime is the default, and @google/adk is needed
6
+ * only for MELCHIZEDEK_RUNTIME=adk and the features only ADK runs. Until
7
+ * 1.0.0 removes ADK (ADR 0045), the engine's objects still carry an ADK
8
+ * face: the tool registry holds FunctionTools that carry their own Tool,
9
+ * the model shims are BaseLlm classes that carry their contract adapter,
10
+ * and the durable session stores are ADK BaseSessionServices as well as
11
+ * the engine's SessionService. Those classes extend ADK's at load time.
12
+ *
13
+ * This module is the one place the package loads ADK. It tries once, when
14
+ * it is first imported, and every other module takes ADK's values from
15
+ * here, never from '@google/adk' directly (a type-only import is fine):
16
+ * - When ADK is installed, each export below IS ADK's own value, so the
17
+ * ADK runtime, `instanceof` and ADK's registry behave exactly as before.
18
+ * - When it is not, the base classes are stand-ins: they construct as
19
+ * ADK's do (a tool's name, a model's id, a toolset's filter) and carry
20
+ * ADK's own Symbol.for marks, so the engine reads them as it reads ADK's,
21
+ * and every method only ADK calls throws AdkNotInstalledError, which
22
+ * names the package. Everything else (`Runner`, `LlmAgent`, the plugins)
23
+ * is reached through requireAdk(feature), which throws the same error.
24
+ *
25
+ * A package that is installed but fails to load for another reason (a
26
+ * missing dependency of its own, a syntax error) is not "absent": that
27
+ * error is rethrown, so nothing hides a broken install.
28
+ *
29
+ * The load is a top-level await of a dynamic import: an ES module cannot
30
+ * load another synchronously, and the exported classes must exist before
31
+ * any subclass is defined.
32
+ */
33
+ import type * as AdkModule from '@google/adk';
34
+ /** The package this module loads. */
35
+ export declare const ADK_PACKAGE = "@google/adk";
36
+ /** @google/adk's module namespace, as its types describe it. */
37
+ export type Adk = typeof AdkModule;
38
+ /** ADK's module when it is installed, else undefined. */
39
+ export declare const adk: Adk | undefined;
40
+ /** Whether @google/adk is installed and loaded. */
41
+ export declare function adkInstalled(): boolean;
42
+ /** The installed @google/adk version, read from its package.json, or undefined when it is not installed. */
43
+ export declare function adkVersion(): Promise<string | undefined>;
44
+ /** A feature only ADK runs was used without @google/adk installed. */
45
+ export declare class AdkNotInstalledError extends Error {
46
+ readonly feature: string;
47
+ constructor(feature: string);
48
+ }
49
+ /** ADK's module, or AdkNotInstalledError naming `feature` when it is not installed. */
50
+ export declare function requireAdk(feature: string): Adk;
51
+ export declare const BaseTool: Adk['BaseTool'];
52
+ export type BaseTool = AdkModule.BaseTool;
53
+ export declare const FunctionTool: Adk['FunctionTool'];
54
+ export type FunctionTool<TParameters extends AdkModule.ToolInputParameters = undefined> = AdkModule.FunctionTool<TParameters>;
55
+ export declare const BaseToolset: Adk['BaseToolset'];
56
+ export type BaseToolset = AdkModule.BaseToolset;
57
+ export declare const BaseLlm: Adk['BaseLlm'];
58
+ export type BaseLlm = AdkModule.BaseLlm;
59
+ export declare const Gemini: Adk['Gemini'];
60
+ export type Gemini = AdkModule.Gemini;
61
+ export declare const BaseSessionService: Adk['BaseSessionService'];
62
+ export type BaseSessionService = AdkModule.BaseSessionService;
63
+ export declare const GOOGLE_SEARCH: Adk['GOOGLE_SEARCH'];
@@ -0,0 +1,240 @@
1
+ /**
2
+ * lib/adkPeer.ts — @google/adk as an optional peer (ADR 0102).
3
+ *
4
+ * WHY this file exists:
5
+ * From 0.20.0 the native runtime is the default, and @google/adk is needed
6
+ * only for MELCHIZEDEK_RUNTIME=adk and the features only ADK runs. Until
7
+ * 1.0.0 removes ADK (ADR 0045), the engine's objects still carry an ADK
8
+ * face: the tool registry holds FunctionTools that carry their own Tool,
9
+ * the model shims are BaseLlm classes that carry their contract adapter,
10
+ * and the durable session stores are ADK BaseSessionServices as well as
11
+ * the engine's SessionService. Those classes extend ADK's at load time.
12
+ *
13
+ * This module is the one place the package loads ADK. It tries once, when
14
+ * it is first imported, and every other module takes ADK's values from
15
+ * here, never from '@google/adk' directly (a type-only import is fine):
16
+ * - When ADK is installed, each export below IS ADK's own value, so the
17
+ * ADK runtime, `instanceof` and ADK's registry behave exactly as before.
18
+ * - When it is not, the base classes are stand-ins: they construct as
19
+ * ADK's do (a tool's name, a model's id, a toolset's filter) and carry
20
+ * ADK's own Symbol.for marks, so the engine reads them as it reads ADK's,
21
+ * and every method only ADK calls throws AdkNotInstalledError, which
22
+ * names the package. Everything else (`Runner`, `LlmAgent`, the plugins)
23
+ * is reached through requireAdk(feature), which throws the same error.
24
+ *
25
+ * A package that is installed but fails to load for another reason (a
26
+ * missing dependency of its own, a syntax error) is not "absent": that
27
+ * error is rethrown, so nothing hides a broken install.
28
+ *
29
+ * The load is a top-level await of a dynamic import: an ES module cannot
30
+ * load another synchronously, and the exported classes must exist before
31
+ * any subclass is defined.
32
+ */
33
+ /** The package this module loads. */
34
+ export const ADK_PACKAGE = '@google/adk';
35
+ /** Whether `err` says the package itself could not be found (and not a module it imports). */
36
+ function isMissingPackage(err) {
37
+ const e = err;
38
+ if (!e || typeof e !== 'object')
39
+ return false;
40
+ if (e.code !== 'ERR_MODULE_NOT_FOUND' && e.code !== 'MODULE_NOT_FOUND')
41
+ return false;
42
+ return typeof e.message === 'string' && e.message.includes(`'${ADK_PACKAGE}'`);
43
+ }
44
+ let loaded;
45
+ try {
46
+ loaded = await import('@google/adk');
47
+ }
48
+ catch (err) {
49
+ if (!isMissingPackage(err))
50
+ throw err;
51
+ }
52
+ /** ADK's module when it is installed, else undefined. */
53
+ export const adk = loaded;
54
+ /** Whether @google/adk is installed and loaded. */
55
+ export function adkInstalled() {
56
+ return loaded !== undefined;
57
+ }
58
+ /** The installed @google/adk version, read from its package.json, or undefined when it is not installed. */
59
+ export async function adkVersion() {
60
+ if (!loaded)
61
+ return undefined;
62
+ try {
63
+ const { createRequire } = await import('node:module');
64
+ const require = createRequire(import.meta.url);
65
+ const fs = await import('node:fs');
66
+ const path = await import('node:path');
67
+ // The package's exports map hides package.json, so walk up from its entry.
68
+ let dir = path.dirname(require.resolve(ADK_PACKAGE));
69
+ for (let i = 0; i < 6; i++) {
70
+ const file = path.join(dir, 'package.json');
71
+ if (fs.existsSync(file)) {
72
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
73
+ if (pkg.name === ADK_PACKAGE)
74
+ return pkg.version;
75
+ }
76
+ dir = path.dirname(dir);
77
+ }
78
+ }
79
+ catch {
80
+ // Unreadable: the version is unknown, not the package absent.
81
+ }
82
+ return undefined;
83
+ }
84
+ /** A feature only ADK runs was used without @google/adk installed. */
85
+ export class AdkNotInstalledError extends Error {
86
+ feature;
87
+ constructor(feature) {
88
+ super(`${feature} needs ${ADK_PACKAGE}, which is not installed. ` +
89
+ `Install it beside melchizedek-agents (npm install ${ADK_PACKAGE}@~2.2.0), ` +
90
+ `or run on the native runtime (the default; unset MELCHIZEDEK_RUNTIME or set it to native).`);
91
+ this.name = 'AdkNotInstalledError';
92
+ this.feature = feature;
93
+ }
94
+ }
95
+ /** ADK's module, or AdkNotInstalledError naming `feature` when it is not installed. */
96
+ export function requireAdk(feature) {
97
+ if (!loaded)
98
+ throw new AdkNotInstalledError(feature);
99
+ return loaded;
100
+ }
101
+ // ── Stand-ins for ADK's base classes ─────────────────────────────────────────
102
+ //
103
+ // Each matches the ADK constructor's effect on the instance and ADK's
104
+ // Symbol.for mark, nothing more. They exist only when ADK is not installed.
105
+ const BASE_TOOL = Symbol.for('google.adk.baseTool');
106
+ const IN_MODEL_TOOL = Symbol.for('google.adk.inModelTool');
107
+ const FUNCTION_TOOL = Symbol.for('google.adk.functionTool');
108
+ const BASE_TOOLSET = Symbol.for('google.adk.baseToolset');
109
+ const BASE_MODEL = Symbol.for('google.adk.baseModel');
110
+ const GEMINI_MODEL = Symbol.for('google.adk.geminiModel');
111
+ function adkOnly(what) {
112
+ throw new AdkNotInstalledError(what);
113
+ }
114
+ class MissingBaseTool {
115
+ [BASE_TOOL] = true;
116
+ name;
117
+ description;
118
+ isLongRunning;
119
+ constructor(params) {
120
+ this.name = params.name;
121
+ this.description = params.description;
122
+ this.isLongRunning = params.isLongRunning ?? false;
123
+ }
124
+ _getDeclaration() {
125
+ return undefined;
126
+ }
127
+ async checkRequireConfirmation() {
128
+ return false;
129
+ }
130
+ async processLlmRequest(_request) {
131
+ adkOnly(`The ADK face of the tool '${this.name}'`);
132
+ }
133
+ async runAsync(_request) {
134
+ return adkOnly(`The ADK face of the tool '${this.name}'`);
135
+ }
136
+ }
137
+ class MissingFunctionTool extends MissingBaseTool {
138
+ [FUNCTION_TOOL] = true;
139
+ execute;
140
+ parameters;
141
+ requireConfirmation;
142
+ constructor(options) {
143
+ const name = options.name ?? options.execute.name;
144
+ if (!name)
145
+ throw new Error('Tool name cannot be empty. Either name the `execute` function or provide a `name`.');
146
+ super({ name, description: options.description, isLongRunning: options.isLongRunning });
147
+ this.execute = options.execute;
148
+ this.parameters = options.parameters;
149
+ this.requireConfirmation = options.requireConfirmation ?? false;
150
+ }
151
+ }
152
+ class MissingBaseToolset {
153
+ [BASE_TOOLSET] = true;
154
+ toolFilter;
155
+ prefix;
156
+ constructor(toolFilter, prefix) {
157
+ this.toolFilter = toolFilter;
158
+ this.prefix = prefix;
159
+ }
160
+ async getTools() {
161
+ return adkOnly('An ADK toolset');
162
+ }
163
+ async close() { }
164
+ }
165
+ class MissingBaseLlm {
166
+ [BASE_MODEL] = true;
167
+ model;
168
+ static supportedModels = [];
169
+ constructor({ model }) {
170
+ this.model = model;
171
+ }
172
+ generateContentAsync() {
173
+ return adkOnly(`The ADK face of the model '${this.model}'`);
174
+ }
175
+ async connect() {
176
+ return adkOnly(`The ADK face of the model '${this.model}'`);
177
+ }
178
+ }
179
+ /**
180
+ * ADK's Gemini, absent: it holds what a caller gave it (the model, a key,
181
+ * Vertex AI's settings), as ADK's does, so the native runtime reads it as it
182
+ * reads TracedGemini (lib/compileNative.ts). Calling it throws.
183
+ */
184
+ class MissingGemini extends MissingBaseLlm {
185
+ [GEMINI_MODEL] = true;
186
+ apiKey;
187
+ vertexai;
188
+ project;
189
+ location;
190
+ headers;
191
+ constructor(params) {
192
+ super({ model: params.model ?? 'gemini-2.5-flash' });
193
+ if (params.apiKey !== undefined)
194
+ this.apiKey = params.apiKey;
195
+ if (params.vertexai !== undefined)
196
+ this.vertexai = params.vertexai;
197
+ if (params.project !== undefined)
198
+ this.project = params.project;
199
+ if (params.location !== undefined)
200
+ this.location = params.location;
201
+ if (params.headers !== undefined)
202
+ this.headers = params.headers;
203
+ }
204
+ }
205
+ /**
206
+ * ADK's session service base, absent. A store that extends it is still the
207
+ * engine's SessionService; only the ADK face (the base's appendEvent, which
208
+ * ADK's Runner reaches) needs ADK.
209
+ */
210
+ class MissingBaseSessionService {
211
+ async appendEvent(_request) {
212
+ return adkOnly('The ADK face of a session store');
213
+ }
214
+ /** ADK's own: the session when it exists, else a new one, through the store's methods. */
215
+ async getOrCreateSession(request) {
216
+ const self = this;
217
+ if (!request.sessionId)
218
+ return self.createSession(request);
219
+ const session = await self.getSession({ appName: request.appName, userId: request.userId, sessionId: request.sessionId });
220
+ return session ?? self.createSession(request);
221
+ }
222
+ }
223
+ /** ADK's GOOGLE_SEARCH, absent: an in-model tool named google_search, which the engine reads by ADK's mark. */
224
+ class MissingGoogleSearchTool extends MissingBaseTool {
225
+ [IN_MODEL_TOOL] = true;
226
+ constructor() {
227
+ super({ name: 'google_search', description: 'Google Search Tool' });
228
+ }
229
+ }
230
+ // ── The values every other module imports ────────────────────────────────────
231
+ //
232
+ // A type of the same name sits beside each value, so `import { BaseTool }`
233
+ // from here serves as both, as it did from '@google/adk'.
234
+ export const BaseTool = loaded?.BaseTool ?? MissingBaseTool;
235
+ export const FunctionTool = loaded?.FunctionTool ?? MissingFunctionTool;
236
+ export const BaseToolset = loaded?.BaseToolset ?? MissingBaseToolset;
237
+ export const BaseLlm = loaded?.BaseLlm ?? MissingBaseLlm;
238
+ export const Gemini = loaded?.Gemini ?? MissingGemini;
239
+ export const BaseSessionService = loaded?.BaseSessionService ?? MissingBaseSessionService;
240
+ export const GOOGLE_SEARCH = loaded?.GOOGLE_SEARCH ?? new MissingGoogleSearchTool();
@@ -1,6 +1,6 @@
1
1
  /**
2
- * lib/compile.ts — the one YAML → agent compiler: a runtime-neutral
3
- * AgentSpec, and the ADK agent graph built from it.
2
+ * lib/compile.ts — the one YAML → agent compiler: an AgentSpec per agent,
3
+ * which lib/compileNative.ts turns into what the runtime runs.
4
4
  *
5
5
  * WHY this file exists:
6
6
  * The A2A server carried this logic as two closures inside its executor,
@@ -12,44 +12,40 @@
12
12
  * So the compiler moved here and both callers import it.
13
13
  *
14
14
  * What it does NOT own: model resolution and nested-config loading. Both are
15
- * injected, because the two callers differ precisely there:
16
- * - the A2A server resolves `model` to a provider INSTANCE carrying the
15
+ * injected, because the callers differ precisely there:
16
+ * - the A2A server resolves `model` to a ModelAdapter carrying the
17
17
  * caller's BYOK key (lib/models/registry.ts resolveModel);
18
- * - the observatory passes the model id through as a string (the
19
- * LLMRegistry routes it) and loads nested syndicates with its
20
- * per-variant overrides already applied.
18
+ * - the observatory passes the model id through as a string (the loop
19
+ * resolves it, lib/models/registry.ts resolveAdapter) and loads nested
20
+ * syndicates with its per-variant overrides already applied.
21
21
  *
22
22
  * ── Two orchestration methods, one compiler ───────────────────────────────
23
- * DELEGATE (no `dispatch:` block): every subagent becomes an AgentTool on
24
- * the orchestrator. PLAN-DISPATCH (`dispatch:` present): the orchestrator
23
+ * DELEGATE (no `dispatch:` block): every subagent becomes a delegation tool
24
+ * on the orchestrator. PLAN-DISPATCH (`dispatch:` present): the orchestrator
25
25
  * is compiled WITHOUT subagent tools — it is a pure classifier — and the
26
- * caller runs `compileSubagent(route)` directly for the chosen route. Both
27
- * paths build subagents through the same function, so the agent a route
28
- * dispatches to is identical to the one DELEGATE would have wrapped.
26
+ * turn runner compiles the chosen route's own spec. Both paths build
27
+ * subagents through the same function, so the agent a route dispatches to
28
+ * is identical to the one DELEGATE would have delegated to.
29
29
  * Contract and rationale: lib/dispatch.ts.
30
30
  *
31
- * ── One spec, two runtimes (ADR 0073) ─────────────────────────────────────
32
- * compileSpec and compileSubagentSpec do the work every runtime shares:
33
- * resolve and gate the tools, append the skills index, resolve the model
34
- * once, build the generateContentConfig. The result is an AgentSpec.
35
- * lib/compileAdk.ts builds ADK's LlmAgent from it (compileGraph and
36
- * compileSubagent are spec + compileAdk), and lib/compileNative.ts builds
37
- * the native loop's NativeAgent (ADR 0045). runSyndicateTurn picks one by
38
- * MELCHIZEDEK_RUNTIME or its `runtime` option.
31
+ * ── The spec (ADR 0073, ADR 0107) ─────────────────────────────────────────
32
+ * compileSpec and compileSubagentSpec resolve and gate the tools, append the
33
+ * skills index, resolve the model once and build the generateContentConfig.
34
+ * The result is an AgentSpec; lib/compileNative.ts builds the loop's
35
+ * NativeAgent from it.
39
36
  */
40
- import { BaseLlm, FunctionTool } from '@google/adk';
41
- import type { BaseTool, LlmAgent } from '@google/adk';
42
37
  import type { ReasoningSetting, SubagentYamlConfig, SyndicateYamlConfig } from './loadSyndicate.ts';
38
+ import type { ModelAdapter } from './models/contract.ts';
43
39
  import type { ExampleConfig } from './tools/examples.ts';
44
40
  import type { SkillsConfig } from './tools/skillToolset.ts';
45
41
  export interface CompileOptions {
46
42
  /**
47
- * Turns the YAML `model` string into what LlmAgent receives. Default:
48
- * identity — the string goes straight to ADK's LLMRegistry, which needs
49
- * `registerAvailableProviders()` to have run (lib/models/registry.ts).
50
- * The A2A server substitutes a BYOK instance factory here.
43
+ * Turns the YAML `model` string into what the agent runs on: a model id,
44
+ * or a ModelAdapter (lib/models/contract.ts). Default: identity — the id
45
+ * resolves through lib/models/registry.ts resolveAdapter when the agent
46
+ * first calls it. The A2A server substitutes a BYOK adapter factory here.
51
47
  */
52
- resolveModel?: (model: string | undefined) => string | BaseLlm | undefined;
48
+ resolveModel?: (model: string | undefined) => string | ModelAdapter | undefined;
53
49
  /**
54
50
  * Loads a nested `yaml_reference:` syndicate. Default: `loadSyndicate(ref)`
55
51
  * with no bindings — the same call the server makes. The observatory wraps
@@ -60,12 +56,6 @@ export interface CompileOptions {
60
56
  onUnknownTool?: (name: string) => void;
61
57
  /** Progress/diagnostic line sink (nested loads, MCP discovery). */
62
58
  log?: (message: string) => void;
63
- /**
64
- * Node settings for an agent compiled as a workflow node (lib/workflow.ts):
65
- * ADK's `retryConfig` and `timeout`, which an LlmAgent takes only at
66
- * construction. Called with the agent's name; undefined means none.
67
- */
68
- nodeConfig?: (agentName: string) => Record<string, unknown> | undefined;
69
59
  }
70
60
  export { REASONING_BUDGETS, reasoningConfig } from './models/reasoning.ts';
71
61
  /**
@@ -79,36 +69,17 @@ export declare function withReasoning(agent: {
79
69
  reasoning?: ReasoningSetting;
80
70
  generateContentConfig?: object;
81
71
  }, model: string | undefined): Record<string, unknown> | undefined;
82
- /** An agent's `context:` block and its default, owned by the native compactor (ADR 0033); compileAdk hands the same values to ADK's. */
72
+ /** An agent's `context:` block and its default, owned by the compactor (ADR 0033). */
83
73
  export type { ContextConfig } from './runtime/native/compaction.ts';
84
74
  import type { ContextConfig } from './runtime/native/compaction.ts';
85
75
  export { DEFAULT_KEEP_RECENT_EVENTS } from './runtime/native/compaction.ts';
86
- /**
87
- * A copy of a FunctionTool that runs only after a person approves the call
88
- * (ADR 0028). ADK's own gate does the work: the call raises an
89
- * `adk_request_confirmation` interrupt pinning the call and its arguments,
90
- * and only an approval bound to that exact call runs it. The original stays
91
- * ungated for every other agent that lists the same tool.
92
- */
93
- export declare function requireApprovalOn(tool: FunctionTool): FunctionTool;
94
- /**
95
- * A copy of an ADK BaseTool that runs only after a person approves the
96
- * call: the same confirmation interrupt FunctionTool's own gate raises, so
97
- * the turn pauses and resumes exactly as ADR 0028 says. The engine no
98
- * longer uses it: an OpenAPI operation is a FunctionTool over an own Tool
99
- * (ADR 0067) and takes requireApprovalOn like every registry tool.
100
- * @deprecated Gate a FunctionTool with requireApprovalOn, or an own Tool
101
- * with requireApproval (lib/tools/tool.ts).
102
- */
103
- export declare function requireApprovalOnBaseTool<T extends BaseTool>(tool: T): T;
104
76
  /** True when any agent of a syndicate may pause for approval: a gated tool, or skill scripts. */
105
77
  export declare function declaresApprovals(config: SyndicateYamlConfig): boolean;
106
78
  export type { ExampleConfig };
107
79
  /**
108
- * An agent's `examples:` as the ADK tool for their InstructionTool
109
- * (lib/tools/examples.ts): never called by the model, it adds the exchanges
110
- * to every request's instruction as few-shot examples, in the words ADK's
111
- * ExampleTool used.
80
+ * An agent's `examples:` as their InstructionTool (lib/tools/examples.ts):
81
+ * never called by the model, it adds the exchanges to every request's
82
+ * instruction as few-shot examples, in the words ADK's ExampleTool used.
112
83
  */
113
84
  export declare function examplesTool(examples: ExampleConfig[] | undefined): unknown[];
114
85
  /** True when a turn running this agent directly may pause for a person (ADR 0028). */
@@ -118,11 +89,12 @@ export declare function agentGates(agent: {
118
89
  } | undefined): boolean;
119
90
  /**
120
91
  * One entry of an agent's tool list, in the order the model sees it.
121
- * `tool` is a resolved tool as the registry gives it: during the dual
122
- * period an ADK object that carries its own Tool or InstructionTool
123
- * (lib/tools/adkTool.ts), an MCP tool or the skills toolset, gated by
124
- * require_approval where the YAML says so. `agent` is a delegated subagent
125
- * (DELEGATE mode), `remote` a subagent served over A2A.
92
+ * `tool` is a resolved tool as the registry gives it: an own Tool,
93
+ * InstructionTool, NativeToolMarker or Toolset (lib/tools/tool.ts), gated
94
+ * by require_approval where the YAML says so. `agent` is a delegated subagent
95
+ * (DELEGATE mode), `remote` a subagent served over A2A, `workflow` a
96
+ * `yaml_reference` to a workflow syndicate, whose whole graph is the tool
97
+ * (ADR 0098).
126
98
  */
127
99
  export type SpecTool = {
128
100
  kind: 'tool';
@@ -135,10 +107,42 @@ export type SpecTool = {
135
107
  name: string;
136
108
  description: string;
137
109
  url: string;
110
+ } | {
111
+ kind: 'workflow';
112
+ workflow: WorkflowSpec;
138
113
  };
139
114
  /**
140
- * One YAML agent, compiled, for either runtime: what lib/compileAdk.ts
141
- * turns into ADK's LlmAgent and lib/compileNative.ts into the native loop's
115
+ * A workflow syndicate, compiled: lib/compileNative.ts builds the walk's
116
+ * graph and agents from it. Nested as a subagent (a `yaml_reference` in
117
+ * DELEGATE mode), the graph runs under the entry's name and description,
118
+ * and that name is the root of every node path.
119
+ */
120
+ export interface WorkflowSpec {
121
+ /** The workflow's name: the syndicate's, or the subagent entry's when nested. */
122
+ name: string;
123
+ /** The tool's description when nested; '' at the root. */
124
+ description: string;
125
+ /** The syndicate, its `syndicate_name` set to `name`. */
126
+ config: SyndicateYamlConfig;
127
+ /** Every agent of the graph, the orchestrator first, as compileSubagentSpec builds it, with its YAML entry. */
128
+ agents: Array<{
129
+ yaml: SubagentYamlConfig;
130
+ spec: AgentSpec;
131
+ }>;
132
+ /**
133
+ * Every node that is a `yaml_reference` to a workflow syndicate, with its
134
+ * YAML entry: the nested graph under the entry's name (ADR 0106). The
135
+ * walk runs it as the node, on its own child session.
136
+ */
137
+ workflows: Array<{
138
+ yaml: SubagentYamlConfig;
139
+ workflow: WorkflowSpec;
140
+ }>;
141
+ /** The registry entry for a tool node's tool name, or undefined (CompileOptions.onUnknownTool applies). */
142
+ resolveTool: (name: string) => unknown;
143
+ }
144
+ /**
145
+ * One YAML agent, compiled: what lib/compileNative.ts turns into the loop's
142
146
  * NativeAgent. Built once per agent by compileSpec and compileSubagentSpec:
143
147
  * the tools resolved (OpenAPI operations built, MCP tools listed) and
144
148
  * gated, the skills index appended to the instruction, the model resolved
@@ -154,14 +158,14 @@ export interface AgentSpec {
154
158
  resolvedModel?: unknown;
155
159
  /** The id the agent runs on: the YAML's, else the resolved adapter's. */
156
160
  modelId?: string;
157
- /** `fallback_model:`, unresolved: each runtime resolves it where it calls it. */
161
+ /** `fallback_model:`, unresolved: the loop resolves it where it calls it. */
158
162
  fallbackModel?: string;
159
163
  /** The YAML instruction, with the skills index appended when the agent has `skills:`. */
160
164
  instruction: string;
161
165
  globalInstruction?: string;
162
166
  tools: SpecTool[];
163
167
  outputSchema?: Record<string, unknown>;
164
- /** The YAML's config with `reasoning:` mapped in and server-side tool invocations on, as both runtimes send it. */
168
+ /** The YAML's config with `reasoning:` mapped in and server-side tool invocations on. */
165
169
  generateContentConfig: Record<string, unknown>;
166
170
  includeContents?: 'default' | 'none';
167
171
  outputKey?: string;
@@ -174,30 +178,54 @@ export interface AgentSpec {
174
178
  /** `mode: task`. */
175
179
  mode?: 'task';
176
180
  }
181
+ /**
182
+ * The spec of a workflow syndicate: every agent through compileSubagentSpec
183
+ * (the orchestrator first, as a node like any other), and the registry's
184
+ * lookup for its tool nodes. `name` and `description` name a nested one
185
+ * after its subagent entry (ADR 0098); `ref` is the file it came from.
186
+ *
187
+ * A nested workflow runs inside its caller's tool call, so a pause inside it
188
+ * could not reach the caller (ADR 0028, as for any nested syndicate): an
189
+ * `ask_user` node is refused by name here.
190
+ */
191
+ export declare function compileWorkflowSpec(config: SyndicateYamlConfig, opts?: CompileOptions, name?: string, description?: string, ref?: string): Promise<WorkflowSpec>;
192
+ /** Every agent spec a workflow runs, its nested workflow nodes' agents included, for one adapter lookup (nativeAdapterFor). */
193
+ export declare function workflowAgentSpecs(spec: WorkflowSpec): AgentSpec[];
194
+ /** A subagent entry, compiled: one agent, or a nested workflow syndicate's whole graph (ADR 0098, ADR 0106). */
195
+ export type EntrySpec = {
196
+ kind: 'agent';
197
+ spec: AgentSpec;
198
+ } | {
199
+ kind: 'workflow';
200
+ workflow: WorkflowSpec;
201
+ };
202
+ /**
203
+ * A subagent entry as what it runs: an inline agent or a nested syndicate's
204
+ * orchestrator as one agent, or a `yaml_reference` to a workflow syndicate
205
+ * as its whole graph under the entry's name and description. A delegated
206
+ * subagent, a dispatch route and a workflow node all compile through here,
207
+ * so the graph a file describes is the graph that runs (ADR 0106).
208
+ */
209
+ export declare function compileEntrySpec(subCfg: SubagentYamlConfig, opts?: CompileOptions): Promise<EntrySpec>;
210
+ /**
211
+ * The names of a syndicate's subagent entries that are `yaml_reference`s to
212
+ * a workflow syndicate. Loads each reference once and compiles nothing, so a
213
+ * runtime can refuse what it cannot run before the session is touched.
214
+ */
215
+ export declare function workflowEntryNames(config: SyndicateYamlConfig, opts?: CompileOptions): string[];
177
216
  /**
178
217
  * The spec of ONE agent from a subagent entry. A `yaml_reference` entry is
179
- * the nested syndicate's whole graph under this entry's name and
180
- * description, so the parent sees one tool (or one route) either way.
218
+ * the nested syndicate's orchestrator under this entry's name and
219
+ * description, its own subagents delegated to as in any DELEGATE graph. A
220
+ * `yaml_reference` to a workflow syndicate has no one agent to build: it
221
+ * runs as its whole graph (compileEntrySpec), and is refused here by name.
181
222
  */
182
223
  export declare function compileSubagentSpec(subCfg: SubagentYamlConfig, opts?: CompileOptions): Promise<AgentSpec>;
183
224
  /**
184
225
  * The spec of a syndicate's orchestrator. In DELEGATE mode its subagents
185
226
  * come first among its tools, as delegations; in PLAN-DISPATCH mode it gets
186
- * none (ADK refuses outputSchema + AgentTool on one agent — see
227
+ * none (a classifier answers with its outputSchema — see
187
228
  * config/agents/critic.yaml), and the caller dispatches to a route's own
188
229
  * spec itself.
189
230
  */
190
231
  export declare function compileSpec(config: SyndicateYamlConfig, opts?: CompileOptions, overrideName?: string, overrideDescription?: string): Promise<AgentSpec>;
191
- /**
192
- * Builds ONE runnable ADK agent from a subagent entry: its spec, as
193
- * lib/compileAdk.ts builds it. A workflow node's settings
194
- * (CompileOptions.nodeConfig) apply to a local agent, not to a nested
195
- * syndicate's orchestrator.
196
- */
197
- export declare function compileSubagent(subCfg: SubagentYamlConfig, opts?: CompileOptions): Promise<LlmAgent>;
198
- /**
199
- * Compiles a syndicate's orchestrator for the ADK runtime. In DELEGATE mode
200
- * its subagents are attached as AgentTools; in PLAN-DISPATCH mode it gets
201
- * none, and the caller dispatches to `compileSubagent(route)` itself.
202
- */
203
- export declare function compileGraph(config: SyndicateYamlConfig, opts?: CompileOptions, overrideName?: string, overrideDescription?: string): Promise<LlmAgent>;