WeKnora/internal/agent
wizardchen a6d4266c93 fix(agent): terminate ReAct loop on final_answer regardless of arg parse success
The agent loop previously kept running when the LLM emitted final_answer with
malformed JSON arguments: observe.analyzeResponse strictly json.Unmarshal'd the
raw args and returned isDone=false on failure, while act.runToolCall separately
repaired the JSON and executed the tool. The mismatch made final_answer
non-terminal, so the LLM saw its own answer in the next round's tool result
and re-emitted final_answer, surfacing near-identical answers multiple times
to the user (issue #1008).

Fix by unifying parsing in a new tools.ParseFinalAnswerArgs helper with three
fallbacks (strict -> RepairJSON -> regex extraction) and making final_answer
always terminal in analyzeResponse. When no answer can be recovered, emit a
user-visible fallback message and a Done=true event so the UI still resolves.

Also route final_answer.Execute through the same helper so tool execution and
loop termination stay consistent.

Adds regression tests in observe_test.go and final_answer_test.go covering
valid args, RepairJSON recovery, unrecoverable args, and garbage input.

Refs: Tencent/WeKnora#1008
2026-04-23 19:36:28 +08:00
..
memory feat(agent): enhance message consolidation and context management 2026-03-25 22:08:29 +08:00
skills feat: adapt preloaded skills to smart-reasoning agent 2026-02-04 20:08:49 +08:00
token feat(agent): enhance message consolidation and context management 2026-03-25 22:08:29 +08:00
tools fix(agent): terminate ReAct loop on final_answer regardless of arg parse success 2026-04-23 19:36:28 +08:00
act.go feat: support parallel tool calling 2026-03-30 10:41:08 +08:00
const.go feat: Implement wiki_config updates in knowledge base management 2026-04-22 21:17:21 +08:00
engine.go feat: Implement wiki_config updates in knowledge base management 2026-04-22 21:17:21 +08:00
engine_image_test.go feat: auto-describe MCP tool result images via VLM 2026-03-25 21:38:15 +08:00
engine_test.go fix(agent): prevent empty response when no Knowledge Base is configured 2026-03-27 14:56:12 +08:00
finalize.go feat(agent): enhance token management and context handling in AgentEngine 2026-03-25 22:08:29 +08:00
observe.go fix(agent): terminate ReAct loop on final_answer regardless of arg parse success 2026-04-23 19:36:28 +08:00
observe_test.go fix(agent): terminate ReAct loop on final_answer regardless of arg parse success 2026-04-23 19:36:28 +08:00
prompts.go feat: Update agent type presets and prompt templates for improved knowledge base handling 2026-04-22 21:18:34 +08:00
prompts_wiki.go feat: Enhance wiki extraction and configuration options 2026-04-22 21:18:32 +08:00
prompts_wiki_test.go feat: Enhance wiki extraction and configuration options 2026-04-22 21:18:32 +08:00
think.go fix(agent): prevent empty response when no Knowledge Base is configured 2026-03-27 14:56:12 +08:00