@agenticprimitives/orchestration-anthropic 0.0.0-alpha.1 → 0.0.0-alpha.3
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/README.md +1 -1
- package/dist/composer.d.ts +13 -0
- package/dist/composer.d.ts.map +1 -0
- package/dist/composer.js +62 -0
- package/dist/composer.js.map +1 -0
- package/dist/fetch-client.d.ts +3 -0
- package/dist/fetch-client.d.ts.map +1 -1
- package/dist/fetch-client.js +91 -2
- package/dist/fetch-client.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/planner.d.ts.map +1 -1
- package/dist/planner.js +14 -5
- package/dist/planner.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/spec.md +8 -5
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ const tools: ToolSpec[] = [
|
|
|
24
24
|
|
|
25
25
|
// Dependency-free client — works in a Cloudflare Worker (no SDK, no node shims).
|
|
26
26
|
const client = createFetchAnthropicClient({ apiKey: env.ANTHROPIC_API_KEY });
|
|
27
|
-
const planner = createAnthropicPlanner({ client, model: 'claude-
|
|
27
|
+
const planner = createAnthropicPlanner({ client, model: 'claude-haiku-4-5-20251001' });
|
|
28
28
|
|
|
29
29
|
const result = await runIntent(
|
|
30
30
|
{ goal: 'show me my profile' },
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AnswerComposer } from '@agenticprimitives/orchestration';
|
|
2
|
+
import type { AnthropicLike } from './types.js';
|
|
3
|
+
export interface AnthropicComposerOpts {
|
|
4
|
+
client: AnthropicLike;
|
|
5
|
+
model?: string;
|
|
6
|
+
maxTokens?: number;
|
|
7
|
+
/** Extra guidance appended after the contract above (e.g. an org's voice). Never replaces it. */
|
|
8
|
+
systemPrompt?: string;
|
|
9
|
+
/** Cap on the observation JSON handed to the model, in characters. */
|
|
10
|
+
maxEvidenceChars?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function createAnthropicComposer(opts: AnthropicComposerOpts): AnswerComposer;
|
|
13
|
+
//# sourceMappingURL=composer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composer.d.ts","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,kCAAkC,CAAC;AAErF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAuBhD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iGAAiG;IACjG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAMD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,qBAAqB,GAAG,cAAc,CAgCnF"}
|
package/dist/composer.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { fitEvidence } from '@agenticprimitives/orchestration';
|
|
2
|
+
import { DEFAULT_PLANNER_MODEL } from './types.js';
|
|
3
|
+
const SYSTEM = [
|
|
4
|
+
'You put an agent\'s findings into plain words for the person who asked.',
|
|
5
|
+
'',
|
|
6
|
+
'You are given the question and the RESULTS the agent\'s tools returned. Answer ONLY from those results.',
|
|
7
|
+
'Every name, number, address and relationship you state must appear in them.',
|
|
8
|
+
'',
|
|
9
|
+
'If the results are empty or do not cover the question, say WHAT WAS LOOKED FOR and that it matched',
|
|
10
|
+
'nothing — "nothing matched a name search for X" — and stop. Never restate an empty lookup as a fact',
|
|
11
|
+
'about the world ("X does not exist"): you know how the search went, not what exists.',
|
|
12
|
+
'And never fill a gap with something plausible: an invented agent is worse than no answer.',
|
|
13
|
+
'',
|
|
14
|
+
'Be brief and concrete. Lead with the answer. Prefer a short list to a paragraph when the results are a',
|
|
15
|
+
'list. Do not describe the tools you used, do not mention JSON or queries, and do not offer to do more.',
|
|
16
|
+
'',
|
|
17
|
+
'ANSWER THE QUESTION THAT WAS ASKED, FIRST. If it asks for one fact (a balance, a count, a name), the',
|
|
18
|
+
'first sentence is that fact, in the unit the results display (never a raw base-unit figure). If the',
|
|
19
|
+
'results do not contain the asked fact, say so in one sentence and stop — do not summarise other data',
|
|
20
|
+
'in its place, and do not compute what the results do not state.',
|
|
21
|
+
].join('\n');
|
|
22
|
+
const stringify = (v) => {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.stringify(v, (_k, x) => (typeof x === 'bigint' ? x.toString() : x));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return String(v);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export function createAnthropicComposer(opts) {
|
|
31
|
+
const model = opts.model ?? DEFAULT_PLANNER_MODEL;
|
|
32
|
+
const maxTokens = opts.maxTokens ?? 700;
|
|
33
|
+
const cap = opts.maxEvidenceChars ?? 24_000;
|
|
34
|
+
return {
|
|
35
|
+
evidenceBudget: cap,
|
|
36
|
+
async compose({ intent, observations, corrections, evidence }) {
|
|
37
|
+
// Only what SUCCEEDED is evidence (a failed step is not a fact about the world), FITTED to the budget —
|
|
38
|
+
// by the caller when it hands `evidence` (the drops are then on its trace), else here. Never sliced:
|
|
39
|
+
// a body that does not fit is replaced by its summary and said so (spec 391).
|
|
40
|
+
const items = evidence ?? fitEvidence(observations, cap).items;
|
|
41
|
+
const body = stringify(items);
|
|
42
|
+
const res = await opts.client.messages.create({
|
|
43
|
+
model, max_tokens: maxTokens,
|
|
44
|
+
system: opts.systemPrompt ? `${SYSTEM}\n\n${opts.systemPrompt}` : SYSTEM,
|
|
45
|
+
messages: [{
|
|
46
|
+
role: 'user',
|
|
47
|
+
content: `Question: ${intent.goal}\n\nResults:\n${body}${corrections?.length
|
|
48
|
+
// The governor's own words, verbatim: it states what was claimed and what the evidence
|
|
49
|
+
// supports, which is exactly the instruction a recompose needs.
|
|
50
|
+
? `\n\nYour previous answer overstated the results. Corrections that MUST be honoured:\n${corrections.map((c) => `- ${c}`).join('\n')}`
|
|
51
|
+
: ''}`,
|
|
52
|
+
}],
|
|
53
|
+
});
|
|
54
|
+
const text = res.content.filter((b) => b.type === 'text').map((b) => b.text ?? '').join('').trim();
|
|
55
|
+
// No text is not an answer. Say nothing rather than something: the caller renders the raw result.
|
|
56
|
+
if (!text)
|
|
57
|
+
throw new Error('the composer returned no text');
|
|
58
|
+
return text;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=composer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composer.js","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,GAAG;IACb,yEAAyE;IACzE,EAAE;IACF,yGAAyG;IACzG,6EAA6E;IAC7E,EAAE;IACF,oGAAoG;IACpG,qGAAqG;IACrG,sFAAsF;IACtF,2FAA2F;IAC3F,EAAE;IACF,wGAAwG;IACxG,wGAAwG;IACxG,EAAE;IACF,sGAAsG;IACtG,qGAAqG;IACrG,sGAAsG;IACtG,iEAAiE;CAClE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAYb,MAAM,SAAS,GAAG,CAAC,CAAU,EAAU,EAAE;IACvC,IAAI,CAAC;QAAC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CA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AC,EACN,EAAE;qBACH,CAAC;aACH,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACnG,kGAAkG;YAClG,IAAI,CAAC,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC5D,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/fetch-client.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export interface FetchAnthropicOpts {
|
|
|
8
8
|
anthropicVersion?: string;
|
|
9
9
|
/** Injectable fetch (for tests / non-global-fetch runtimes). Default the global `fetch`. */
|
|
10
10
|
fetchImpl?: typeof fetch;
|
|
11
|
+
/** Escape hatch: send a blocking request instead of streaming. Only for a consumer whose transport
|
|
12
|
+
* cannot read a stream — it reintroduces the timeout this client exists to avoid. */
|
|
13
|
+
disableStreaming?: boolean;
|
|
11
14
|
}
|
|
12
15
|
/** Build a minimal `AnthropicLike` client backed by `fetch`. */
|
|
13
16
|
export declare function createFetchAnthropicClient(opts: FetchAnthropicOpts): AnthropicLike;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAyE,MAAM,YAAY,CAAC;AAEvH,MAAM,WAAW,kBAAkB;IACjC,oFAAoF;IACpF,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4FAA4F;IAC5F,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB;0FACsF;IACtF,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAkFD,gEAAgE;AAChE,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,kBAAkB,GAAG,aAAa,CA0BlF"}
|
package/dist/fetch-client.js
CHANGED
|
@@ -1,8 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reassemble an SSE stream into the response shape the blocking call produced.
|
|
3
|
+
*
|
|
4
|
+
* Text and tool arguments both arrive in fragments — `text_delta` for prose, `input_json_delta` for a
|
|
5
|
+
* tool's JSON input, the latter as a string built across many events and parsed only at the end. A
|
|
6
|
+
* tool call is the whole point of the planner, so a partial-JSON parse failure must SURFACE rather
|
|
7
|
+
* than yield a plausible half-formed step.
|
|
8
|
+
*/
|
|
9
|
+
async function readStream(resp) {
|
|
10
|
+
const reader = resp.body?.getReader();
|
|
11
|
+
if (!reader)
|
|
12
|
+
throw new Error('anthropic stream had no body');
|
|
13
|
+
const decoder = new TextDecoder();
|
|
14
|
+
const blocks = [];
|
|
15
|
+
/** Raw `input_json_delta` text per block index — parsed once the block closes. */
|
|
16
|
+
const partialJson = {};
|
|
17
|
+
let stopReason;
|
|
18
|
+
let buffer = '';
|
|
19
|
+
for (;;) {
|
|
20
|
+
const { done, value } = await reader.read();
|
|
21
|
+
if (done)
|
|
22
|
+
break;
|
|
23
|
+
buffer += decoder.decode(value, { stream: true });
|
|
24
|
+
// SSE frames are separated by a blank line; a frame can straddle two chunks, so only complete
|
|
25
|
+
// ones are consumed and the remainder stays buffered.
|
|
26
|
+
let sep;
|
|
27
|
+
while ((sep = buffer.indexOf('\n\n')) !== -1) {
|
|
28
|
+
const frame = buffer.slice(0, sep);
|
|
29
|
+
buffer = buffer.slice(sep + 2);
|
|
30
|
+
const dataLine = frame.split('\n').find((l) => l.startsWith('data:'));
|
|
31
|
+
if (!dataLine)
|
|
32
|
+
continue;
|
|
33
|
+
const payload = dataLine.slice(5).trim();
|
|
34
|
+
if (!payload || payload === '[DONE]')
|
|
35
|
+
continue;
|
|
36
|
+
let ev;
|
|
37
|
+
try {
|
|
38
|
+
ev = JSON.parse(payload);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
continue; // a frame we cannot parse is not worth failing the whole turn over
|
|
42
|
+
}
|
|
43
|
+
const type = ev.type;
|
|
44
|
+
const index = typeof ev.index === 'number' ? ev.index : 0;
|
|
45
|
+
if (type === 'error') {
|
|
46
|
+
const err = ev.error;
|
|
47
|
+
throw new Error(`anthropic stream error: ${err?.type ?? 'unknown'}${err?.message ? `: ${err.message}` : ''}`);
|
|
48
|
+
}
|
|
49
|
+
if (type === 'content_block_start') {
|
|
50
|
+
const cb = (ev.content_block ?? {});
|
|
51
|
+
blocks[index] = { type: cb.type ?? 'text', ...(cb.id ? { id: cb.id } : {}), ...(cb.name ? { name: cb.name } : {}), ...(cb.type === 'text' ? { text: cb.text ?? '' } : {}) };
|
|
52
|
+
if (cb.type === 'tool_use')
|
|
53
|
+
partialJson[index] = '';
|
|
54
|
+
}
|
|
55
|
+
else if (type === 'content_block_delta') {
|
|
56
|
+
const d = (ev.delta ?? {});
|
|
57
|
+
if (d.type === 'text_delta') {
|
|
58
|
+
const b = (blocks[index] ??= { type: 'text', text: '' });
|
|
59
|
+
b.text = (b.text ?? '') + (d.text ?? '');
|
|
60
|
+
}
|
|
61
|
+
else if (d.type === 'input_json_delta') {
|
|
62
|
+
partialJson[index] = (partialJson[index] ?? '') + (d.partial_json ?? '');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (type === 'content_block_stop') {
|
|
66
|
+
const raw = partialJson[index];
|
|
67
|
+
if (raw !== undefined && blocks[index]) {
|
|
68
|
+
try {
|
|
69
|
+
blocks[index].input = raw.trim() ? JSON.parse(raw) : {};
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
// A tool call whose arguments did not parse is the mid-emit cut this whole path is
|
|
73
|
+
// about. Say so precisely — silently dropping it is what made it look like the model
|
|
74
|
+
// never called the tool at all.
|
|
75
|
+
throw new Error(`anthropic tool input JSON was incomplete after ${raw.length} chars — the generation was cut before the arguments closed (${e instanceof Error ? e.message : String(e)})`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (type === 'message_delta') {
|
|
80
|
+
const d = (ev.delta ?? {});
|
|
81
|
+
if (d.stop_reason !== undefined)
|
|
82
|
+
stopReason = d.stop_reason;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { content: blocks.filter(Boolean), ...(stopReason !== undefined ? { stop_reason: stopReason } : {}) };
|
|
87
|
+
}
|
|
1
88
|
/** Build a minimal `AnthropicLike` client backed by `fetch`. */
|
|
2
89
|
export function createFetchAnthropicClient(opts) {
|
|
3
90
|
const f = opts.fetchImpl ?? fetch;
|
|
4
91
|
const base = (opts.baseUrl ?? 'https://api.anthropic.com').replace(/\/+$/, '');
|
|
5
92
|
const version = opts.anthropicVersion ?? '2023-06-01';
|
|
93
|
+
const stream = !opts.disableStreaming;
|
|
6
94
|
return {
|
|
7
95
|
messages: {
|
|
8
96
|
async create(params) {
|
|
@@ -12,14 +100,15 @@ export function createFetchAnthropicClient(opts) {
|
|
|
12
100
|
'content-type': 'application/json',
|
|
13
101
|
'x-api-key': opts.apiKey,
|
|
14
102
|
'anthropic-version': version,
|
|
103
|
+
...(stream ? { accept: 'text/event-stream' } : {}),
|
|
15
104
|
},
|
|
16
|
-
body: JSON.stringify(params),
|
|
105
|
+
body: JSON.stringify(stream ? { ...params, stream: true } : params),
|
|
17
106
|
});
|
|
18
107
|
if (!resp.ok) {
|
|
19
108
|
const detail = await resp.text().catch(() => '');
|
|
20
109
|
throw new Error(`anthropic messages.create failed (HTTP ${resp.status})${detail ? `: ${detail}` : ''}`);
|
|
21
110
|
}
|
|
22
|
-
return (await resp.json());
|
|
111
|
+
return stream ? readStream(resp) : (await resp.json());
|
|
23
112
|
},
|
|
24
113
|
},
|
|
25
114
|
};
|
package/dist/fetch-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-client.js","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch-client.js","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"AAiCA;;;;;;;GAOG;AACH,KAAK,UAAU,UAAU,CAAC,IAAc;IACtC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC;IACtC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,kFAAkF;IAClF,MAAM,WAAW,GAA2B,EAAE,CAAC;IAC/C,IAAI,UAAqC,CAAC;IAC1C,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,SAAS,CAAC;QACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,IAAI;YAAE,MAAM;QAChB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,8FAA8F;QAC9F,sDAAsD;QACtD,IAAI,GAAW,CAAC;QAChB,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACnC,MAAM,GAAG,MAA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
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ export { createAnthropicPlanner } from './planner.js';
|
|
|
4
4
|
export type { AnthropicPlannerOpts } from './planner.js';
|
|
5
5
|
export { createFetchAnthropicClient } from './fetch-client.js';
|
|
6
6
|
export type { FetchAnthropicOpts } from './fetch-client.js';
|
|
7
|
+
export { createAnthropicComposer } from './composer.js';
|
|
8
|
+
export type { AnthropicComposerOpts } from './composer.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC3F,YAAY,EACV,aAAa,EACb,4BAA4B,EAC5B,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC3F,YAAY,EACV,aAAa,EACb,4BAA4B,EAC5B,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,4 +5,6 @@
|
|
|
5
5
|
export { PACKAGE_NAME, PACKAGE_STATUS, SPEC_REF, DEFAULT_PLANNER_MODEL } from './types.js';
|
|
6
6
|
export { createAnthropicPlanner } from './planner.js';
|
|
7
7
|
export { createFetchAnthropicClient } from './fetch-client.js';
|
|
8
|
+
// Spec 350 §3.7 — the answering half: what the tools returned, in plain words, grounded in them.
|
|
9
|
+
export { createAnthropicComposer } from './composer.js';
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,uGAAuG;AACvG,4GAA4G;AAC5G,6CAA6C;AAE7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAU3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,uGAAuG;AACvG,4GAA4G;AAC5G,6CAA6C;AAE7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAU3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAG/D,iGAAiG;AACjG,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/planner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../src/planner.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../src/planner.ts"],"names":[],"mappings":"AAIA,OAAO,EAIL,KAAK,OAAO,EAMb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAyB,KAAK,aAAa,EAAyB,MAAM,YAAY,CAAC;AAE9F,MAAM,WAAW,oBAAoB;IACnC,+EAA+E;IAC/E,MAAM,EAAE,aAAa,CAAC;IACtB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+FAA+F;IAC/F,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAiCD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CA0B1E"}
|
package/dist/planner.js
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
// goal + the agent's exposed tools to Claude; read back the chosen tool + args as a `Plan`. Authority is NOT
|
|
3
3
|
// here — the chosen tool's call still rides the task delegation at the invoker (ADR-0041). The model only
|
|
4
4
|
// decides WHICH tool; it never gains authority by being asked.
|
|
5
|
-
import { OrchestrationError, } from '@agenticprimitives/orchestration';
|
|
5
|
+
import { OrchestrationError, toolNameMap, planStepFromToolArgs, } from '@agenticprimitives/orchestration';
|
|
6
6
|
import { DEFAULT_PLANNER_MODEL } from './types.js';
|
|
7
7
|
const DEFAULT_SYSTEM = 'You are the planning component of an agent. Choose the single tool that best satisfies the user\'s goal, ' +
|
|
8
8
|
'and provide its arguments. You may ONLY use the provided tools. Do not answer in prose — select a tool.';
|
|
9
|
+
// Anthropic tool names must match `^[a-zA-Z0-9_-]{1,128}$`, and capability ids are DOTTED (`treasury.payment.
|
|
10
|
+
// execute`, ADR-0051) — the first capability-declaring tool was an HTTP 400 until the wire name was derived and
|
|
11
|
+
// mapped back. That mapping, and the `$ref`/`$forEach`/`$after`/`$when` lift, are the plan-shape convention
|
|
12
|
+
// every adapter needs verbatim, so they live in the core (`toolNameMap`, `planStepFromToolArgs`; spec 377 §2).
|
|
9
13
|
/** Map an orchestration `ToolSpec` to an Anthropic tool definition (object-root schema by default). */
|
|
10
|
-
function toAnthropicTool(t) {
|
|
14
|
+
function toAnthropicTool(t, wireName) {
|
|
11
15
|
return {
|
|
12
|
-
name:
|
|
16
|
+
name: wireName,
|
|
13
17
|
description: t.description,
|
|
14
18
|
input_schema: t.inputSchema ?? { type: 'object', properties: {}, additionalProperties: true },
|
|
15
19
|
};
|
|
@@ -39,17 +43,22 @@ export function createAnthropicPlanner(opts) {
|
|
|
39
43
|
const model = opts.model ?? DEFAULT_PLANNER_MODEL;
|
|
40
44
|
return {
|
|
41
45
|
async plan(input) {
|
|
46
|
+
const names = toolNameMap(input.tools);
|
|
42
47
|
const res = await opts.client.messages.create({
|
|
43
48
|
model,
|
|
44
49
|
max_tokens: opts.maxTokens ?? 1024,
|
|
45
50
|
system: opts.systemPrompt ?? DEFAULT_SYSTEM,
|
|
46
51
|
messages: [{ role: 'user', content: buildUserMessage(input) }],
|
|
47
|
-
tools: input.tools.map(toAnthropicTool),
|
|
52
|
+
tools: input.tools.map((t) => toAnthropicTool(t, names.toWire.get(t.id))),
|
|
48
53
|
tool_choice: { type: 'any' }, // force a tool selection (no prose-only answer)
|
|
49
54
|
});
|
|
50
55
|
const steps = res.content
|
|
51
56
|
.filter((b) => b.type === 'tool_use' && typeof b.name === 'string')
|
|
52
|
-
|
|
57
|
+
// Map the API name BACK to the tool id. A name we did not issue is a hallucinated tool: kept as-is so
|
|
58
|
+
// the loop's unknown-tool gate refuses it (fail-closed), never mapped to a nearest id.
|
|
59
|
+
// Spec 358 W4 / 370 P3 — the plan-shape convention (`$ref`, `$forEach`, `$after`, `$when`) rides
|
|
60
|
+
// INSIDE the tool args because tool_use blocks carry only args; the core lifts it into PlanStep.
|
|
61
|
+
.map((b) => planStepFromToolArgs(names.fromWire.get(b.name) ?? b.name, (b.input ?? {})));
|
|
53
62
|
if (steps.length === 0) {
|
|
54
63
|
throw new OrchestrationError('no_plan', `the model (${model}) selected no tool for the goal`);
|
|
55
64
|
}
|
package/dist/planner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.js","sourceRoot":"","sources":["../src/planner.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,6GAA6G;AAC7G,0GAA0G;AAC1G,+DAA+D;AAC/D,OAAO,EACL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"planner.js","sourceRoot":"","sources":["../src/planner.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,6GAA6G;AAC7G,0GAA0G;AAC1G,+DAA+D;AAC/D,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,oBAAoB,GAOrB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAA6C,MAAM,YAAY,CAAC;AAa9F,MAAM,cAAc,GAClB,2GAA2G;IAC3G,yGAAyG,CAAC;AAE5G,8GAA8G;AAC9G,gHAAgH;AAChH,4GAA4G;AAC5G,+GAA+G;AAE/G,uGAAuG;AACvG,SAAS,eAAe,CAAC,CAAW,EAAE,QAAgB;IACpD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,YAAY,EAAE,CAAC,CAAC,WAAW,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE;KAC9F,CAAC;AACJ,CAAC;AAED,6GAA6G;AAC7G,SAAS,gBAAgB,CAAC,KAAgB;IACxC,MAAM,KAAK,GAAG,CAA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KAGE_STATUS: "w1-adapter";
|
|
3
3
|
export declare const SPEC_REF: "packages/orchestration-anthropic/spec.md";
|
|
4
4
|
/** A sensible default planning model — fast + capable. Override via `createAnthropicPlanner({ model })`. */
|
|
5
|
-
|
|
5
|
+
/** The model when a deployment names none. Haiku 4.5 since 2026-09-10 (the user: "a cheaper model") — planning is a
|
|
6
|
+
* tool choice over a fitted prompt and composition is grounded on evidence, neither needs the frontier model;
|
|
7
|
+
* `ORCHESTRATION_MODEL` names a different one per deployment. */
|
|
8
|
+
export declare const DEFAULT_PLANNER_MODEL: "claude-haiku-4-5-20251001";
|
|
6
9
|
/** One Anthropic tool definition (the subset we send): the planner maps each `ToolSpec` to this. */
|
|
7
10
|
export interface AnthropicToolDef {
|
|
8
11
|
name: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,EAAG,4CAAqD,CAAC;AAClF,eAAO,MAAM,cAAc,EAAG,YAAqB,CAAC;AACpD,eAAO,MAAM,QAAQ,EAAG,0CAAmD,CAAC;AAE5E,4GAA4G;AAC5G,eAAO,MAAM,qBAAqB,EAAG,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,EAAG,4CAAqD,CAAC;AAClF,eAAO,MAAM,cAAc,EAAG,YAAqB,CAAC;AACpD,eAAO,MAAM,QAAQ,EAAG,0CAAmD,CAAC;AAE5E,4GAA4G;AAC5G;;kEAEkE;AAClE,eAAO,MAAM,qBAAqB,EAAG,2BAAoC,CAAC;AAE1E,oGAAoG;AACpG,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAA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
11
|
export const SPEC_REF = 'packages/orchestration-anthropic/spec.md';
|
|
12
12
|
/** A sensible default planning model — fast + capable. Override via `createAnthropicPlanner({ model })`. */
|
|
13
|
-
|
|
13
|
+
/** The model when a deployment names none. Haiku 4.5 since 2026-09-10 (the user: "a cheaper model") — planning is a
|
|
14
|
+
* tool choice over a fitted prompt and composition is grounded on evidence, neither needs the frontier model;
|
|
15
|
+
* `ORCHESTRATION_MODEL` names a different one per deployment. */
|
|
16
|
+
export const DEFAULT_PLANNER_MODEL = 'claude-haiku-4-5-20251001';
|
|
14
17
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,EAAE;AACF,0GAA0G;AAC1G,2GAA2G;AAC3G,8GAA8G;AAC9G,0GAA0G;AAC1G,4GAA4G;AAC5G,4EAA4E;AAE5E,MAAM,CAAC,MAAM,YAAY,GAAG,4CAAqD,CAAC;AAClF,MAAM,CAAC,MAAM,cAAc,GAAG,YAAqB,CAAC;AACpD,MAAM,CAAC,MAAM,QAAQ,GAAG,0CAAmD,CAAC;AAE5E,4GAA4G;AAC5G,MAAM,CAAC,MAAM,qBAAqB,GAAG,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,EAAE;AACF,0GAA0G;AAC1G,2GAA2G;AAC3G,8GAA8G;AAC9G,0GAA0G;AAC1G,4GAA4G;AAC5G,4EAA4E;AAE5E,MAAM,CAAC,MAAM,YAAY,GAAG,4CAAqD,CAAC;AAClF,MAAM,CAAC,MAAM,cAAc,GAAG,YAAqB,CAAC;AACpD,MAAM,CAAC,MAAM,QAAQ,GAAG,0CAAmD,CAAC;AAE5E,4GAA4G;AAC5G;;kEAEkE;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG,2BAAoC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenticprimitives/orchestration-anthropic",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.3",
|
|
4
4
|
"description": "Anthropic LLM binding for the @agenticprimitives/orchestration Planner port (the in-repo adapter, chain-state-viem pattern): createAnthropicPlanner turns a goal + exposed tools into a plan via Anthropic tool-use, plus a dependency-free fetch-based AnthropicLike client (Cloudflare-Worker friendly). The pure orchestration core stays vendor-free; authority is never here.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@agenticprimitives/orchestration": "0.0.0-alpha.
|
|
34
|
+
"@agenticprimitives/orchestration": "0.0.0-alpha.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"vitest": "^4.1.8",
|
|
38
|
-
"@agenticprimitives/orchestration": "0.0.0-alpha.
|
|
38
|
+
"@agenticprimitives/orchestration": "0.0.0-alpha.2"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"agentic",
|
package/spec.md
CHANGED
|
@@ -27,13 +27,14 @@ We DEFINE the minimal `messages.create` request/response shapes rather than impo
|
|
|
27
27
|
|
|
28
28
|
`createFetchAnthropicClient({ apiKey, baseUrl?, anthropicVersion?, fetchImpl? })` is a dependency-free
|
|
29
29
|
`AnthropicLike` over `fetch` (POST `/v1/messages` with `x-api-key` + `anthropic-version`). The default model
|
|
30
|
-
is `DEFAULT_PLANNER_MODEL` (`claude-
|
|
30
|
+
is `DEFAULT_PLANNER_MODEL` (`claude-haiku-4-5-20251001`).
|
|
31
31
|
|
|
32
32
|
## 4. Runtime activation
|
|
33
33
|
|
|
34
|
-
The app selects this planner when its config enables the LLM path (e.g. demo-a2a:
|
|
35
|
-
`
|
|
36
|
-
|
|
34
|
+
The app selects this planner when its config enables the LLM path (e.g. demo-a2a: `env.ANTHROPIC_API_KEY`
|
|
35
|
+
present + `anthropic` listed in `env.ORCHESTRATION_LLM` — an ordered allowlist since spec 377, whose first
|
|
36
|
+
entry is the default and which a turn may override), else it uses the deterministic `createRuleBasedPlanner`.
|
|
37
|
+
The key is a Worker secret — never logged, never in code.
|
|
37
38
|
|
|
38
39
|
## 5. Boundaries
|
|
39
40
|
|
|
@@ -43,4 +44,6 @@ Imports `@agenticprimitives/orchestration` (+ `types`). Forbidden: `a2a`, `mcp-r
|
|
|
43
44
|
## 6. Out of scope
|
|
44
45
|
|
|
45
46
|
Multi-turn tool-result feedback to the model (the loop re-plans with observation summaries, not full
|
|
46
|
-
tool-result message threads);
|
|
47
|
+
tool-result message threads); non-Anthropic vendors — separate sibling adapters, the first being
|
|
48
|
+
[`orchestration-openai-compat`](../orchestration-openai-compat/spec.md) (spec 377). The plan-shape convention
|
|
49
|
+
(`toolNameMap`, `planStepFromToolArgs`) both adapters share lives in the core.
|