feat: make maxOldToolCallTokens configurable in agent YAML#2192
feat: make maxOldToolCallTokens configurable in agent YAML#2192gtardif wants to merge 1 commit intodocker:mainfrom
Conversation
| } | ||
| sess.MaxIterations = agent.MaxIterations() | ||
| sess.MaxConsecutiveToolCalls = agent.MaxConsecutiveToolCalls() | ||
| sess.MaxOldToolCallTokens = agent.MaxOldToolCallTokens() |
There was a problem hiding this comment.
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.
|
Note: taken from #1831, credits to @krissetto (only the old tool truncation bit in this PR) |
3a3e75e to
6321959
Compare
| return []session.Opt{ | ||
| session.WithMaxIterations(maxIterations), | ||
| session.WithMaxIterations(agt.MaxIterations()), | ||
| session.WithMaxConsecutiveToolCalls(agt.MaxConsecutiveToolCalls()), |
There was a problem hiding this comment.
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)
pkg/session/session.go
Outdated
| 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. |
There was a problem hiding this comment.
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>
6321959 to
2025cf9
Compare
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:
Configuration semantics:
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