Feature: max_response_tokens parameter on Task tool for agent return size limits
Problem
There is no mechanism to deterministically cap the size of an agent's return message when using the Task tool. All output size control is soft guidance (agent prompts, SubagentStart hook injection) or observational (SubagentStop hooks that fire after the response is already in the caller's context window).
When an Explore agent is given a broad prompt like "inventory everything in this directory," it can return 20K+ characters (~2,700 words) in a single response, consuming a significant portion of the orchestrator's context window. SubagentStop hooks detect this but cannot truncate or replace the response — the blast has already happened.
Current Workarounds
- SubagentStart hooks inject guidance like "keep return under 1500 tokens" — agents may or may not comply
- SubagentStop hooks measure word count and flag violations — but the oversized response is already in context
- Trace Protocol (writing verbose output to disk, returning summaries) — works well when agents comply, but is not enforced
These are probabilistic compliance mechanisms, not deterministic enforcement.
Proposed Solution
Add an optional max_response_tokens parameter to the Task tool that hard-caps the agent's return message size at the platform level:
{
"subagent_type": "Explore",
"prompt": "Search for all hooks in the project",
"max_response_tokens": 1500
}
When the agent's response exceeds this limit, the platform would truncate it and append a system note like [Response truncated at 1500 tokens. Full response available via trace protocol.]
This would give hook authors and orchestrators deterministic control over context window consumption from subagent returns.
Alternatives Considered
- max_turns: Caps agent work capacity, not output size. An agent can accumulate large results in few turns.
- Soft guidance in prompts: Works most of the time but is not guaranteed. Different agent types (especially built-in ones like Explore) have varying compliance rates.
- SubagentStop truncation: Would require hooks to be able to modify/replace agent responses, which is not currently supported.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