refactor(agent): remove final_answer tool references and update related logic

- Eliminated all instances of the final_answer tool from the agent's configuration and logic, transitioning to a model where the agent concludes responses with plain text instead.
- Updated event handling and response analysis to reflect this change, ensuring that the agent's output is now directly delivered as text without relying on a dedicated final answer tool.
- Adjusted localization strings across multiple languages to remove references to final_answer, enhancing clarity and consistency in user-facing messages.
- Improved the overall structure of the agent's response handling to streamline the process and reduce potential confusion regarding tool usage.

refactor(agent): streamline answer handling and preamble logic

- Updated the agent's response handling to treat any text streamed before a tool call as a preamble, ensuring it is not included in the final answer.
- Removed the superseded marker logic from the event emission process, simplifying the flow of answer content and enhancing clarity in the UI.
- Adjusted the event handling to ensure that preamble segments are correctly retracted and relocated into the steps tree, improving the overall user experience.
- Enhanced the agent's internal logic to better manage answer segments and their states during streaming, leading to a more coherent response structure.
This commit is contained in:
wizardchen
2026-06-04 02:35:54 +08:00
committed by lyingbug
parent b9dde2abe8
commit d38a6efd87
31 changed files with 722 additions and 663 deletions
+13 -2
View File
@@ -594,7 +594,7 @@ func (e *AgentEngine) runReActIteration(
return iterOutcomeBreak, nil
}
// 2. Analyze: Check for stop conditions (natural stop or final_answer tool)
// 2. Analyze: Check for stop conditions (natural stop with no tool calls)
verdict := e.analyzeResponse(ctx, response, step, state.CurrentRound, sessionID, roundStart)
if verdict.isDone {
// Guard against empty content: when the LLM stops naturally with no
@@ -607,7 +607,7 @@ func (e *AgentEngine) runReActIteration(
round, *emptyRetries, maxEmptyResponseRetries)
*messagesPtr = append(*messagesPtr, chat.Message{
Role: "user",
Content: "Please provide your answer by calling the final_answer tool.",
Content: "Please provide your complete answer now as plain text.",
})
return iterOutcomeContinue, nil
}
@@ -625,6 +625,17 @@ func (e *AgentEngine) runReActIteration(
return iterOutcomeBreak, nil
}
// This round is non-terminal (it will execute tools and loop again). Any
// plain assistant text streamed live to the answer area this round was a
// preamble (e.g. "let me search the knowledge base…"), not the final
// answer. No explicit retraction signal is emitted: the agent only ends by
// stopping naturally with plain text and no tool calls, so the upcoming
// tool-call events are themselves the authoritative "that wasn't the final
// answer" marker. Both the stream handler and the UI treat any answer text
// preceding a tool call in the same stream as a preamble and relocate it
// into the steps tree. The preamble is still preserved as this round's
// Thought.
// 3. Act: Execute tool calls
e.executeToolCalls(ctx, response, &step, state.CurrentRound, sessionID, assistantMessageID)
toolCallCount = len(step.ToolCalls)