Skip to content

fix(agent): give to_model_output and next_turn_params parsed input, and map unsent results - #42

Merged
alexb-openrouter merged 2 commits into
mainfrom
devin/1796053817-to-model-output-parsed-input
Nov 30, 2026
Merged

alexb-openrouter merged 2 commits into
mainfrom
devin/1796053817-to-model-output-parsed-input

Conversation

@alexb-openrouter

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

Copy link
Copy Markdown
Contributor

Summary

Python port of upstream typescript-agent #155, plus the same fix for next_turn_params.

  • Parsed input. execute gets validate_schema(input_schema, call.arguments), but to_model_output (input) and next_turn_params callbacks got the raw call.arguments. A mapper or callback that relies on schema defaults or coercions ({"count": "3"} → {"count": 3, "mode": "safe"}) saw different values than execute. Both now get parsed_tool_input(tool, arguments): the same parse approval predicates already use (_parse_tool_arguments, Pydantic models dumped to dicts), falling back to the raw arguments if validation fails.
  • Unsent results. _execute_calls_to_unsent_results (calls auto-executed before an approval pause) stored the raw tool result, and unsent_results_to_api_format serialized it on resume without to_model_output. The model then got the full raw result, including fields the mapper drops. Results are now mapped before they are stored:
# before
create_unsent_result(call.id, call.name, raw_result)
# after
_, model_output = await self._model_output_value(call, tool, raw_result)  # content array or json value
create_unsent_result(call.id, call.name, model_output)

_tool_result_to_output now uses the same _model_output_value helper, so the main loop, the approved-call resume and the unsent path all map results the same way.

Overlap with #41

#41 (draft) changes which calls are added to executed_calls in model_result.py. This PR doesn't touch that list. It only changes the arguments execute_next_turn_params_functions passes to each callback, so the two PRs should merge cleanly in either order.

Tests

tests/unit/test_to_model_output_parity.py adds 3 tests. All 3 fail on main and pass with this change. The full unit suite passes (162), and ruff and mypy are clean.

@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
@alexb-openrouter
alexb-openrouter requested review from LukasParke and mattapperson and removed request for mattapperson November 30, 2026 16:59
@alexb-openrouter
alexb-openrouter marked this pull request as ready for review November 30, 2026 17:00
@alexb-openrouter
alexb-openrouter merged commit 1d309f1 into main Nov 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant