From 84ad7451a7d2e120c07bc7451b0384dc15b301dc Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Wed, 1 Apr 2026 13:28:12 +0200 Subject: [PATCH] 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. --- agent/loop.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/agent/loop.go b/agent/loop.go index 6cd86f5..c6d3413 100644 --- a/agent/loop.go +++ b/agent/loop.go @@ -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, }) }