Skip to content

feat: milestone-gated multiturn tasks (hook trajectories, milestone-gates hook, user-sim presets) - #912

Merged
kaihackney-scale merged 19 commits into
mainfrom
kai/milestone-gates-hook
Nov 25, 2026
Merged

kaihackney-scale merged 19 commits into
mainfrom
kai/milestone-gates-hook

Conversation

@kaihackney-scale

@kaihackney-scale kaihackney-scale commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces #852 and #901, which are closed in favour of this one. Three parts, in the order they build on each other.

Why

A multiturn task is a chain of milestones: the user asks for one thing, checks it, presses on what isn't done, and only then asks for the next. A user sim that judges "done" from the agent's reply alone moves on too early or too late. Here a post-turn hook checks each milestone's gates against the env and the agent's own work after every agent turn and tells the user sim what it found, and the user sim has a preset that knows how to take those notes.

1. Post-turn hooks can read the agent's per-turn trajectories (was #852)

A hook could read the envs and the agent's reply, but not its tool calls and their results. prompt_agent already stores each turn's native trajectory before the hooks run; this hands them to the hook:

  • turn.trajectory_urls: one entry per turn so far, oldest first; None for a turn with no trajectory or one that couldn't be fetched; empty when the agent's card offers none.
  • await turn.read_trajectory(n): turn n's trajectory as text (1 is the first turn), or None; a turn that hasn't happened raises IndexError.

Two more small additions to post-turn hooks:

  • Turn.summarize(summary): a hook keeps one summary of the conversation at metadata["post_turn_hook_summaries"][step_id][hook].
  • an optional check_params(params) in a hook's script, called when the step loads the hook, before the first message; a ValueError fails the step there.

2. The milestone-gates hook (src/agent_env/examples/milestone-gates/)

The hook, its README, a small runnable example task on a local env, and the bundle registration. A task opts in with one post_turn_hooks entry; the conversation loop doesn't change.

After each agent turn it runs the open milestone's gates (code checks over an artifact's text, reads of the env's tools as a privileged role, a judge over an artifact, or a judge over the agent's trajectory), then, in a note only the user sim sees:

  • all gates pass: the milestone is done and the note opens the next one with its line, or asks the sim to wrap up after the last;
  • a gate fails: the note carries that gate's nudge, written by the task author and vague on purpose (where to look, never the value);
  • still failing after the milestone's max_nudges turns: a blocking milestone ends the conversation (gate_never_passed:<id>); any other is let go and the next one opens.

After the wrap-up is answered, the last milestone is checked once more, so the summary matches what the agent left; if any milestone was let go, the wrap-up note says to wrap up without claiming everything is done. Later milestones the agent already did are skipped, a sim that moves on by itself is followed, and enabled: false switches it off. Its summary gives each milestone's status (passed, gave_up, derailed, skipped, ...), the turns it opened and closed on, nudges used, and each gate's last verdict and type. Its check_params refuses malformed gates, unknown keys and repeated ids at load.

