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.
- package/.env.example +4 -5
- package/AGENT_SETUP.md +3 -3
- package/CHANGELOG.md +492 -76
- package/DOCUMENTATION.md +153 -132
- package/QUICKSTART.md +14 -10
- package/README.md +12 -15
- package/config/agents/examples/image_production.yaml +2 -2
- package/config/agents/syndicateSchema.yaml +55 -26
- package/dist/lib/a2a/app.d.ts +17 -12
- package/dist/lib/a2a/app.js +16 -6
- package/dist/lib/a2a/executor.d.ts +10 -14
- package/dist/lib/a2a/executor.js +10 -18
- package/dist/lib/a2a/remoteAgent.d.ts +5 -12
- package/dist/lib/a2a/remoteAgent.js +5 -12
- package/dist/lib/adkPeer.d.ts +63 -0
- package/dist/lib/adkPeer.js +240 -0
- package/dist/lib/compile.d.ts +109 -81
- package/dist/lib/compile.js +163 -111
- package/dist/lib/compileAdk.d.ts +7 -4
- package/dist/lib/compileAdk.js +22 -12
- package/dist/lib/compileNative.d.ts +63 -49
- package/dist/lib/compileNative.js +136 -78
- package/dist/lib/config.d.ts +6 -6
- package/dist/lib/config.js +6 -6
- package/dist/lib/doctor.d.ts +22 -1
- package/dist/lib/doctor.js +27 -2
- package/dist/lib/index.d.ts +14 -7
- package/dist/lib/index.js +11 -7
- package/dist/lib/loadSyndicate.d.ts +3 -3
- package/dist/lib/loadSyndicate.js +2 -2
- package/dist/lib/memory/erase.d.ts +1 -1
- package/dist/lib/memory/erase.js +1 -1
- package/dist/lib/memory/namespace.d.ts +12 -14
- package/dist/lib/memory/namespace.js +13 -14
- package/dist/lib/memory/providers.d.ts +4 -5
- package/dist/lib/memory/providers.js +12 -6
- package/dist/lib/memory/supabaseMemoryService.d.ts +9 -30
- package/dist/lib/memory/supabaseMemoryService.js +8 -30
- package/dist/lib/model.d.ts +6 -12
- package/dist/lib/model.js +6 -12
- package/dist/lib/models/adapterResolver.d.ts +21 -38
- package/dist/lib/models/adapterResolver.js +33 -40
- package/dist/lib/models/adkGeminiAdapter.js +2 -0
- package/dist/lib/models/adkShim.d.ts +1 -1
- package/dist/lib/models/adkShim.js +1 -1
- package/dist/lib/models/capabilities.js +13 -10
- package/dist/lib/models/chatCompletionsAdapter.d.ts +12 -33
- package/dist/lib/models/chatCompletionsAdapter.js +13 -18
- package/dist/lib/models/circuitBreaker.d.ts +5 -5
- package/dist/lib/models/circuitBreaker.js +5 -5
- package/dist/lib/models/claudeAdapter.d.ts +9 -26
- package/dist/lib/models/claudeAdapter.js +11 -15
- package/dist/lib/models/claudeLlm.js +2 -2
- package/dist/lib/models/claudeModels.d.ts +4 -4
- package/dist/lib/models/claudeModels.js +4 -4
- package/dist/lib/models/contract.d.ts +11 -11
- package/dist/lib/models/contract.js +6 -6
- package/dist/lib/models/errorResponse.d.ts +13 -20
- package/dist/lib/models/errorResponse.js +0 -12
- package/dist/lib/models/fallback.d.ts +1 -1
- package/dist/lib/models/fallback.js +1 -1
- package/dist/lib/models/fallbackAdapter.d.ts +7 -8
- package/dist/lib/models/gatewayAdapter.d.ts +1 -1
- package/dist/lib/models/gatewayAdapter.js +1 -1
- package/dist/lib/models/gatewayLlm.js +2 -2
- package/dist/lib/models/geminiAdapter.d.ts +11 -10
- package/dist/lib/models/geminiAdapter.js +37 -15
- package/dist/lib/models/geminiState.d.ts +29 -8
- package/dist/lib/models/geminiState.js +34 -8
- package/dist/lib/models/genaiMapping.d.ts +104 -38
- package/dist/lib/models/genaiMapping.js +146 -43
- package/dist/lib/models/gptAdapter.d.ts +11 -11
- package/dist/lib/models/gptAdapter.js +13 -13
- package/dist/lib/models/gptLlm.js +2 -2
- package/dist/lib/models/grokLlm.js +2 -2
- package/dist/lib/models/kimiAdapter.d.ts +6 -7
- package/dist/lib/models/kimiAdapter.js +6 -9
- package/dist/lib/models/kimiLlm.js +2 -2
- package/dist/lib/models/ollamaAdapter.d.ts +3 -3
- package/dist/lib/models/ollamaAdapter.js +3 -3
- package/dist/lib/models/ollamaLlm.js +2 -2
- package/dist/lib/models/providerMap.d.ts +6 -5
- package/dist/lib/models/providerMap.js +6 -5
- package/dist/lib/models/providerState.d.ts +3 -2
- package/dist/lib/models/providerState.js +3 -2
- package/dist/lib/models/reasoning.d.ts +1 -1
- package/dist/lib/models/registry.d.ts +26 -69
- package/dist/lib/models/registry.js +32 -140
- package/dist/lib/models/retry.d.ts +2 -2
- package/dist/lib/models/retry.js +2 -2
- package/dist/lib/models/schemaNormalize.d.ts +25 -55
- package/dist/lib/models/schemaNormalize.js +30 -100
- package/dist/lib/models/tracedGemini.d.ts +1 -1
- package/dist/lib/models/tracedGemini.js +1 -1
- package/dist/lib/observability/lineage.d.ts +3 -3
- package/dist/lib/observability/lineage.js +10 -10
- package/dist/lib/observability/supabaseSpanExporter.js +1 -1
- package/dist/lib/observability/tracer.d.ts +25 -23
- package/dist/lib/observability/tracer.js +26 -63
- package/dist/lib/persistence/supabaseProvider.d.ts +4 -3
- package/dist/lib/runtime/adkSessionBridge.d.ts +1 -1
- package/dist/lib/runtime/adkSessionBridge.js +1 -1
- package/dist/lib/runtime/approvals.d.ts +6 -1
- package/dist/lib/runtime/approvals.js +39 -8
- package/dist/lib/runtime/credentials.d.ts +4 -2
- package/dist/lib/runtime/credentials.js +6 -1
- package/dist/lib/runtime/events.d.ts +3 -4
- package/dist/lib/runtime/events.js +3 -4
- package/dist/lib/runtime/logging.d.ts +3 -8
- package/dist/lib/runtime/logging.js +3 -8
- package/dist/lib/runtime/memoryService.d.ts +4 -6
- package/dist/lib/runtime/memoryService.js +3 -5
- package/dist/lib/runtime/native/agentLoop.d.ts +24 -16
- package/dist/lib/runtime/native/agentLoop.js +67 -37
- package/dist/lib/runtime/native/compaction.d.ts +10 -11
- package/dist/lib/runtime/native/compaction.js +10 -11
- package/dist/lib/runtime/native/delegate.d.ts +64 -12
- package/dist/lib/runtime/native/delegate.js +101 -25
- package/dist/lib/runtime/native/history.d.ts +5 -6
- package/dist/lib/runtime/native/history.js +5 -6
- package/dist/lib/runtime/native/interrupts.d.ts +12 -9
- package/dist/lib/runtime/native/interrupts.js +29 -10
- package/dist/lib/runtime/native/request.d.ts +25 -25
- package/dist/lib/runtime/native/request.js +36 -25
- package/dist/lib/runtime/native/selfCorrection.d.ts +75 -17
- package/dist/lib/runtime/native/selfCorrection.js +93 -19
- package/dist/lib/runtime/native/step.d.ts +34 -26
- package/dist/lib/runtime/native/step.js +78 -32
- package/dist/lib/runtime/native/taskMode.d.ts +8 -8
- package/dist/lib/runtime/native/taskMode.js +8 -8
- package/dist/lib/runtime/native/telemetry.d.ts +11 -11
- package/dist/lib/runtime/native/telemetry.js +11 -11
- package/dist/lib/runtime/native/tempState.d.ts +4 -4
- package/dist/lib/runtime/native/tempState.js +4 -4
- package/dist/lib/runtime/nativeTurn.d.ts +29 -32
- package/dist/lib/runtime/nativeTurn.js +30 -41
- package/dist/lib/runtime/questions.d.ts +8 -9
- package/dist/lib/runtime/questions.js +1 -2
- package/dist/lib/runtime/runtimeFlag.d.ts +35 -13
- package/dist/lib/runtime/runtimeFlag.js +46 -16
- package/dist/lib/runtime/sessions.d.ts +10 -12
- package/dist/lib/runtime/sessions.js +10 -12
- package/dist/lib/runtime/syndicateTurn.d.ts +46 -42
- package/dist/lib/runtime/syndicateTurn.js +182 -150
- package/dist/lib/runtime/turnControl.d.ts +8 -8
- package/dist/lib/runtime/turnControl.js +8 -8
- package/dist/lib/runtime/valueDepth.d.ts +23 -0
- package/dist/lib/runtime/valueDepth.js +41 -0
- package/dist/lib/session/supabaseSessionService.d.ts +7 -21
- package/dist/lib/session/supabaseSessionService.js +7 -43
- package/dist/lib/session/transcript.d.ts +16 -26
- package/dist/lib/session/transcript.js +17 -55
- package/dist/lib/storage/postgres/sessionService.d.ts +6 -20
- package/dist/lib/storage/postgres/sessionService.js +6 -39
- package/dist/lib/syndicateSchema.d.ts +2 -0
- package/dist/lib/syndicateSchema.js +32 -10
- package/dist/lib/toolRegistry.d.ts +20 -14
- package/dist/lib/toolRegistry.js +76 -33
- package/dist/lib/tools/adkTool.d.ts +1 -1
- package/dist/lib/tools/adkTool.js +1 -1
- package/dist/lib/tools/auth.d.ts +1 -1
- package/dist/lib/tools/auth.js +1 -1
- package/dist/lib/tools/collectionsSearchTool.d.ts +1 -1
- package/dist/lib/tools/collectionsSearchTool.js +1 -1
- package/dist/lib/tools/examples.d.ts +2 -4
- package/dist/lib/tools/examples.js +2 -4
- package/dist/lib/tools/generateImageTool.d.ts +3 -3
- package/dist/lib/tools/generateImageTool.js +4 -5
- package/dist/lib/tools/inspectImageTool.d.ts +2 -2
- package/dist/lib/tools/inspectImageTool.js +3 -4
- package/dist/lib/tools/mcpToolFactory.d.ts +4 -24
- package/dist/lib/tools/mcpToolFactory.js +19 -9
- package/dist/lib/tools/memoryTools.d.ts +5 -6
- package/dist/lib/tools/memoryTools.js +5 -6
- package/dist/lib/tools/nativeTools.d.ts +9 -14
- package/dist/lib/tools/nativeTools.js +9 -14
- package/dist/lib/tools/openapiTools.d.ts +5 -7
- package/dist/lib/tools/openapiTools.js +6 -13
- package/dist/lib/tools/scienceTools.d.ts +3 -3
- package/dist/lib/tools/scienceTools.js +8 -10
- package/dist/lib/tools/skillToolset.d.ts +1 -2
- package/dist/lib/tools/skillToolset.js +1 -2
- package/dist/lib/tools/skills/executor.d.ts +1 -1
- package/dist/lib/tools/skills/executor.js +1 -1
- package/dist/lib/tools/skills/frontmatter.d.ts +2 -2
- package/dist/lib/tools/skills/frontmatter.js +2 -2
- package/dist/lib/tools/skills/tools.d.ts +8 -10
- package/dist/lib/tools/skills/tools.js +9 -11
- package/dist/lib/tools/tool.d.ts +24 -40
- package/dist/lib/tools/tool.js +24 -56
- package/dist/lib/tools/toolContract.d.ts +8 -13
- package/dist/lib/tools/toolContract.js +6 -17
- package/dist/lib/tools/urlContextTool.d.ts +1 -1
- package/dist/lib/tools/urlContextTool.js +1 -1
- package/dist/lib/tools/webExtractTool.d.ts +2 -2
- package/dist/lib/tools/webExtractTool.js +3 -4
- package/dist/lib/tools/webSearchTool.d.ts +1 -1
- package/dist/lib/tools/webSearchTool.js +1 -1
- package/dist/lib/tools/wikiTools.d.ts +2 -2
- package/dist/lib/tools/wikiTools.js +5 -6
- package/dist/lib/tools/xApiSearchTool.d.ts +2 -2
- package/dist/lib/tools/xApiSearchTool.js +3 -4
- package/dist/lib/tools/xSearchTool.d.ts +1 -1
- package/dist/lib/tools/xSearchTool.js +1 -1
- package/dist/lib/tools/xaiSearchParams.d.ts +2 -5
- package/dist/lib/tools/xaiSearchParams.js +2 -5
- package/dist/lib/wiki/agentRun.d.ts +10 -11
- package/dist/lib/wiki/agentRun.js +24 -41
- package/dist/lib/workflow/agentNode.d.ts +31 -5
- package/dist/lib/workflow/agentNode.js +101 -8
- package/dist/lib/workflow/graph.d.ts +13 -13
- package/dist/lib/workflow/graph.js +25 -15
- package/dist/lib/workflow/nodeEvents.d.ts +5 -5
- package/dist/lib/workflow/nodeEvents.js +5 -5
- package/dist/lib/workflow/pause.d.ts +5 -4
- package/dist/lib/workflow/pause.js +5 -4
- package/dist/lib/workflow/resume.d.ts +14 -13
- package/dist/lib/workflow/resume.js +17 -16
- package/dist/lib/workflow/route.d.ts +7 -7
- package/dist/lib/workflow/route.js +8 -8
- package/dist/lib/workflow/scheduler.d.ts +54 -9
- package/dist/lib/workflow/scheduler.js +75 -8
- package/dist/lib/workflow/toolNode.d.ts +18 -29
- package/dist/lib/workflow/toolNode.js +29 -35
- package/dist/lib/workflow/turn.d.ts +29 -20
- package/dist/lib/workflow/turn.js +111 -24
- package/dist/lib/workflow.d.ts +38 -42
- package/dist/lib/workflow.js +38 -150
- package/dist/lib/workflowConfig.d.ts +6 -10
- package/dist/lib/workflowConfig.js +2 -27
- package/dist/scripts/a2a_server.js +1 -2
- package/dist/scripts/assistant_worker.d.ts +2 -2
- package/dist/scripts/assistant_worker.js +8 -7
- package/dist/scripts/doctor.d.ts +3 -1
- package/dist/scripts/doctor.js +4 -2
- package/dist/scripts/syndicate_chat.js +14 -24
- package/package.json +3 -6
- package/skills/briefs/_shared.md +2 -2
- package/skills/briefs/melchizedek-author.md +2 -2
- package/skills/briefs/melchizedek-models.md +6 -6
- package/skills/melchizedek-author/SKILL.md +2 -2
- package/skills/melchizedek-models/SKILL.md +5 -5
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* lib/models/adapterResolver.ts — one model id to one ModelAdapter on the
|
|
3
|
-
* engine's own contract (ADR 0048, ADR 0060
|
|
4
|
-
* import graph.
|
|
3
|
+
* engine's own contract (ADR 0048, ADR 0060, ADR 0107).
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* resolveModel and for its own resolveAdapter.
|
|
5
|
+
* The routing step (routeFor: the provider from the prefix table, the
|
|
6
|
+
* caller's endpoint merged over the environment's, the transport from
|
|
7
|
+
* planTransport), the BYOK scoping and the contract adapter table live
|
|
8
|
+
* here. lib/models/registry.ts re-exports the resolver and builds
|
|
9
|
+
* resolveModel on it; `melchizedek-agents/model` (lib/model.ts) exports it
|
|
10
|
+
* with no compiler or runtime in its import graph (ADR 0068).
|
|
13
11
|
*
|
|
14
|
-
* GEMINI (ADR
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* `adk` is asked for, by the option or by GEMINI_ADAPTER=adk, which throws
|
|
19
|
-
* and names the entry that has it.
|
|
12
|
+
* GEMINI (ADR 0100, ADR 0107): a Gemini id gets the engine's GeminiAdapter.
|
|
13
|
+
* GEMINI_ADAPTER=engine, or the `gemini: 'engine'` option, is accepted and
|
|
14
|
+
* changes nothing; `adk`, the ADK Gemini adapter that 1.0.0 removed, throws
|
|
15
|
+
* an error naming the release.
|
|
20
16
|
*/
|
|
21
17
|
import type { ModelAdapter } from './contract.ts';
|
|
22
18
|
import type { ProviderEndpoint } from './endpoints.ts';
|
|
@@ -50,14 +46,9 @@ export declare function routeFor(model: string, apiKey: string | undefined, endp
|
|
|
50
46
|
export declare function scopedKey(model: string, apiKey: string | undefined, keyProvider: ProviderId): string | undefined;
|
|
51
47
|
/** A provider name as the A2A X-Provider header gives it; anything unknown reads as gemini. */
|
|
52
48
|
export declare function normalizeProvider(provider?: string): ProviderId;
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* `engine`, the engine's own GeminiAdapter on @google/genai
|
|
57
|
-
* (lib/models/geminiAdapter.ts).
|
|
58
|
-
*/
|
|
59
|
-
export type GeminiAdapterChoice = 'adk' | 'engine';
|
|
60
|
-
/** GEMINI_ADAPTER as set (`adk` or `engine`), or undefined when unset. Any other value is a configuration error. */
|
|
49
|
+
/** Which adapter serves a Gemini id: the engine's GeminiAdapter (lib/models/geminiAdapter.ts), the only one since 1.0.0. */
|
|
50
|
+
export type GeminiAdapterChoice = 'engine';
|
|
51
|
+
/** GEMINI_ADAPTER as set (`engine`), or undefined when unset. `adk` throws, naming 1.0.0; any other value is a configuration error. */
|
|
61
52
|
export declare function geminiAdapterSetting(env?: NodeJS.ProcessEnv): GeminiAdapterChoice | undefined;
|
|
62
53
|
export interface ResolveAdapterOptions {
|
|
63
54
|
/**
|
|
@@ -74,32 +65,24 @@ export interface ResolveAdapterOptions {
|
|
|
74
65
|
/** Where requests go (ADR 0023), merged over the environment's endpoint for the model's provider. */
|
|
75
66
|
endpoint?: Partial<ProviderEndpoint>;
|
|
76
67
|
/**
|
|
77
|
-
* Which Gemini adapter a Gemini id gets
|
|
78
|
-
*
|
|
79
|
-
* `melchizedek-agents/model`, which has no `adk`.
|
|
68
|
+
* Which Gemini adapter a Gemini id gets: `engine`, the only one (ADR 0107).
|
|
69
|
+
* GEMINI_ADAPTER is still read, so `adk` there throws.
|
|
80
70
|
*/
|
|
81
71
|
gemini?: GeminiAdapterChoice;
|
|
82
72
|
}
|
|
83
73
|
/** What a direct route's adapter is built from. */
|
|
84
74
|
export type AdapterRoute = Pick<Route, 'model' | 'apiKey' | 'endpoint'>;
|
|
85
|
-
/** Builds the temporary AdkGeminiAdapter; only lib/models/registry.ts supplies one. */
|
|
86
|
-
export type AdkGeminiFactory = (route: AdapterRoute) => ModelAdapter;
|
|
87
75
|
export interface AdapterResolver {
|
|
88
76
|
resolveAdapter(modelId: string, options?: ResolveAdapterOptions): ModelAdapter;
|
|
89
77
|
resolveAdapterWithFallback(modelId: string, fallbackId: string | undefined, options?: ResolveAdapterOptions, fallbackOptions?: FallbackAdapterOptions): ModelAdapter;
|
|
90
78
|
}
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
* AdkGeminiAdapter unless `engine` is asked for (ADR 0060). Without it, a
|
|
94
|
-
* Gemini id gets GeminiAdapter, and asking for `adk` throws (ADR 0068).
|
|
95
|
-
*/
|
|
96
|
-
export declare function adapterResolver(adkGemini?: AdkGeminiFactory): AdapterResolver;
|
|
79
|
+
/** A resolver over the one prefix table. A Gemini id gets GeminiAdapter (ADR 0100, ADR 0107). */
|
|
80
|
+
export declare function adapterResolver(): AdapterResolver;
|
|
97
81
|
/**
|
|
98
82
|
* Resolves a model id to the engine's own ModelAdapter (ADR 0048), from the
|
|
99
|
-
* prefix table and the transport rule
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* GeminiAdapter (ADR 0068). The adapter opens no span and charges nothing:
|
|
83
|
+
* prefix table and the transport rule: the provider's adapter when its key
|
|
84
|
+
* (env, BYOK or endpoint) is present, the gateway's when it is absent and
|
|
85
|
+
* MODEL_GATEWAY is set. A Gemini id gets GeminiAdapter. The adapter opens no span and charges nothing:
|
|
103
86
|
* its caller does (ADR 0053).
|
|
104
87
|
*/
|
|
105
88
|
export declare function resolveAdapter(modelId: string, options?: ResolveAdapterOptions): ModelAdapter;
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* lib/models/adapterResolver.ts — one model id to one ModelAdapter on the
|
|
3
|
-
* engine's own contract (ADR 0048, ADR 0060
|
|
4
|
-
* import graph.
|
|
3
|
+
* engine's own contract (ADR 0048, ADR 0060, ADR 0107).
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* resolveModel and for its own resolveAdapter.
|
|
5
|
+
* The routing step (routeFor: the provider from the prefix table, the
|
|
6
|
+
* caller's endpoint merged over the environment's, the transport from
|
|
7
|
+
* planTransport), the BYOK scoping and the contract adapter table live
|
|
8
|
+
* here. lib/models/registry.ts re-exports the resolver and builds
|
|
9
|
+
* resolveModel on it; `melchizedek-agents/model` (lib/model.ts) exports it
|
|
10
|
+
* with no compiler or runtime in its import graph (ADR 0068).
|
|
13
11
|
*
|
|
14
|
-
* GEMINI (ADR
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* `adk` is asked for, by the option or by GEMINI_ADAPTER=adk, which throws
|
|
19
|
-
* and names the entry that has it.
|
|
12
|
+
* GEMINI (ADR 0100, ADR 0107): a Gemini id gets the engine's GeminiAdapter.
|
|
13
|
+
* GEMINI_ADAPTER=engine, or the `gemini: 'engine'` option, is accepted and
|
|
14
|
+
* changes nothing; `adk`, the ADK Gemini adapter that 1.0.0 removed, throws
|
|
15
|
+
* an error naming the release.
|
|
20
16
|
*/
|
|
21
17
|
import { ClaudeAdapter } from './claudeAdapter.js';
|
|
22
18
|
import { mergeEndpoint } from './endpoints.js';
|
|
@@ -60,14 +56,21 @@ export function normalizeProvider(provider) {
|
|
|
60
56
|
}
|
|
61
57
|
return 'gemini';
|
|
62
58
|
}
|
|
63
|
-
/**
|
|
59
|
+
/** The error for GEMINI_ADAPTER=adk, or the `gemini: 'adk'` option: the ADK Gemini adapter left in 1.0.0. */
|
|
60
|
+
function adkGeminiRemoved(source) {
|
|
61
|
+
return new Error(`${source} asks for the ADK Gemini adapter, which was removed in melchizedek-agents 1.0.0 (ADR 0107): ` +
|
|
62
|
+
`every Gemini id runs on the engine's GeminiAdapter. Unset ${source} (or set it to "engine").`);
|
|
63
|
+
}
|
|
64
|
+
/** GEMINI_ADAPTER as set (`engine`), or undefined when unset. `adk` throws, naming 1.0.0; any other value is a configuration error. */
|
|
64
65
|
export function geminiAdapterSetting(env = process.env) {
|
|
65
66
|
const raw = env.GEMINI_ADAPTER?.trim().toLowerCase();
|
|
66
67
|
if (!raw)
|
|
67
68
|
return undefined;
|
|
68
|
-
if (raw === '
|
|
69
|
+
if (raw === 'engine')
|
|
69
70
|
return raw;
|
|
70
|
-
|
|
71
|
+
if (raw === 'adk')
|
|
72
|
+
throw adkGeminiRemoved('GEMINI_ADAPTER');
|
|
73
|
+
throw new Error('GEMINI_ADAPTER must be "engine" (the only Gemini adapter since 1.0.0).');
|
|
71
74
|
}
|
|
72
75
|
/** Each non-Gemini provider's contract adapter for a direct route. */
|
|
73
76
|
const CONTRACT_ADAPTER = {
|
|
@@ -77,21 +80,12 @@ const CONTRACT_ADAPTER = {
|
|
|
77
80
|
xai: (r) => new GrokAdapter({ model: r.model, apiKey: r.apiKey }),
|
|
78
81
|
moonshot: (r) => new KimiAdapter({ model: r.model, apiKey: r.apiKey, baseUrl: r.endpoint?.baseURL }),
|
|
79
82
|
};
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
* AdkGeminiAdapter unless `engine` is asked for (ADR 0060). Without it, a
|
|
83
|
-
* Gemini id gets GeminiAdapter, and asking for `adk` throws (ADR 0068).
|
|
84
|
-
*/
|
|
85
|
-
export function adapterResolver(adkGemini) {
|
|
83
|
+
/** A resolver over the one prefix table. A Gemini id gets GeminiAdapter (ADR 0100, ADR 0107). */
|
|
84
|
+
export function adapterResolver() {
|
|
86
85
|
const geminiFor = (r, choice) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (!adkGemini) {
|
|
91
|
-
throw new Error('The ADK Gemini adapter is not available from melchizedek-agents/model, which loads no @google/adk. ' +
|
|
92
|
-
'Use gemini: "engine" (or unset GEMINI_ADAPTER), or resolve through melchizedek-agents/models/registry.');
|
|
93
|
-
}
|
|
94
|
-
return adkGemini(route);
|
|
86
|
+
if (choice !== 'engine')
|
|
87
|
+
throw adkGeminiRemoved(`The gemini option ("${choice}")`);
|
|
88
|
+
return new GeminiAdapter({ model: r.model, apiKey: r.apiKey, endpoint: r.endpoint });
|
|
95
89
|
};
|
|
96
90
|
function resolveAdapter(modelId, options = {}) {
|
|
97
91
|
const keyProvider = options.keyProvider === undefined ? providerForModel(modelId) : normalizeProvider(options.keyProvider);
|
|
@@ -99,7 +93,7 @@ export function adapterResolver(adkGemini) {
|
|
|
99
93
|
if (route.transport === 'gateway')
|
|
100
94
|
return new GatewayAdapter({ model: modelId });
|
|
101
95
|
if (route.provider === 'gemini') {
|
|
102
|
-
return geminiFor(route, options.gemini ?? geminiAdapterSetting() ??
|
|
96
|
+
return geminiFor(route, options.gemini ?? geminiAdapterSetting() ?? 'engine');
|
|
103
97
|
}
|
|
104
98
|
return CONTRACT_ADAPTER[route.provider](route);
|
|
105
99
|
}
|
|
@@ -112,17 +106,16 @@ export function adapterResolver(adkGemini) {
|
|
|
112
106
|
}
|
|
113
107
|
return { resolveAdapter, resolveAdapterWithFallback };
|
|
114
108
|
}
|
|
115
|
-
const
|
|
109
|
+
const RESOLVER = adapterResolver();
|
|
116
110
|
/**
|
|
117
111
|
* Resolves a model id to the engine's own ModelAdapter (ADR 0048), from the
|
|
118
|
-
* prefix table and the transport rule
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* GeminiAdapter (ADR 0068). The adapter opens no span and charges nothing:
|
|
112
|
+
* prefix table and the transport rule: the provider's adapter when its key
|
|
113
|
+
* (env, BYOK or endpoint) is present, the gateway's when it is absent and
|
|
114
|
+
* MODEL_GATEWAY is set. A Gemini id gets GeminiAdapter. The adapter opens no span and charges nothing:
|
|
122
115
|
* its caller does (ADR 0053).
|
|
123
116
|
*/
|
|
124
117
|
export function resolveAdapter(modelId, options = {}) {
|
|
125
|
-
return
|
|
118
|
+
return RESOLVER.resolveAdapter(modelId, options);
|
|
126
119
|
}
|
|
127
120
|
/**
|
|
128
121
|
* An agent's model and its `fallback_model:`: a FallbackAdapter (ADR 0044)
|
|
@@ -132,5 +125,5 @@ export function resolveAdapter(modelId, options = {}) {
|
|
|
132
125
|
* server env.
|
|
133
126
|
*/
|
|
134
127
|
export function resolveAdapterWithFallback(modelId, fallbackId, options = {}, fallbackOptions = {}) {
|
|
135
|
-
return
|
|
128
|
+
return RESOLVER.resolveAdapterWithFallback(modelId, fallbackId, options, fallbackOptions);
|
|
136
129
|
}
|
|
@@ -71,6 +71,7 @@ import { errorText } from './errorResponse.js';
|
|
|
71
71
|
import { GEMINI_PROVIDER } from './geminiState.js';
|
|
72
72
|
import { llmResponseToModelResponse, modelRequestToLlmRequest, nativeToolsWithoutGeminiTool } from './genaiMapping.js';
|
|
73
73
|
import { TracedGemini } from './tracedGemini.js';
|
|
74
|
+
import { requireAdk } from '../adkPeer.js';
|
|
74
75
|
import { classifyError, errorStatus } from './retry.js';
|
|
75
76
|
import { setLlmSpanAttribute } from '../observability/tracer.js';
|
|
76
77
|
/** The prefix of a call id ADK (or the engine after it) made: such an id never goes on the wire. */
|
|
@@ -85,6 +86,7 @@ export class AdkGeminiAdapter {
|
|
|
85
86
|
#connection;
|
|
86
87
|
#warned = new Set();
|
|
87
88
|
constructor(options) {
|
|
89
|
+
requireAdk('GEMINI_ADAPTER=adk (AdkGeminiAdapter, which runs ADK\'s Gemini)');
|
|
88
90
|
this.model = options.model;
|
|
89
91
|
this.#apiKey = nonEmpty(options.apiKey);
|
|
90
92
|
this.#endpoint = options.endpoint;
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* is charged and traced on its own, as today. A FallbackAdapter behind one
|
|
52
52
|
* shim would make a redirected call one span and one charge.
|
|
53
53
|
*/
|
|
54
|
-
import { BaseLlm } from '
|
|
54
|
+
import { BaseLlm } from '../adkPeer.ts';
|
|
55
55
|
import type { BaseLlmConnection, BaseLlmType, LlmRequest, LlmResponse } from '@google/adk';
|
|
56
56
|
import type { ModelAdapter, ModelRequest, ModelResponse } from './contract.ts';
|
|
57
57
|
import type { ModelRequestOptions } from './genaiMapping.ts';
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* is charged and traced on its own, as today. A FallbackAdapter behind one
|
|
52
52
|
* shim would make a redirected call one span and one charge.
|
|
53
53
|
*/
|
|
54
|
-
import { BaseLlm } from '
|
|
54
|
+
import { BaseLlm } from '../adkPeer.js';
|
|
55
55
|
import { llmRequestToModelRequest, modelResponseToLlmResponse } from './genaiMapping.js';
|
|
56
56
|
import { traceLlmGeneration } from '../observability/tracer.js';
|
|
57
57
|
import { currentTurnSignal } from '../runtime/turnControl.js';
|
|
@@ -108,8 +108,11 @@ export function capabilitySummary(agentName, r) {
|
|
|
108
108
|
//
|
|
109
109
|
// `evidence: 'test'` cells are asserted against the real outgoing request body
|
|
110
110
|
// in tests/capabilityMatrix.test.ts, so changing an adapter without changing
|
|
111
|
-
// its row fails a test.
|
|
112
|
-
//
|
|
111
|
+
// its row fails a test. Every cell is `test`. The Gemini row is the engine's
|
|
112
|
+
// own GeminiAdapter (lib/models/geminiAdapter.ts), asserted on the real
|
|
113
|
+
// @google/genai client over a stubbed fetch (gate G3, ADR 0100). `'adk'`
|
|
114
|
+
// (a cell taken on trust from ADK's own Gemini) stays in the type because the
|
|
115
|
+
// type is published (`melchizedek-agents/models/*`); no cell uses it.
|
|
113
116
|
export const CAPABILITIES = [
|
|
114
117
|
'delegation',
|
|
115
118
|
'memory_tools',
|
|
@@ -132,18 +135,18 @@ const ok = (evidence = 'test', note) => note ? { support: 'supported', note, evi
|
|
|
132
135
|
const degraded = (note) => ({ support: 'degraded', note, evidence: 'test' });
|
|
133
136
|
const unsupported = (note) => ({ support: 'unsupported', note, evidence: 'test' });
|
|
134
137
|
const nativeSearch = (row) => SERVER_SIDE_TOOLS.web_search.includes(row)
|
|
135
|
-
? ok(
|
|
138
|
+
? ok()
|
|
136
139
|
: unsupported('no native search on this path; the web_search sentinel is dropped (use web_extract)');
|
|
137
140
|
const responsesReasoningNote = (ids) => `encrypted reasoning items are replayed verbatim within the turn's tool loop, with store: false (ADR 0050); ${ids}`;
|
|
138
141
|
const CHAT_THINKING_NOTE = "reasoning: is the lever, sent as reasoning_effort in the model's word, a thinking budget as the level that covers it (ADR 0047); the reasoning is not carried between tool steps, so the model re-reasons each step";
|
|
139
142
|
export const CAPABILITY_MATRIX = {
|
|
140
143
|
gemini: {
|
|
141
|
-
delegation: ok(
|
|
142
|
-
memory_tools: ok(
|
|
143
|
-
structured_output: ok(
|
|
144
|
-
thinking_with_tools: ok(
|
|
145
|
-
streaming: ok(
|
|
146
|
-
vision: ok(
|
|
144
|
+
delegation: ok(),
|
|
145
|
+
memory_tools: ok(),
|
|
146
|
+
structured_output: ok(),
|
|
147
|
+
thinking_with_tools: ok(),
|
|
148
|
+
streaming: ok(),
|
|
149
|
+
vision: ok(),
|
|
147
150
|
native_search: nativeSearch('gemini'),
|
|
148
151
|
},
|
|
149
152
|
anthropic: {
|
|
@@ -286,7 +289,7 @@ export function renderCapabilityMatrix() {
|
|
|
286
289
|
lines.push(`| ${CAPABILITY_LABELS[cap]} | ${cells.join(' | ')} |`);
|
|
287
290
|
}
|
|
288
291
|
lines.push('');
|
|
289
|
-
lines.push('✓ supported · ◐ degraded · ✗ unsupported.
|
|
292
|
+
lines.push('✓ supported · ◐ degraded · ✗ unsupported. Every cell is asserted against the request the adapter sends; the Gemini column is the engine\'s own Gemini adapter.');
|
|
290
293
|
lines.push('');
|
|
291
294
|
notes.forEach((n, i) => lines.push(`${i + 1}. ${n}`));
|
|
292
295
|
lines.push('');
|
|
@@ -11,9 +11,7 @@
|
|
|
11
11
|
* is a small subclass supplying the endpoint, the auth headers, the wire
|
|
12
12
|
* model name, its reasoning field, the tool choices it honours and its
|
|
13
13
|
* error wording (lib/models/ollamaAdapter.ts, kimiAdapter.ts,
|
|
14
|
-
* gatewayAdapter.ts).
|
|
15
|
-
* behind its shim class (OllamaLlm, KimiLlm, GatewayLlm, through
|
|
16
|
-
* OpenAiCompatibleLlm in lib/models/openAiCompatibleLlm.ts, ADR 0057).
|
|
14
|
+
* gatewayAdapter.ts; ADR 0057).
|
|
17
15
|
* wiki/models/model-contract.md ("Chat completions") is the mapping spec.
|
|
18
16
|
*
|
|
19
17
|
* WHAT THE BASE PROVIDES (uniformly, for every subclass):
|
|
@@ -21,8 +19,8 @@
|
|
|
21
19
|
* message first; user text and inline images (data URIs; a URL blob is
|
|
22
20
|
* not sent); assistant text and tool_calls; one `tool` message per tool
|
|
23
21
|
* result, its content the result's JSON in the genai envelope ({ result }
|
|
24
|
-
* for a non-object, { error } for a failure),
|
|
25
|
-
*
|
|
22
|
+
* for a non-object, { error } for a failure), the wire ADK sent.
|
|
23
|
+
* Thinking is never sent.
|
|
26
24
|
* - Tools as function tools, the schema as written (lowercase JSON Schema),
|
|
27
25
|
* its strict form with `strict: true` when the declaration asks.
|
|
28
26
|
* `toolChoice: 'none'` sends no tools; `required` and a named tool go as
|
|
@@ -57,24 +55,6 @@
|
|
|
57
55
|
* llm.retries, llm.retry_without_thinking, and the search and drop marks.
|
|
58
56
|
*/
|
|
59
57
|
import type { ModelAdapter, ModelRequest, ModelResponse, ReasoningSetting, ToolChoiceMode, Usage } from './contract.ts';
|
|
60
|
-
/**
|
|
61
|
-
* What an agent's older generateContentConfig spelling asks of a
|
|
62
|
-
* chat-completions provider that the contract has no field for (ADR 0047;
|
|
63
|
-
* "What the contract leaves out" in wiki/models/model-contract.md). Only the
|
|
64
|
-
* ADK shim around these adapters sets it, from the LlmRequest, so an agent
|
|
65
|
-
* keeps it on the ADK runtime; the native runtime never sets it.
|
|
66
|
-
*/
|
|
67
|
-
export interface OlderSpelling {
|
|
68
|
-
/**
|
|
69
|
-
* An effort word that is not a contract level, such as Kimi K3's `max`,
|
|
70
|
-
* sent as `reasoning_effort` as written, in place of `reasoning`'s word.
|
|
71
|
-
*/
|
|
72
|
-
reasoningEffort?: string;
|
|
73
|
-
}
|
|
74
|
-
/** A ModelRequest, plus what the ADK path carries beside the contract. */
|
|
75
|
-
export interface ChatCompletionsRequest extends ModelRequest {
|
|
76
|
-
olderSpelling?: OlderSpelling;
|
|
77
|
-
}
|
|
78
58
|
type ChatContentPart = {
|
|
79
59
|
type: 'text';
|
|
80
60
|
text: string;
|
|
@@ -116,9 +96,9 @@ export interface ChatFailure {
|
|
|
116
96
|
/** The providerState kind an opted-in adapter writes: an assistant message's reasoning_content. */
|
|
117
97
|
export declare const REASONING_CONTENT_KIND = "reasoning_content";
|
|
118
98
|
/**
|
|
119
|
-
* The prefix of a call id the engine made when the provider returned none
|
|
120
|
-
* ADK
|
|
121
|
-
*
|
|
99
|
+
* The prefix of a call id the engine made when the provider returned none:
|
|
100
|
+
* ADK's prefix for its own ids, kept so sessions ADK wrote and sessions the
|
|
101
|
+
* engine writes read alike.
|
|
122
102
|
*/
|
|
123
103
|
export declare const ENGINE_CALL_ID_PREFIX = "adk-";
|
|
124
104
|
/**
|
|
@@ -210,13 +190,12 @@ export declare abstract class ChatCompletionsAdapter implements ModelAdapter {
|
|
|
210
190
|
/**
|
|
211
191
|
* The body fields for the request's reasoning. Default: `reasoning_effort`
|
|
212
192
|
* as the effort word ADR 0047 gives this model (lib/models/reasoning.ts),
|
|
213
|
-
* the field every chat-completions provider and gateway reads;
|
|
214
|
-
*
|
|
215
|
-
* neither is set.
|
|
193
|
+
* the field every chat-completions provider and gateway reads; nothing
|
|
194
|
+
* when the request sets no reasoning.
|
|
216
195
|
*/
|
|
217
|
-
protected reasoningFields(model: string, setting: ReasoningSetting | undefined
|
|
196
|
+
protected reasoningFields(model: string, setting: ReasoningSetting | undefined): Record<string, unknown>;
|
|
218
197
|
/** Provider-specific body fields, merged last. */
|
|
219
|
-
protected extraBodyFields(_request:
|
|
198
|
+
protected extraBodyFields(_request: ModelRequest): Record<string, unknown>;
|
|
220
199
|
/**
|
|
221
200
|
* Body fields enabling the provider's NATIVE web search, or null when the
|
|
222
201
|
* provider has none (the base then drops the tool, marks the span and
|
|
@@ -270,9 +249,9 @@ export declare abstract class ChatCompletionsAdapter implements ModelAdapter {
|
|
|
270
249
|
* usage, so budgets and the ledger still count it. A request that already
|
|
271
250
|
* asks for no reasoning is not retried.
|
|
272
251
|
*/
|
|
273
|
-
generate(request:
|
|
252
|
+
generate(request: ModelRequest): AsyncGenerator<ModelResponse, void>;
|
|
274
253
|
/** The chat messages this adapter sends for a request, the system message first. */
|
|
275
|
-
messagesFor(request:
|
|
254
|
+
messagesFor(request: ModelRequest): ChatMessage[];
|
|
276
255
|
/** The function tools this adapter sends for a request: none under `toolChoice: 'none'`. */
|
|
277
256
|
toolsFor(request: ModelRequest): Array<Record<string, unknown>>;
|
|
278
257
|
}
|
|
@@ -11,9 +11,7 @@
|
|
|
11
11
|
* is a small subclass supplying the endpoint, the auth headers, the wire
|
|
12
12
|
* model name, its reasoning field, the tool choices it honours and its
|
|
13
13
|
* error wording (lib/models/ollamaAdapter.ts, kimiAdapter.ts,
|
|
14
|
-
* gatewayAdapter.ts).
|
|
15
|
-
* behind its shim class (OllamaLlm, KimiLlm, GatewayLlm, through
|
|
16
|
-
* OpenAiCompatibleLlm in lib/models/openAiCompatibleLlm.ts, ADR 0057).
|
|
14
|
+
* gatewayAdapter.ts; ADR 0057).
|
|
17
15
|
* wiki/models/model-contract.md ("Chat completions") is the mapping spec.
|
|
18
16
|
*
|
|
19
17
|
* WHAT THE BASE PROVIDES (uniformly, for every subclass):
|
|
@@ -21,8 +19,8 @@
|
|
|
21
19
|
* message first; user text and inline images (data URIs; a URL blob is
|
|
22
20
|
* not sent); assistant text and tool_calls; one `tool` message per tool
|
|
23
21
|
* result, its content the result's JSON in the genai envelope ({ result }
|
|
24
|
-
* for a non-object, { error } for a failure),
|
|
25
|
-
*
|
|
22
|
+
* for a non-object, { error } for a failure), the wire ADK sent.
|
|
23
|
+
* Thinking is never sent.
|
|
26
24
|
* - Tools as function tools, the schema as written (lowercase JSON Schema),
|
|
27
25
|
* its strict form with `strict: true` when the declaration asks.
|
|
28
26
|
* `toolChoice: 'none'` sends no tools; `required` and a named tool go as
|
|
@@ -66,9 +64,9 @@ import { currentTurnSignal } from '../runtime/turnControl.js';
|
|
|
66
64
|
/** The providerState kind an opted-in adapter writes: an assistant message's reasoning_content. */
|
|
67
65
|
export const REASONING_CONTENT_KIND = 'reasoning_content';
|
|
68
66
|
/**
|
|
69
|
-
* The prefix of a call id the engine made when the provider returned none
|
|
70
|
-
* ADK
|
|
71
|
-
*
|
|
67
|
+
* The prefix of a call id the engine made when the provider returned none:
|
|
68
|
+
* ADK's prefix for its own ids, kept so sessions ADK wrote and sessions the
|
|
69
|
+
* engine writes read alike.
|
|
72
70
|
*/
|
|
73
71
|
export const ENGINE_CALL_ID_PREFIX = 'adk-';
|
|
74
72
|
// ── <think> blocks ───────────────────────────────────────────────────────────
|
|
@@ -203,7 +201,7 @@ export function sumUsage(a, b) {
|
|
|
203
201
|
export function reasonsNotAtAll(setting) {
|
|
204
202
|
return setting === 'none' || (typeof setting === 'object' && setting !== null && setting.budget_tokens <= 0);
|
|
205
203
|
}
|
|
206
|
-
/** A tool result as the tool message's content: the genai envelope,
|
|
204
|
+
/** A tool result as the tool message's content: the genai envelope, the wire ADK sent. */
|
|
207
205
|
function resultContent(part) {
|
|
208
206
|
const response = part.isError ? { error: part.result } : isPlainObject(part.result) ? part.result : { result: part.result };
|
|
209
207
|
return JSON.stringify(response);
|
|
@@ -329,12 +327,11 @@ export class ChatCompletionsAdapter {
|
|
|
329
327
|
/**
|
|
330
328
|
* The body fields for the request's reasoning. Default: `reasoning_effort`
|
|
331
329
|
* as the effort word ADR 0047 gives this model (lib/models/reasoning.ts),
|
|
332
|
-
* the field every chat-completions provider and gateway reads;
|
|
333
|
-
*
|
|
334
|
-
* neither is set.
|
|
330
|
+
* the field every chat-completions provider and gateway reads; nothing
|
|
331
|
+
* when the request sets no reasoning.
|
|
335
332
|
*/
|
|
336
|
-
reasoningFields(model, setting
|
|
337
|
-
const word =
|
|
333
|
+
reasoningFields(model, setting) {
|
|
334
|
+
const word = setting !== undefined ? reasoningConfig(model, setting).reasoningEffort : undefined;
|
|
338
335
|
return word !== undefined ? { reasoning_effort: word } : {};
|
|
339
336
|
}
|
|
340
337
|
/** Provider-specific body fields, merged last. */
|
|
@@ -437,9 +434,7 @@ export class ChatCompletionsAdapter {
|
|
|
437
434
|
return;
|
|
438
435
|
setLlmSpanAttribute('llm.retry_without_thinking', held.error?.code ?? true);
|
|
439
436
|
this.#warnOnce('retry', `⚠ ${model} thought without answering (${held.error?.code}); retrying once with thinking off.`);
|
|
440
|
-
|
|
441
|
-
const { olderSpelling: _older, ...rest } = request;
|
|
442
|
-
const retry = { ...rest, reasoning: 'none' };
|
|
437
|
+
const retry = { ...request, reasoning: 'none' };
|
|
443
438
|
for await (const response of this.#attempt(retry, model)) {
|
|
444
439
|
if (response.partial) {
|
|
445
440
|
yield response;
|
|
@@ -672,7 +667,7 @@ export class ChatCompletionsAdapter {
|
|
|
672
667
|
...(sampling.topP !== undefined ? { top_p: sampling.topP } : {}),
|
|
673
668
|
...(sampling.maxOutputTokens !== undefined ? { max_tokens: sampling.maxOutputTokens } : {}),
|
|
674
669
|
...(sampling.stop?.length ? { stop: [...sampling.stop] } : {}),
|
|
675
|
-
...this.reasoningFields(model, request.reasoning
|
|
670
|
+
...this.reasoningFields(model, request.reasoning),
|
|
676
671
|
...(tools.length > 0 ? { tools } : {}),
|
|
677
672
|
...(tools.length > 0 ? this.#toolChoice(choice, model, request.reasoning) : {}),
|
|
678
673
|
...this.#responseFormat(request),
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* `fallback_model:` (ADR 0044).
|
|
4
4
|
*
|
|
5
5
|
* WHY its own module:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* FallbackAdapter (lib/models/fallbackAdapter.ts) answers a failing
|
|
7
|
+
* provider from an agent's fallback model, around two adapters on the
|
|
8
|
+
* engine's own contract (ADR 0048), and the native loop's own fallback
|
|
9
|
+
* step does the same. Both read and write the circuits here, so a provider
|
|
10
|
+
* tripped on one path is skipped on the other.
|
|
11
11
|
*
|
|
12
12
|
* THE RULES:
|
|
13
13
|
* - One circuit per provider id (lib/models/providerMap.ts), shared by
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* `fallback_model:` (ADR 0044).
|
|
4
4
|
*
|
|
5
5
|
* WHY its own module:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* FallbackAdapter (lib/models/fallbackAdapter.ts) answers a failing
|
|
7
|
+
* provider from an agent's fallback model, around two adapters on the
|
|
8
|
+
* engine's own contract (ADR 0048), and the native loop's own fallback
|
|
9
|
+
* step does the same. Both read and write the circuits here, so a provider
|
|
10
|
+
* tripped on one path is skipped on the other.
|
|
11
11
|
*
|
|
12
12
|
* THE RULES:
|
|
13
13
|
* - One circuit per provider id (lib/models/providerMap.ts), shared by
|
|
@@ -4,11 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* WHY this file exists:
|
|
6
6
|
* Claude's translation reads a ModelRequest and yields ModelResponses, so
|
|
7
|
-
* the native
|
|
8
|
-
* the
|
|
9
|
-
*
|
|
10
|
-
* turn and opens the llm.request span, and this adapter only decorates
|
|
11
|
-
* that span with setLlmSpanAttribute.
|
|
7
|
+
* the native loop (ADR 0045) calls it directly: the loop charges the turn
|
|
8
|
+
* and opens the llm.request span (ADR 0053), and this adapter only
|
|
9
|
+
* decorates that span with setLlmSpanAttribute.
|
|
12
10
|
*
|
|
13
11
|
* THE MAPPING is the Anthropic table of wiki/models/model-contract.md;
|
|
14
12
|
* wiki/models/claude-adapter.md records the choices made inside it:
|
|
@@ -22,15 +20,13 @@
|
|
|
22
20
|
* the part they preceded as providerState (ADR 0046), and are replayed
|
|
23
21
|
* before that part within the current turn's tool loop, for this model
|
|
24
22
|
* only.
|
|
25
|
-
* - A tool result's content is the JSON of the result in the shape the
|
|
26
|
-
*
|
|
27
|
-
* `{ error }` for a failure),
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* ADR 0049 reads it, which this adapter reads in place of `reasoning`
|
|
31
|
-
* (ClaudeModelRequest, ADR 0055). The native runtime never sets it.
|
|
23
|
+
* - A tool result's content is the JSON of the result in the shape the
|
|
24
|
+
* stored events keep it (`{ result }` for a value that is not an object,
|
|
25
|
+
* `{ error }` for a failure), the bytes ADK sent (ADR 0055).
|
|
26
|
+
* - Reasoning is the contract's `reasoning`, read by claudeReasoningOf
|
|
27
|
+
* (ADR 0049).
|
|
32
28
|
* - `outputFormat: 'json'` sends nothing: the Messages API has no JSON
|
|
33
|
-
* mode without a schema, and
|
|
29
|
+
* mode without a schema, and ADK's Claude path never sent one for
|
|
34
30
|
* `responseMimeType` alone (ADR 0061). The prompt asks for the JSON.
|
|
35
31
|
*
|
|
36
32
|
* THE ADAPTER RULES (contract.ts header) as this adapter keeps them:
|
|
@@ -45,25 +41,12 @@
|
|
|
45
41
|
*/
|
|
46
42
|
import type { JsonSchema, ModelAdapter, ModelRequest, ModelResponse } from './contract.ts';
|
|
47
43
|
import type { ProviderEndpoint } from './endpoints.ts';
|
|
48
|
-
import type { ClaudeReasoning } from './claudeModels.ts';
|
|
49
44
|
/** The provider id this adapter reports and writes its state under (lib/models/providerMap.ts). */
|
|
50
45
|
export declare const ANTHROPIC_PROVIDER = "anthropic";
|
|
51
46
|
/** The providerState kind this adapter writes: the signed blocks that preceded a part. */
|
|
52
47
|
export declare const THINKING_STATE_KIND = "thinking_blocks";
|
|
53
48
|
/** Name of the tool that carries an outputSchema answer where output_config.format is not used. */
|
|
54
49
|
export declare const STRUCTURED_OUTPUT_TOOL = "structured_output";
|
|
55
|
-
/**
|
|
56
|
-
* A ModelRequest as the ADK path's ClaudeLlm hands it to this adapter
|
|
57
|
-
* (ADR 0055). `claudeReasoning` is the agent's older reasoning spelling
|
|
58
|
-
* (generateContentConfig.reasoningEffort and thinkingConfig.thinkingBudget)
|
|
59
|
-
* read as ADR 0049 reads it, which `reasoning` cannot say in full: the effort
|
|
60
|
-
* words `xhigh` and `max`, `minimal` as `low`, and the budget rows' reading
|
|
61
|
-
* of the budget alone. When set it is read in place of `reasoning`. The
|
|
62
|
-
* native runtime never sets it.
|
|
63
|
-
*/
|
|
64
|
-
export interface ClaudeModelRequest extends ModelRequest {
|
|
65
|
-
claudeReasoning?: ClaudeReasoning;
|
|
66
|
-
}
|
|
67
50
|
/** A tool definition as the Messages API takes it: a client tool, or Anthropic's web search server tool. */
|
|
68
51
|
export type AnthropicTool = {
|
|
69
52
|
name: string;
|