Pipe Mastra agent responses through jq to colorize reasoning and tool calls in the terminal
Mastra’s agent HTTP API returns a JSON structure with steps, each containing content items typed as reasoning, tool-call, tool-result, and text. The raw output is dense. Start by exploring it: # Hit the API and see raw structure http localhost:4111/api/agents/weather-agent/generate \ messages[0]="what's the weather in montreal?" | jq . # Get just the final answer http localhost:4111/api/agents/weather-agent/generate \ messages[0]="what's the weather in montreal?" | jq -r '.text' # Explore what's inside steps http localhost:4111/api/agents/weather-agent/generate \ messages[0]="what's the weather in montreal?" | jq '.steps[].content[] | .type' # "reasoning" # "tool-call" # "tool-result" # "text" # "reasoning" # "text" # See what fields each type has http localhost:4111/api/agents/weather-agent/generate \ messages[0]="what's the weather in montreal?" | jq '.steps[].content[] | select(.type == "tool-call")' Once the structure is clear, pipe through jq -r with inline ANSI escape sequences to colorize each piece: ...