import type { JsonObject } from "../core/json.js"; import type { ModelAdapterIdentity, ModelAdapterReleaseIdentity } from "../adapters/model-adapters.js"; import type { ThoughtEvent } from "../events/types.js"; import type { InferenceBudgetPolicy, InferenceUsage } from "../store/types.js"; import type { AgentContextPacket } from "./context.js"; import type { OutputContractIdentity, SemanticOutput } from "./output-contracts.js"; import type { CapturedProposal, ProposalDeclarationName } from "./proposals.js"; export type AgentMode = "deterministic" | "pi" | "letta-agent-sdk"; export type LettaSkillSource = "bundled" | "global" | "agent" | "project"; export interface ContextDocumentSubscription { source: string; paths: string[]; required: boolean; } export interface AgentRetryPolicy { initialDelayMs: number; maxDelayMs: number; } export type ConversationCompactionPolicy = | { mode: "consume"; agentId: string; } | { mode: "produce"; targetAgentId: string; triggerInputChars: number; retainInputChars: number; }; export interface LettaAgentSdkConfiguration { backend: "cloud" | "local"; agentIdEnv: string; agentId?: string | undefined; conversation: "main" | "per-document"; responseMode: "strict-json" | "conversation-text"; batchResponseMode?: "strict-json" | undefined; outputOnly: boolean; proposalTool?: "public-knowledge-diff" | undefined; permissionMode: "standard" | "acceptEdits" | "unrestricted" | "strict"; skillSources?: LettaSkillSource[] | undefined; memoryDirEnv?: string | undefined; reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | undefined; dreaming: { trigger: "off" | "step-count" | "compaction-event"; stepCount?: number | undefined; }; sandbox: { ttlMinutes: number; terminateOnClose: boolean; }; } export interface ThoughtAgentDeclaration { id: string; version: number; name: string; description: string; mode: AgentMode; role?: "standard" | "repair" | "compactor"; outputContract?: OutputContractIdentity; declarationFingerprint?: string; provider?: "tinker" | "openai-compatible" | "letta-cloud" | "letta-local" | undefined; providerProfile?: string | undefined; modelTier?: "triage-small" | "reasoning-small" | "escalation" | undefined; model?: string | undefined; thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined; modelAdapterRelease?: ModelAdapterReleaseIdentity | undefined; modelAdapter?: ModelAdapterIdentity | undefined; adapterCatalogDigest?: string | undefined; adapterCatalogGeneration?: number | undefined; lettaAgent?: LettaAgentSdkConfiguration | undefined; outputMode?: "strict-json" | "conversation-text" | "compaction-text" | undefined; eventTypes: string[]; compiledEventTypes: string[]; sourcePatterns: string[]; acceptedPrivacy: Array; privacyFloor?: ThoughtEvent["privacy"] | undefined; initialReplay?: "beginning" | "now" | undefined; outputEventType: string; emit: string[]; promptRef: string; systemPrompt: string; enabled: boolean; maxEvents: number; maxInputChars: number; contextStrategy?: "single-event" | "telegram-conversation" | "telegram-compaction" | "agent-conversation" | "atproto-batch" | "activity-batch" | "coil-public-knowledge" | undefined; contextDocumentMaxChars?: number | undefined; contextDocumentSubscriptions?: ContextDocumentSubscription[] | undefined; conversationHistoryAgentIds?: string[] | undefined; conversationAssistantHistoryMaxTurns?: number | undefined; conversationCompaction?: ConversationCompactionPolicy | undefined; payloadFields?: string[] | undefined; atprotoObjectContext?: boolean | undefined; requireCompletedAgentOutputs?: boolean | undefined; maxOutputTokens: number; timeoutMs: number; accounting?: InferenceBudgetPolicy | undefined; retry?: AgentRetryPolicy | undefined; tools: string[]; proposals?: ProposalDeclarationName[] | undefined; externalActions: false; } export interface AgentRunInput { runId: string; attempt?: number; declaration: ThoughtAgentDeclaration; event: ThoughtEvent; context: AgentContextPacket; } export type AgentOutput = SemanticOutput & { model?: { provider: string; id: string; revision?: string | undefined; } | undefined; enrichments?: EnrichmentOutcome[] | undefined; /** Trusted provider telemetry. Never part of the semantic output contract. */ usage?: InferenceUsage | undefined; /** Validated inert model requests. Never part of the semantic output contract or run result. */ proposals?: CapturedProposal[] | undefined; }; export interface EnrichmentOutcome { tool: string; status: "succeeded" | "failed"; requestKeys: string[]; argumentsRedacted: true; resultPresent: boolean; resultKeys?: string[] | undefined; resultSha256?: string | undefined; errorCode?: string | undefined; } export interface RunnerTrace { kind: string; data: unknown; at?: string; } export class AgentRunFailure extends Error { readonly diagnostic: JsonObject | undefined; readonly advanceProgress: boolean; readonly usage: InferenceUsage | undefined; constructor( message: string, options: { cause?: unknown; diagnostic?: JsonObject; advanceProgress?: boolean; usage?: InferenceUsage } = {}, ) { super(message, options.cause === undefined ? undefined : { cause: options.cause }); this.name = "AgentRunFailure"; this.diagnostic = options.diagnostic; this.advanceProgress = options.advanceProgress ?? true; this.usage = options.usage; } } export interface AgentRunner { readonly mode: AgentMode; run(input: AgentRunInput, onTrace: (trace: RunnerTrace) => Promise): Promise; }