@mastra/core
Version:
92 lines • 4.33 kB
TypeScript
import { Agent } from '../agent/index.js';
import type { ToolsInput, ToolsetsInput } from '../agent/types.js';
import type { MastraModelConfig } from '../llm/model/shared.types.js';
import type { Mastra } from '../mastra/index.js';
import { RequestContext } from '../request-context/index.js';
import { askUserTool } from '../tools/builtin/ask-user.js';
import { submitPlanTool } from '../tools/builtin/submit-plan.js';
import type { AgentControllerSubagent } from './types.js';
export { askUserTool };
export { submitPlanTool };
export { taskWriteTool, taskUpdateTool, taskCompleteTool, taskCheckTool, assignTaskIds, summarizeTaskCheck, } from '../tools/builtin/task-tools.js';
export type { TaskItem, TaskItemInput, TaskItemSnapshot, TaskCheckResult, TaskCheckSummary, } from '../tools/builtin/task-tools.js';
export { TaskStateProcessor } from '../tools/builtin/task-state-processor.js';
export interface CreateSubagentToolOptions {
subagents: AgentControllerSubagent[];
resolveModel: (modelId: string) => MastraModelConfig;
/** Resolved controller tools (already evaluated from DynamicArgument) */
controllerTools?: ToolsInput;
/** Fallback model ID when subagent definition has no defaultModelId */
fallbackModelId?: string;
/** Returns the parent model ID for display when a subagent call is forked. */
getParentModelId?: () => string;
/**
* Returns the parent Agent that owns the current run. Invoked when a
* subagent call is forked so the fork can reuse the parent's
* instructions, tools, and model to preserve prompt-cache prefix.
*/
getParentAgent?: () => Agent | undefined;
/**
* Clones the parent thread so a forked subagent can run on a copy
* without polluting the parent conversation. Typically delegates to
* `AgentController.cloneThread`. Returns the new thread metadata.
*/
cloneThreadForFork?: (opts: {
sourceThreadId: string;
resourceId?: string;
title?: string;
}) => Promise<{
id: string;
resourceId: string;
}>;
/**
* Resolves the toolsets the parent agent runs with for the current request.
* When set, forked subagents inherit the parent's toolsets so controller-injected
* tools like `ask_user` / `submit_plan` / user-configured controller tools remain
* available inside the fork. The `subagent` entry is preserved for prompt-cache
* stability, but its runtime execute function is patched to block recursion.
*/
getParentToolsets?: (requestContext?: RequestContext) => Promise<ToolsetsInput | undefined>;
/**
* Internal Mastra instance passed to each subagent Agent constructor so the
* bare model id resolves through the same gateways as the parent and the
* agent inherits pubsub/observability.
*/
mastra?: Mastra;
}
/**
* Creates a `subagent` tool from registered subagent definitions.
* The tool spawns a fresh Agent per invocation with constrained tools,
* streams the response, and forwards events to the controller.
*/
export declare function createSubagentTool(opts: CreateSubagentToolOptions): import("../tools").Tool<{
agentType: string;
task: string;
modelId?: string | undefined;
forked?: boolean | undefined;
}, unknown, unknown, unknown, import("../tools").ToolExecutionContext<unknown, unknown, unknown>, "subagent", unknown>;
/**
* Parse subagent metadata from a tool result string.
*
* Older persisted threads may have an internal `<subagent-meta />` tag
* appended to the subagent tool result content (carrying modelId / durationMs
* / sub-tool-call summary, used by history-render UIs to reconstruct the
* subagent activity box when live events aren't available).
*
* New runs no longer append the tag — the metadata leaked into model context
* and could be echoed back as visible assistant text — but this parser is
* retained so existing threads continue to render cleanly. It also strips the
* tag so callers never display it to users.
*
* Returns the cleaned text plus any parsed metadata.
*/
export declare function parseSubagentMeta(content: string): {
text: string;
modelId?: string;
durationMs?: number;
toolCalls?: Array<{
name: string;
isError: boolean;
}>;
};
//# sourceMappingURL=tools.d.ts.map