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:
wizardchen
2026-03-06 12:21:23 +08:00
committed by lyingbug
parent bedb8ceb08
commit a4b255a456
21 changed files with 1311 additions and 777 deletions
@@ -422,6 +422,7 @@ func (h *AgentStreamHandler) handleComplete(ctx context.Context, evt event.Event
if data.MessageID == h.assistantMessageID {
// h.assistantMessage.Content = data.FinalAnswer
h.assistantMessage.IsCompleted = true
h.assistantMessage.AgentDurationMs = data.TotalDurationMs
// Update knowledge references if provided
if len(data.KnowledgeRefs) > 0 {
@@ -434,6 +435,8 @@ func (h *AgentStreamHandler) handleComplete(ctx context.Context, evt event.Event
h.assistantMessage.KnowledgeReferences = knowledgeRefs
}
h.assistantMessage.Content += data.FinalAnswer
// Update agent steps if provided
if data.AgentSteps != nil {
if steps, ok := data.AgentSteps.([]types.AgentStep); ok {