agent: add Usage field to OutputMsg

OutputMsg.Usage carries the raw backend.Usage value when Role=="usage",
rather than formatting it into Content. main.go can now read em.Usage
directly instead of parsing the formatted string.
This commit is contained in:
Levi Neely 2026-04-01 13:28:12 +02:00
parent ace6afb853
commit 84ad7451a7
1 changed files with 3 additions and 2 deletions

View File

@ -16,6 +16,7 @@ type OutputMsg struct {
Role string
Name string
Content string
Usage backend.Usage
}
type Config struct {
@ -116,8 +117,8 @@ func (l *Loop) Run(ctx context.Context, state State) error {
// intermediate steps and avoids [↑0 ↓0 tokens] noise).
if resp.Usage.InputTokens > 0 || resp.Usage.OutputTokens > 0 {
l.emit(OutputMsg{
Role: "usage",
Content: fmt.Sprintf("↑%d ↓%d tokens", resp.Usage.InputTokens, resp.Usage.OutputTokens),
Role: "usage",
Usage: resp.Usage,
})
}