@agenticprimitives/orchestration-anthropic 0.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/fetch-client.d.ts +14 -0
- package/dist/fetch-client.d.ts.map +1 -0
- package/dist/fetch-client.js +27 -0
- package/dist/fetch-client.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/planner.d.ts +20 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +60 -0
- package/dist/planner.js.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
- package/spec.md +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agentic Trust Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @agenticprimitives/orchestration-anthropic
|
|
2
|
+
|
|
3
|
+
The **Anthropic LLM binding** for the [`@agenticprimitives/orchestration`](../orchestration) `Planner` port —
|
|
4
|
+
the in-repo adapter (the `chain-state` / `chain-state-viem` pattern). The pure orchestration core stays
|
|
5
|
+
vendor-free; the Anthropic-specific translation lives here. Swap it in for the deterministic planner without
|
|
6
|
+
touching the loop.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @agenticprimitives/orchestration-anthropic @agenticprimitives/orchestration
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { runIntent, type ToolSpec } from '@agenticprimitives/orchestration';
|
|
18
|
+
import { createAnthropicPlanner, createFetchAnthropicClient } from '@agenticprimitives/orchestration-anthropic';
|
|
19
|
+
|
|
20
|
+
const tools: ToolSpec[] = [
|
|
21
|
+
{ id: 'get_vault_record', description: 'Read a vault record by recordType.', inputSchema: { type: 'object', properties: { recordType: { type: 'string' } }, required: ['recordType'] } },
|
|
22
|
+
{ id: 'get_pii', description: 'Read the principal’s PII (high sensitivity).' },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
// Dependency-free client — works in a Cloudflare Worker (no SDK, no node shims).
|
|
26
|
+
const client = createFetchAnthropicClient({ apiKey: env.ANTHROPIC_API_KEY });
|
|
27
|
+
const planner = createAnthropicPlanner({ client, model: 'claude-sonnet-4-6' });
|
|
28
|
+
|
|
29
|
+
const result = await runIntent(
|
|
30
|
+
{ goal: 'show me my profile' },
|
|
31
|
+
{ planner, tools, invoke: async (toolId, args) => myDelegatedMcpCall(toolId, args) },
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The model chooses **which** tool fits the goal; the chosen call still rides the task's on-chain delegation at
|
|
36
|
+
the invoker (ADR-0041). The model never gains authority by being asked.
|
|
37
|
+
|
|
38
|
+
## `AnthropicLike`
|
|
39
|
+
|
|
40
|
+
`createAnthropicPlanner` takes a structural `AnthropicLike` client (the minimal `messages.create` surface).
|
|
41
|
+
Pass either:
|
|
42
|
+
- `createFetchAnthropicClient({ apiKey })` — dependency-free, Worker-friendly; or
|
|
43
|
+
- the official `new Anthropic({ apiKey })` — it satisfies the same shape.
|
|
44
|
+
|
|
45
|
+
This keeps the planner unit-testable with a fake and avoids a hard SDK dependency.
|
|
46
|
+
|
|
47
|
+
## Boundaries
|
|
48
|
+
|
|
49
|
+
Imports only `@agenticprimitives/orchestration` (+ `types`). Forbidden: `a2a`, `mcp-runtime`, `mcp-protocol`,
|
|
50
|
+
`delegation`, `service-agent`. See `spec.md` + `capability.manifest.json`.
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AnthropicLike } from './types.js';
|
|
2
|
+
export interface FetchAnthropicOpts {
|
|
3
|
+
/** The Anthropic API key. Never log this; the app reads it from a Worker secret. */
|
|
4
|
+
apiKey: string;
|
|
5
|
+
/** API base. Default `https://api.anthropic.com`. */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/** `anthropic-version` header. Default `2023-06-01`. */
|
|
8
|
+
anthropicVersion?: string;
|
|
9
|
+
/** Injectable fetch (for tests / non-global-fetch runtimes). Default the global `fetch`. */
|
|
10
|
+
fetchImpl?: typeof fetch;
|
|
11
|
+
}
|
|
12
|
+
/** Build a minimal `AnthropicLike` client backed by `fetch`. */
|
|
13
|
+
export declare function createFetchAnthropicClient(opts: FetchAnthropicOpts): AnthropicLike;
|
|
14
|
+
//# sourceMappingURL=fetch-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-client.d.ts","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAkD,MAAM,YAAY,CAAC;AAEhG,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;CAC1B;AAED,gEAAgE;AAChE,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,kBAAkB,GAAG,aAAa,CAwBlF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Build a minimal `AnthropicLike` client backed by `fetch`. */
|
|
2
|
+
export function createFetchAnthropicClient(opts) {
|
|
3
|
+
const f = opts.fetchImpl ?? fetch;
|
|
4
|
+
const base = (opts.baseUrl ?? 'https://api.anthropic.com').replace(/\/+$/, '');
|
|
5
|
+
const version = opts.anthropicVersion ?? '2023-06-01';
|
|
6
|
+
return {
|
|
7
|
+
messages: {
|
|
8
|
+
async create(params) {
|
|
9
|
+
const resp = await f(`${base}/v1/messages`, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: {
|
|
12
|
+
'content-type': 'application/json',
|
|
13
|
+
'x-api-key': opts.apiKey,
|
|
14
|
+
'anthropic-version': version,
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify(params),
|
|
17
|
+
});
|
|
18
|
+
if (!resp.ok) {
|
|
19
|
+
const detail = await resp.text().catch(() => '');
|
|
20
|
+
throw new Error(`anthropic messages.create failed (HTTP ${resp.status})${detail ? `: ${detail}` : ''}`);
|
|
21
|
+
}
|
|
22
|
+
return (await resp.json());
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=fetch-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-client.js","sourceRoot":"","sources":["../src/fetch-client.ts"],"names":[],"mappings":"AAiBA,gEAAgE;AAChE,MAAM,UAAU,0BAA0B,CAAC,IAAwB;IACjE,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;IAClC,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,IAAI,YAAY,CAAC;IACtD,OAAO;QACL,QAAQ,EAAE;YACR,KAAK,CAAC,MAAM,CAAC,MAAoC;gBAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,cAAc,EAAE;oBAC1C,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE;wBACP,cAAc,EAAE,kBAAkB;wBAClC,WAAW,EAAE,IAAI,CAAC,MAAM;wBACxB,mBAAmB,EAAE,OAAO;qBAC7B;oBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;iBAC7B,CAAC,CAAC;gBACH,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;oBACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;oBACjD,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC1G,CAAC;gBACD,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAqB,CAAC;YACjD,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PACKAGE_NAME, PACKAGE_STATUS, SPEC_REF, DEFAULT_PLANNER_MODEL } from './types.js';
|
|
2
|
+
export type { AnthropicLike, AnthropicMessageCreateParams, AnthropicMessage, AnthropicContentBlock, AnthropicToolDef, AnthropicToolChoice, } from './types.js';
|
|
3
|
+
export { createAnthropicPlanner } from './planner.js';
|
|
4
|
+
export type { AnthropicPlannerOpts } from './planner.js';
|
|
5
|
+
export { createFetchAnthropicClient } from './fetch-client.js';
|
|
6
|
+
export type { FetchAnthropicOpts } from './fetch-client.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @agenticprimitives/orchestration-anthropic — public API. The Anthropic LLM binding for the orchestration
|
|
2
|
+
// `Planner` port (the in-repo adapter, chain-state-viem pattern). The pure core stays vendor-free; the
|
|
3
|
+
// Anthropic-specific translation lives here. Authority is never here — a chosen tool's call still rides the
|
|
4
|
+
// task delegation at the invoker (ADR-0041).
|
|
5
|
+
export { PACKAGE_NAME, PACKAGE_STATUS, SPEC_REF, DEFAULT_PLANNER_MODEL } from './types.js';
|
|
6
|
+
export { createAnthropicPlanner } from './planner.js';
|
|
7
|
+
export { createFetchAnthropicClient } from './fetch-client.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Planner } from '@agenticprimitives/orchestration';
|
|
2
|
+
import { type AnthropicLike } from './types.js';
|
|
3
|
+
export interface AnthropicPlannerOpts {
|
|
4
|
+
/** The structural client (real SDK client OR `createFetchAnthropicClient`). */
|
|
5
|
+
client: AnthropicLike;
|
|
6
|
+
/** Planning model. Default `DEFAULT_PLANNER_MODEL`. */
|
|
7
|
+
model?: string;
|
|
8
|
+
/** Max tokens for the planning turn. Default 1024. */
|
|
9
|
+
maxTokens?: number;
|
|
10
|
+
/** Override the system prompt (the default constrains the model to the tool-selection job). */
|
|
11
|
+
systemPrompt?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a `Planner` backed by Anthropic tool-use. Fail-closed: if the model returns no tool_use block (no
|
|
15
|
+
* tool chosen), the planner throws `OrchestrationError('no_plan')` — the loop surfaces it as a failed run.
|
|
16
|
+
* One or more tool_use blocks become the plan steps (in order). The loop's `assertKnownTools` is the backstop
|
|
17
|
+
* if the model ever names a tool outside the provided set.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createAnthropicPlanner(opts: AnthropicPlannerOpts): Planner;
|
|
20
|
+
//# sourceMappingURL=planner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../src/planner.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,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;AA4BD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAqB1E"}
|
package/dist/planner.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// createAnthropicPlanner — implements the orchestration `Planner` port via Anthropic tool-use. Present the
|
|
2
|
+
// goal + the agent's exposed tools to Claude; read back the chosen tool + args as a `Plan`. Authority is NOT
|
|
3
|
+
// here — the chosen tool's call still rides the task delegation at the invoker (ADR-0041). The model only
|
|
4
|
+
// decides WHICH tool; it never gains authority by being asked.
|
|
5
|
+
import { OrchestrationError, } from '@agenticprimitives/orchestration';
|
|
6
|
+
import { DEFAULT_PLANNER_MODEL } from './types.js';
|
|
7
|
+
const DEFAULT_SYSTEM = 'You are the planning component of an agent. Choose the single tool that best satisfies the user\'s goal, ' +
|
|
8
|
+
'and provide its arguments. You may ONLY use the provided tools. Do not answer in prose — select a tool.';
|
|
9
|
+
/** Map an orchestration `ToolSpec` to an Anthropic tool definition (object-root schema by default). */
|
|
10
|
+
function toAnthropicTool(t) {
|
|
11
|
+
return {
|
|
12
|
+
name: t.id,
|
|
13
|
+
description: t.description,
|
|
14
|
+
input_schema: t.inputSchema ?? { type: 'object', properties: {}, additionalProperties: true },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Build the user turn: the goal, plus any prior failed observations so a re-plan can choose differently. */
|
|
18
|
+
function buildUserMessage(input) {
|
|
19
|
+
const lines = [`Goal: ${input.intent.goal}`];
|
|
20
|
+
if (input.intent.constraints)
|
|
21
|
+
lines.push(`Constraints: ${JSON.stringify(input.intent.constraints)}`);
|
|
22
|
+
if (input.intent.context)
|
|
23
|
+
lines.push(`Context: ${JSON.stringify(input.intent.context)}`);
|
|
24
|
+
const failed = (input.observations ?? []).filter((o) => !o.ok);
|
|
25
|
+
if (failed.length) {
|
|
26
|
+
lines.push('Previous attempts failed — choose a different approach:');
|
|
27
|
+
for (const o of failed)
|
|
28
|
+
lines.push(`- ${o.step.toolId} failed: ${o.error ?? 'unknown error'}`);
|
|
29
|
+
}
|
|
30
|
+
return lines.join('\n');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a `Planner` backed by Anthropic tool-use. Fail-closed: if the model returns no tool_use block (no
|
|
34
|
+
* tool chosen), the planner throws `OrchestrationError('no_plan')` — the loop surfaces it as a failed run.
|
|
35
|
+
* One or more tool_use blocks become the plan steps (in order). The loop's `assertKnownTools` is the backstop
|
|
36
|
+
* if the model ever names a tool outside the provided set.
|
|
37
|
+
*/
|
|
38
|
+
export function createAnthropicPlanner(opts) {
|
|
39
|
+
const model = opts.model ?? DEFAULT_PLANNER_MODEL;
|
|
40
|
+
return {
|
|
41
|
+
async plan(input) {
|
|
42
|
+
const res = await opts.client.messages.create({
|
|
43
|
+
model,
|
|
44
|
+
max_tokens: opts.maxTokens ?? 1024,
|
|
45
|
+
system: opts.systemPrompt ?? DEFAULT_SYSTEM,
|
|
46
|
+
messages: [{ role: 'user', content: buildUserMessage(input) }],
|
|
47
|
+
tools: input.tools.map(toAnthropicTool),
|
|
48
|
+
tool_choice: { type: 'any' }, // force a tool selection (no prose-only answer)
|
|
49
|
+
});
|
|
50
|
+
const steps = res.content
|
|
51
|
+
.filter((b) => b.type === 'tool_use' && typeof b.name === 'string')
|
|
52
|
+
.map((b) => ({ toolId: b.name, args: (b.input ?? {}) }));
|
|
53
|
+
if (steps.length === 0) {
|
|
54
|
+
throw new OrchestrationError('no_plan', `the model (${model}) selected no tool for the goal`);
|
|
55
|
+
}
|
|
56
|
+
return { steps, rationale: `anthropic(${model})` };
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=planner.js.map
|
|
@@ -0,0 +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,GAOnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAA6C,MAAM,YAAY,CAAC;AAa9F,MAAM,cAAc,GAClB,2GAA2G;IAC3G,yGAAyG,CAAC;AAE5G,uGAAuG;AACvG,SAAS,eAAe,CAAC,CAAW;IAClC,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,EAAE;QACV,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,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,IAAI,KAAK,CAAC,MAAM,CAAC,WAAW;QAAE,KAAK,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAA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,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gDAAgD;aAC/E,CAAC,CAAC;YACH,MAAM,KAAK,GAAe,GAAG,CAAC,OAAO;iBAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;iBAClE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,IAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAA4B,EAAE,CAAC,CAAC,CAAC;YAChG,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,MAAM,IAAI,kBAAkB,CAAC,SAAS,EAAE,cAAc,KAAK,iCAAiC,CAAC,CAAC;YAChG,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,KAAK,GAAG,EAAE,CAAC;QACrD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const PACKAGE_NAME: "@agenticprimitives/orchestration-anthropic";
|
|
2
|
+
export declare const PACKAGE_STATUS: "w1-adapter";
|
|
3
|
+
export declare const SPEC_REF: "packages/orchestration-anthropic/spec.md";
|
|
4
|
+
/** A sensible default planning model — fast + capable. Override via `createAnthropicPlanner({ model })`. */
|
|
5
|
+
export declare const DEFAULT_PLANNER_MODEL: "claude-sonnet-4-6";
|
|
6
|
+
/** One Anthropic tool definition (the subset we send): the planner maps each `ToolSpec` to this. */
|
|
7
|
+
export interface AnthropicToolDef {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
/** JSON Schema for the tool input (object root). */
|
|
11
|
+
input_schema: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/** The `tool_choice` modes we use — force a tool selection so the planner always yields a step (or none). */
|
|
14
|
+
export type AnthropicToolChoice = {
|
|
15
|
+
type: 'auto';
|
|
16
|
+
} | {
|
|
17
|
+
type: 'any';
|
|
18
|
+
} | {
|
|
19
|
+
type: 'tool';
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
/** The Messages-API request subset the planner sends. Matches the official SDK's `messages.create` params. */
|
|
23
|
+
export interface AnthropicMessageCreateParams {
|
|
24
|
+
model: string;
|
|
25
|
+
max_tokens: number;
|
|
26
|
+
system?: string;
|
|
27
|
+
messages: {
|
|
28
|
+
role: 'user' | 'assistant';
|
|
29
|
+
content: string;
|
|
30
|
+
}[];
|
|
31
|
+
tools?: AnthropicToolDef[];
|
|
32
|
+
tool_choice?: AnthropicToolChoice;
|
|
33
|
+
}
|
|
34
|
+
/** One content block in a response. `tool_use` blocks carry the chosen tool `name` + `input` (the args). */
|
|
35
|
+
export interface AnthropicContentBlock {
|
|
36
|
+
type: string;
|
|
37
|
+
text?: string;
|
|
38
|
+
id?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
input?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/** The Messages-API response subset we read. */
|
|
43
|
+
export interface AnthropicMessage {
|
|
44
|
+
content: AnthropicContentBlock[];
|
|
45
|
+
stop_reason?: string | null;
|
|
46
|
+
}
|
|
47
|
+
/** The structural client the planner needs — satisfied by `new Anthropic()` OR `createFetchAnthropicClient`. */
|
|
48
|
+
export interface AnthropicLike {
|
|
49
|
+
messages: {
|
|
50
|
+
create(params: AnthropicMessageCreateParams): Promise<AnthropicMessage>;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;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AgH;AAChH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE;QACR,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;KACzE,CAAC;CACH"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @agenticprimitives/orchestration-anthropic — the LLM binding for the orchestration Planner port.
|
|
2
|
+
//
|
|
3
|
+
// This is the in-repo ADAPTER (the chain-state / chain-state-viem pattern): the pure `orchestration` core
|
|
4
|
+
// stays vendor-free; the Anthropic-specific protocol translation lives HERE, behind the `Planner` port. We
|
|
5
|
+
// define a STRUCTURAL `AnthropicLike` client interface rather than depending on `@anthropic-ai/sdk` directly,
|
|
6
|
+
// so (a) the planner is unit-testable with a fake, (b) a consumer can pass either the real SDK client (it
|
|
7
|
+
// satisfies the shape) OR our dependency-free fetch client (Worker-friendly), and (c) this package needs no
|
|
8
|
+
// heavy runtime dep. The SDK remains the reference, not a build dependency.
|
|
9
|
+
export const PACKAGE_NAME = '@agenticprimitives/orchestration-anthropic';
|
|
10
|
+
export const PACKAGE_STATUS = 'w1-adapter';
|
|
11
|
+
export const SPEC_REF = 'packages/orchestration-anthropic/spec.md';
|
|
12
|
+
/** A sensible default planning model — fast + capable. Override via `createAnthropicPlanner({ model })`. */
|
|
13
|
+
export const DEFAULT_PLANNER_MODEL = 'claude-sonnet-4-6';
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +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,mBAA4B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agenticprimitives/orchestration-anthropic",
|
|
3
|
+
"version": "0.0.0-alpha.1",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
|
|
9
|
+
"directory": "packages/orchestration-anthropic"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/agentictrustlabs/agenticprimitives/tree/master/packages/orchestration-anthropic",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/agentictrustlabs/agenticprimitives/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"dist",
|
|
27
|
+
"spec.md",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@agenticprimitives/orchestration": "0.0.0-alpha.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"vitest": "^4.1.8",
|
|
38
|
+
"@agenticprimitives/orchestration": "0.0.0-alpha.1"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"agentic",
|
|
42
|
+
"primitives",
|
|
43
|
+
"orchestration",
|
|
44
|
+
"planner",
|
|
45
|
+
"anthropic",
|
|
46
|
+
"llm-adapter"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.build.json",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:unit": "vitest run test/unit --passWithNoTests",
|
|
53
|
+
"test:watch": "vitest",
|
|
54
|
+
"clean": "rm -rf dist"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/spec.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# orchestration-anthropic — the Anthropic LLM binding
|
|
2
|
+
|
|
3
|
+
**Status:** w1-adapter. **Doctrine:** [ADR-0044](../../docs/architecture/decisions/0044-a2a-is-the-agentic-orchestration-layer.md)
|
|
4
|
+
+ memory `feedback_orchestration_is_ring0`. **Core:** [`@agenticprimitives/orchestration`](../orchestration/spec.md).
|
|
5
|
+
|
|
6
|
+
## 1. Why
|
|
7
|
+
|
|
8
|
+
The doctrine: orchestration is a Ring-0 primitive, but ONLY the concrete LLM-framework binding lives in a
|
|
9
|
+
dedicated in-repo adapter behind the port (the `chain-state` + `chain-state-viem` pattern — the core stays
|
|
10
|
+
pure; the vendor specifics are exiled to the adapter). This package is that adapter for Anthropic.
|
|
11
|
+
|
|
12
|
+
## 2. The binding
|
|
13
|
+
|
|
14
|
+
- **`createAnthropicPlanner({ client, model?, maxTokens?, systemPrompt? })`** implements the core's `Planner`
|
|
15
|
+
port. It maps each exposed `ToolSpec` to an Anthropic tool definition, sends the goal (plus any prior failed
|
|
16
|
+
observations, so a re-plan chooses differently) with `tool_choice: { type: 'any' }`, and turns the response's
|
|
17
|
+
`tool_use` blocks into `Plan` steps. No tool chosen → `OrchestrationError('no_plan')` (fail-closed).
|
|
18
|
+
- The loop's `assertKnownTools` is the backstop: a tool the model names outside the provided set is rejected
|
|
19
|
+
before any invocation. The model decides *which* tool; it never gains *authority*.
|
|
20
|
+
|
|
21
|
+
## 3. The structural client (`AnthropicLike`)
|
|
22
|
+
|
|
23
|
+
We DEFINE the minimal `messages.create` request/response shapes rather than importing `@anthropic-ai/sdk`:
|
|
24
|
+
- The planner is unit-testable with a fake client.
|
|
25
|
+
- A consumer may pass either the real SDK client (it satisfies `AnthropicLike`) OR our `createFetchAnthropicClient`.
|
|
26
|
+
- The package needs no heavy runtime dep and runs in a Cloudflare Worker.
|
|
27
|
+
|
|
28
|
+
`createFetchAnthropicClient({ apiKey, baseUrl?, anthropicVersion?, fetchImpl? })` is a dependency-free
|
|
29
|
+
`AnthropicLike` over `fetch` (POST `/v1/messages` with `x-api-key` + `anthropic-version`). The default model
|
|
30
|
+
is `DEFAULT_PLANNER_MODEL` (`claude-sonnet-4-6`).
|
|
31
|
+
|
|
32
|
+
## 4. Runtime activation
|
|
33
|
+
|
|
34
|
+
The app selects this planner when its config enables the LLM path (e.g. demo-a2a:
|
|
35
|
+
`env.ANTHROPIC_API_KEY` present + `env.ORCHESTRATION_LLM === 'anthropic'`), else it uses the deterministic
|
|
36
|
+
`createRuleBasedPlanner`. The key is a Worker secret — never logged, never in code.
|
|
37
|
+
|
|
38
|
+
## 5. Boundaries
|
|
39
|
+
|
|
40
|
+
Imports `@agenticprimitives/orchestration` (+ `types`). Forbidden: `a2a`, `mcp-runtime`, `mcp-protocol`,
|
|
41
|
+
`delegation`, `service-agent`. Authority, the loop, and the model live elsewhere.
|
|
42
|
+
|
|
43
|
+
## 6. Out of scope
|
|
44
|
+
|
|
45
|
+
Multi-turn tool-result feedback to the model (the loop re-plans with observation summaries, not full
|
|
46
|
+
tool-result message threads); streaming; non-Anthropic vendors (separate sibling adapters).
|