import type { Prompt } from '@effect/ai'; import type { Effect, Stream } from 'effect'; import type * as Schema from 'effect/Schema'; import type { StreamEvent } from '../stream/events'; import type { ProviderConnectionId, ProviderConnectionNamespace } from '../platform/connections'; export type AgentPromptVariable = string | number | boolean; export interface AgentTemplatePrompt { readonly template: string; readonly variables?: Readonly>; } export interface AgentBamlPrompt { readonly baml: { readonly function: string; }; } /** * Prompt sources supported by core agents. * * BAML sources are resolved by an adapter-provided PromptSourceService. Core * intentionally does not import or inspect generated BAML clients. */ export type AgentPrompt = string | AgentTemplatePrompt | AgentBamlPrompt; export type AgentToolChoice = 'auto' | 'required' | 'none' | { type: 'tool'; toolName: string; } | { tool: string; } | { mode?: 'auto' | 'required'; oneOf: ReadonlyArray; }; export type ProviderToolChoice = 'auto' | 'required' | 'none' | { tool: string; } | { mode?: 'auto' | 'required'; oneOf: ReadonlyArray; }; /** * Supported AI platforms * This is a union type of all supported platforms, but the actual * list is dynamically determined by available provider packs */ export type AIPlatform = 'openai' | 'groq' | 'anthropic' | 'google' | 'mistral' | 'cohere' | 'vercel' | 'azure-openai' | 'azure-anthropic' | 'azure' | 'fireworks' | 'xai' | 'ollama' | 'ai21' | 'nvidia' | 'bedrock' | 'amazon-bedrock' | 'cloudflare' | 'elevenlabs' | 'lepton' | 'perplexity' | 'replicate' | 'together' | 'upstash' | string; /** * Agent configuration */ export interface AgentOutputRetryPolicy { /** Number of additional generation attempts after malformed output. */ readonly maxRetries?: number; } /** Correlation metadata available when an agent invocation is nested in a workflow/session. */ export interface AgentInvocationMetadata { readonly workflowId?: string; readonly sessionId?: string; } export interface AgentStreamOptions extends AgentInvocationMetadata { readonly threadId?: string; } export interface AgentConfig { id: string; systemMessage?: AgentPrompt; platform: AIPlatform; /** Explicit persisted provider connection. Omit only to use legacy environment configuration. */ connectionId?: ProviderConnectionId; /** Consumer-owned isolation namespace required with a persisted connection. */ connectionNamespace?: ProviderConnectionNamespace; model: string; tools?: string[]; temperature?: number; maxTokens?: number; utterances?: string[]; /** MCP server references (string[] of server IDs from global config) */ mcpServers?: string[]; maxSteps?: number; toolChoice?: AgentToolChoice; toolTimeout?: number; persistHistory?: boolean; toolRetry?: ToolRetryPolicy; /** Programmatic-only schema used to validate and encode direct agent input. */ input?: InputSchema; /** Programmatic-only schema used for provider-backed structured output. */ output?: OutputSchema; /** Retry policy applied only to malformed structured model output. */ outputRetry?: AgentOutputRetryPolicy; } /** * Tool retry policy configuration * Only retries errors classified as RETRYABLE (transient network/rate limit errors) */ export interface ToolRetryPolicy { maxRetries?: number; backoffMs?: number; maxBackoffMs?: number; jitterMs?: number; timeoutBackoffMs?: number; } /** * Retry diagnostics attached to provider errors after exhausting retries. * * Providers (e.g. Groq) attach this metadata to errors so the factory * can propagate structured retry information to CLI consumers. */ export interface RetryDiagnostics { readonly provider: string; readonly retryable: boolean; readonly attempts: number; readonly maxRetries: number; readonly lastStatusCode?: number; readonly failureCategory: string; } /** * Error with retry diagnostics attached. * * Used as a branded intersection so consumers can access diagnostics * without unsafe `as any` casts. */ export interface ErrorWithRetryDiagnostics extends Error { readonly _retryDiagnostics: RetryDiagnostics; } /** * Type guard for errors carrying retry diagnostics metadata. */ export declare function hasRetryDiagnostics(error: unknown): error is ErrorWithRetryDiagnostics; export declare function normalizeToolChoice(toolChoice: AgentToolChoice | undefined): ProviderToolChoice | undefined; /** * Agent instance (created from config) */ export interface AgentInstance { id: string; config: AgentConfig; /** Validate and execute a typed input directly. */ run: (input: Schema.Schema.Type, messages?: AgentMessage[], metadata?: AgentInvocationMetadata) => Effect.Effect>, Error>; /** Compatibility entrypoint for routed and conversational string messages. */ processMessage: (message: string, messages?: AgentMessage[], metadata?: AgentInvocationMetadata) => Effect.Effect>, Error>; streamMessage?: (message: string, messages?: AgentMessage[], options?: AgentStreamOptions) => Stream.Stream; } /** Type-erased forms used by heterogeneous runtime registries and ID lookup. */ export type AnyAgentConfig = AgentConfig; export type AnyAgentInstance = AgentInstance; /** * Message to send to an agent * Aligned with Effect Prompt message encoding for type compatibility */ export type AgentMessage = Prompt.MessageEncoded; /** * Agent response */ export interface AgentResponse { content: string; /** Decoded value when the agent has an output Effect Schema. */ output?: Output; toolCalls?: Array<{ toolId: string; args: Record; result?: any; metadata?: Record; /** Error info for failed tool calls (OpenAI API standard) */ error?: { code: string; message: string; }; }>; usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number; }; handoff?: { type: 'handoff'; agentId: string; message: string; context?: Record; }; /** Routing explanation (populated when routing explainability is enabled) */ routingExplanation?: import('../routing/types').RoutingExplanation; } //# sourceMappingURL=agent.d.ts.map