Truncates tool output to a 1 MiB limit, preserving image envelopes.
# Source: https://github.com/omnigent-ai/omnigent | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Canonical cap for a ``function_call_output``'s ``output``, applied by every
producer so a multi-MB tool result can't become one giant SSE frame."""
import json
from omnigent.runtime.mcp_tool_result import decode_mcp_image_result, encode_mcp_image_result
from omnigent.runtime.tool_result_replay import image_omitted_placeholder
from omnigent.util.json_types import JsonObject
# 1 MiB: bounds AP's streamed/persisted mirror; the model's own view stays full.
MAX_TOOL_OUTPUT_BYTES = 1024 * 1024
def cap_tool_output(output: str) -> str:
"""Cap *output* to ``MAX_TOOL_OUTPUT_BYTES`` U
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key