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:
@@ -2,13 +2,14 @@
|
||||
//
|
||||
// Helpers for normalising LLM-emitted final answers before rendering.
|
||||
//
|
||||
// Background: not every model reliably calls our `final_answer` tool. Many
|
||||
// models — especially smaller ones or those SFT'd on different conventions —
|
||||
// instead embed the answer inside <answer>…</answer>, <final_answer>…</final_answer>,
|
||||
// or prefix it with "Final Answer:" / "最终答案:". When the agent loop accepts
|
||||
// such a natural-stop response as the final answer, those wrappers leak into
|
||||
// the rendered output. This module provides a single helper to strip them
|
||||
// before the markdown renderer sees the text.
|
||||
// Background: the agent ends a turn by writing its answer as plain assistant
|
||||
// text. Many models — especially smaller ones or those SFT'd on different
|
||||
// conventions — wrap that answer inside <answer>…</answer>,
|
||||
// <final_answer>…</final_answer>, or prefix it with "Final Answer:" /
|
||||
// "最终答案:". When the agent loop accepts such a natural-stop response as the
|
||||
// final answer, those wrappers leak into the rendered output. This module
|
||||
// provides a single helper to strip them before the markdown renderer sees
|
||||
// the text.
|
||||
//
|
||||
// The function is intentionally conservative: it only strips a wrapper when
|
||||
// it covers the *entire* trimmed content. We don't want to corrupt user-
|
||||
@@ -25,8 +26,8 @@ const ANSWER_PREFIX_RE =
|
||||
/^\s*(?:final\s*answer|最终答案|答案|答)\s*[::]\s*/i;
|
||||
|
||||
/**
|
||||
* Remove common "final answer" wrappers that some models emit instead of
|
||||
* calling the structured `final_answer` tool. Returns the original string
|
||||
* Remove common "final answer" wrappers that some models wrap their
|
||||
* plain-text answer in. Returns the original string
|
||||
* (trimmed only when stripping happens) when no wrapper is detected.
|
||||
*
|
||||
* Recognised wrappers (must cover the entire trimmed content):
|
||||
|
||||
Reference in New Issue
Block a user