Skip to content

Agent swaps and forks

These commands fork a finished run into a new one, replaying its remaining rounds under a controlled change: a different agent in one seat, an agent imported from another run, or the same team under different knobs. One more flow starts a new run in which chosen agents begin with histories from an earlier run. The earlier run can be a run of another scenario.

Every fork cuts at the end of a round: --after-round N keeps rounds 1..N complete, verdict and postmortem included, and the new run plays round N+1 onward.

Command What it does
replace-agent Fork after round N with one agent restarted on a fresh history
cross-run-replace-agent Same, but the seat is filled by an agent carrying its full history from a different run
fork-at-round Fork after round N with no agent replaced, under merged knob overrides
scheduled_events Swap agents at round boundaries inside one live run
run --history-from-run Start a new run in which chosen agents begin with histories from an earlier run, which can be of another scenario

replace-agent, cross-run-replace-agent, fork-at-round and scheduled_events keep every non-replaced agent on its exact original model and full reconstructed history. To carry on inside an existing run instead of forking it into a new one, see Continuing a run.

Each command prepares the new run directory, prints new_run_id= and new_run_dir=, and spawns a detached simulation. Watch <new_run_dir>/<scenario>_stdout.log for progress. From a checkout, spell each command VIRTUAL_ENV= uv run --no-sync python -m glossogen ....

For the mechanics behind all of this (how a run is cloned, how a history is rebuilt, how the boundary round is ordered), see Architecture: replace-agent, cross-run, fork-at-round, in-run swaps.

Replace an agent at a round boundary

Keeps rounds 1..N as the source played them and puts a new agent in one seat for round N+1 onward, while everyone else continues from where they were. The question it answers: could a newcomer pick up the protocol the others built?

Replacing an agent at a round boundary

glossogen replace-agent veyru \
  --source-run-dir ./runs/veyru/<timestamp> \
  --after-round 4 \
  --replaced-agent-id field_observer \
  --model claude-sonnet-4-6 --provider anthropic \
  --runs-dir ./runs \
  [--rounds-after K] \
  [--visible-history-channel CHANNEL ...] \
  [--history-from-round R] \
  [--knobs <preset-name|path>]
  • --after-round must be ≥ 1.
  • --rounds-after defaults to the source rounds past the boundary (source_round_count - after_round). The new run's round_count becomes after_round + rounds_after. A round_count carried by --knobs (every shipped preset has one) sets the total when the flag is omitted, and must agree with it when both are given, so a whole preset alongside --rounds-after errors unless the numbers line up. Leave round_count out of override files. The same rule holds on cross-run-replace-agent and fork-at-round.
  • --model / --provider set the replacement agent only.
  • --knobs names a preset the scenario ships, or a path to a JSON file of your own, merged onto the source's recorded scenario_config before validation. It resolves exactly as --config does on run, and is optional: no overrides is a resumed run's normal state. A whole preset passed here replaces every field it declares, so an override file naming only what changes is usually what you want.

The replaced agent's own event log is preserved on disk. What it sees is reconstructed without text and thinking parts, and without tool calls on channels the scenario blocks (veyru's postmortem, for instance). Every other tool call its predecessor made stays, result included. In a scenario without channels, such as signal_game, that is the predecessor's whole record of moves and boards; --history-from-round windows it (see Channel history visibility).

Passing postmortem_disabled_at_start: true here drops the postmortem channel for the rest of the resumed run: no postmortem injections, no postmortem phase, sends rejected.

A replace-agent run can be forked again only by replacing the same agent. Its log holds the predecessor's unfiltered turns, and the filters that hid them live in its replace_manifest.json, which a fork does not inherit.

Import an agent from another run

Fills the seat with an agent from a different completed run, carrying its full history (text, thinking, tool calls) from that run. Same scenario and same agent_id only. The question it answers: how does an agent that learned one protocol behave when dropped into a team that learned another?

Importing an agent from another run

glossogen cross-run-replace-agent veyru \
  --source-a-run-dir ./runs/veyru/<sim_a_timestamp> \
  --source-b-run-dir ./runs/veyru/<sim_b_timestamp> \
  --replaced-agent-id field_observer \
  --after-round 14 \
  --runs-dir ./runs \
  [--source-b-round-end N] \
  [--model M --provider P] \
  [--rounds-after K] \
  [--visible-history-channel CHANNEL ...] \
  [--knobs <preset-name|path>]

