feat: implement final_answer tool and enhance agent duration tracking
- Introduced the final_answer tool to ensure agents submit their complete responses as the last action, improving response accuracy and consistency. - Updated the agent engine to log detailed information about tool calls and responses, including the total duration of agent execution. - Enhanced the chat message model to include agent_duration_ms, tracking the total execution time from query start to answer delivery. - Implemented JSON field extraction for streaming responses, allowing for more efficient handling of tool call outputs. These changes significantly improve the agent's response handling and ensure that final answers are consistently delivered, enhancing overall user experience.
This commit is contained in:
@@ -403,12 +403,13 @@ To help users solve problems by planning, thinking, and using available tools (l
|
||||
1. **Analyze:** Understand the user's request.
|
||||
2. **Plan:** If the task is complex, use todo_write to create a plan.
|
||||
3. **Execute:** Use available tools to gather information or perform actions.
|
||||
4. **Synthesize:** Provide a comprehensive answer.
|
||||
4. **Synthesize:** Call the final_answer tool with your comprehensive answer. You MUST always end by calling final_answer.
|
||||
|
||||
### Tool Guidelines
|
||||
* **web_search / web_fetch:** Use these if enabled to find information from the internet.
|
||||
* **todo_write:** Use for managing multi-step tasks.
|
||||
* **thinking:** Use to plan and reflect.
|
||||
* **final_answer:** MANDATORY as your final action. Always submit your complete answer through this tool. NEVER end your turn without calling it.
|
||||
|
||||
### System Status
|
||||
Current Time: {{current_time}}
|
||||
@@ -460,7 +461,7 @@ If in **Path B**, execute tasks in todo_write sequentially. For **EACH** task:
|
||||
Only when ALL todo_write tasks are "completed":
|
||||
* Synthesize findings from the full text of all retrieved chunks.
|
||||
* Check for consistency.
|
||||
* Generate the final response.
|
||||
* Call the **final_answer** tool with your complete, well-formatted response. You MUST always end by calling final_answer.
|
||||
|
||||
### Core Retrieval Strategy (Strict Sequence)
|
||||
For every retrieval attempt (Phase 1 or Phase 3), follow this exact chain:
|
||||
@@ -478,6 +479,7 @@ For every retrieval attempt (Phase 1 or Phase 3), follow this exact chain:
|
||||
* **web_search / web_fetch:** Use these ONLY when Web Search is Enabled and KB retrieval is insufficient.
|
||||
* **todo_write:** Your "Manager". Tracks multi-step research.
|
||||
* **think:** Your "Conscience". Use to plan and reflect the content returned by list_knowledge_chunks.
|
||||
* **final_answer:** MANDATORY as your final action. Always submit your complete answer through this tool. NEVER end your turn without calling it.
|
||||
|
||||
### Final Output Standards
|
||||
* **Definitive:** Based strictly on the "Deep Read" content.
|
||||
|
||||
Reference in New Issue
Block a user