Skip to content

feat(runtime): smarter handling of large tool outputs (opt-in middle-out truncation) #3436

Description

@aheritier

Summary

Add smarter truncation for oversized tool outputs. Today max_old_tool_call_tokens is opt-in and only replaces OLDER tool results wholesale with "[content truncated]"; there is no cap on a single large tool output at ingest and no middle-out truncation.

Proposed behavior

  • Add a per-result cap with middle-out truncation (keep head + tail, drop the middle) for oversized single tool outputs at ingest.
  • Decision: keep defaults OFF — ship this opt-in first. A non-zero default for max_old_tool_call_tokens is explicitly deferred (would be a behavior change for existing users).

Implementation notes (starting points)

  • pkg/session/session.go (truncateOldToolContent at ~1290-1293, 1536-1540; add an ingest-time cap)
  • Config key(s) in pkg/config/latest/types.go + agent-schema.json + example YAML
  • Must NOT weaken the kept-suffix turn-boundary logic (SplitIndexForKeep in pkg/compaction)

Complexity: M.

Background: shared plan context-management-gap-analysis (Phase 2, item 5).

Dependencies / Relationships

  • Independent — no dependencies on the other context-management issues.

Metadata

Metadata

Assignees

Labels

area/configFor configuration parsing, YAML, environment variablesarea/runtimeRuntime engine, agent loop execution, tool dispatch, loop detectionarea/sessionsFor features/issues/fixes related to session lifecycle (resume, persistence, export)kind/featPR adds a new feature (maps to feat:). Use on PRs only.

Fields

No fields configured for Enhancement.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions