Skip to content

feat(cli): add --output-format json flag for structured query output#2916

Open
xmxdeusltd wants to merge 1 commit intoNousResearch:mainfrom
xmxdeusltd:feat/output-format-json
Open

feat(cli): add --output-format json flag for structured query output#2916
xmxdeusltd wants to merge 1 commit intoNousResearch:mainfrom
xmxdeusltd:feat/output-format-json

Conversation

@xmxdeusltd
Copy link

What

Adds --output-format json flag to hermes chat -q for structured output.

Why

Enables programmatic orchestration of Hermes by external tools (Symphony, CI pipelines, MCP servers) that need structured agent output — token counts, cost, session ID, model info — in a machine-readable format.

Output schema aligns with Codex --json and Claude Code --output-format json conventions (type/subtype/is_error/result/session_id/usage/duration_ms/total_cost_usd).

How to test

hermes chat -q "What is 2+2?" --output-format json

Returns clean JSON:

{"type":"result","subtype":"success","is_error":false,"result":"4",
 "session_id":"...","model":"...","provider":"...","num_turns":1,
 "duration_ms":3509,"total_cost_usd":0.0,"usage":{...},"tool_call_count":0}

Text mode (default) is unchanged. --output-format json auto-enables quiet mode so stdout is clean JSON only.

Changes

  • hermes_cli/main.py: Add --output-format argument (choices: text/json, default: text) + pass through kwargs
  • cli.py: Add output_format parameter to main(), JSON implies quiet, suppress streaming UI during agent run, emit structured JSON result

Tested on

  • macOS 15, Python 3.11, Hermes v0.4.0
  • Verified: clean JSON output, text mode unchanged, valid JSON parses with python3 -m json.tool

Add --output-format flag to hermes chat with 'text' (default) and 'json'
options. When set to 'json', outputs a single JSON object with structured
metrics aligned with Codex/Claude Code output formats:

- type, subtype, is_error (status)
- result, session_id (response)
- model, provider (runtime info)
- num_turns, duration_ms, total_cost_usd (performance)
- usage.input_tokens, output_tokens, cache_read/creation, reasoning_tokens
- tool_call_count

JSON mode auto-enables quiet mode and suppresses streaming UI output
(response box, spinners) so stdout contains only valid JSON.

Enables programmatic orchestration of Hermes by external tools (e.g.
Symphony, CI/CD pipelines) that need structured agent output.
@xmxdeusltd
Copy link
Author

Aim was to create parity with codex app-server / claude cli json outputs. It's a mild addition and shouldn't interfere with anything else (unless you have bigger plans for this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant