feat: add generation metrics to logs (think, rounds, tokens)

Log think flag, round count, prompt/output token counts per generation.
Change log category from 'usage' to 'generation' for clean MCP filtering.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 14:14:41 -04:00
parent 3e42992f67
commit 25d448f896
3 changed files with 21 additions and 3 deletions
+8 -1
View File
@@ -149,6 +149,9 @@ class ChatChunk:
type: Literal["content", "thinking", "tool_calls", "done"]
content: str = ""
tool_calls: list[dict] | None = None
# Token counts from the Ollama done event (only set on type="done")
prompt_tokens: int | None = None
output_tokens: int | None = None
async def stream_chat_with_tools(
@@ -221,7 +224,11 @@ async def stream_chat_with_tools(
yield ChatChunk(type="tool_calls", tool_calls=accumulated_tool_calls)
else:
logger.debug("Ollama done with no tool calls")
yield ChatChunk(type="done")
yield ChatChunk(
type="done",
prompt_tokens=data.get("prompt_eval_count"),
output_tokens=data.get("eval_count"),
)
break