Skip to content

feat: make maxOldToolCallTokens configurable in agent YAML#2192

Open
gtardif wants to merge 1 commit intodocker:mainfrom
gtardif:configurable_max_tool_call_token
Open

feat: make maxOldToolCallTokens configurable in agent YAML#2192
gtardif wants to merge 1 commit intodocker:mainfrom
gtardif:configurable_max_tool_call_token

Conversation

@gtardif
Copy link
Contributor

@gtardif gtardif commented Mar 20, 2026

Add max_old_tool_call_tokens configuration option to control how much historical tool call content is retained in the context.

This allows to deactivate the old tool token truncation form the agent config file

Changes:

  • Add maxOldToolCallTokens field to AgentConfig (pkg/config/latest/types.go)
  • Update JSON schema with new max_old_tool_call_tokens property
  • Add maxOldToolCallTokens field and getter to Agent struct
  • Add maxOldToolCallTokens field to Session struct
  • Update GetMessages() to use configured value or fall back to DefaultMaxOldToolCallTokens (40000)
  • Propagate maxOldToolCallTokens through all session creation points:
    • A2A adapter
    • ACP agent
    • MCP server
    • Runtime agent delegation (transfer_task, sub-sessions)
    • HTTP/API server session manager

Configuration semantics:

  • Not set or 0: Use default (40000 tokens)
  • Positive value: Use that specific limit
  • -1: Unlimited (no truncation)

When max_old_tool_call_tokens is exceeded, older tool calls have their content replaced with "[content truncated]" to keep context size manageable. Tokens are approximated as string_length/4.

Assisted-By: docker-agent

@gtardif gtardif requested a review from a team as a code owner March 20, 2026 09:27
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟡 NEEDS ATTENTION

}
sess.MaxIterations = agent.MaxIterations()
sess.MaxConsecutiveToolCalls = agent.MaxConsecutiveToolCalls()
sess.MaxOldToolCallTokens = agent.MaxOldToolCallTokens()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Session-specific MaxOldToolCallTokens may be overwritten

The new line sess.MaxOldToolCallTokens = agent.MaxOldToolCallTokens() follows the same pattern as MaxIterations and MaxConsecutiveToolCalls on lines 349-350, which unconditionally overwrites session-specific values with agent configuration when runtimeForSession is called.

Impact: If a session is created with a specific MaxOldToolCallTokens value (via CreateSession at lines 77-80), that value will be lost when the session is loaded or when a runtime is created for it.

Note: This pattern was already established for MaxIterations and MaxConsecutiveToolCalls, so this PR is just maintaining consistency. However, if the intention is for session-specific overrides to persist across reloads, this behavior may be unexpected.

Recommendation: Consider whether session-specific settings should persist, or document that sessions always use current agent configuration.

@gtardif
Copy link
Contributor Author

gtardif commented Mar 20, 2026

Note: taken from #1831, credits to @krissetto (only the old tool truncation bit in this PR)
Leaving the default behaviour as it is for now, but allowing to deactivate truncation from the agent config

@gtardif gtardif force-pushed the configurable_max_tool_call_token branch from 3a3e75e to 6321959 Compare March 20, 2026 09:33
return []session.Opt{
session.WithMaxIterations(maxIterations),
session.WithMaxIterations(agt.MaxIterations()),
session.WithMaxConsecutiveToolCalls(agt.MaxConsecutiveToolCalls()),
Copy link
Contributor Author

@gtardif gtardif Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @derekmisler I noticed the WithMaxConsecutiveToolCalls was not propagated properly (had the same issue initially for WithMaxOldToolCallTokens, I added the propagation here. We didn't noticed because we only use the default value I suppose)

messages = truncateOldToolContent(messages, MaxToolCallTokens)
// Use configured max tokens or fall back to default constant.
// -1 means unlimited (no truncation).
// 0 or any positive value uses that as the limit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is a bit misleading regarding the value when max old.. is zero

Add max_tool_call_tokens configuration option to control how much
historical tool call content is retained in the context. This helps
manage context size in long-running sessions.

Changes:
- Add maxOldToolCallTokens field to AgentConfig (pkg/config/latest/types.go)
- Update JSON schema with new max_old_tool_call_tokens property
- Add maxOldToolCallTokens field and getter to Agent struct
- Add maxOldToolCallTokens field to Session struct
- Update GetMessages() to use configured value or fall back to
  DefaultMaxOldToolCallTokens (40000)
- Propagate maxOldToolCallTokens through all session creation points:
  - A2A adapter
  - ACP agent
  - MCP server
  - Runtime agent delegation (transfer_task, sub-sessions)
  - HTTP/API server session manager

Configuration semantics:
- Not set or 0: Use default (40000 tokens)
- Positive value: Use that specific limit
- -1: Unlimited (no truncation)

When max_old_tool_call_tokens is exceeded, older tool calls have their
content replaced with "[content truncated]" to keep context size
manageable. Tokens are approximated as string_length/4.

Assisted-By: docker-agent
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
@gtardif gtardif force-pushed the configurable_max_tool_call_token branch from 6321959 to 2025cf9 Compare March 20, 2026 10:15
@gtardif gtardif requested a review from rumpl March 20, 2026 10:27
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