@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
95 lines • 3.55 kB
TypeScript
/**
* Factory function to create a DurableAgent that wraps an existing Agent.
*
* This is the recommended way to add durable execution capabilities to an agent.
* The factory creates a DurableAgent instance with resumable streams.
*
* @example
* ```typescript
* import { Agent } from '@mastra/core/agent';
* import { createDurableAgent } from '@mastra/core/agent/durable';
*
* const agent = new Agent({
* id: 'my-agent',
* name: 'My Agent',
* instructions: 'You are a helpful assistant',
* model: openai('gpt-4'),
* });
*
* const durableAgent = createDurableAgent({ agent });
*
* const mastra = new Mastra({
* agents: { myAgent: durableAgent },
* });
* ```
*/
import type { MastraServerCache } from '../../cache/base.js';
import type { PubSub } from '../../events/pubsub.js';
import type { Agent } from '../agent.js';
import { DurableAgent } from './durable-agent.js';
/**
* Options for createDurableAgent factory function.
*/
export interface CreateDurableAgentOptions<TAgentId extends string = string, TTools extends Record<string, any> = Record<string, any>, TOutput = undefined> {
/** The Agent to wrap with durable execution capabilities */
agent: Agent<TAgentId, TTools, TOutput>;
/** Optional ID override (defaults to agent.id) */
id?: TAgentId;
/** Optional name override (defaults to agent.name) */
name?: string;
/**
* Cache instance for storing stream events.
* Enables resumable streams - clients can disconnect and reconnect
* without missing events.
*
* - If not provided: Inherits from Mastra instance, or uses InMemoryServerCache
* - If provided: Uses the provided cache backend (e.g., Redis)
* - If set to `false`: Disables caching (streams are not resumable)
*/
cache?: MastraServerCache | false;
/**
* PubSub instance for streaming events.
* Optional - if not provided, defaults to EventEmitterPubSub.
*/
pubsub?: PubSub;
/** Maximum steps for agentic loop */
maxSteps?: number;
}
/**
* Create a DurableAgent that wraps an existing Agent.
*
* This factory function is the recommended way to add durable execution
* capabilities to an agent. It creates a DurableAgent instance with
* resumable streams.
*
* @param options - Configuration options
* @returns A DurableAgent instance
*
* @example
* ```typescript
* const agent = new Agent({
* id: 'my-agent',
* instructions: 'You are helpful',
* model: openai('gpt-4'),
* });
*
* const durableAgent = createDurableAgent({ agent });
*
* const mastra = new Mastra({
* agents: { myAgent: durableAgent },
* });
* ```
*/
export declare function createDurableAgent<TAgentId extends string = string, TTools extends Record<string, any> = Record<string, any>, TOutput = undefined>(options: CreateDurableAgentOptions<TAgentId, TTools, TOutput>): DurableAgent<TAgentId, TTools, TOutput>;
/**
* Check if an object is a DurableAgent
*/
export declare function isDurableAgent(obj: any): obj is DurableAgent;
/**
* Alias for isDurableAgent for backwards compatibility
* @deprecated Use isDurableAgent instead
*/
export declare const isLocalDurableAgent: typeof isDurableAgent;
export type { DurableAgentConfig, DurableAgentStreamOptions, DurableAgentStreamResult } from './durable-agent.js';
export type LocalDurableAgent<TAgentId extends string = string, TTools extends Record<string, any> = Record<string, any>, TOutput = undefined> = DurableAgent<TAgentId, TTools, TOutput>;
//# sourceMappingURL=create-durable-agent.d.ts.map