Repository navigation
feat: milestone-gated multiturn tasks (hook trajectories, milestone-gates hook, user-sim presets) - #912
Merged
Conversation
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
changed the base branch from
kai/post-turn-hook-trajectories
to
main
November 24, 2026 15:16
This was referenced 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>
This was referenced Nov 24, 2026
…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
approved these changes
Nov 24, 2026
sarah-chitty-1
left a comment
Collaborator
There was a problem hiding this comment.
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>
Collaborator
Author
|
Good catch, thanks. Fixed in e5de591: the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_agentalready 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;Nonefor 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): turnn's trajectory as text (1 is the first turn), orNone; a turn that hasn't happened raisesIndexError.Two more small additions to post-turn hooks:
Turn.summarize(summary): a hook keeps one summary of the conversation atmetadata["post_turn_hook_summaries"][step_id][hook].check_params(params)in a hook's script, called when the step loads the hook, before the first message; aValueErrorfails 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_hooksentry; 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:
line, or asks the sim to wrap up after the last;max_nudgesturns: ablockingmilestone 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: falseswitches 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. Itscheck_paramsrefuses malformed gates, unknown keys and repeated ids at load.3. User-sim presets (was #901)
deploy_user_sim_agenttakes an optionalpreset:chatreplyanddone(nono_reply)always_onmilestoneA
chatormilestoneuser always answers: its answer format (the line in its prompt and reads, and the schema set on its agent) offers onlyreplyanddone, and ano_replyfrom it is a format error, asked again once. As a backstop, amilestoneuser that answersno_replyto 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 asuser_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
chatoralways_onbymulti_day, as before. Theuser_simsrecord carriespresetandfeatures, 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: amilestoneuser whoseprompt_agenthas nopost_turn_hooksor that noprompt_agenttalks to, analways_onstep playing achatormilestoneuser, andchatormilestonewithmulti_day: true.Tests
test_prompt_agent_post_turn_hooks.py: trajectory URLs and reads over three turns (one with no trajectory),summarize, andcheck_paramsfailing 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 asuser_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.computer_execandtest_mcp_cli_buildertests that fail on main.End to end
prompt_agenttask on a deployed Claude Code agent, with a hook that read each turn's trajectory back after every turn; a turn ahead was refused.enabled: falseit checked nothing. The summary was read back from the run.milestonepreset 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


Confidence 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.
Reviews (10) · Last reviewed commit: "docs(user sim): preset chat differs from..." · Reviewed by Greptile