/** * Agents Service * * Main service class for agentic workflows operations. * Provides CRUD operations and execution for Ductape Agents. * * Agentic workflows extend Ductape's workflow engine to support AI-driven, * autonomous multi-step processes where an LLM dynamically decides the * next action based on observations and reasoning. */ import { IAgentServiceConfig, IDefineAgentOptions, IDefinedAgent, IAgentToolSchema, IRunAgentOptions, IAgentExecutionResult, IDispatchAgentOptions, IDispatchAgentResult, ISendAgentSignalOptions, IAgentStatusOptions, IAgentState, IListAgentExecutionsOptions, IAgentExecutionListResult, IAgentTool, IAgentToolDefinition } from './types'; /** * Error class for agent-related errors */ export declare class AgentError extends Error { readonly code: string; readonly details?: Record; constructor(message: string, code: string, details?: Record); static configurationError(message: string): AgentError; static validationError(message: string, details?: Record): AgentError; static notFoundError(message: string): AgentError; static executionError(message: string, details?: Record): AgentError; } /** * Main Agents Service class * Provides unified interface for agent management and execution */ export declare class AgentsService { /** Service configuration */ private config; /** ProductBuilder instances cache (keyed by product tag) */ private productBuilders; /** Local agent definitions */ private localAgents; /** Tool registries per agent */ private toolRegistries; /** Active executors (for status/signal handling) */ private activeExecutors; /** LogService instance for logging operations */ private logService; /** Current product ID for logging */ private productId; private _privateKey; /** * Create a new AgentsService instance * @param config - Optional configuration for authentication and workspace context */ constructor(config?: IAgentServiceConfig & { private_key: string; access_key: string; }); /** * Update service configuration */ updateConfig(config: IAgentServiceConfig & { access_key: string; }): void; /** * Get service configuration */ getConfig(): IAgentServiceConfig | null; /** * Create a new ProductBuilder instance */ private createNewProductBuilder; /** * Get or create a ProductBuilder instance for the given product tag */ private getOrCreateProductBuilder; private ensureAgentBootstrap; private getProductBuilder; /** * Initialize logging service */ private initializeLogService; /** * Create a new ProcessorService instance */ private createNewProcessor; /** * Create a resilience service wrapper for agent operations */ private createResilienceService; /** * Get context services for agent execution */ private getContextServices; /** * Define a new agent and optionally persist to database * * @example * ```ts * // Define and persist to database * const agent = await ductape.agents.define({ * product: 'my-product', * tag: 'customer-support', * name: 'Customer Support Agent', * model: { provider: 'anthropic', model: 'claude-sonnet-4-20250514' }, * systemPrompt: 'You are a helpful customer support agent...', * tools: [ * { * tag: 'lookup-order', * description: 'Look up order details', * parameters: { orderId: { type: 'string', description: 'Order ID' } }, * handler: async (ctx, params) => ctx.database.query({ ... }), * }, * ], * }); * ``` */ define>(options: IDefineAgentOptions): Promise; /** * Register a defined agent with a product (persists to database) * * @example * ```ts * await ductape.agents.register('my-product', agent); * ``` */ register(product: string, agent: IDefinedAgent): Promise; /** * Run an agent * * @example * ```ts * const result = await ductape.agents.run({ * product: 'my-product', * env: 'production', * tag: 'customer-support', * input: { * ticketId: 'TICKET-123', * message: 'I need help with my order', * }, * }); * ``` */ run(options: IRunAgentOptions): Promise>; /** * Dispatch an agent for scheduled or deferred execution * * @example * ```ts * const job = await ductape.agents.dispatch({ * product: 'my-product', * env: 'production', * agent: 'daily-report-agent', * input: { reportType: 'daily' }, * schedule: { cron: '0 9 * * *' }, // Daily at 9 AM * }); * ``` */ dispatch(options: IDispatchAgentOptions): Promise; /** * Send a signal to a running agent * * @example * ```ts * // Stop an agent * await ductape.agents.signal({ * product: 'my-product', * env: 'production', * execution_id: 'exec-123', * signal: 'stop', * }); * * // Approve a tool call * await ductape.agents.signal({ * product: 'my-product', * env: 'production', * execution_id: 'exec-123', * signal: 'approve', * payload: { toolCallId: 'tc-456' }, * }); * ``` */ signal(options: ISendAgentSignalOptions): Promise; /** * Get the status of an agent execution * * @example * ```ts * const status = await ductape.agents.status({ * product: 'my-product', * env: 'production', * execution_id: 'exec-123', * }); * ``` */ status(options: IAgentStatusOptions): Promise; /** * List agent executions * * @example * ```ts * const executions = await ductape.agents.list({ * product: 'my-product', * env: 'production', * agent: 'customer-support', * status: 'completed', * limit: 10, * }); * ``` */ list(options: IListAgentExecutionsOptions): Promise; /** * Add a tool to an agent * * @example * ```ts * await ductape.agents.addTool('customer-support', { * tag: 'new-tool', * description: 'A new tool', * parameters: { ... }, * handler: async (ctx, params) => { ... }, * }); * ``` */ addTool(agentTag: string, tool: IAgentTool): void; /** * Remove a tool from an agent */ removeTool(agentTag: string, toolTag: string): boolean; /** * Get tools for an agent */ getTools(agentTag: string): IAgentToolSchema[]; /** * Convert an agent into a tool that can be used by another agent * * This enables multi-agent orchestration where a "manager" agent can * delegate tasks to specialized agents. * * @example * ```ts * // Define specialized agents * const researchAgent = await ductape.agents.define({ * tag: 'research-agent', * name: 'Research Agent', * // ... * }); * * const writerAgent = await ductape.agents.define({ * tag: 'writer-agent', * name: 'Writer Agent', * // ... * }); * * // Create a manager agent that can delegate to specialists * const managerAgent = await ductape.agents.define({ * tag: 'manager-agent', * name: 'Project Manager', * tools: [ * ductape.agents.asTool({ * agentTag: 'research-agent', * product: 'my-product', * options: { * toolDescription: 'Delegate research tasks to the research specialist', * }, * }), * ductape.agents.asTool({ * agentTag: 'writer-agent', * product: 'my-product', * options: { * toolDescription: 'Delegate writing tasks to the writing specialist', * }, * }), * ], * }); * ``` */ asTool(definition: IAgentToolDefinition): IAgentTool; /** * Create an agent tool from a handlerRef string * * @example * ```ts * // In tool definition * { * tag: 'delegate-research', * handlerRef: 'agent:research-agent', * } * ``` */ createAgentToolFromRef(handlerRef: string, product: string, env: string): IAgentTool['handler']; /** * Get a defined agent by tag */ getAgent(tag: string): IDefinedAgent | undefined; /** * List all defined agents */ listAgents(): IDefinedAgent[]; /** * Delete an agent definition */ deleteAgent(tag: string): boolean; /** * Clear all agent definitions */ clearAll(): void; /** * Convert a stored IProductAgent to IDefinedAgent format */ private convertProductAgentToDefinedAgent; /** * Create a handler function from a handlerRef string * Format: "type:tag:event" (e.g., "action:payment-app:process-payment", "feature:checkout-flow") */ private createHandlerFromRef; } export declare const agentsService: AgentsService; export default AgentsService;