Sim A is the timeline that continues. Sim B is where the imported agent comes from.

  • --source-b-round-end defaults to min(after_round, B_max_round), the largest slice of B that is temporally aligned with A's swap point without exceeding what B actually played.
  • --model / --provider default to whatever the imported agent ran under in Sim B. Pass both together to override, which is how you test a different model in the same seat.
  • The imported agent runs with Sim A's agent_model_settings, not the ones Sim B recorded for it, unless --knobs names model_settings in its model_overrides entry. When the two runs differ (a thinking level, say), the imported agent changes settings at the swap; pass Sim B's settings in that entry to keep them. The entry names the same model and provider the imported agent runs under, and a model_overrides in --knobs replaces Sim A's recorded map whole, so list every other seat whose own settings the run should keep.

A cross-run run cannot itself be forked again: its log holds the replaced-away agent's turns before the import boundary, so a fork would seed the seat with the wrong agent.

Set postmortem_disabled_at_start for cross-team runs. This flow does not set it. Without it the agents have a backchannel that re-aligns their protocols within a round or two, which washes out the effect you are trying to measure.

Label cross-run runs cross_team plus the range of rounds played after the swap, such as 15-25, as soon as the run directory exists. Analysis groups them by those labels to compare round_success_after_resume per imported model and boundary round against both sources over the same rounds.

Start a run with agents from another run

glossogen run --history-from-run gives chosen agents of a new run a copy of the history that an agent built in an earlier run. This section uses these terms:

  • The source run is the earlier run whose agent's history is copied. It can be a run of another scenario. In the fork sections of this page, "the source" means something else: the run that a fork copies.
  • The source agent is the agent of the source run whose history is copied.
  • A transferred seat is an agent of the new run that begins with that copy. A transferred seat and its source agent can have different agent ids, whether or not the two runs share a scenario.
  • The opening message is a user message that tells a transferred seat about the new run.
  • The transferred history is what a transferred seat begins with: the source agent's history, followed by the opening message.
  • A history-transfer run is a run with at least one transferred seat.

Use a history-transfer run to test whether an agent reuses, extends or drops a protocol that it built in another scenario.

The flow is a set of flags on glossogen run. The other run flags and the key=value overrides work as in any run. The one exception is --resume: glossogen run refuses --resume together with --history-from-run, because --history-from-run starts a new run. To continue a crashed history-transfer run, pass --resume without the --history-* flags, as the list of files below describes.

glossogen run spot_the_difference \
  --model gpt-6.1-sol --provider openai \
  --runs-dir ./runs --config knobs_single_team \
  --history-from-run ./runs/veyru/<timestamp> \
  --history-seat viewer_left=field_observer \
  --history-seat viewer_right=stabilization_engineer \
  [--history-through-round N]
  • --history-from-run names the source run's directory. The command takes the source run's scenario from the name of the directory that holds the source run's directory, because glossogen run stores each run at <runs-dir>/<scenario>/<timestamp>. If the source run was moved out of that layout, the command fails with "source run log not found".
  • --history-seat SEAT=SOURCE_AGENT makes the agent SEAT a transferred seat with the history of SOURCE_AGENT. Repeat the flag for each transferred seat, and name at least one. An agent that no flag names starts with an empty history, as in any run. The command refuses a source agent that has no model response in the rounds that the history keeps.
  • --history-through-round N keeps rounds 1 to N of the source run. The source run must have completed round N, by the same check that fork-at-round applies to its boundary. Without the flag, N is the source run's last round, and the source run must have ended with scenario_complete. A run that was killed, that failed, or that is still running has not completed its last round.

The history ends where round N + 1 started. A tool call that the source agent made in round N and whose result came back after that point is left out with its result, because that result belongs to round N + 1. When N is the source run's last round, the history runs to the end of the source log.

On a transferred seat's first turn, the runner sends the seat's model its transferred history:

  1. The source agent's history up to the end of round N. It holds the source scenario's system prompt for that agent, the agent's text and thinking, and its tool calls with their results.
  2. The opening message. It starts with "The session above has ended. A new session starts now. Its instructions follow, and they replace the earlier ones." It then gives the new scenario's system prompt and initial prompt for that seat. Its template is history_transfer_prompt.jinja, beside the platform's other prompt templates in scenario_contract/runner_prompts/.

The system prompt of every request stays the source scenario's system prompt. pydantic-ai adds an agent's system prompt only when the history is empty, so the new scenario's system prompt reaches the model only inside the opening message.

When the source run is of another scenario, some tool calls in the history name the source scenario's own tools, which the new run does not offer. Calls to the platform's communication tools, such as send_message and read_channel, name tools that the new run also offers, unless the new scenario hides those tools. A provider's API could refuse a history with calls to tools that the request does not offer. Self-hosted models have not been tried with such a history.

