-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: add --output-format json flag to goose run command #5525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds JSON output format support to the Goose CLI, allowing users to receive structured JSON responses instead of text-based output. The feature is controlled via a new --output-format command-line argument that accepts either "text" (default) or "json" values.
Key changes:
- Added
output_formatfield to session configuration, builder, and CLI arguments - Introduced JSON data structures (
JsonOutput,JsonMessage,JsonToolCall,JsonToolResponse,JsonMetadata) for structured output - Modified message processing to capture and serialize messages, tool calls, and responses when JSON format is requested
- Suppressed text-based rendering when JSON output is active
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/goose-cli/src/session/mod.rs | Added JSON structs, output_format field to CliSession, and logic to collect/serialize session data as JSON |
| crates/goose-cli/src/session/builder.rs | Added output_format field to SessionBuilderConfig with default implementation, updated builder to pass format through |
| crates/goose-cli/src/cli.rs | Added --output-format CLI argument with default value "text" |
| crates/goose-cli/src/scenario_tests/scenario_runner.rs | Updated CliSession::new call to include default "text" output format |
| crates/goose-cli/src/commands/bench.rs | Updated SessionBuilderConfig to include default "text" output format |
Comments suppressed due to low confidence (1)
crates/goose-cli/src/session/mod.rs:1159
- Similar to Comment 6, this progress_bars.log call at line 1159 is not guarded by output_format check, potentially contaminating JSON output with text messages in non-JSON mode contexts.
progress_bars.log(&formatted_message);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
thanks for your contribution! please be sure to sign the DCO |
712537b to
1fad026
Compare
|
I've addressed all the Copilot AI suggestions from the recent code review. Happy to address any feedback. |
Thank you for reviewing and pointing this out. |
9abdac1 to
54f2414
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the idea and am surprised we don't support some form of this already. Left a question
crates/goose-cli/src/session/mod.rs
Outdated
|
|
||
| let json_output = JsonOutput { | ||
| messages: json_messages, | ||
| tool_calls: json_tool_calls, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you adhering to anything that has become a standard for representing agent exchanges in json form?
Given that goose models ToolRequest and ToolResponse as message content, I think it should reflect these in the list of messages, not as separate lists.
goose/crates/goose/src/conversation/message.rs
Lines 134 to 135 in 37e1bb1
| ToolRequest(ToolRequest), | |
| ToolResponse(ToolResponse), |
Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad.. I wasn't following any particular standard.. I'm a bit new to goose and rust. Seemed like a simple fix. I play around with json and flags stuff from time to time.. Anyway, I'll refactor this to serialize the the complete Message objects (including all MessageContent variants like ToolRequest/ToolResponse) directly in the messages array, rather than splitting them.
Just to clarify should the JSON output serialize the messages as-is using the existing serde derives on Message and MessageContent, or would you prefer a flattened/simplified format for the JSON output specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"serialize the messages as-is" is what I would do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Messages now should serialize as-is
Signed-off-by: sheikhlimon <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: sheikhlimon <[email protected]> Signed-off-by: Sheikh Limon <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: sheikhlimon <[email protected]> Signed-off-by: Sheikh Limon <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: sheikhlimon <[email protected]> Signed-off-by: Sheikh Limon <[email protected]>
- Cache output_format check in process_agent_response to avoid repeated string comparisons - Prevent empty messages from being included in JSON output - Prevent MCP notification output leakage in JSON mode - Add documentation for manual Default implementation in SessionBuilderConfig - Fix test to include missing output_format field Signed-off-by: sheikhlimon <[email protected]> Signed-off-by: Sheikh Limon <[email protected]>
f96fe46 to
d923b5c
Compare
|
Working nicely for me! |
|
Getting a clippy error in |
- Remove separate JsonMessage, JsonToolCall, and JsonToolResponse structs - Use Vec<Message> directly in JsonOutput to preserve MessageContent structure - Fix conflict markers left from rebase in scenario_runner.rs and builder.rs Signed-off-by: sheikhlimon <[email protected]>
cb211fd to
df3aae7
Compare
|
@sheikhlimon yeah those resolutions seem fine |
@alexhancock ok.. do i create an issue for this or are you aware already? this could be created by running |
|
@sheikhlimon we'll deal with the other computercontroller thing |
|
thanks! |
…est-and-fix * 'main' of github.com:block/goose: improve linux tray icon support (#5425) feat: log rotation (#5561) use app.isPackaged instead of checking for node env development (#5465) disable RPM build-ID generation to prevent package conflicts (#5563) Add Diagnostics Info to Q&A and Bug Report Templates (#5565) fix: improve server error messages to include HTTP status code (#5532) improvement: add useful error message when attempting to use unauthenticated cursor-agent (#5300) fix: unblock acp via databricks (#5562) feat: add --output-format json flag to goose run command (#5525)
* main: (85 commits) improve linux tray icon support (#5425) feat: log rotation (#5561) use app.isPackaged instead of checking for node env development (#5465) disable RPM build-ID generation to prevent package conflicts (#5563) Add Diagnostics Info to Q&A and Bug Report Templates (#5565) fix: improve server error messages to include HTTP status code (#5532) improvement: add useful error message when attempting to use unauthenticated cursor-agent (#5300) fix: unblock acp via databricks (#5562) feat: add --output-format json flag to goose run command (#5525) Sessions required (#5548) feat: add grouped extension loading notification (#5529) we should run this on main and also test open models at least via ope… (#5556) info: print location of sessions.db via goose info (#5557) chore: remove yarn usage from documentation (#5555) cli: adjust default theme to address #1905 (#5552) Manual compaction counting fix + cli cleanup (#5480) chore(deps): bump prismjs and react-syntax-highlighter in /ui/desktop (#5549) fix: remove qwen3-coder from provider/mcp smoke tests (#5551) fix: do not build unsigned desktop app bundles on every PR in ci. add manual option. (#5550) fix: update Husky prepare script to v9 format (#5522) ...
* main: (54 commits) add clippy warning for string_slice (#5422) improve linux tray icon support (#5425) feat: log rotation (#5561) use app.isPackaged instead of checking for node env development (#5465) disable RPM build-ID generation to prevent package conflicts (#5563) Add Diagnostics Info to Q&A and Bug Report Templates (#5565) fix: improve server error messages to include HTTP status code (#5532) improvement: add useful error message when attempting to use unauthenticated cursor-agent (#5300) fix: unblock acp via databricks (#5562) feat: add --output-format json flag to goose run command (#5525) Sessions required (#5548) feat: add grouped extension loading notification (#5529) we should run this on main and also test open models at least via ope… (#5556) info: print location of sessions.db via goose info (#5557) chore: remove yarn usage from documentation (#5555) cli: adjust default theme to address #1905 (#5552) Manual compaction counting fix + cli cleanup (#5480) chore(deps): bump prismjs and react-syntax-highlighter in /ui/desktop (#5549) fix: remove qwen3-coder from provider/mcp smoke tests (#5551) fix: do not build unsigned desktop app bundles on every PR in ci. add manual option. (#5550) ...
Signed-off-by: sheikhlimon <[email protected]> Signed-off-by: Sheikh Limon <[email protected]> Signed-off-by: fbalicchia <[email protected]>
Signed-off-by: sheikhlimon <[email protected]> Signed-off-by: Sheikh Limon <[email protected]> Signed-off-by: Blair Allan <[email protected]>
Summary
This pull request implements the requested
--output-format jsonflag for the goose run command, enabling structured JSON output for programmatic parsing. The feature allows users to parse tool calls and responses programmatically, similar to Claude Code's--output-format jsonfunctionality.Key changes:
--output-formatflag with default value "text" (preserving backward compatibility)Type of Change
Testing
goose run --text "..." --output-format jsonand confirming structured JSON outputgoose run --text "..." --output-format textand default behavior to ensure existing functionality preserved--helpoutput and accepts valid valuescargo buildandcargo checkThe changes have been manually validated to work as specified in the feature request while maintaining all existing functionality.
Related Issues
Relates to #4419