feat: Enhance event duration tracking and UI components in chat

- Added duration tracking for agent steps and tool calls, improving event data accuracy.
- Updated AgentStreamDisplay and ToolResultRenderer components to include fallback headers and improved output styling.
- Refactored duration handling in the agent engine and session management to ensure consistent duration reporting.
- Enhanced UI elements for better user experience, including scrollable output areas and improved tooltip visibility.
This commit is contained in:
wizardchen
2025-11-12 14:27:00 +08:00
parent 05154c8d75
commit 38beca1146
6 changed files with 219 additions and 81 deletions
+2 -13
View File
@@ -164,19 +164,6 @@ func (e *AgentEngine) executeLoop(
Timestamp: time.Now(),
}
// Emit step event
e.eventBus.Emit(ctx, event.Event{
ID: generateEventID("step"),
Type: event.EventAgentStep,
SessionID: sessionID,
Data: event.AgentStepData{
Iteration: state.CurrentRound,
Thought: response.Content,
ToolCalls: step.ToolCalls,
Duration: time.Since(roundStart).Milliseconds(),
},
})
// 2. Check finish reason - if stop and no tool calls, agent is done
if response.FinishReason == "stop" && len(response.ToolCalls) == 0 {
logger.Infof(ctx, "[Agent][Round-%d] Agent finished - no more tool calls needed", state.CurrentRound+1)
@@ -195,6 +182,7 @@ func (e *AgentEngine) executeLoop(
Done: true,
},
})
step.Duration = time.Since(roundStart).Milliseconds()
logger.Infof(ctx, "[Agent][Round-%d] Duration: %dms", state.CurrentRound+1, time.Since(roundStart).Milliseconds())
break
}
@@ -345,6 +333,7 @@ func (e *AgentEngine) executeLoop(
}
}
step.Duration = time.Since(roundStart).Milliseconds()
state.RoundSteps = append(state.RoundSteps, step)
// 4. Observe: Add tool results to messages and write to context
messages = e.appendToolResults(ctx, messages, step)