Skip to content

feat(engine): auto-parse script agent JSON stdout into output fields#122

Open
PolyphonyRequiem wants to merge 2 commits intomicrosoft:mainfrom
PolyphonyRequiem:feat/script-json-stdout
Open

feat(engine): auto-parse script agent JSON stdout into output fields#122
PolyphonyRequiem wants to merge 2 commits intomicrosoft:mainfrom
PolyphonyRequiem:feat/script-json-stdout

Conversation

@PolyphonyRequiem
Copy link
Copy Markdown
Member

Summary

When a script agent's stdout is valid JSON, the parsed fields are now merged into the output dict alongside stdout/stderr/exit_code. This makes parsed fields accessible in route conditions and downstream templates as output.field_name — matching LLM structured output behavior.

Motivation

Script agents are the deterministic workhorses of conductor workflows (P8). They emit structured data via JSON stdout, but currently that data is only accessible as a raw string (output.stdout). Routing on specific fields requires opaque exit codes instead of readable field-based conditions.

Before:

# Must use exit codes for routing
routes:
  - to: planner
    when: "exit_code == 20"  # What does 20 mean?

After:

# Route on parsed JSON fields directly
routes:
  - to: planner
    when: "route == 'planning'"  # Self-documenting

Changes

  • src/conductor/engine/workflow.py: After capturing script output, attempt json.loads(stdout). If it parses as a dict, merge fields into output_content (7 lines).
  • tests/test_engine/test_workflow.py: End-to-end test verifying JSON parsing, field access, and field-based routing.

Design decisions

  • Backward compatiblestdout, stderr, exit_code always present. Non-JSON stdout is unchanged. JSON arrays/scalars are ignored (only objects merged).
  • No schema changes — parsed fields are dynamic, not declared. This matches how script output is already untyped.
  • Merge semantics — parsed fields could theoretically shadow stdout/stderr/exit_code if a script outputs those as JSON keys. This is intentional: scripts that output {"exit_code": 42} probably want the JSON value to win over the raw field.

Testing

  • 75 workflow engine tests pass (including new JSON parsing test)
  • Test covers: field parsing, backward compat (stdout still present), field-based routing

When a script agent's stdout is valid JSON, the parsed fields are now
merged into the output dict alongside stdout/stderr/exit_code. This
makes parsed fields accessible in route conditions and downstream
templates as output.field_name.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@PolyphonyRequiem PolyphonyRequiem force-pushed the feat/script-json-stdout branch from daa7b50 to 8d72ee3 Compare April 25, 2026 03:13
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@dbcf20f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/conductor/engine/workflow.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #122   +/-   ##
=======================================
  Coverage        ?   84.90%           
=======================================
  Files           ?       53           
  Lines           ?     7174           
  Branches        ?        0           
=======================================
  Hits            ?     6091           
  Misses          ?     1083           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add debug-level logging when a script's parsed JSON output contains keys
that shadow the built-in stdout/stderr/exit_code fields. Makes the
intentional shadowing behavior observable for debugging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants