[FEATURE] Output schema for subagent definitions (unknown key outputSchema is silently ignored)
Summary
Subagent definitions (plugin agents, .claude/agents/*.md, --agents) cannot declare an output schema, and an unknown key such as outputSchema is accepted silently and ignored. Workflow agent(prompt, {schema}) already enforces output natively through StructuredOutput, so the capability exists; it is just not reachable from an agent definition spawned with the Agent tool.
This re-raises #20625 (closed as stale, now locked), with a concrete repro and a use case.
Repro (Claude Code 2.1.289)
claude -p --agents '{"echoer":{"description":"test","prompt":"Reply with the word hello.","outputSchema":{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"],"additionalProperties":false}}}' \
"Use the echoer agent and show me exactly what it returned."
- Expected: the agent's result is validated against the schema (as in a workflow
agent(..., {schema})), or the CLI warns thatoutputSchemais not a supported key. - Actual: no warning; the agent returns
hello.
Use case
A subagent that fronts external work, for example dispatching a job to another tool and handing back a reference, must return an exact set of fields, never its own paraphrase. In our measurements, instruction-only compliance was 8 of 33 replies; the rest were prose, and some contained invented content.
Inside workflows the schema fixes this natively. For Agent-tool spawns the only way we found is a pair of hooks:
SubagentStopthat blocks until the final message equals the expected fields;PreToolUseonSubagentHandback, because in auto mode an agent ends with a handback and aSubagentStopblock after it has no effect.
With those hooks in place, compliance was 31 of 31. A native schema on the agent definition would make both hooks unnecessary.
Request
- Support an output schema in agent definitions (frontmatter,
--agentsJSON, plugin agents), enforced the same way as workflowagent(..., {schema}). - Warn on unknown keys in agent definitions instead of ignoring them silently.