Problem
Current error responses are designed for human developers — Python tracebacks, natural language messages, unstructured strings. For agent personas (CLI+AI and MCP), these errors impose unnecessary thinking token costs. The agent must interpret the error, reason about what went wrong, and decide whether to retry, change approach, or give up. Every ambiguous error message converts directly to thinking tokens spent on interpretation rather than action.
Three token costs are at play for agents:
A well-structured error minimizes all three. A raw traceback maximizes thinking cost and often triggers unnecessary re-reads (input cost) and blind retries (output cost).
Proposal
Define a structured error format used consistently across CLI (`--format json`) and MCP tool responses:
```json { "error": true, "code": "validation_failed", "message": "Field 'status' is not a recognized top-level parameter", "detail": "For type 'backlog_item', 'status' should be passed in the metadata dict", "suggestion": "Retry with metadata={\"status\": \"proposed\"}", "retryable": true } ```
Key fields:
For CLI human-readable output, these render as a formatted error message. For `--format json` and MCP, they return as structured JSON.
Error categories to define
Impact
Reduces agent token costs on every failed interaction. The `suggestion` field alone can eliminate entire retry cycles — instead of the agent reasoning about what to try differently, Pyrite tells it directly. This is measurable: fewer thinking tokens, fewer round-trips, lower cost per agent session.
Also improves human CLI experience — structured errors with suggestions are better for everyone.