Repository navigation
Description
Summary
The total_turns field in the agent completion logs always reads 1 in normal back-and-forth chat.
It is populated from the per-request AgentContext.Turns (which resets on every user message)
instead of the session-cumulative counter, so it never reflects the conversation's real turn count.
Steps to Reproduce
infer chat.- Send a message and wait for the reply; send a second message and wait for the reply (two simple
turns, no tool calls). - Inspect the day's log:
grep total_turns ~/.infer/logs/app-$(date +%F).log- every completed run logs"total_turns":1,
including the second (and every later) turn.
Expected Behavior
A field named total_turns should reflect the cumulative number of model turns in the session (e.g. 2
after two conversational turns) - or be renamed so it is clearly a per-request iteration count. The
session already tracks the cumulative value via sessionTurns.
Actual Behavior
Every completed run logs total_turns:1 for simple chat. The value only exceeds 1 within a single run
that loops through tools; it resets on each new user message, so it never accumulates across the
conversation.
Root Cause
AgentContext.Turnsstarts at 0 per agent run (internal/agent/agent_event_driven.go:77) and is
incremented once per LLM streaming iteration instartStreaming(internal/agent/agent_streaming.go:20).
A freshEventDrivenAgent/AgentContextis built for everyRunWithStream(i.e. every user
message), soTurnsis per-request and resets each turn - as documented at
internal/agent/agent.go:41-47.- The completion logs label this per-request value
total_turns:
internal/agent/states/completing.go:48and:80, plusinternal/agent/agent_event_driven.go:257
("agent reached Idle state - turn complete"). - The session-cumulative counter that would match "total" -
AgentServiceImpl.sessionTurns
(internal/agent/agent.go:48), incremented alongsideTurnsatagent_streaming.go:21- is already
maintained (it drives reminder cadence viainjectDueReminders,agent_utils.go:854) but is never
surfaced in these logs.
Proposed Fix
Either (observability-only, no behavioural change):
- Log the session-cumulative count under
total_turns(or add a distinctsession_turnsfield sourced
fromsessionTurns) at the completion / reached-Idle log sites, and/or - Rename the existing per-request field to something unambiguous (e.g.
run_turns/iterations) so it
is not read as a session total.
Turn limiting is unaffected - MaxTurns continues to gate the per-request Turns.
Environment
inference-gateway/cli, main. Surfaced while reviewing agent logs after #722 / #725 cleared unrelated
log noise.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
chore(release): 0.128.0 [skip ci]
inference-gateway-releaser commentedon Jul 3, 2026
🎉 This issue has been resolved in version 0.128.0 🎉
The release is available on:
Your semantic-release bot 📦🚀