UNPKG

@mastra/core

Version:
131 lines 6.06 kB
import type { MastraMemory } from '../../memory/memory.js'; import type { InputProcessorOrWorkflow, OutputProcessorOrWorkflow } from '../../processors/index.js'; import type { InlineSkill } from '../../skills/types.js'; import type { AnyWorkspace } from '../../workspace/index.js'; import { Agent } from '../agent.js'; import type { AgentConfig, ToolsInput } from '../types.js'; /** * Identity helper for a file-system routed agent config. Returns the provided * partial config unchanged — its only purpose is to give authors editor types * for `agents/<name>/config.ts` while letting `instructions`/`model`/`tools` be * supplied by sibling files (`instructions.md`, `tools/*.ts`). * * @example * ```ts * // src/mastra/agents/weather/config.ts * import { agentConfig } from '@mastra/core/agent'; * * export default agentConfig({ * model: 'openai/gpt-4o', * // instructions omitted -> taken from instructions.md * // tools omitted -> taken from tools/*.ts * }); * ``` */ export type FsAgentConfig = Partial<Omit<AgentConfig, 'id' | 'name'>> & { id?: string; name?: string; }; export declare function agentConfig(config: FsAgentConfig): FsAgentConfig; /** * A single tool discovered under `agents/<name>/tools/`. `key` defaults to the * filename slug; `tool` is the default export of that module. */ export interface FsAgentToolEntry { key: string; tool: ToolsInput[string]; } export interface FsAgentEntry { /** Agent directory name. Used as the default `id`/`name`. */ name: string; /** * Default export of `config.ts`, if present. Either an `agentConfig(...)` * partial or a fully code-defined `Agent` instance (`new Agent({...})`). */ config?: FsAgentConfig | Agent; /** Raw contents of `instructions.md`, if present. */ instructionsMd?: string; /** Tools discovered under `tools/`, already loaded. */ tools?: FsAgentToolEntry[]; /** * Skills discovered under `skills/`, already loaded as inline skills * (the codegen layer inlines each `SKILL.md` + references via `createSkill`). */ skills?: InlineSkill[]; /** * Default export of `agents/<name>/workspace.ts`, if present. A `Workspace` * instance that overrides the convention default. */ workspace?: AnyWorkspace; /** * Default export of `agents/<name>/memory.ts`, if present. A `MastraMemory` * instance wired into the assembled agent as its `memory`. `config.memory` * (from `config.ts`) takes precedence on conflict. */ memory?: MastraMemory; /** * Base path for the convention default workspace. When provided and neither * `config.workspace` nor `workspace.ts` supplies one, an FS agent gets a * default `Workspace` (a contained `LocalFilesystem` rooted here plus a * `LocalSandbox`), giving file-based agents file/shell tools automatically. * Callers (the deployer codegen layer) pass a per-agent directory here. */ defaultWorkspaceBasePath?: string; /** * Input processors discovered under `processors/input/`, already loaded. * Merged with `config.inputProcessors`; config takes precedence on collision. */ inputProcessors?: InputProcessorOrWorkflow[]; /** * Output processors discovered under `processors/output/`, already loaded. * Merged with `config.outputProcessors`; config takes precedence on collision. */ outputProcessors?: OutputProcessorOrWorkflow[]; /** * Declared subagents discovered under `agents/<name>/subagents/<childId>/`. * Each entry is assembled into its own `Agent` and wired into the parent's * `agents` map under its directory name, becoming a model-visible delegation * tool. Subagents may declare their own `subagents`, up to * `MAX_FS_SUBAGENT_DEPTH` levels below the top-level agent; deeper entries * are ignored with a warning. */ subagents?: FsAgentEntry[]; } /** * Maximum nesting depth for declared subagents. A top-level agent is depth 0; * its subagents are depth 1, and so on. Subagents declared deeper than this * are ignored with a warning. The cap keeps delegation trees a sane size and * guards `assembleAgentFromFsEntry` against cyclic entry objects. */ export declare const MAX_FS_SUBAGENT_DEPTH = 3; /** * Assemble a single `Agent` from already-loaded file-system entries for one * `agents/<name>/` directory. Performs no filesystem access — callers load the * modules and pass them in, keeping this unit-testable and runtime-portable. * * Precedence rules: * - `id`/`name` default to the directory name when omitted in config. * - `instructions`: a dynamic (function) `config.instructions` wins over * `instructions.md`; otherwise `instructions.md` wins over a static * `config.instructions`. Missing both is an error. * - `model` is required (from config); missing is an error. * - `tools`: discovered `tools/*.ts` are merged with `config.tools`; on key * collision `config.tools` wins (a warning is surfaced via `onWarn`). * - `skills`: discovered `skills/*` are merged with `config.skills`; on name * collision `config.skills` wins (a warning is surfaced via `onWarn`). A * dynamic (function) `config.skills` wins wholesale and discovered skills are * ignored with a warning. * - `memory`: `memory.ts`'s default export is used unless `config.memory` is * set, in which case `config.memory` wins (a warning is surfaced via * `onWarn`). Missing both leaves the agent without memory. * * If `config` is already an `Agent` instance (the author wrote * `export default new Agent({...})` in `config.ts`), it is used as-is — no * partial-config assembly is performed. This lets a folder under `agents/` * hold either an `agentConfig(...)` partial or a fully code-defined * `new Agent(...)` without the loader trying to re-wrap the latter. */ export declare function assembleAgentFromFsEntry(entry: FsAgentEntry, options?: { onWarn?: (message: string) => void; }): Agent; //# sourceMappingURL=index.d.ts.map