import type { ModelSelector } from '@contractspec/lib.ai-providers/selector-types'; import type { AgentRegistry, 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, Tool } 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, AgentSessionState, ToolHandler } from '../types'; import { ContractSpecAgent } from './contract-spec-agent'; /** * Factory configuration for creating agents. */ export interface AgentFactoryConfig { /** Default language model to use */ defaultModel: LanguageModel; /** Agent registry for looking up specs */ registry: AgentRegistry; /** Global tool handlers map */ toolHandlers: Map; /** Optional OperationSpecRegistry for operation-backed tools (operationRef) */ operationRegistry?: OperationSpecRegistry; /** Optional registry for subagent-backed tools (subagentRef) */ subagentRegistry?: SubagentRegistry; /** Optional storage for memory tools (when spec.memoryTools.provider is anthropic) */ agentMemoryStore?: AgentMemoryStore; /** Optional knowledge retriever */ knowledgeRetriever?: KnowledgeRetriever; /** Optional session store */ sessionStore?: AgentSessionStore; /** Optional telemetry collector */ telemetryCollector?: TelemetryCollector; /** PostHog LLM Analytics config for automatic $ai_generation event capture */ posthogConfig?: PostHogLLMConfig & { tracingOptions?: PostHogTracingOptions; }; /** Additional tools to provide to all agents */ additionalTools?: Record>; /** MCP servers to provide to all agents */ 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 escalation and tool approvals. */ approvalWorkflow?: ApprovalWorkflow; /** Event emitter for lifecycle/audit events. */ eventEmitter?: AgentEventEmitter; } /** * Options for creating an agent instance. */ export interface CreateAgentOptions { /** Override the default model */ model?: LanguageModel; /** Additional tool handlers specific to this instance */ toolHandlers?: Map; /** Additional tools for this instance */ additionalTools?: Record>; /** MCP servers for this instance */ mcpServers?: McpClientConfig[]; /** Override OperationSpecRegistry for operation-backed tools */ operationRegistry?: OperationSpecRegistry; /** Override SubagentRegistry for subagent-backed tools */ subagentRegistry?: SubagentRegistry; /** Override runtime adapters for this instance. */ runtimeAdapters?: Partial>>; /** Override approval workflow for this instance. */ approvalWorkflow?: ApprovalWorkflow; } /** * Factory for creating ContractSpec agents from specs. * * Provides a centralized way to instantiate agents with * consistent configuration. * * @example * ```typescript * const factory = createAgentFactory({ * defaultModel: mistral('mistral-large-latest'), * registry: agentRegistry, * toolHandlers: globalToolHandlers, * sessionStore: mySessionStore, * }); * * const agent = await factory.create('support.bot'); * const result = await agent.generate({ prompt: 'Help me with...' }); * ``` */ export declare class AgentFactory { private readonly config; private readonly cache; constructor(config: AgentFactoryConfig); /** * Create an agent by name. * * @param name - Agent name (e.g., "support.bot") * @param version - Optional specific version * @param options - Optional creation options */ create(name: string, version?: string, options?: CreateAgentOptions): Promise; /** * Create an agent from a spec directly. * * @param spec - Agent specification * @param options - Optional creation options */ createFromSpec(spec: AgentSpec, options?: CreateAgentOptions): Promise; /** * Get or create a cached agent instance. * * Use this when you want to reuse agent instances. * * @param name - Agent name * @param version - Optional specific version */ getOrCreate(name: string, version?: string): Promise; /** * Clear the agent cache. */ clearCache(): void; /** * List all available agent names. */ listAvailable(): string[]; } /** * Create an agent factory. */ export declare function createAgentFactory(config: AgentFactoryConfig): AgentFactory;