/** * Claude Agent SDK Adapter * * Integrates agents built with Anthropic's Claude Agent SDK * (`@anthropic-ai/claude-agent-sdk`) with the SwarmOrchestrator. The SDK's * `query()` function runs a full agentic loop (tool use, file edits, shell) * and streams SDK messages; this adapter drives that loop and returns the * final result to the swarm. * * Strictly BYOC: the SDK is never imported here. Callers pass the SDK's * `query` function (or any compatible implementation) at registration time. * * Usage: * import { query } from '@anthropic-ai/claude-agent-sdk'; * * const adapter = new ClaudeAgentSDKAdapter(); * await adapter.initialize({}); * adapter.registerAgent('coder', { * query, // the SDK's query function * options: { maxTurns: 10, allowedTools: ['Read', 'Grep'] }, * systemPrompt: 'You are a careful refactoring agent.', * }); * * await registry.addAdapter(adapter); * // orchestrator: delegateTask({ targetAgent: 'claude-agent-sdk:coder', ... }) * * @module ClaudeAgentSDKAdapter * @version 1.0.0 */ import { BaseAdapter } from './base-adapter'; import type { AdapterCapabilities, AgentPayload, AgentContext, AgentResult } from '../types/agent-adapter'; /** * A message yielded by the Claude Agent SDK's query loop. Only the fields * this adapter consumes are modeled; extra fields pass through untouched. */ export interface ClaudeSDKMessage { /** Message kind — 'assistant', 'user', 'system', 'result', ... */ type: string; /** For result messages: 'success' or an error subtype */ subtype?: string; /** For result messages: the final result text */ result?: string; /** Total cost in USD, when reported */ total_cost_usd?: number; /** Number of agentic turns taken */ num_turns?: number; /** Session identifier assigned by the SDK */ session_id?: string; /** Token usage, when reported */ usage?: Record; /** Whether the run ended in an error */ is_error?: boolean; } /** * The Claude Agent SDK `query` function shape. Matches * `@anthropic-ai/claude-agent-sdk`'s `query({ prompt, options })`, which * returns an async iterable of SDK messages. */ export type ClaudeAgentQueryFn = (params: { prompt: string; options?: Record; }) => AsyncIterable; /** Configuration for a registered Claude Agent SDK agent */ export interface ClaudeAgentSDKConfig { /** The SDK's query function (BYOC — required) */ query: ClaudeAgentQueryFn; /** * Options forwarded to the SDK on every run — e.g. `maxTurns`, * `allowedTools`, `permissionMode`, `cwd`, `model`. */ options?: Record; /** System prompt override — forwarded as `options.systemPrompt` */ systemPrompt?: string; /** * Called for every intermediate SDK message (assistant turns, tool use) * before the final result — useful for progress reporting. */ onMessage?: (message: ClaudeSDKMessage) => void; } /** * Adapter that runs Claude Agent SDK agentic loops as swarm agents. * The final `result` message becomes the AgentResult; intermediate messages * are surfaced through the per-agent `onMessage` callback. */ export declare class ClaudeAgentSDKAdapter extends BaseAdapter { readonly name = "claude-agent-sdk"; readonly version = "1.0.0"; private agents; get capabilities(): AdapterCapabilities; /** * Register a Claude Agent SDK-powered agent. * * @param agentId Unique identifier used in `delegateTask` calls. * @param config Agent configuration — `query` is required. */ registerAgent(agentId: string, config: ClaudeAgentSDKConfig): void; executeAgent(agentId: string, payload: AgentPayload, context: AgentContext): Promise; shutdown(): Promise; } //# sourceMappingURL=claude-agent-sdk-adapter.d.ts.map