import type { ModelSelector } from '@contractspec/lib.ai-providers/selector-types'; import { type AgentSpec } from '@contractspec/lib.contracts-spec/agent'; import type { OperationSpecRegistry } from '@contractspec/lib.contracts-spec/operations/registry'; import type { KnowledgeRetriever } from '@contractspec/lib.knowledge/retriever'; import { type LanguageModel, type Tool, type ToolSet } from 'ai'; import { type ApprovalWorkflow } from '../approval/workflow'; import type { AgentRuntimeAdapterBundle } from '../interop/runtime-adapters'; import { type AgentSessionStore } from '../session/store'; import { type TelemetryCollector } from '../telemetry/adapter'; import type { PostHogLLMConfig, PostHogTracingOptions } from '../telemetry/posthog-types'; import type { AgentMemoryStore } from '../tools/agent-memory-store'; import { type McpClientConfig } from '../tools/mcp-client'; import { type SubagentRegistry } from '../tools/tool-adapter'; import type { AgentEventEmitter, AgentGenerateParams, AgentGenerateResult, AgentSessionState, AgentStreamParams, ToolHandler } from '../types'; /** * Type for tool with execute function (compatible with AI SDK Tool) */ type ExecutableTool = Tool; /** * Configuration for creating a ContractSpecAgent. */ export interface ContractSpecAgentConfig { /** The agent specification */ spec: AgentSpec; /** AI SDK language model */ model: LanguageModel; /** Map of tool name to handler function */ toolHandlers: Map; /** Optional OperationSpecRegistry for operation-backed tools (operationRef) */ operationRegistry?: OperationSpecRegistry; /** Optional knowledge retriever for RAG */ knowledgeRetriever?: KnowledgeRetriever; /** Optional session store for persistence */ sessionStore?: AgentSessionStore; /** Optional telemetry collector for evolution */ telemetryCollector?: TelemetryCollector; /** PostHog LLM Analytics config for automatic $ai_generation event capture */ posthogConfig?: PostHogLLMConfig & { /** Per-call tracing overrides (e.g., distinctId from the current user) */ tracingOptions?: PostHogTracingOptions; }; /** Additional AI SDK tools (e.g., from MCP servers) */ additionalTools?: Record; /** Registry for subagent-backed tools (subagentRef) */ subagentRegistry?: SubagentRegistry; /** Storage for memory tools (when memoryTools.provider is anthropic) */ agentMemoryStore?: AgentMemoryStore; /** MCP servers to connect and expose as tools */ mcpServers?: McpClientConfig[]; /** Ranking-driven model selector for dynamic per-call routing */ modelSelector?: ModelSelector; /** Optional external adapter bundles keyed by runtime id. */ runtimeAdapters?: Partial>>; /** Approval workflow used for escalations and tool approvals. */ approvalWorkflow?: ApprovalWorkflow; /** Optional lifecycle/audit event emitter. */ eventEmitter?: AgentEventEmitter; } /** * ContractSpec Agent implementation using AI SDK v6. * * Integrates ContractSpec's spec-first governance with AI SDK's * ToolLoopAgent, providing: * - Spec-defined tools with type-safe handlers * - Hybrid knowledge injection (static + dynamic RAG) * - Session persistence * - Telemetry for evolution * - MCP interoperability */ export declare class ContractSpecAgent { readonly version = "agent-v1"; readonly id: string; readonly spec: AgentSpec; readonly tools: Record; private readonly config; private instructions; private mcpCleanup?; private readonly activeStepContexts; private constructor(); /** * Create a ContractSpecAgent instance. * This is async because knowledge injection may need to fetch static content. */ static create(config: ContractSpecAgentConfig): Promise; /** * Cleanup resources held by this agent (e.g., MCP connections). */ cleanup(): Promise; /** * Generate a response (non-streaming). */ generate(params: AgentGenerateParams): Promise; /** * Stream a response with real-time updates. */ stream(params: AgentStreamParams): Promise>; /** * Handle step completion for persistence and telemetry. */ private handleStepFinish; private ensureSession; private resolveRuntimeAdapter; private syncSessionCheckpoint; private runSessionMiddleware; private requestApproval; private emitAgentEvent; private createInnerAgent; private resolveModelForCall; } export {};