A transferred seat uses the model that the new run's config sets for it, which can differ from the source agent's model. When the model or the provider differs, the transferred history leaves out the source agent's thinking, because a provider takes back only the thinking that its own model wrote. The text and the tool calls stay.

The transferred history counts toward the seat's context window on every request. A scenario that limits the tokens its agents read also counts it.

A history-transfer run directory holds these files besides those of any run. In the file names, <agent_id> is the transferred seat's agent id.

  • history_transfer_manifest.json names the source run and the value of N. For each transferred seat, it names the source agent and the model and provider that the source agent ran on.
  • transferred_history_<agent_id>.json holds the seat's transferred history in pydantic-ai's JSON message format. To continue a crashed history-transfer run, run glossogen run with --resume <run dir> and without the --history-* flags. --resume reads this file and appends the seat's own turns from the new run's log. It reads nothing from the source run, so the source run can be moved or deleted after the launch.
  • resume_context_<agent_id>.json holds the history that the seat started with at the latest launch, in the shorter form that Verifying the reconstructed history describes, for reading by eye. After the first launch, it holds the transferred history. After a --resume, it holds the transferred history and the seat's turns up to the crash.

The protocol_probe and protocol_explanation metrics put a seat's transferred history in front of its turns in the run, as --resume does. The ATIF export and the thread export do not: they show only the seat's turns in the new run. If an in-run swap gives a transferred seat to another agent, a --resume and the probes rebuild that seat without the transferred history, because the agent swapped in did not start with it.

Some commands refuse a history-transfer run or its agents:

  • replace-agent, fork-at-round and cross-run-replace-agent refuse a history-transfer run as the run to fork. They rebuild each agent from the log of the run to fork, and that log does not hold the transferred histories.
  • For the same reason, a transferred seat cannot be the source agent of a later history transfer. It also cannot be the imported agent of cross-run-replace-agent. In a history-transfer run, an agent that started with an empty history can be the source agent of a later history transfer, and it can be the imported agent of cross-run-replace-agent.
  • glossogen run refuses a source agent if an in-run swap (scheduled_events) replaced it before the end of round N. It also refuses a source agent if the source run was made by replace-agent or cross-run-replace-agent and that agent is the one which replace-agent or cross-run-replace-agent put in. In both cases, the source log holds the turns of two different agents under that agent id.

The runs index, the run page and the CSV export's lineage.* columns do not link the new run to its source run. Inside the new run's directory, only history_transfer_manifest.json names the source run.

Fork at a round (no replacement)

Forks after round N with no agent replaced. Every agent keeps its full history, and the fork differs from the source only through merged knob overrides. Useful for injecting scheduled_events after the fact, toggling the postmortem mid-experiment, or replaying the remaining rounds on a different configuration. --rounds-after sets how far the fork plays, past the source's own end included, and resolves against a round_count in --knobs as on replace-agent.

Forking a run at a round

glossogen fork-at-round veyru \
  --source-run-dir ./runs/veyru/<timestamp> \
  --after-round 15 \
  --runs-dir ./runs \
  [--knobs <preset-name|path>] \
  [--rounds-after K]

Every agent is pinned to whichever model it was running at the boundary.

Forking after the final round. A completed run can be forked past its own end: --after-round <final round> with an explicit --rounds-after plays rounds the source never did. No default exists there, because the default replays the source's remaining rounds and a final-round fork has none. The resumed clock records the advance into the new round as RoundAdvanced(trigger="fork_after_round"). The clone ends before the source told its agents the game was over, so every rebuilt agent remembers the final round and its verdict but not the ending, and keeps playing.

Inherited scheduled_events. The source's schedule carries over unless --knobs overrides it. Entries at at_round ≤ after_round never re-fire: the fork keeps those rounds as the source played them. An entry at after_round + 1 fires on resume, because the clone is captured before the source dispatched that boundary.

Knob-schema drift. If the scenario gained a required knob after the source ran, pass it via --knobs or validation rejects the merged config.

If a fork crashes. --resume on the fork's directory continues it from where it stopped, like any interrupted run. Only a fork that never played resumes at its boundary. A cross-run fork that crashed after playing past its boundary is the exception: its imported history cannot be rebuilt past the boundary, so re-create it.

In-run swaps

scheduled_events swaps agents at round boundaries inside a single live run, on one continuous timeline. Three swaps produce four phases (A → B → C → D).

In-run swaps on one timeline

