/** * Shared setup-phase helpers for the two tool-loop implementations * (SmartAgent._runStreamingToolLoop and ToolLoopHandler.execute). * * These helpers are INTERNAL to llm-agent-libs and are NOT exported from * the package barrel (src/index.ts). */ import type { CallOptions, IMcpClient, IMcpFailureClassifier, IToolCache, LlmStreamChunk, LlmTool, Message, Result, TimingEntry } from '@mcp-abap-adt/llm-agent'; import { OrchestratorError } from '@mcp-abap-adt/llm-agent'; import type { IMetrics } from '../../metrics/types.js'; import type { PendingToolResultsRegistry } from '../../policy/pending-tool-results-registry.js'; import { type ToolAvailabilityRegistry } from '../../policy/tool-availability-registry.js'; import type { ISpan, ITracer } from '../../tracer/types.js'; import type { IOutputValidator } from '../../validator/types.js'; export type ParsedToolCall = { id: string; name: string; arguments: Record; }; export interface IClassifiedToolCalls { internalCalls: ParsedToolCall[]; validExternalCalls: ParsedToolCall[]; blockedCalls: ParsedToolCall[]; hallucinations: ParsedToolCall[]; } /** Partition tool calls into internal / valid-external / blocked / hallucinated. */ export declare function classifyToolCalls(toolCalls: ParsedToolCall[], toolClientMap: Map, externalToolNames: Set, toolAvailabilityRegistry: ToolAvailabilityRegistry, sessionId: string): IClassifiedToolCalls; /** Append the client-tool priority instruction to the system message when * external tools are present. Returns messages unchanged otherwise. */ export declare function injectToolPriority(messages: Message[], externalTools: LlmTool[]): Message[]; /** Filter out session-blocked tools; log the blocked set when non-empty. * Returns the allowed subset. */ export declare function filterAvailableTools(registry: ToolAvailabilityRegistry, sessionId: string, currentTools: LlmTool[], iteration: number, options: CallOptions | undefined): LlmTool[]; /** Inject pending internal tool results from a prior mixed-call request. */ export declare function injectPendingResults(messages: Message[], pendingToolResults: PendingToolResultsRegistry, sessionId: string, options: CallOptions | undefined): Promise; export type SyntheticToolGroup = { assistant: Message; results: Message[]; }; /** Build an assistant(tool_calls=blocked) + per-blocked tool-error messages; * log the interception. Returns a `{ assistant, results }` group — the * caller appends `group.assistant, ...group.results` to its message list. */ export declare function buildBlockedToolMessages(content: string, blockedCalls: ParsedToolCall[], options?: CallOptions | undefined): SyntheticToolGroup; /** Build an assistant(tool_calls=ALL calls) + per-hallucination "not found" * tool messages. Returns a `{ assistant, results }` group — the caller * appends `group.assistant, ...group.results` to its message list. */ export declare function buildHallucinatedToolMessages(content: string, toolCalls: ParsedToolCall[], hallucinations: ParsedToolCall[]): SyntheticToolGroup; export type ToolExecResult = { tc: ParsedToolCall; text: string; res: Result<{ content: string | Record; isError?: boolean; }, { message: string; }> | null; duration: number; cached: boolean; }; export type ToolResultMeta = { identityKey?: string; isError: boolean; }; export type BatchOutcome = { escalated: true; } | { escalated: false; currentTools: LlmTool[]; toolCallCount: number; toolMessages: Message[]; resultMeta: ToolResultMeta[]; }; export interface IExecuteToolBatchArgs { batch: ParsedToolCall[]; toolClientMap: Map; toolCache: IToolCache; tracer: ITracer; metrics: IMetrics; parentSpan: ISpan; toolAvailabilityRegistry: ToolAvailabilityRegistry; sessionId: string; externalToolNames: Set; currentTools: LlmTool[]; toolCallCount: number; timingLog: TimingEntry[]; heartbeatMs: number; options: CallOptions | undefined; onToolExecuted?: (r: ToolExecResult) => void; mcpFailureClassifier?: IMcpFailureClassifier; } /** Execute a batch of internal tool calls concurrently, yielding heartbeat * chunks while they run; on an MCP-availability escalation yield an error * chunk and return `{ escalated: true }`; otherwise return the updated * currentTools / toolCallCount / tool messages. */ export declare function executeToolBatchWithHeartbeat(args: IExecuteToolBatchArgs): AsyncGenerator, BatchOutcome>; export interface IReprompt { reprompt: boolean; messages: Message[]; } /** Validate the no-tool-call output; on invalid, append the assistant reply + * a correction user message and signal a reprompt. Otherwise pass through. */ export declare function runOutputValidationReprompt(outputValidator: IOutputValidator, content: string, messages: Message[], currentTools: LlmTool[], options: CallOptions | undefined): Promise; //# sourceMappingURL=tool-loop-core.d.ts.map