fix(core): auto-wrap primitive action input in normalizeResponse

Small models sometimes output single-field tool args as primitives
(e.g. {"click_element_by_index": 2} instead of {"index": 2}).
normalizeResponse now accepts an optional tools map and wraps
such values using the tool schema. Renamed invoke tools to macroTool.
This commit is contained in:
Simon
2026-02-25 17:01:45 +08:00
parent 22fe448d95
commit cbe223dac5
2 changed files with 29 additions and 4 deletions

View File

@@ -248,16 +248,16 @@ export class PageAgentCore extends EventTarget {
{ role: 'user' as const, content: await this.#assembleUserPrompt() },
]
const tools = { AgentOutput: this.#packMacroTool() }
const macroTool = { AgentOutput: this.#packMacroTool() }
// invoke LLM
console.log(chalk.blue.bold('🧠 Thinking...'))
this.#emitActivity({ type: 'thinking' })
const result = await this.#llm.invoke(messages, tools, this.#abortController.signal, {
const result = await this.#llm.invoke(messages, macroTool, this.#abortController.signal, {
toolChoiceName: 'AgentOutput',
normalizeResponse,
normalizeResponse: (res) => normalizeResponse(res, this.tools),
})
// assemble history