3. User-sim presets (was #901)

deploy_user_sim_agent takes an optional preset:

Preset Prompt
chat today's single-session prompt, except the answer format offers only reply and done (no no_reply)
always_on today's multi-day prompt, byte for byte
milestone adds how the user takes a post-turn hook's note: trust it over the reply, always reply while it says something isn't done, press on what it raises in their own words and never more specifically (no name or figure it doesn't give, the assistant's own included), move on and send the line it gives only when it says so, answer done only after it says everything is done

A chat or milestone user always answers: its answer format (the line in its prompt and reads, and the schema set on its agent) offers only reply and done, and a no_reply from it is a format error, asked again once. As a backstop, a milestone user that answers no_reply to a turn that carried a hook's note is asked again in the same session, up to twice, reusing the user-sim gate's rewrite path; one that still won't reply ends the run as user_sim_error, so verifiers skip it and it is redone. In live runs the prompt alone didn't hold.

Without a preset the sim is chat or always_on by multi_day, as before. The user_sims record carries preset and features, the parts of the prompt and run a judge's rules may depend on (told_lines, should_know_lines, permission_rules, when_done, phone, milestones, hook_notes), so a judge can read them from the record. Refused at load: a milestone user whose prompt_agent has no post_turn_hooks or that no prompt_agent talks to, an always_on step playing a chat or milestone user, and chat or milestone with multi_day: true.

Tests

  • test_prompt_agent_post_turn_hooks.py: trajectory URLs and reads over three turns (one with no trajectory), summarize, and check_params failing the step before the agent is prompted.
  • test_milestone_gates_hook.py (48): the state machine, each gate kind, nudges and give-up, skip-if-done, following the sim, the trajectory judge's rendering, the switch, the summary, and the load-time checks.
  • test_prompt_agent_built_in_user_sim.py: a milestone user's no_reply to a note is asked again and its reply goes on; one that keeps refusing ends the run as user_sim_error; without the preset a no_reply still ends the run.
  • test_user_sim_presets.py (14): chat and always_on prompts byte for byte (the always_on prompt's sha256 is the pinned one), the milestone prompt's lines, the prompt rebuilt from the record, features, and the load-time refusals.
  • task_step, task and agents unit suites: 6221 passed; the 6 failures are the computer_exec and test_mcp_cli_builder tests that fail on main.

End to end

  • Trajectories: a two-turn prompt_agent task on a deployed Claude Code agent, with a hook that read each turn's trajectory back after every turn; a turn ahead was refused.
  • The example task, run locally (desk env, Claude Code solver, built-in user sim): M1's gates passed on turn 1, the note opened M2, the sim sent its line, M2 passed on turn 2, the sim wrapped up and the hook ended the conversation; with enabled: false it checked nothing. The summary was read back from the run.
  • A three-milestone task with nine trajectory-judge gates, run end to end twice: each gate's last verdict matched the task's own final rubric on the same run, 9/9 both times. Without a preset the user sim answered done on a failing milestone; with the first milestone preset it answered no reply on one. A third run with the tightened prompt: gates 9/9 again, no early done and no leaked names, but the sim still answered no reply once on a failing milestone, which is why the guard above is in code. A fourth run with the guard ran to the end; it found the agent changing its work after the hook's last check and a wrap-up note that overclaimed after a give-up, both now fixed.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The latest documentation-only changes appear safe to merge.

Summary

This PR adds milestone gates, hook access to per-turn trajectories, and user-sim presets.

  • Post-turn hooks can read the agent’s work from each turn.
  • Milestone gates check each task step and guide the next reply.
  • User-sim presets shape how chat and milestone conversations respond.

Reviews (10) · Last reviewed commit: "docs(user sim): preset chat differs from..." · Reviewed by Greptile

kaihackney-scale and others added 11 commits November 20, 2026 16:50
A post-turn hook could read the envs and the agent's reply, but not what the agent did to get there: the tool calls
and their results. prompt_agent already stores each turn's native trajectory before the hooks run. Turn now carries
trajectory_urls, one per turn so far (None for a turn without one, empty when the agent's card offers none), and
read_trajectory(n) returns turn n's as text. A hook can then check a milestone against the work itself, as a
trajectory-reading verifier does, without its own copy of the env state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…offers no trajectories

With no trajectories, trajectory_urls is empty, so reading a turn that happened raised IndexError instead of
returning None. The turn number is now checked against the conversation's turn, and a turn with no entry is None.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both sides extend the hook Turn: keeps read_trajectory and main's ask_user(note),
and run_post_turn_hooks takes both note-capable ask_user and trajectory_urls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… milestones while the conversation runs

After each agent turn the hook runs the open milestone's gates (code over an
artifact's text, a read tool's state, or one judge call over the artifact or
the agent's trajectory) and tells the user sim what it found in a note only
it sees: the next milestone's line when every gate passes, a vague
author-written nudge when one fails. A blocking milestone that never passes
ends the conversation. Ships with a small desk env and an example task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… model

The built-in user sim runs on the Claude Code harness, which calls the Messages API; the model proxy no longer
translates it for non-Claude models, so a gpt-4o-mini sim failed on its first turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gates run only when a prompt_agent step lists the hook. "enabled": false keeps the milestones in the task but
switches the gates off: the hook checks its params, runs no gate, sends the user sim no note and records `disabled`
once, so the same task runs with and without gates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…milestone-gates sets one per milestone

Turn.summarize(obj) keeps one object per hook per step at metadata["post_turn_hook_summaries"][step_id][hook],
replacing the last, so a verifier or the hub can read where a hook says the conversation got to without parsing its
records. The milestone-gates hook sets it every turn: each milestone's status (passed, skipped, gave_up, passed_over,
derailed, open, not_reached), the turns it opened and closed, nudges spent and each gate's last verdict and type,
then the furthest milestone reached, how many were done and the end reason. A blocking milestone that never passes
now names its end reason in its record too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…estone-gates checks every gate's shape

A hook's script may define `def check_params(params)`, which the step calls when it loads the hook, before the
first message; a ValueError fails the step there. milestone-gates uses it, and now also refuses unknown gate keys,
a check that isn't exactly one kind or lacks what its kind needs, a gate type outside format/action/content, and
repeated gate or milestone ids. Before, a malformed check failed as a gate on every turn and nudged the agent about
nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ilestone)

deploy_user_sim_agent takes an optional preset naming the kind of run the user is in. chat and always_on keep
today's prompts byte for byte; milestone adds how the user takes a post-turn hook's note (trust it over the reply,
press on what it raises never more specifically, move on and send the next line only when it says so, done only
after everything is done). The step records the preset and features: the parts of the prompt and run a judge's
rules may depend on, from the persona's sections, its permissions and the preset. A preset that doesn't fit the
task's other steps is refused when the task loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A trajectory judge can check an action or a format criterion; the summary called every judged gate content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…thing isn't done

In a live run the user sim answered no_reply while the hook's note still said the milestone failed, which ended the
conversation, and once named an item from the assistant's own reply as what to add. The milestone preset now says to
always reply while a note says something isn't done, and to give no name or figure the note doesn't, the assistant's
own included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaihackney-scale
kaihackney-scale requested a review from a team as a code owner November 24, 2026 15:05
@kaihackney-scale
kaihackney-scale changed the base branch from kai/post-turn-hook-trajectories to main November 24, 2026 15:16
@kaihackney-scale kaihackney-scale changed the title feat(examples): milestone-gates, a post-turn hook that runs a multiturn task as checked milestones feat: milestone-gated multiturn tasks (hook trajectories, milestone-gates hook, user-sim presets) Nov 24, 2026
…asked again, then fails the run

In three live runs the milestone user sim stopped on a failing milestone, by done or no_reply, despite its prompt; the
prompt alone doesn't hold. Now prompt_agent asks a milestone user who answers no_reply to a turn that carried a hook's
note again in the same session, up to NOTE_REPLY_TRIES (2) times, reusing the user-sim gate's rewrite path. One that
still won't reply ends the run as a user-sim error, so verifiers skip it and it is redone, instead of the agent being
graded on a conversation the user abandoned mid-milestone. The sim's person now carries its preset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd the milestone user guard

milestone-gates:
- no_new baselines are kept per gate, so two gates watching different tools don't share one count; a baseline read
  that fails leaves only its gate unknown instead of failing the step.
- an artifact read that returns a tool error is an error, not the artifact's text.
- a milestone whose gates pass on the final turn is passed in the summary.
- writes are rendered in full, as documented; trajectory_max_chars bounds the whole log.
- a step turn whose trajectory isn't in a format the hook reads makes trajectory gates unknown, not judged on nothing.
- the sim's own fields are read from this step only (Turn.step_id), since turn numbers restart per step.
- load-time checks refuse wrong value types (max_paragraphs "2", contains_all as text, count bounds, baseline_count).
- an artifact may take one field of the found item (field), and the example's draft gate counts the body's
  paragraphs rather than the item's JSON.

prompt_agent:
- in a run that prescribes atif/1, post-turn hooks get each turn's native trajectory during the conversation; the
  step's record keeps the run's copies.
- a milestone user's gate rewrite that comes back as no_reply goes through the same keep-replying guard.

The installer journey counts the new example bundle (11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kaihackney-scale and others added 2 commits November 24, 2026 13:19
…ap-up, and a wrap-up after a give-up says so

In a live run the agent sent a second reply while answering the wrap-up, after the hook's last check, so the hook's
verdicts disagreed with the task's final rubric; and the wrap-up after letting the last milestone go said
"everything you asked for is done", which the user sim took as leave to approve the agent's next send. Now the turn
after the wrap-up re-checks the last milestone (its baselines and step turns carried over) and the summary records
it, passing a milestone that ended up done; and when any milestone was let go the wrap-up note (final_note_gave_up)
asks the user to wrap up without saying it's all done or taking on anything new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n their answer format

The built-in user sim's answer line ({"outcome": "reply" | "no_reply" | "done", ...}), shown in its system prompt and
at the end of every read, and the schema set on its agent now follow its preset. A chat or milestone user is offered
only reply and done, its reads close with "reply, or say you're done", and a no_reply or empty reply from it is a format
error, asked again once in the same session. Without a preset, and for always_on, nothing changes. The milestone
guard stays as the backstop for a sim that still won't reply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nal check reads the right milestone and can undo one

- milestone-gates: a tool or state gate that couldn't be checked (a no_new gate with no baseline) holds its milestone
  instead of letting it pass; a judge that can't answer still doesn't. A no_new gate keeps an addition one call found
  even when another call has no baseline.
- the final check after the wrap-up reads the last milestone skipped as done, not the one before it, and a milestone
  it finds broken is "undone" in the summary and no longer counted done.
- a chat or milestone user's gate rewrite is held to the same outcomes as its answers: a no_reply is asked again once
  in the answer's format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@sarah-chitty-1 sarah-chitty-1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "always answers" change looks good, including the extra retry on rewrites for every user sim. One thing: the description and user_sim.md table still say chat is "today's single-session prompt, byte for byte," but preset: chat now drops no_reply, so it differs from a task with no preset. Can you update both to say so? Otherwise good to merge from my side.

The user_sim.md preset table said preset chat changes nothing, but a chat user
always answers: its answer line, each read and its agent's schema offer only
reply and done. The table row and the preset tests' docstring now say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaihackney-scale

Copy link
Copy Markdown
Collaborator Author

Good catch, thanks. Fixed in e5de591: the user_sim.md table and the description now say preset: chat differs from a task with no preset only in its answer format (reply or done, no no_reply).

@kaihackney-scale
kaihackney-scale merged commit f647c13 into main Nov 25, 2026
56 checks passed
@kaihackney-scale
kaihackney-scale deleted the kai/milestone-gates-hook branch November 25, 2026 00:05
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.

2 participants