Repository navigation
feat(post_turn_hooks): a hook can read the agent's per-turn trajectories - #852
Closed
kaihackney-scale wants to merge 3 commits into
Closed
kaihackney-scale wants to merge 3 commits into
kaihackney-scale wants to merge 3 commits into
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>
Collaborator
Author
|
Combined into #912, which carries this change together with the milestone-gates hook and the user-sim presets, so they're reviewed and merged as one. |
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.
What and why
A post-turn hook can read the envs and the agent's reply after each turn, but not what the agent did to get there:
its tool calls and their results. A hook that checks a milestone against the agent's work, the way a
trajectory-reading verifier grades it, needs that.
prompt_agentalready stores each turn's native trajectory before the hooks run. This hands those to the hook:turn.trajectory_urls: one entry per turn so far, oldest first;Nonefor a turn whose trajectory the agentreturned none of or that couldn't be fetched; empty when the agent's card offers no trajectories.
await turn.read_trajectory(n): turnn's trajectory as text (1 is the first turn), orNonewhen that turn hasnone. A turn that hasn't happened raises
IndexError.Hooks that don't use them are unaffected;
run_post_turn_hookstakestrajectory_urlsas an optional argument.How it was tested
test_prompt_agent_post_turn_hooks.py: over three turns, where the agent returns no trajectoryfor one of them, the hook sees one URL per turn so far,
Nonefor the missing turn, reads each stored trajectory'stext, and is refused a turn ahead; an agent whose card offers no trajectories hands the hook an empty tuple. The first
test fails without the one-line
prompt_agentchange.pytest tst/unit/task_step -k "prompt_agent or post_turn or hook or user_sim or always_on": 1120 passed.ruff checkon the changed files: passed.agent-env task runof a two-turnprompt_agenttask on a deployed claude-code agent, with ahook that records
trajectory_urlsand reads each trajectory back after every turn. After turn 1 it had one URL andread that turn's trajectory (with the agent's one tool call); after turn 2 it had two and read both; reading a turn
ahead was refused both times.
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues remain.Summary
Hooks can now read the agent’s stored trajectories after each turn.
Reviews (3) · Last reviewed commit: "Merge main into kai/post-turn-hook-traje..." · Reviewed by Greptile