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.Turns starts at 0 per agent run (internal/agent/agent_event_driven.go:77) and is
incremented once per LLM streaming iteration in startStreaming (internal/agent/agent_streaming.go:20).
A fresh EventDrivenAgent / AgentContext is built for every RunWithStream (i.e. every user
message), so Turns is 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:48 and :80, plus internal/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 alongside Turns at agent_streaming.go:21 - is already
maintained (it drives reminder cadence via injectDueReminders, 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 distinct session_turns field sourced
from sessionTurns) 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.
Summary
The
total_turnsfield in the agent completion logs always reads1in 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.turns, no tool calls).
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_turnsshould reflect the cumulative number of model turns in the session (e.g.2after 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:1for simple chat. The value only exceeds 1 within a single runthat 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 isincremented once per LLM streaming iteration in
startStreaming(internal/agent/agent_streaming.go:20).A fresh
EventDrivenAgent/AgentContextis built for everyRunWithStream(i.e. every usermessage), so
Turnsis per-request and resets each turn - as documented atinternal/agent/agent.go:41-47.total_turns:internal/agent/states/completing.go:48and:80, plusinternal/agent/agent_event_driven.go:257("agent reached Idle state - turn complete").
AgentServiceImpl.sessionTurns(
internal/agent/agent.go:48), incremented alongsideTurnsatagent_streaming.go:21- is alreadymaintained (it drives reminder cadence via
injectDueReminders,agent_utils.go:854) but is neversurfaced in these logs.
Proposed Fix
Either (observability-only, no behavioural change):
total_turns(or add a distinctsession_turnsfield sourcedfrom
sessionTurns) at the completion / reached-Idle log sites, and/orrun_turns/iterations) so itis not read as a session total.
Turn limiting is unaffected -
MaxTurnscontinues to gate the per-requestTurns.Environment
inference-gateway/cli,main. Surfaced while reviewing agent logs after #722 / #725 cleared unrelatedlog noise.