Skip to content

feat: show sub-agent run-stats (tools · tokens · time) on completion#16

Merged
mudler merged 8 commits into
masterfrom
feat/subagent-completion-stats
Jun 4, 2026
Merged

feat: show sub-agent run-stats (tools · tokens · time) on completion#16
mudler merged 8 commits into
masterfrom
feat/subagent-completion-stats

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Summary

When a spawned sub-agent finishes, nib now shows a one-line run summary in both the TUI and the plain CLI:

sub-agent explore finished · 3 tools · 12.4k tokens · 1m 03s
  • chat.AgentEvent carries three new completion fields: ToolCount, TotalTokens, Elapsed.
  • emitAgentEvent times each sub-agent (spawn → completion via a mutex-guarded start-time map) and reads len(Fragment.Status.ToolsCalled) + Fragment.Status.CumulativeUsage.TotalTokens from the completed AgentState.Fragment (nil-safe for failed agents).
  • Pure formatters (humanTokens, humanDuration, AgentEvent.StatsSuffix) render the suffix, omitting zero/unknown segments.
  • The TUI now always shows the completion marker (previously suppressed when a result block was present); the CLI appends the suffix to the completed line.

Cumulative tokens are the sum across every LLM call the sub-agent made.

Depends on

Test Plan

  • chat/agentstats_test.go: humanTokens / humanDuration boundaries; StatsSuffix plural/singular + zero-omission.
  • chat/agentusage_test.go: agentUsage nil-fragment and populated cases.
  • tui/agents_stats_test.go: completed transcript line contains the stats segments.
  • cmd/cli_agents_test.go: CLI completed line contains the stats segments.
  • Full go test ./... + go vet ./... green; manual end-to-end review of the cogito→AgentState→event→render chain.

🤖 Generated with Claude Code

mudler and others added 8 commits June 4, 2026 08:24
Spec for rendering a Claude-Code-style completion summary
(tools · cumulative tokens · elapsed) when a spawned sub-agent
finishes, in both the TUI and the plain CLI. Cumulative token
tracking requires a small cogito-side accumulator exposed on the
returned fragment.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Temporary: lets nib build against the un-released CumulativeUsage change.
Removed once cogito is tagged (see plan Task 9).
…al replace

cogito's CumulativeUsage (mudler/cogito#55) is now released on main, so nib
depends on the published pseudo-version and the dev-time local replace is
removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mudler mudler force-pushed the feat/subagent-completion-stats branch from 56b1ad9 to b6b4aa8 Compare June 4, 2026 08:26
@mudler mudler merged commit ae6d397 into master Jun 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants