UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

19 lines (18 loc) • 1.07 kB
import type { ToolCall } from "../internal/llm.js"; /** * Best-effort recovery of tool calls that a weaker (non-native-function-calling) model emitted as * TEXT instead of structured tool calls. Recognizes `<tool_call>{...}</tool_call>` / * `<function_call>...` tags and fenced ```json blocks containing `{name|tool, arguments|parameters|input}` * (or an array of them). Only names present in `toolNames` are promoted. * * Returns the promoted tool calls and the text with those blocks removed. Off by default — enable via * `createOpenAIBrain({ repairTextToolCalls: true })` only for models that need it. * * A fenced block must carry an arguments face to be promoted at all (HRD-BRN-3) and a block is only removed * from the text when everything in it was promoted (HRD-BRN-3) — so this never fabricates a call out of a * JSON object that merely names a tool, and never deletes text it did not turn into a call. */ export declare function repairTextToolCalls(text: string, toolNames: Set<string>): { toolCalls: ToolCall[]; cleanedText: string; };