@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
83 lines • 5.16 kB
TypeScript
/**
* Durable Agent Module
*
* This module provides durable execution patterns for AI agents with
* resumable streams. If a client disconnects and reconnects, they can
* receive missed events from the cache.
*
* ## Factory Functions
*
* - `createDurableAgent({ agent })` - Local execution with resumable streams
* - `createEventedAgent({ agent })` - Built-in evented workflow engine (fire-and-forget)
* - `createInngestAgent({ agent, inngest })` - Inngest durable execution (from @mastra/inngest)
*
* ## Class Hierarchy
*
* - `DurableAgent` extends `Agent` - Base durable agent with resumable streams
* - `EventedAgent` extends `DurableAgent` - Fire-and-forget execution
* - `InngestAgent` extends `DurableAgent` - Inngest-powered execution (from @mastra/inngest)
*
* ## Features
*
* 1. **Resumable Streams**: Events are cached, allowing reconnection without missing data
* 2. **Pluggable Cache**: Use InMemoryServerCache (default) or custom backends (Redis, etc.)
* 3. **Cache Inheritance**: Durable agents inherit cache from Mastra if not explicitly provided
* 4. **Durable Execution**: Run agentic loops on workflow engines (Inngest, evented, etc.)
*
* @example Basic usage with resumable streams
* ```typescript
* import { Agent } from '@mastra/core/agent';
* import { createDurableAgent } from '@mastra/core/agent/durable';
*
* const agent = new Agent({
* id: 'my-agent',
* instructions: 'You are a helpful assistant',
* model: openai('gpt-4'),
* });
*
* // Wrap with resumable streams
* const durableAgent = createDurableAgent({ agent });
*
* const { output, runId, cleanup } = await durableAgent.stream('Hello!');
* const text = await output.text;
* cleanup();
* ```
*
* @example Custom cache backend (e.g., Redis)
* ```typescript
* import { RedisServerCache } from '@mastra/redis'; // hypothetical
*
* const durableAgent = createDurableAgent({
* agent,
* cache: new RedisServerCache({ url: 'redis://...' }),
* });
* ```
*
* @example Cache inheritance from Mastra
* ```typescript
* const mastra = new Mastra({
* cache: new RedisServerCache({ url: 'redis://...' }),
* agents: {
* myAgent: createDurableAgent({ agent }), // Inherits Redis cache from Mastra
* },
* });
* ```
*/
export { createDurableAgent, isDurableAgent, isLocalDurableAgent, // Backwards compatibility alias
type CreateDurableAgentOptions, type LocalDurableAgent, } from './create-durable-agent.js';
export { DurableAgent, type DurableAgentConfig, type DurableAgentStreamOptions, type DurableAgentStreamResult, } from './durable-agent.js';
export { EventedAgent, isEventedAgentClass, type EventedAgentConfig } from './evented-agent.js';
export { createEventedAgent, isEventedAgent, type CreateEventedAgentOptions } from './create-evented-agent.js';
export { runDurableStreamUntilIdle, type DurableStreamUntilIdleDeps } from './durable-stream-until-idle.js';
export { prepareForDurableExecution, type PreparationOptions, type PreparationResult } from './preparation.js';
export { RunRegistry, ExtendedRunRegistry, type ExtendedRunRegistryEntry } from './run-registry.js';
export { createDurableAgentStream, emitChunkEvent, emitStepStartEvent, emitStepFinishEvent, emitFinishEvent, emitErrorEvent, emitSuspendedEvent, type DurableAgentStreamOptions as StreamAdapterOptions, type DurableAgentStreamResult as StreamAdapterResult, } from './stream-adapter.js';
export { AGENT_STREAM_TOPIC, AgentStreamEventTypes, DurableAgentDefaults, DurableStepIds } from './constants.js';
export type { SerializableToolMetadata, SerializableModelConfig, SerializableDurableState, SerializableDurableOptions, DurableAgenticWorkflowInput, DurableLLMStepOutput, DurableToolCallInput, DurableToolCallOutput, DurableAgenticExecutionOutput, DurableAgenticLoopOutput, AgentStreamEventType, AgentStreamEvent, AgentChunkEventData, AgentStepFinishEventData, AgentFinishEventData, AgentErrorEventData, AgentSuspendedEventData, RunRegistryEntry, DurableStepContext, } from './types.js';
export { createWorkflowInput, serializeToolsMetadata, serializeModelConfig, serializeDurableState, serializeDurableOptions, } from './utils/serialize-state.js';
export { resolveRuntimeDependencies, resolveModel, resolveInternalState, resolveTool, toolRequiresApproval, type ResolvedRuntimeDependencies, type ResolveRuntimeOptions, } from './utils/resolve-runtime.js';
export { createDurableAgenticWorkflow, type DurableAgenticWorkflowOptions } from './workflows/index.js';
export { createDurableBackgroundTaskCheckStep, createDurableLLMExecutionStep, createDurableToolCallStep, createDurableLLMMappingStep, } from './workflows/steps/index.js';
export { executeDurableToolCalls, modelConfigSchema, modelListEntrySchema, accumulatedUsageSchema, durableAgenticOutputSchema, baseDurableAgenticInputSchema, baseIterationStateSchema, calculateAccumulatedUsage, buildStepRecord, createBaseIterationStateUpdate, } from './workflows/shared/index.js';
export type { ToolExecutionContext, ToolExecutionError, BaseIterationState, AccumulatedUsage, IterationStateUpdateInput, StepRecord, } from './workflows/shared/index.js';
//# sourceMappingURL=index.d.ts.map