fix(telemetry): pull missing token metrics, accurate route mapping, added ToolCalls header counter
This commit is contained in:
parent
8613712852
commit
f521aefa58
2 changed files with 12 additions and 5 deletions
|
|
@ -1637,7 +1637,7 @@ func (al *AgentLoop) runAgentLoop(
|
|||
}
|
||||
|
||||
providerName := al.GetConfig().Agents.Defaults.Provider
|
||||
modelName := al.GetConfig().Agents.Defaults.GetModelName()
|
||||
modelName := agent.Model
|
||||
|
||||
m := Metrics{
|
||||
Version: version,
|
||||
|
|
@ -1646,6 +1646,7 @@ func (al *AgentLoop) runAgentLoop(
|
|||
Model: modelName,
|
||||
Complexity: calculateComplexity(promptTokens, compTokens),
|
||||
Tokens: totalTokens,
|
||||
ToolCalls: ts.currentIteration(),
|
||||
Processing: time.Since(ts.startedAt),
|
||||
}
|
||||
|
||||
|
|
@ -2268,10 +2269,15 @@ turnLoop:
|
|||
}
|
||||
}
|
||||
|
||||
// Save finishReason to turnState for SubTurn truncation detection
|
||||
// Save finishReason and Usage permanently to the primary turnState
|
||||
ts.SetLastFinishReason(response.FinishReason)
|
||||
if response.Usage != nil {
|
||||
ts.SetLastUsage(response.Usage)
|
||||
}
|
||||
|
||||
// Save to inner context if truncated
|
||||
if innerTS := turnStateFromContext(ctx); innerTS != nil {
|
||||
innerTS.SetLastFinishReason(response.FinishReason)
|
||||
// Save usage for token budget tracking
|
||||
if response.Usage != nil {
|
||||
innerTS.SetLastUsage(response.Usage)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ type Metrics struct {
|
|||
Model string
|
||||
Complexity int
|
||||
Tokens int
|
||||
ToolCalls int
|
||||
Processing time.Duration
|
||||
}
|
||||
|
||||
func WrapResponse(rawOutput string, m Metrics) string {
|
||||
header := fmt.Sprintf(
|
||||
"System: picoclaw-%s\nAgent: %s\nRoute: %s\nModel: %s\nComplexity: %d\nTokens: %d\nProcessing: %.1fs\n\n",
|
||||
m.Version, m.Agent, m.Route, m.Model, m.Complexity, m.Tokens, m.Processing.Seconds(),
|
||||
"System: picoclaw-%s\nAgent: %s\nRoute: %s\nModel: %s\nComplexity: %d\nTokens: %d\nTool Calls: %d\nProcessing: %.1fs\n\n",
|
||||
m.Version, m.Agent, m.Route, m.Model, m.Complexity, m.Tokens, m.ToolCalls, m.Processing.Seconds(),
|
||||
)
|
||||
return header + rawOutput
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue