melchizedek-agents 1.0.3 → 1.2.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 (172) hide show
  1. package/.env.example +29 -2
  2. package/AGENT_SETUP.md +3 -1
  3. package/CHANGELOG.md +524 -0
  4. package/DOCUMENTATION.md +178 -43
  5. package/ONBOARDING.md +339 -0
  6. package/QUICKSTART.md +15 -2
  7. package/README.md +6 -2
  8. package/config/agents/README.md +2 -2
  9. package/config/agents/examples/ares.yaml +6 -10
  10. package/config/agents/examples/assistant.yaml +6 -6
  11. package/config/agents/examples/augustin.yaml +9 -15
  12. package/config/agents/examples/cartographers.yaml +6 -6
  13. package/config/agents/examples/council.yaml +7 -7
  14. package/config/agents/examples/critic.yaml +24 -24
  15. package/config/agents/examples/harness.yaml +4 -4
  16. package/config/agents/examples/image_production.yaml +37 -35
  17. package/config/agents/examples/librarian.yaml +4 -4
  18. package/config/agents/examples/patient_advocate.yaml +6 -10
  19. package/config/agents/examples/pipeline.yaml +20 -19
  20. package/config/agents/examples/research.yaml +36 -43
  21. package/config/agents/examples/scribe.yaml +31 -32
  22. package/config/agents/examples/scriptorium.yaml +6 -6
  23. package/config/agents/examples/structured_critic.yaml +82 -0
  24. package/config/agents/examples/style_council.yaml +9 -11
  25. package/config/agents/examples/syndicate.yaml +3 -5
  26. package/config/agents/examples/tutor.yaml +2 -2
  27. package/config/agents/examples/weather.yaml +2 -2
  28. package/config/agents/syndicate.schema.json +859 -13
  29. package/config/agents/syndicateSchema.yaml +122 -73
  30. package/config/agents/templates/README.md +1 -1
  31. package/config/agents/templates/account_memory.yaml +4 -4
  32. package/config/agents/templates/case_desk.yaml +6 -6
  33. package/config/agents/templates/conversational.yaml +2 -2
  34. package/config/agents/templates/draft_review.yaml +6 -6
  35. package/config/agents/templates/intake_extractor.yaml +64 -62
  36. package/config/agents/templates/research_brief.yaml +6 -6
  37. package/config/agents/templates/research_desk.yaml +6 -6
  38. package/config/agents/templates/review_panel.yaml +8 -8
  39. package/config/agents/templates/support_triage.yaml +30 -29
  40. package/config/agents/templates/systems_operator.yaml +24 -5
  41. package/db/migrations/0014_durable_runs.sql +31 -0
  42. package/dist/lib/a2a/app.d.ts +27 -0
  43. package/dist/lib/a2a/app.js +64 -5
  44. package/dist/lib/a2a/executor.d.ts +7 -1
  45. package/dist/lib/a2a/executor.js +43 -5
  46. package/dist/lib/a2a/oauthSetup.d.ts +106 -0
  47. package/dist/lib/a2a/oauthSetup.js +259 -0
  48. package/dist/lib/agentDialect.d.ts +76 -0
  49. package/dist/lib/agentDialect.js +151 -0
  50. package/dist/lib/compile.d.ts +42 -6
  51. package/dist/lib/compile.js +97 -45
  52. package/dist/lib/compileNative.d.ts +11 -3
  53. package/dist/lib/compileNative.js +20 -1
  54. package/dist/lib/dispatch.d.ts +10 -5
  55. package/dist/lib/dispatch.js +10 -5
  56. package/dist/lib/doctor.d.ts +110 -1
  57. package/dist/lib/doctor.js +205 -9
  58. package/dist/lib/loadSyndicate.d.ts +54 -2
  59. package/dist/lib/loadSyndicate.js +22 -2
  60. package/dist/lib/memory/namespace.d.ts +6 -5
  61. package/dist/lib/memory/namespace.js +6 -5
  62. package/dist/lib/memory/providers.js +3 -4
  63. package/dist/lib/models/capabilities.d.ts +25 -1
  64. package/dist/lib/models/capabilities.js +79 -1
  65. package/dist/lib/models/chatCompletionsAdapter.d.ts +11 -3
  66. package/dist/lib/models/chatCompletionsAdapter.js +19 -5
  67. package/dist/lib/models/claudeAdapter.js +4 -0
  68. package/dist/lib/models/contract.d.ts +5 -2
  69. package/dist/lib/models/gateway.d.ts +2 -1
  70. package/dist/lib/models/gateway.js +4 -2
  71. package/dist/lib/models/gatewayAdapter.d.ts +7 -1
  72. package/dist/lib/models/gatewayAdapter.js +8 -0
  73. package/dist/lib/models/geminiAdapter.js +8 -2
  74. package/dist/lib/models/genaiMapping.d.ts +8 -4
  75. package/dist/lib/models/genaiMapping.js +23 -9
  76. package/dist/lib/models/gptAdapter.d.ts +4 -2
  77. package/dist/lib/models/gptAdapter.js +11 -4
  78. package/dist/lib/models/grokAdapter.d.ts +3 -1
  79. package/dist/lib/models/grokAdapter.js +11 -3
  80. package/dist/lib/models/kimiAdapter.d.ts +2 -1
  81. package/dist/lib/models/kimiAdapter.js +3 -3
  82. package/dist/lib/models/reasoning.d.ts +30 -2
  83. package/dist/lib/models/reasoning.js +56 -5
  84. package/dist/lib/observability/tracer.d.ts +8 -1
  85. package/dist/lib/observability/tracer.js +33 -5
  86. package/dist/lib/onboarding.d.ts +134 -0
  87. package/dist/lib/onboarding.js +539 -0
  88. package/dist/lib/runtime/approvals.d.ts +8 -0
  89. package/dist/lib/runtime/approvals.js +4 -3
  90. package/dist/lib/runtime/credentials.d.ts +6 -0
  91. package/dist/lib/runtime/native/agentLoop.d.ts +23 -3
  92. package/dist/lib/runtime/native/agentLoop.js +107 -11
  93. package/dist/lib/runtime/native/checkpoint.d.ts +171 -0
  94. package/dist/lib/runtime/native/checkpoint.js +359 -0
  95. package/dist/lib/runtime/native/delegate.d.ts +222 -18
  96. package/dist/lib/runtime/native/delegate.js +390 -39
  97. package/dist/lib/runtime/native/interrupts.d.ts +184 -2
  98. package/dist/lib/runtime/native/interrupts.js +391 -1
  99. package/dist/lib/runtime/native/request.d.ts +13 -3
  100. package/dist/lib/runtime/native/request.js +28 -4
  101. package/dist/lib/runtime/native/telemetry.js +10 -15
  102. package/dist/lib/runtime/questions.d.ts +7 -4
  103. package/dist/lib/runtime/sessions.d.ts +1 -1
  104. package/dist/lib/runtime/syndicateTurn.d.ts +11 -3
  105. package/dist/lib/runtime/syndicateTurn.js +353 -68
  106. package/dist/lib/runtime/turnControl.d.ts +56 -0
  107. package/dist/lib/runtime/turnControl.js +10 -0
  108. package/dist/lib/session/transcript.d.ts +9 -0
  109. package/dist/lib/session/transcript.js +20 -1
  110. package/dist/lib/skills.d.ts +18 -0
  111. package/dist/lib/skills.js +73 -1
  112. package/dist/lib/storage/postgres/index.d.ts +12 -2
  113. package/dist/lib/storage/postgres/index.js +8 -3
  114. package/dist/lib/storage/postgres/taskQueue.d.ts +20 -4
  115. package/dist/lib/storage/postgres/taskQueue.js +29 -5
  116. package/dist/lib/storage/postgres/taskStore.d.ts +26 -2
  117. package/dist/lib/storage/postgres/taskStore.js +74 -8
  118. package/dist/lib/syndicateSchema.d.ts +316 -1
  119. package/dist/lib/syndicateSchema.js +203 -29
  120. package/dist/lib/tools/auth.d.ts +20 -6
  121. package/dist/lib/tools/auth.js +21 -5
  122. package/dist/lib/tools/credentialEnv.d.ts +28 -0
  123. package/dist/lib/tools/credentialEnv.js +52 -0
  124. package/dist/lib/tools/credentialHosts.d.ts +88 -0
  125. package/dist/lib/tools/credentialHosts.js +165 -0
  126. package/dist/lib/tools/credentialStore.js +9 -2
  127. package/dist/lib/tools/credentialUses.d.ts +92 -0
  128. package/dist/lib/tools/credentialUses.js +112 -0
  129. package/dist/lib/tools/mcpToolFactory.d.ts +25 -2
  130. package/dist/lib/tools/mcpToolFactory.js +179 -21
  131. package/dist/lib/tools/oauthConsent.js +8 -1
  132. package/dist/lib/tools/oauthHosts.d.ts +73 -0
  133. package/dist/lib/tools/oauthHosts.js +154 -0
  134. package/dist/lib/tools/oauthTools.d.ts +242 -0
  135. package/dist/lib/tools/oauthTools.js +447 -0
  136. package/dist/lib/tools/openapiTools.d.ts +11 -6
  137. package/dist/lib/tools/openapiTools.js +88 -38
  138. package/dist/lib/tools/taskTools.d.ts +61 -6
  139. package/dist/lib/tools/taskTools.js +145 -21
  140. package/dist/lib/workflow/turn.d.ts +22 -3
  141. package/dist/lib/workflow/turn.js +151 -31
  142. package/dist/lib/workflow.d.ts +14 -7
  143. package/dist/lib/workflow.js +14 -7
  144. package/dist/lib/workflowConfig.d.ts +6 -0
  145. package/dist/scripts/a2a_server.d.ts +36 -0
  146. package/dist/scripts/a2a_server.js +131 -1
  147. package/dist/scripts/assistant_worker.d.ts +12 -0
  148. package/dist/scripts/assistant_worker.js +81 -22
  149. package/dist/scripts/doctor.d.ts +7 -2
  150. package/dist/scripts/doctor.js +9 -4
  151. package/dist/scripts/setup.d.ts +23 -0
  152. package/dist/scripts/setup.js +154 -0
  153. package/dist/scripts/skills_install.d.ts +3 -1
  154. package/dist/scripts/skills_install.js +17 -2
  155. package/dist/scripts/yaml_codemod.d.ts +62 -0
  156. package/dist/scripts/yaml_codemod.js +652 -0
  157. package/package.json +8 -2
  158. package/skills/README.md +11 -2
  159. package/skills/briefs/_shared.md +1 -1
  160. package/skills/briefs/melchizedek-author.md +7 -5
  161. package/skills/briefs/melchizedek-models.md +7 -4
  162. package/skills/briefs/melchizedek.md +1 -0
  163. package/skills/briefs/skills-readme.md +3 -1
  164. package/skills/melchizedek/SKILL.md +1 -0
  165. package/skills/melchizedek-author/SKILL.md +7 -4
  166. package/skills/melchizedek-author/assets/minimal.yaml +13 -13
  167. package/skills/melchizedek-models/SKILL.md +11 -4
  168. package/skills/melchizedek-onboard/SKILL.md +49 -0
  169. package/skills/melchizedek-onboard-cloud/SKILL.md +38 -0
  170. package/skills/melchizedek-onboard-keys/SKILL.md +35 -0
  171. package/skills/melchizedek-onboard-local/SKILL.md +41 -0
  172. package/skills/melchizedek-onboard-serve/SKILL.md +43 -0
