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
+3 -14
View File
@@ -229,12 +229,12 @@ func (c *OllamaChat) ChatStream(
}
// Ollama returns tool calls as complete objects (not incremental deltas).
// Log this so we can trace non-streaming answer delivery.
// Log this so we can trace non-streaming thought delivery.
for _, tc := range resp.Message.ToolCalls {
if tc.Function.Name == "final_answer" || tc.Function.Name == "thinking" {
if tc.Function.Name == "thinking" {
argsBytes, _ := json.Marshal(tc.Function.Arguments)
logger.Warnf(ctx, "[Ollama Stream] Tool %q arrived non-incrementally (%d bytes args), "+
"answer will not be token-streamed to frontend",
"thought will not be token-streamed to frontend",
tc.Function.Name, len(argsBytes))
}
}
@@ -242,17 +242,6 @@ func (c *OllamaChat) ChatStream(
for _, tc := range resp.Message.ToolCalls {
argsMap := tc.Function.Arguments.ToMap()
switch tc.Function.Name {
case "final_answer":
if answer, ok := argsMap["answer"].(string); ok && answer != "" {
streamChan <- types.StreamResponse{
ResponseType: types.ResponseTypeAnswer,
Content: answer,
Done: false,
Data: map[string]interface{}{
"source": "final_answer_tool",
},
}
}
case "thinking":
if thought, ok := argsMap["thought"].(string); ok && thought != "" {
streamChan <- types.StreamResponse{