Skip to content

Prevent oversized connector results from entering LLM context#87

Open
arnaugrispg wants to merge 10 commits into
mainfrom
arnaugris/sc-15180/prevent-oversized-connector-results-from
Open

Prevent oversized connector results from entering LLM context#87
arnaugrispg wants to merge 10 commits into
mainfrom
arnaugris/sc-15180/prevent-oversized-connector-results-from

Conversation

@arnaugrispg

Copy link
Copy Markdown
Contributor

Rejects oversized Smart Agent and MCP tool results before they enter the LLM context.

Oversized results are replaced with bounded retry guidance, allowing the agent to retry with narrower filters, pagination, aggregation, or summaries. Each rejection also emits a visible Tool result rejected step with safe size metadata for traceability.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a safety budget for connector/tool outputs so oversized Smart Agent and MCP results are rejected before entering the LLM context, replacing them with bounded retry guidance and emitting traceable “Tool result rejected” steps.

Changes:

  • Introduces ResultPayloadBudget / OversizedResult and inspect_text_blocks() to detect oversized tool payloads and produce safe, non-sensitive retry guidance.
  • Adds configurable budget knobs (max_tool_result_bytes, max_tool_result_item_bytes) to ContextAgentConfig.
  • Integrates payload inspection + rejection steps into Smart Agent and MCP Agent execution paths, with new tests covering rejection/trace behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
hyperforge/tests/test_result_payload.py Unit tests for payload inspection and safe rendering behavior.
hyperforge/src/hyperforge/result_payload.py New budget/inspection utilities for rejecting oversized connector results.
hyperforge/src/hyperforge/context/config.py Adds config fields to control max tool-result byte budgets.
agents/smart/tests/test_result_payload.py Smart Agent tests for rejecting oversized Context/ToolError and recording safe steps.
agents/smart/src/hyperforge_smart/agent.py Integrates result inspection and replaces oversized outputs with retry guidance + trace steps.
agents/mcp/tests/test_result_payload.py MCP tests ensuring oversized content/structured/resources are rejected with safe history.
agents/mcp/src/hyperforge_mcp/agent.py Adds payload extraction + budget checks and records “Tool result rejected” steps on overflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hyperforge/src/hyperforge/result_payload.py Outdated
Comment thread agents/mcp/src/hyperforge_mcp/agent.py Outdated
arnaugrispg and others added 3 commits July 23, 2026 10:47
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@carlesonielfa carlesonielfa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment regarding where we store the limits

Comment thread hyperforge/src/hyperforge/context/config.py Outdated
Comment thread hyperforge/src/hyperforge/result_payload.py Outdated
Comment thread hyperforge/src/hyperforge/result_payload.py Outdated
@BillFarber

Copy link
Copy Markdown
Contributor

Will I be able to disable these limits in the MarkLogic MCP server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants