Skip to content

fix(agent): send the json value returned by toModelOutput instead of the raw tool result - #173

Open
alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796054089-json-to-model-output
Open

alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796054089-json-to-model-output

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

computeToolOutputForModel only used a toModelOutput result when it had type: 'content'. Any other return, including { type: 'json', value }, fell through to JSON.stringify(result), so the raw execute result reached the model. A mapper written to hide fields had no effect. This matches the behavior the Python agent SDK already has for json.

Changes:

  • ToModelOutputResult adds { type: 'json'; value: unknown }.
  • computeToolOutputForModel: json returns JSON.stringify(value) ?? 'null'. Any other type throws instead of sending the raw result.
  • unsentModelOutput (approval resume, auto-approved calls in a paused batch, background runs settled into unsent results): when the mapped output is the serialized json string, it is parsed back so unsentResultsToAPIFormat serializes it once. Before, this path also returned the raw result for anything that was not a content array.

Tests

tests/unit/to-model-output-json.test.ts checks that the raw value never appears in any function_call_output and that the json value does, for:

  • direct tool round
  • background tool settled within graceMs
  • approved call on resume
  • sync and background calls auto-approved next to a call that needs approval
  • an unsupported mapper type (fails closed)

All 6 fail on main and pass with this change. pnpm run lint, pnpm run typecheck and pnpm run test pass.

Not covered

Background results delivered after graceMs as a tool_task_result envelope (flushAsyncToolDeliveries and the detached-run state write) embed task.result directly and never call toModelOutput for any type. That is a separate gap and is not changed here.

@devin-ai-integration

devin-ai-integration Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Contributor

This branch has not been deployed

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

Labels

None yet

1 participant