Something went wrong. Try again.
A local-first event pipeline for independent agents, built on Jazz.
Something went wrong. Try again.
5.8 kB · 168 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169import 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<ThoughtEvent["privacy"]>; 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<void>): Promise<AgentOutput>;}