{
  "scheduled_events": [
    { "type": "set_postmortem", "at_round": 16, "enabled": false },
    { "type": "swap_agent", "at_round": 16, "agent_id": "field_observer",
      "model": "claude-sonnet-4-6", "provider": "anthropic",
      "channel_visibility": { "link": { "kind": "full" } } },
    { "type": "swap_agent", "at_round": 31, "agent_id": "stabilization_engineer",
      "model": "claude-sonnet-4-6", "provider": "anthropic",
      "channel_visibility": { "link": { "kind": "from_round", "round_floor": 16 } } }
  ]
}

Each swap writes an AgentSwappedMidRun event and a resume_context_<agent_id>_round_<R>.json file holding the seed history the swapped-in agent received.

Fork a swapped source before its first swap fires. All three fork commands refuse a boundary behind an in-run swap that already fired. That swap's history filters and swapped-in model live only in its config and its AgentSwappedMidRun event, so a fork would rebuild the seat with its predecessor's full turns under the pre-swap model. Post-hoc swap studies inject new scheduled_events into a clean source instead. Replacing that same agent is the one fork allowed past the swap.

Channel history visibility

All the swap flows choose, per channel, how much of the predecessor's history the new agent can see. In scheduled_events this is the channel_visibility map, a per-channel discriminated union:

  • {"kind": "full"} — the whole prior history. The default for any channel not listed
  • {"kind": "none"} — the prior history is hidden. read_channel returns only messages sent after the swap, and the predecessor's sends and reads on the channel are dropped from the rebuilt history. The new agent stays a member and can still send
  • {"kind": "from_round", "round_floor": R} — windowed to round R onward. The predecessor's send_message calls are kept from round R, and all its read_channel calls are dropped, since their results would carry older messages

With flags, on the replace flows

On the two flows that replace an agent the choice is coarser. --visible-history-channel (repeatable) names the channels whose history stays visible. Omit the flag and the list is every channel the agent belongs to, less those the source's replace_agent_default_channel_visibility knob maps to false.

Leaving a channel out of that list does not hide it. Its join index is left as the resumed run set it, so read_channel there still returns the whole prior history, and the predecessor's tool calls on it stay in the rebuilt history. The only channels hidden on these flows are the ones the scenario blocks (get_replace_agent_blocked_tool_call_channels, its postmortem channels by default), which are treated as none, and on cross-run-replace-agent the imported agent's Sim B channels that Sim A does not have. The shipped presets map only postmortem channels to false, and those are blocked anyway.

On replace-agent, --history-from-round R then windows the replaced agent's history to round R onward: the channels in the list, and every other tool call its predecessor made (read_notifications, the scenario's own tools). A channel left out of the list is not windowed.

For the previous P rounds before the boundary, pass after_round - P + 1. Passing after_round + 1 keeps no prior history on the listed and blocked channels, which with the shipped presets' default list is every channel. In a scenario without channels that is the only way to give the seat nothing of its predecessor's. cross-run-replace-agent has no such flag: the imported agent brings its own history. fork-at-round replaces no agent, so neither flag applies.

On an in-run swap, a channel the scenario has globally disabled (the postmortem, after a set_postmortem event closes it) is forced to none regardless of what channel_visibility asks for.

Scoring a swap

round_success_after_resume re-scores the post-swap window and states the difference against a baseline: the source run over the same rounds for the CLI flows (Sim A for a cross-run run), the previous phase for an in-run swap. The summary gives the baseline's score and the difference as Δ vs source: ±N pp. It emits one measurement per swap, named round_success_after_resume_round_<R>_<agent_id> for in-run swaps.

glossogen evaluate veyru \
  --run-dir ./runs/veyru/<new_timestamp> \
  --metrics round_success,round_success_after_resume,protocol_learned_after_swap \
  --model claude-haiku-4-5-20251001 --provider anthropic

protocol_learned_after_swap asks the complementary question: is there observable evidence the newcomer picked up the protocol? See Evaluation.

Verifying the reconstructed history

Every resumed run writes resume_context_<agent_id>.json, the exact pydantic-ai messages handed to that agent on its first turn. Read it before trusting a result.

For a cross-run run in particular, the tail of the imported agent's file should match Sim B's last few messages for that role verbatim. That is what confirms the history came from B and was not contaminated by A.

Each thinking entry in that file shows the part's id, provider_name and whether a signature_recorded. Those are what the provider needs to take the part back as its own reasoning (OpenAI's reasoning item id and encrypted content, Anthropic's block signature), and the run records them per part on every llm_response_received event as thinking_parts.

A run that recorded its reasoning as text only, without thinking_parts, rebuilds into a history with no thinking at all. A fork of such a run differs from its source in what the model remembers of its own reasoning.