Token-Efficient Response

Minimize response size while preserving essential information.

category: Tool Output
arcade.dev/patterns

Context

Any tool returning data to an agent.

Problem

Large responses consume context window tokens and degrade agent performance.

Solution

Optimize for token efficiency:
- Essential only: Remove unnecessary fields
- Concise values: Use codes not descriptions
- Truncate: Limit long text fields
- Count, don't list: "42 results" not all 42

Examples

Python
@tool
def list_emails(
    limit: int = 20,
    include_body: bool = False  # Body is expensive
) -> EmailList:
    """List emails. Bodies excluded by default for efficiency.
    
    To see full email content, call get_email(id) for specific emails.
    """
    emails = mail_api.list(limit=limit)
    return EmailList(
        count=len(emails),
        emails=[summarize_email(e, include_body) for e in emails]
    )

def summarize_email(e, include_body):
    return EmailSummary(
        id=e.id,
        subject=e.subject[:100],  # Truncate
        sender=e.sender_email,
        date=e.date.isoformat(),
        preview=e.body[:200] if include_body else None
    )

Considerations

  • Default to minimal response, allow expansion
  • Provide a way to get full details when needed
  • Log response sizes for monitoring

Related Patterns

More in Tool Output