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
|
providerName := al.GetConfig().Agents.Defaults.Provider
|
||||||
modelName := al.GetConfig().Agents.Defaults.GetModelName()
|
modelName := agent.Model
|
||||||
|
|
||||||
m := Metrics{
|
m := Metrics{
|
||||||
Version: version,
|
Version: version,
|
||||||
|
|
@ -1646,6 +1646,7 @@ func (al *AgentLoop) runAgentLoop(
|
||||||
Model: modelName,
|
Model: modelName,
|
||||||
Complexity: calculateComplexity(promptTokens, compTokens),
|
Complexity: calculateComplexity(promptTokens, compTokens),
|
||||||
Tokens: totalTokens,
|
Tokens: totalTokens,
|
||||||
|
ToolCalls: ts.currentIteration(),
|
||||||
Processing: time.Since(ts.startedAt),
|
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 {
|
if innerTS := turnStateFromContext(ctx); innerTS != nil {
|
||||||
innerTS.SetLastFinishReason(response.FinishReason)
|
innerTS.SetLastFinishReason(response.FinishReason)
|
||||||
// Save usage for token budget tracking
|
|
||||||
if response.Usage != nil {
|
if response.Usage != nil {
|
||||||
innerTS.SetLastUsage(response.Usage)
|
innerTS.SetLastUsage(response.Usage)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,14 @@ type Metrics struct {
|
||||||
Model string
|
Model string
|
||||||
Complexity int
|
Complexity int
|
||||||
Tokens int
|
Tokens int
|
||||||
|
ToolCalls int
|
||||||
Processing time.Duration
|
Processing time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func WrapResponse(rawOutput string, m Metrics) string {
|
func WrapResponse(rawOutput string, m Metrics) string {
|
||||||
header := fmt.Sprintf(
|
header := fmt.Sprintf(
|
||||||
"System: picoclaw-%s\nAgent: %s\nRoute: %s\nModel: %s\nComplexity: %d\nTokens: %d\nProcessing: %.1fs\n\n",
|
"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.Processing.Seconds(),
|
m.Version, m.Agent, m.Route, m.Model, m.Complexity, m.Tokens, m.ToolCalls, m.Processing.Seconds(),
|
||||||
)
|
)
|
||||||
return header + rawOutput
|
return header + rawOutput
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue