/** * AnthropicProvider — wraps `@anthropic-ai/sdk` as an `LLMProvider`. * * Pattern: Adapter (GoF) + Ports-and-Adapters (Cockburn 2005). * Role: Outer ring — translates `LLMRequest`/`LLMResponse` to/from * Anthropic's Messages API. Knows nothing about agents, * recorders, or compositions. * Emits: N/A — providers don't emit; recorders observe via Agent. * * ─── Limitations ──────────────────────────────────────────────────── * * • Multi-modal content (images, video) NOT supported — the framework's * `LLMMessage.content` is `string`. The adapter accepts text-only. * May extend in a future release the message shape; this provider will be updated * in lockstep. * • `responseFormat` (JSON-Schema-coerced output) NOT exposed * — consumers can pass schema instructions via `systemPrompt`. */ import type { LLMCallHooks, LLMChunk, LLMProvider, LLMRequest, LLMResponse } from '../types.js'; interface AnthropicClient { messages: { create(params: AnthropicCreateParams): Promise; stream(params: AnthropicCreateParams): AnthropicStream; }; } interface AnthropicCreateParams { model: string; max_tokens: number; messages: AnthropicMessageParam[]; system?: string; tools?: AnthropicTool[]; temperature?: number; stop_sequences?: string[]; thinking?: { type: 'enabled'; budget_tokens: number; }; tool_choice?: { type: 'auto'; disable_parallel_tool_use: true; }; } interface AnthropicMessageParam { role: 'user' | 'assistant'; content: string | AnthropicContentBlock[]; } type AnthropicContentBlock = { type: 'text'; text: string; } | { type: 'tool_use'; id: string; name: string; input: Record; } | { type: 'tool_result'; tool_use_id: string; content: string; is_error?: boolean; } | { type: 'thinking'; thinking: string; signature?: string; } | { type: 'redacted_thinking'; signature?: string; }; interface AnthropicTool { name: string; description: string; input_schema: Record; } interface AnthropicMessage { id: string; model: string; role: 'assistant'; content: AnthropicContentBlock[]; stop_reason: 'end_turn' | 'tool_use' | 'max_tokens' | string; usage: { input_tokens: number; output_tokens: number; }; } interface AnthropicStream { finalMessage(): Promise; [Symbol.asyncIterator](): AsyncIterator; } interface AnthropicStreamEvent { type: string; delta?: { type: string; text?: string; }; } export interface AnthropicProviderOptions { /** API key. Defaults to `ANTHROPIC_API_KEY` env var. */ readonly apiKey?: string; /** * Default model used when `LLMRequest.model` is `'anthropic'` (the * shorthand). When the request specifies a full model id, that wins. */ readonly defaultModel?: string; /** Default max tokens when the request doesn't set it. Default 4096. */ readonly defaultMaxTokens?: number; /** * Per-request timeout in milliseconds, passed to the Anthropic client. * Long non-streaming turns (slow models, long conversations, agent loops) * can exceed the SDK default and surface as "Request timed out" — raise * this for such workloads. Omit to use the SDK default. */ readonly timeout?: number; /** * How many times the Anthropic client retries a failed request (timeouts, * connection errors, 429/5xx) before giving up. Omit to use the SDK default. */ readonly maxRetries?: number; /** * May the model ask for several tools at once in a single reply? * * Anthropic's default is `true`: one assistant message can carry many * `tool_use` blocks, and the agent runs them all inside ONE loop * iteration. Set `false` to cap it at one tool per reply — the model * still chooses which tool (or none), it just cannot batch. * * Set `false` when the SHAPE of the loop is part of what you are * measuring, not only its answer. A batched reply collapses several * tool results into one iteration, so per-iteration analysis * (`localizeContextBug` seeds one `'tool'` suspect per iteration from * `lastToolResult`, and `removableSources` de-duplicates by tool name) * attributes that iteration to the LAST tool of the batch — the others * never appear as separate influence rows and cannot be ablated * individually. One tool per iteration keeps every source separately * attributable, at the cost of one extra round trip per tool. * * Prompting for it is not equivalent: "call one tool at a time" in the * system prompt is a request the model may ignore, whereas this is a * request parameter the API enforces. * * `true` (and omitting the option) sends nothing — Anthropic's own * default already allows batching. Only `false` puts `tool_choice` on * the wire, and only on requests that actually carry tools. * * @default undefined (Anthropic's default — batching allowed) */ readonly parallelToolCalls?: boolean; /** @internal Pre-built client for testing. Skips SDK import. */ readonly _client?: AnthropicClient; } /** * Build an `LLMProvider` backed by Anthropic's Messages API. * * @example * import { Agent } from 'agentfootprint'; * import { anthropic } from 'agentfootprint/llm-providers'; * * const agent = Agent.create({ * provider: anthropic({ defaultModel: 'claude-sonnet-4-5-20250929' }), * model: 'anthropic', * }) * .tool(weatherTool) * .build(); */ export declare function anthropic(options?: AnthropicProviderOptions): LLMProvider; /** * Class form for consumers who prefer `new AnthropicProvider(...)` over * the `anthropic(...)` factory. Identical behavior; trivial wrapper. */ export declare class AnthropicProvider implements LLMProvider { readonly name = "anthropic"; private readonly inner; constructor(options?: AnthropicProviderOptions); complete(req: LLMRequest, hooks?: LLMCallHooks): Promise; stream(req: LLMRequest, hooks?: LLMCallHooks): AsyncIterable; } export {}; //# sourceMappingURL=AnthropicProvider.d.ts.map