@@ -13,8 +13,12 @@
13
13
  *
14
14
  * THE REQUEST, in the order ADK built it:
15
15
  * 1. The agent's generateContentConfig, and its output schema when it has
16
- * no tools (or the model takes a schema beside tools: Gemini 2 and
17
- * later on Vertex AI).
16
+ * no tools, or when every model the step may call (its own and its
17
+ * fallback_model) takes a schema beside tools in one request: Claude
18
+ * from Opus 4.8, Sonnet 5 and Haiku 5.5 on, OpenAI, Gemini 2 and later
19
+ * on Vertex AI (outputSchemaBesideTools, lib/models/capabilities.ts,
20
+ * ADR 0109). That is how an orchestrator that delegates answers in a
21
+ * schema without a set_model_response call.
18
22
  * 2. The system prompt, each piece joined to the last by a blank line:
19
23
  * - the identity lines ("You are an agent. Your internal name is …"),
20
24
  * unless the agent may transfer to no one (an output schema rules
@@ -66,6 +70,7 @@
66
70
  * and defineTool, as registerTool refuses one (ADR 0107).
67
71
  */
68
72
  import { contentsToMessages, reasoningOf, samplingOf, systemText, toolChoiceOf } from '../../models/genaiMapping.js';
73
+ import { outputSchemaBesideTools } from '../../models/capabilities.js';
69
74
  import { providerForModel } from '../../models/providerMap.js';
70
75
  import { contractToolDeclaration, nativeToolOf, toContractJsonSchema } from '../../models/schemaNormalize.js';
71
76
  import { createToolContext, instructionToolOf, isTool, toolOf } from '../../tools/tool.js';
@@ -131,10 +136,26 @@ function vertexAi() {
131
136
  return envFlag('GOOGLE_GENAI_USE_ENTERPRISE');
132
137
  return envFlag('GOOGLE_GENAI_USE_VERTEXAI');
133
138
  }
134
- /** Whether the model takes an output schema beside tools in one request (ADK: Vertex AI, Gemini 2 and later). */
139
+ /**
140
+ * ADK's rule for whether the model takes an output schema beside tools in one
141
+ * request (Vertex AI, Gemini 2 and later). `mode: task` keeps it as it is,
142
+ * for the instruction line ADK's processor writes there.
143
+ */
135
144
  export function outputSchemaWithTools(model) {
136
145
  return vertexAi() && isGemini2OrAbove(model);
137
146
  }
147
+ /**
148
+ * Whether the agent's output schema travels beside its tools as the
149
+ * provider's own structured-output field (ADR 0109): on every model the step
150
+ * may call, its own and its fallback_model, since a fallback answers the same
151
+ * request. ADK's Gemini rule still holds; the capability matrix's
152
+ * `structured_output_with_tools` adds Claude's current generations and
153
+ * OpenAI. Anywhere else the schema is the set_model_response tool.
154
+ */
155
+ function schemaBesideTools(agent) {
156
+ const models = agent.fallbackModel ? [agent.model, agent.fallbackModel] : [agent.model];
157
+ return models.every((m) => outputSchemaWithTools(m) || outputSchemaBesideTools(m));
158
+ }
138
159
  // ── Session state in an instruction (ADK's injectSessionState) ───────────────
139
160
  const STATE_PREFIXES = ['app:', 'user:', 'temp:'];
140
161
  const ARTIFACT_PREFIX = 'artifact.';
@@ -437,7 +458,10 @@ export async function buildModelRequest(agent, ctx) {
437
458
  throw new Error('Response schema must be set via LlmAgent.output_schema.');
438
459
  const listed = agent.tools ?? [];
439
460
  const taskMode = agent.mode === 'task';
440
- const schemaWithTools = !!agent.outputSchema && listed.length > 0 && !outputSchemaWithTools(model);
461
+ // An output schema beside tools: set_model_response unless the step's models take both in one request
462
+ // (ADR 0109). Task mode keeps ADK's rule: finish_task carries the schema there.
463
+ const besideTools = !!agent.outputSchema && listed.length > 0;
464
+ const schemaWithTools = besideTools && !(taskMode ? outputSchemaWithTools(model) : schemaBesideTools(agent));
441
465
  // 1. Basic: the config, and the output schema where the model takes it (never in task mode: finish_task carries it).
442
466
  if (agent.outputSchema && !schemaWithTools && !taskMode) {
443
467
  cfg.responseSchema = agent.outputSchema;
@@ -40,10 +40,11 @@ import { SpanStatusCode, context, trace } from '@opentelemetry/api';
40
40
  import { resolveAdapter } from '../../models/registry.js';
41
41
  import { RUNTIME_SPAN_SCOPE } from '../../observability/lineage.js';
42
42
  import { payloadPolicyFromEnv } from '../../observability/supabaseSpanExporter.js';
43
- import { initializeTracing } from '../../observability/tracer.js';
43
+ import { startEngineSpan } from '../../observability/tracer.js';
44
44
  /** The most a payload attribute holds, as for a failed call's (lib/observability/tracer.ts). */
45
45
  const PAYLOAD_MAX_CHARS = 200_000;
46
- const runtimeTracer = () => trace.getTracer(RUNTIME_SPAN_SCOPE);
46
+ /** A loop span in scope melchizedek.runtime; a non-recording one in a turn that opted out of tracing. */
47
+ const startRuntimeSpan = (name, options) => startEngineSpan(RUNTIME_SPAN_SCOPE, name, options);
47
48
  /** JSON that never throws and never exceeds the cap. */
48
49
  function payloadJson(value) {
49
50
  let json;
@@ -85,8 +86,7 @@ function failed(span, error) {
85
86
  }
86
87
  /** The agent's run as an `agent.invoke <name>` span, opened when the run starts. */
87
88
  export async function* traceAgentInvocation(agent, ctx, run) {
88
- initializeTracing();
89
- const span = runtimeTracer().startSpan(`agent.invoke ${agent.name}`, {
89
+ const span = startRuntimeSpan(`agent.invoke ${agent.name}`, {
90
90
  attributes: {
91
91
  'gen_ai.operation.name': 'invoke_agent',
92
92
  'gen_ai.agent.name': agent.name,
@@ -116,8 +116,7 @@ export async function* traceAgentInvocation(agent, ctx, run) {
116
116
  * provider that answered (the fallback's, when a fallback answered).
117
117
  */
118
118
  export async function* traceModelCall(agent, ctx, step) {
119
- initializeTracing();
120
- const span = runtimeTracer().startSpan('model.call', {
119
+ const span = startRuntimeSpan('model.call', {
121
120
  attributes: {
122
121
  'gen_ai.operation.name': 'chat',
123
122
  'gen_ai.agent.name': agent.name,
@@ -173,7 +172,7 @@ function recordModelCall(span, result, provider) {
173
172
  span.setAttribute('llm.error_code', String(response.error.code));
174
173
  return;
175
174
  }
176
- if (payloadPolicyFromEnv().mode === 'off')
175
+ if (!span.isRecording() || payloadPolicyFromEnv().mode === 'off')
177
176
  return;
178
177
  const { signal: _signal, ...request } = result.request;
179
178
  span.setAttribute('llm.payload.request', payloadJson(request));
@@ -181,10 +180,9 @@ function recordModelCall(span, result, provider) {
181
180
  }
182
181
  /** One tool call as a `tool.execute <name>` span, under the agent's. */
183
182
  export async function traceToolCall(call, tool, run) {
184
- initializeTracing();
185
183
  const name = call.name || '<unnamed>';
186
184
  const description = tool && typeof tool === 'object' ? tool.description : undefined;
187
- const span = runtimeTracer().startSpan(`tool.execute ${name}`, {
185
+ const span = startRuntimeSpan(`tool.execute ${name}`, {
188
186
  attributes: {
189
187
  'gen_ai.operation.name': 'execute_tool',
190
188
  'gen_ai.tool.name': name,
@@ -221,8 +219,7 @@ export async function traceToolCall(call, tool, run) {
221
219
  // attributes each model call to the node's agent, as on ADK.
222
220
  /** The walk as a `workflow.invoke <name>` span; every node span opens under it. */
223
221
  export async function traceWorkflowInvocation(workflow, ctx, run) {
224
- initializeTracing();
225
- const span = runtimeTracer().startSpan(`workflow.invoke ${workflow.name}`, {
222
+ const span = startRuntimeSpan(`workflow.invoke ${workflow.name}`, {
226
223
  attributes: {
227
224
  'gen_ai.operation.name': 'invoke_workflow',
228
225
  'gen_ai.conversation.id': ctx.sessionId,
@@ -248,8 +245,7 @@ export async function traceWorkflowInvocation(workflow, ctx, run) {
248
245
  * attempts the run made.
249
246
  */
250
247
  export async function traceNodeExecution(node, run) {
251
- initializeTracing();
252
- const span = runtimeTracer().startSpan(`node.execute ${node.name}`, {
248
+ const span = startRuntimeSpan(`node.execute ${node.name}`, {
253
249
  attributes: {
254
250
  'gen_ai.operation.name': 'execute_node',
255
251
  'adk.node.path': node.path,
@@ -274,9 +270,8 @@ export async function traceNodeExecution(node, run) {
274
270
  }
275
271
  /** A tool node's call as a `tool.execute <name>` span, under its node's (ToolNodeContext.traceCall). */
276
272
  export async function traceToolNodeCall(call, tool, run) {
277
- initializeTracing();
278
273
  const description = tool && typeof tool === 'object' ? tool.description : undefined;
279
- const span = runtimeTracer().startSpan(`tool.execute ${call.name}`, {
274
+ const span = startRuntimeSpan(`tool.execute ${call.name}`, {
280
275
  attributes: {
281
276
  'gen_ai.operation.name': 'execute_tool',
282
277
  'gen_ai.tool.name': call.name,
@@ -17,10 +17,13 @@
17
17
  * (lib/workflow.ts) and an approval (ADR 0028); a client handles all three
18
18
  * by showing `result.input` (or the approval) and sending the next message.
19
19
  *
20
- * WHERE: only on an agent the turn runs directly (the orchestrator, or a
21
- * plan-dispatch route), as with approval gates: inside a delegated
22
- * subagent the pause cannot reach the person. Not inside a workflow node
23
- * yet. The schema refuses both.
20
+ * WHERE: on any agent of a delegate or dispatch syndicate, as with approval
21
+ * gates. Inside a delegated subagent the question waits in the child's
22
+ * session, below the call its caller left open, and reaches the person
23
+ * with the agent path (`result.input.path`, ADR 0110); the next message is
24
+ * stored as the answer and carried down to the child
25
+ * (lib/runtime/native/interrupts.ts). Not inside a workflow node yet; the
26
+ * schema refuses it there.
24
27
  *
25
28
  * RESUME: the answer is an ordinary function response, so the loop resumes
26
29
  * a question ADK opened before 1.0.0 as one it opened itself (ADR 0079); no
@@ -37,7 +37,7 @@
37
37
  import type { TurnEvent } from './events.ts';
38
38
  /** A conversation's address. Stores key it as `<appName>:<userId>:<sessionId>`. */
39
39
  export interface SessionKey {
40
- /** The syndicate (or, for a DELEGATE subagent's own row, the subagent's name). */
40
+ /** The syndicate (or, for a DELEGATE subagent's own row, its agent path: lib/runtime/native/delegate.ts childAppName). */
41
41
  appName: string;
42
42
  userId: string;
43
43
  sessionId: string;
@@ -144,7 +144,13 @@ export interface SyndicateTurnOptions {
144
144
  maxLlmCalls?: number;
145
145
  /** Ask adapters for token-by-token partial events (the REPL's live view). */
146
146
  streaming?: boolean;
147
- /** Root-span metadata; `false` disables tracing for the turn. */
147
+ /**
148
+ * Root-span metadata. `false` disables tracing for the turn: it records no
149
+ * span, so no row reaches the ledger (adk_telemetry, adk_turns,
150
+ * adk_payloads), the console exporter, the in-process listeners or an OTLP
151
+ * endpoint, and the turn does not start the tracer. The step budget and
152
+ * the usage in the result are unaffected. Default: traced.
153
+ */
148
154
  trace?: TraceOptions | false;
149
155
  events?: TurnEvents;
150
156
  /**
@@ -152,7 +158,8 @@ export interface SyndicateTurnOptions {
152
158
  * the native runtime. The store is pinned to `appName`; a tool reads the
153
159
  * grant of `userId` only. With `consent`, a call whose provider the user
154
160
  * has not granted pauses the turn input-required (`result.consent`), and
155
- * the next message after the grant resumes it. Omitted: tools have no
161
+ * the next message after the grant resumes it; inside a delegated
162
+ * subagent too, with `consent.path` set (ADR 0118). Omitted: tools have no
156
163
  * `accessToken`, as before.
157
164
  */
158
165
  toolCredentials?: ToolCredentials;
@@ -223,7 +230,8 @@ export interface SyndicateTurnResult {
223
230
  input?: PendingInput;
224
231
  /** The OAuth grant a paused call waits for, when status is input-required
225
232
  * (ADR 0085): the person opens `consent.authUri`; their next message after
226
- * the grant is stored resumes the call. */
233
+ * the grant is stored resumes the call. `consent.path` is set for a call
234
+ * inside a delegated subagent (ADR 0118). */
227
235
  consent?: PendingConsent;
228
236
  /** The text the user receives (relay fallback and guards applied). */
229
237
  text: string;