import { type CallToolRequest, type Tool } from '@frontmcp/protocol'; import { AgentContext, AgentEntry, type AgentCallArgs, type AgentCallExtra, type AgentInputOf, type AgentLlmAdapter, type AgentOutputOf, type AgentRecord, type EntryOwnerRef, type ParsedAgentResult, type SafeTransformResult, type ScopeEntry, type ToolInputType, type ToolOutputType } from '../common'; import type HookRegistry from '../hooks/hook.registry'; import type ProviderRegistry from '../provider/provider.registry'; import { ToolInstance } from '../tool/tool.instance'; /** * Concrete implementation of AgentEntry. * * AgentInstance manages an agent's lifecycle, including: * - LLM adapter initialization and configuration * - Agent-scoped tool registration (tools are private to this agent) * - Hook registration for agent-specific flows * - Input/output schema parsing and validation * - Tool definition generation for MCP exposure * - Swarm visibility configuration * * @template InSchema - Zod schema type for agent input * @template OutSchema - Zod schema type for agent output * @template In - Inferred input type from InSchema * @template Out - Inferred output type from OutSchema * * @example * ```typescript * // Created internally by AgentRegistry * const instance = new AgentInstance(record, providers, owner); * await instance.ready; * * // Create an execution context * const context = instance.create(input, { authInfo }); * const result = await context.execute(input); * ``` */ export declare class AgentInstance, Out = AgentOutputOf<{ outputSchema: OutSchema; }>> extends AgentEntry { private readonly providers; readonly scope: ScopeEntry; readonly hooks: HookRegistry; /** The LLM adapter for this agent */ private llmAdapter; /** Agent-scoped tools (from @Agent({ tools: [...] })) */ private agentTools; /** Agent's private scope (like a private app with its own registries) */ private agentScope; /** * The agent exposed as a standard tool for registration in parent scope. * This allows the agent to be called like any other tool (use-agent:*) and * go through the standard tools:call-tool flow with all plugins/hooks. */ private agentToolInstance; constructor(record: AgentRecord, providers: ProviderRegistry, owner: EntryOwnerRef); protected initialize(): Promise; /** * Initialize the agent's private scope. * * The AgentScope acts as a "private app" with its own registries for: * - Tools (from @Agent({ tools: [...] })) * - Plugins (from @Agent({ plugins: [...] })) * - Adapters (from @Agent({ adapters: [...] })) * - Providers (from @Agent({ providers: [...] })) * - Resources, Prompts, nested Agents * * This scope is isolated from the parent scope and not exposed externally. * Tool calls are routed through the scope's call-tool flow for full lifecycle support. */ private initializeAgentTools; /** * Initialize the LLM adapter from the agent's metadata configuration. */ private initializeLlmAdapter; /** * Create a ConfigResolver from the ConfigService. * Uses getAll() and manual path traversal to avoid DottedPath type complexity. */ private createConfigResolver; /** * Register hooks from the agent class. * Validates that hooks are only registered for agent-specific flows. * * @throws InvalidHookFlowError If hooks are registered for non-agent flows */ private registerHooks; /** * Get the class name from the record's provide property. * Used for error messages and logging. */ private getClassName; /** * Create the agent as a standard ToolInstance for registration in parent scope. * * This follows the same pattern as OpenAPI adapters that create dynamic tools * with a prebuilt execute function. The agent's execute handler internally calls * the agent's LLM execution loop. * * Benefits: * - Agent tools go through standard tools:call-tool flow * - Plugin metadata extensions (cache, codecall) work on agents * - CodeCall can discover and search for agent tools * - Unified hook/plugin execution */ private createAgentAsTool; /** * Build ToolMetadata from AgentMetadata. * * Includes plugin metadata extensions (cache, codecall) from agent metadata * so plugins can apply to agent tools. */ private buildAgentToolMetadata; /** * Create the execute handler for the agent tool. * * This handler is called when the tool is invoked through the standard * tools:call-tool flow. It creates an AgentContext and runs the LLM loop. */ private createAgentToolExecuteHandler; /** * Get the ToolInstance representing this agent. * * This is used by AgentRegistry to register the agent tool in the parent * scope's ToolRegistry, enabling standard tool flow with plugins/hooks. * * @returns The agent's ToolInstance, or null if not created */ getToolInstance(): ToolInstance | null; getMetadata(): import("../common").AgentMetadata>; }>, ToolOutputType>; getOutputSchema(): OutSchema | undefined; /** * Get the LLM adapter for this agent. */ getLlmAdapter(): AgentLlmAdapter | null; /** * Create an AgentContext instance for executing this agent. * * @param input - The input arguments for the agent * @param ctx - Extra context including authInfo * @returns A new AgentContext instance ready for execution * @throws AgentNotConfiguredError If no LLM adapter is configured */ create(input: AgentCallArgs, ctx: AgentCallExtra): AgentContext; /** * Build the constructor arguments for creating an AgentContext. * * @param input - The input arguments for the agent * @param ctx - Extra context including authInfo * @param llmAdapter - The LLM adapter (passed explicitly to avoid non-null assertion) */ private buildAgentCtorArgs; /** * Get tool definitions available to this agent. * Returns only the agent's own tools (from @Agent({ tools: [...] })). */ private getToolDefinitions; /** * Create a tool executor for agent-scoped tools. * * When `execution.useToolFlow` is enabled (default: true), tool calls are routed * through the agent's private scope's call-tool flow. This enables full lifecycle * support including: * - Plugin integration (cache, PII, rate limiting, etc.) * - Hook execution (will/did/around stages) * - Authorization checks * - UI rendering * - MCP-compliant error handling * * When `execution.useToolFlow` is false, tools are executed directly for * performance-critical scenarios. * * @param ctx - Extra context including authInfo * @returns A function that executes tools by name */ private createToolExecutor; /** * Extract the actual result from MCP CallToolResult format. * * The call-tool flow returns a CallToolResult with: * - structuredContent: The raw tool output (preferred) * - content: Array of text/image content (fallback) * - isError: Whether the tool execution failed * * @param mcpResult - The CallToolResult from the flow * @returns The extracted tool result * @throws Error if the tool execution failed */ private extractToolResult; parseInput(input: CallToolRequest['params']): AgentCallArgs; parseOutput(raw: Out | Partial | unknown): ParsedAgentResult; safeParseOutput(raw: Out | Partial | unknown): SafeTransformResult; /** * Get the MCP Tool definition for this agent. * This allows the agent to be invoked as a tool by other agents or clients. * * @returns Tool definition with name, description, and input schema */ getToolDefinition(): Tool; /** * Build the tool description from metadata. */ private buildToolDescription; isVisibleToSwarm(): boolean; canSeeSwarm(): boolean; getVisibleAgentIds(): string[]; } //# sourceMappingURL=agent.instance.d.ts.map