UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

120 lines 5.34 kB
import type { MastraLanguageModel } from '../../../llm/model/shared.types.js'; import type { StreamInternal } from '../../../loop/types.js'; import type { Mastra } from '../../../mastra/index.js'; import type { MastraMemory } from '../../../memory/memory.js'; import type { CoreTool } from '../../../tools/types.js'; import type { Workspace } from '../../../workspace/index.js'; import { MessageList } from '../../message-list/index.js'; import { SaveQueueManager } from '../../save-queue/index.js'; import type { SerializableDurableState, SerializableModelConfig, SerializableModelListEntry, SerializableToolMetadata, DurableAgenticWorkflowInput, RegistryModelListEntry } from '../types.js'; /** * Runtime dependencies that need to be resolved at step execution time. * These cannot be serialized and must be recreated from available context. */ export interface ResolvedRuntimeDependencies { /** Reconstructed _internal object for compatibility with existing code */ _internal: StreamInternal; /** Resolved tools with execute functions */ tools: Record<string, CoreTool>; /** Resolved language model */ model: MastraLanguageModel; /** Resolved model list for fallback support (actual model instances) */ modelList?: RegistryModelListEntry[]; /** Deserialized MessageList */ messageList: MessageList; /** Memory instance (if available) */ memory?: MastraMemory; /** SaveQueueManager for message persistence */ saveQueueManager?: SaveQueueManager; /** Workspace for file/sandbox operations */ workspace?: Workspace; } /** * Options for resolving runtime dependencies */ export interface ResolveRuntimeOptions { /** Mastra instance for accessing services */ mastra?: Mastra; /** Run identifier */ runId: string; /** Agent identifier */ agentId: string; /** Workflow input containing serialized state */ input: DurableAgenticWorkflowInput; /** Logger for debugging */ logger?: { debug?: (...args: any[]) => void; error?: (...args: any[]) => void; }; } /** * Resolve all runtime dependencies needed for durable step execution. * * This function reconstructs the non-serializable state needed to execute * agent steps from: * 1. The Mastra instance (for agent lookup, tools, model) * 2. The serialized workflow input (for MessageList, state) * * Unlike the registry-based approach, this reconstructs tools and model * from the agent registered with Mastra, making it truly durable across * process restarts. */ export declare function resolveRuntimeDependencies(options: ResolveRuntimeOptions): Promise<ResolvedRuntimeDependencies>; /** * Resolve the language model from serialized config. * * Note: This is a fallback when the model is not in the run registry. * The preferred approach is to store the actual model instance in the * run registry during preparation and retrieve it via runRegistry.getModel(). * * This fallback returns a metadata-only stub that will fail the * isSupportedLanguageModel check with a descriptive error message. */ export declare function resolveModel(config: SerializableModelConfig, _mastra?: Mastra): MastraLanguageModel; /** * Reconstruct the _internal (StreamInternal) object from available state */ export declare function resolveInternalState(options: { state: SerializableDurableState; memory?: MastraMemory; saveQueueManager?: SaveQueueManager; tools?: Record<string, CoreTool>; }): StreamInternal; /** * Resolve a single tool by name from Mastra's global tool registry */ export declare function resolveTool(toolName: string, mastra?: Mastra): CoreTool | undefined; /** * Check if a tool requires human approval. * * If the tool has a `needsApprovalFn`, it takes precedence over both the * global `requireToolApproval` flag and the tool-level `requireApproval` flag. * This matches the behavior of the non-durable agent's tool-call-step. */ export declare function toolRequiresApproval(tool: CoreTool, globalRequireApproval?: boolean, args?: Record<string, unknown>): Promise<boolean>; /** * Extract tool metadata needed for LLM from resolved tools * This is useful when we need to pass tool info to the model */ export declare function extractToolsForModel(tools: Record<string, CoreTool>, _toolsMetadata: SerializableToolMetadata[]): Record<string, CoreTool>; /** * Resolve a language model from a serialized model config. * * This is used during durable execution to reconstruct models from * serialized configuration. It uses the originalConfig string (e.g., 'openai/gpt-4o') * to resolve the model through the standard model resolution pipeline. * * @param config The serialized model configuration * @param mastra Optional Mastra instance for custom gateways * @returns Resolved language model */ export declare function resolveModelFromConfig(config: SerializableModelConfig, mastra?: Mastra): Promise<MastraLanguageModel>; /** * Resolve a model from a model list entry. * * @param entry The model list entry with config, maxRetries, enabled * @param mastra Optional Mastra instance * @returns Resolved language model */ export declare function resolveModelFromListEntry(entry: SerializableModelListEntry, mastra?: Mastra): Promise<MastraLanguageModel>; //# sourceMappingURL=resolve-runtime.d.ts.map