Skip to content

ToolOutputTrimmer summaries can exceed max_output_chars for string outputs #4622

Description

@CoffeeDrivenCoder

Describe the bug

ToolOutputTrimmer can emit a string summary longer than the configured max_output_chars budget. This happens when the existing rich summary is shorter than the original tool output but larger than the configured budget.

Repro steps

With openai-agents 0.22.0:

from types import SimpleNamespace
from agents.extensions import ToolOutputTrimmer
from agents.run_config import ModelInputData

items = [
    {"type": "function_call", "name": "search", "call_id": "call_1", "arguments": "{}"},
    {"type": "function_call_output", "call_id": "call_1", "output": "x" * 1000},
]
data = SimpleNamespace(
    model_data=ModelInputData(input=items, instructions=None),
)
result = ToolOutputTrimmer(max_output_chars=40)(data)
print(len(result.model_data.input[1]["output"]))

The emitted summary is longer than 40 characters.

Expected behavior

Every supported string function-call output replacement should respect max_output_chars. Existing summaries should remain unchanged when they already fit, and outputs should remain untrimmed when the rich summary would not be shorter than the original.

Debug information

  • Agents SDK version: 0.22.0
  • Python: 3.12.14
  • OS: Ubuntu 22.04
  • Reproducible: yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions