Skip to content

bt trace import claude loses the result of workflow agents that return structured output #316

In progress

Description

Problem

A workflow agent() call with a schema returns its result as the input of a final
StructuredOutput tool call. The import sets the agent's span output from its last
assistant text instead. That's empty or a stale line from earlier in its work, so the
result is lost.

Impact

On one engineer's machine, 27 of 29 workflow agents end with StructuredOutput: 7 have no
output in their span, and 20 show a stale line. The trace shows the workflow's agents but
not what they returned.

Steps to reproduce

In a git repository with src/a.txt, src/b.txt and src/c.txt (Claude Code 2.1.311):

claude -p --model haiku --allowedTools "Workflow Glob Read Agent" --output-format json "ultracode: use a workflow with two parallel agents. Give each agent() call a schema option so it returns structured output: the first lists the files in src/ with Glob and returns {files: string[]}, the second reads src/b.txt and returns {contents: string}. Report what each returned."
bt trace import claude <session-id>
  • On disk: the two agents' transcripts under subagents/workflows/wf_…/ end with
    StructuredOutput {"files": ["src/a.txt", "src/b.txt", "src/c.txt"]} and
    StructuredOutput {"contents": "file b\n"}, with no text after them.
  • Today: both subagent: workflow-subagent spans have output: null.
  • Expected: each span's output is its structured result.

We ran it with bt 0.33.0 into a Braintrust project, and read the stored trace back with
bt sql. A debug build of bt-daemon at dc5f7ea gives the same result.

Root cause

A sub-agent's output comes from last_assistant_text, or from
successful_subagent_handback_message, which only reads SubagentHandback calls
(transcript_import/claude.rs:639-641,
:695,
translate/claude.rs:1625-1633).
Nothing reads StructuredOutput.

Possible fixes

  • Treat a successful final StructuredOutput like SubagentHandback. Its input
    becomes the agent's output. That extends the hand-back lookup that already exists.
  • Prefer the agent's result from the workflow's own record, if the run's summary holds
    each agent's return value. We haven't checked whether it does.

Related

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

Metadata

Metadata

Labels

bugclaude-code

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions