Skip to content

Make trajectory serialization JSON-safe#1

Open
yishangupenn wants to merge 3 commits into
mainfrom
upstream-pr-728
Open

Make trajectory serialization JSON-safe#1
yishangupenn wants to merge 3 commits into
mainfrom
upstream-pr-728

Conversation

@yishangupenn

@yishangupenn yishangupenn commented Mar 10, 2026

Copy link
Copy Markdown

Copied from upstream: SWE-agent/mini-swe-agent#728
Original author: @SailorJoe6
Originally opened: 2026-02-04


Fixes SWE-agent#727

Summary

When a tool‑calling model emits an invalid tool call, the resulting FormatError can include non‑JSON‑serializable data, which causes agent.save() to fail and prevents the trajectory file from being written. This PR makes the error payload JSON‑safe and hardens serialization so trajectories are always persisted.

Changes

  • Wrap FormatError in LitellmModel with a JSON‑safe debug payload that preserves raw assistant content/tool_calls and response metadata.
  • Add to_jsonable utility and use it in DefaultAgent.save() to guarantee JSON serialization of trajectories.

Why

Losing the trajectory on invalid tool calls breaks expected SWE‑bench behavior and makes debugging difficult. This ensures trajectories are written even on malformed tool calls.

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.

Invalid tool call FormatError sometimes breaks trajectory serialization

2 participants