context.eviction
Large tool output eviction.
Saves oversized tool results to files in the agent's workspace,
replacing them with a compact preview + file reference. The agent
can still access the full content via read_file.
ToolOutputEviction Objects
class ToolOutputEviction()
Evict oversized tool outputs to files.
Parameters
token_limit : int Tool outputs estimated to exceed this token count are evicted. eviction_dir : str Directory where evicted files are stored. preview_lines : int Number of lines to show in the preview (head + tail).
should_evict
def should_evict(content: str) -> bool
Check whether content should be evicted based on estimated tokens.
evict
def evict(tool_name: str, content: str) -> str
Save content to a file and return a compact preview.
Parameters
tool_name : str Name of the tool that produced the output. content : str The full tool output.
Returns
str A compact preview with a file reference.
process_tool_result
def process_tool_result(tool_name: str, result: Any) -> Any
Process a tool result — evict if too large, return as-is otherwise.