Repository navigation
feat(simple_agent): continue an agent session across activations - #5465
Conversation
|
/ok to test be98a71 |
be98a71 to
371e2bd
Compare
|
/ok to test 371e2bd |
|
/ok to test c725911 |
|
/ok to test 94ff125 |
|
/ok to test c3167e7 |
|
/ok to test b709095 |
|
The inline comments are notes. One point needs the description instead: rollout evidence at this head. The c-Interact smoke run (10 rollouts through #5409) predates the rebase. It also predates 7d17f1a and b709095, which changed what a continuation session does:
Could you add a short c-Interact smoke run with #5409 rebased on this head? It should check that the close returns one invocation per activation and that the model server keeps one session for the episode. Two description fixes:
|
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44831686166 |
|
/ok to test 7886722 |
|
/ok to test 2160aa8 |
|
/ok to test 01d21ec |
A user-simulation Environment Server activates the agent once for each turn of the conversation and sends only the new user message. Simple Agent now accepts a seed that asks for continuation: each activation runs the turn loop on the session's conversation plus its new input, and keeps the first activation's tools and instructions. - An activation without new input, or one that replaces the session's tools or instructions, gets 422. - A retried activation gets its reply without another model call. - The close returns the trajectory of every activation. - A continuation seed is refused when partial-rollout checkpoints are on, because a checkpoint exports no conversation history. Carried over from #5202, which prototyped it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…able and explicit Review fixes for simple_agent's continuation sessions: - Checkpointing: a continuation seed is accepted, and its reply carries CHECKPOINT_RESTART_HEADER, because a checkpoint does not export the conversation; the episode starts over after a restore. A session restored without its conversation refuses its next activation (409). - Opt-in: only a class that sets continuation_supported in its own body supports continuation, so DeepAgentsAgent, which replaces responses(), refuses a continuation seed again. - Settings: a later activation that changes any setting of the first (tool_choice, temperature, ...), not only tools or instructions, gets 422 instead of having it silently dropped. - Observations: a continuation session always collects the trajectory and timing its seed confirms, also without observability_enabled. A failed or cancelled activation adds a failed or incomplete invocation and an agent_activation_interrupted gap before it re-raises. Turns carry their activation_id. Each invocation keeps only its activation's new input and output, so the close payload grows linearly. - Model server: the session keeps the model server's cookies across activations, so it stays on one model-server session. - A test checks that a later activation resends the earlier turns' token IDs and log probabilities. max_steps still bounds each activation, as it bounds one /v1/responses call; the Environment Server bounds the activations. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…base hook Main checks that no agent overrides seed_agent_session. Simple Agent now implements the base agent's _seed_restarts hook instead: under checkpointing, a checkpoint does not export a continuation session's conversation, so the seed reply marks the episode as a restart. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
A protocol whose turn ends at a submission, such as the BIRD-Interact ADK's c-Interact, must end the agent's activation without another model call. The ADK does it in a before-model callback; a Gym Environment Server sees only the tool calls, so it signals it on the reply. ToolResult.ends_activation sets X-NeMo-Gym-End-Activation: true on the direct HTTP reply. simple_agent runs the rest of the model response's tool calls and returns the activation without calling the model again. MCP has no field for it, so an MCP agent calls the model again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…ntinuation lost its conversation Main now requires every 409 session refusal in an agent to raise AgentSessionConflictError (#5691, enforced by tests/unit_tests/test_session_contract_repo.py). The continuation session's refusal after a restore raised a plain HTTPException(409); it keeps the same status and detail. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…ook, and document continuation A continuation activation called _create_episode directly, so a subclass whose task context lives in its session state (_create_session_episode) lost it from the first activation on. It now goes through the hook, as an activation without continuation does. The comment on the trajectory said the close payload grows linearly; each turn's question still holds the model-visible prefix, as in one activation. The continuation test now checks each activation's model route and metadata. integrate-existing-agents.mdx describes simple_agent's continuation, and multi-step-tasks.mdx says which harness can continue in a lent sandbox. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…ent Server in the core suite Core coverage measures responses_api_agents/simple_agent/app.py, because core tests import it, but counts only core tests. The continuation code this PR adds is tested in the server's own suite, so core coverage fell to 94.95%, under the 95% gate. These tests drive a real Simple Agent session from a BaseEnvironmentServerWithTools episode: a tool that ends the activation ends the turn, the next activation continues the conversation, a failed activation stays in the trajectory, and an activation the session cannot run gets a 422 before any model call. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
- A tool result that is not JSON becomes a 500 error that no longer ends the activation, so the agent shows the model the error. - The end-activation docstrings and the MCP tutorial say that only simple_agent honors the header. - With execute_tools on, a function call cut off before its tools ran is not sent to the next activation. - Comments say what a failed activation keeps and that each turn's question keeps the whole prefix; the docs say close returns every activation's trajectory and use "borrowed sandbox". - Tests: close during an activation (incomplete, CancelledError), an activation without new input, the model server's cookie between activations, tool cookies and evidence across activations, the cut-off call. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
|
/ok to test f4f827c |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45121219212 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45123313803 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45125290520 |
On
main(theBaseEnvironmentServerWithToolsstack, #5346 → #5917, has merged). This is the first PR of the BIRD-Interact stack: this PR → #5409 (BIRD-Interact). Its diff issimple_agent, plus a smallnemo_gym/server_runtimechange that lets a tool reply end the agent's activation (second section below).What changed
simple_agentaccepts a seed that asks for continuation (AgentSeedSessionRequest.continuation). Each activation of the session then runs the turn loop on the session's conversation plus its new input, and keeps the first activation's tools and instructions.tools,instructions,tool_choice,temperature, ...), gets 422; onlyinputandmetadatachange per activation.observability_enabled, because the seed confirms it. Turns and invocations carry theiractivation_id. Each invocation keeps only its activation's new input and output; each turn's question still holds the model-visible prefix, as in one activation. A failed or cancelled activation adds afailedorincompleteinvocation and anagent_activation_interruptedgap.continuation_supportedin its own body supports continuation, so a subclass that replaces the turn loop, such asDeepAgentsAgent, refuses a continuation seed.max_stepsbounds each activation; the Environment Server bounds the activations.CHECKPOINT_RESTART_HEADER(now exported fromnemo_gym.server_runtime): a checkpoint exports no conversation, so the episode starts over after a restore. A session restored without its conversation refuses its next activation withAgentSessionConflictError(409), as main's session contract requires since refactor(sessions): raise the session conflict errors for every 409 refusal #5691.A tool reply can end the activation
ToolResult.ends_activation(nemo_gym/server_runtime/episode_tools.py): aBaseEnvironmentServerWithToolstool marks its reply as the end of the agent's activation. Over direct HTTP the reply carriesX-NeMo-Gym-End-Activation: true(END_ACTIVATION_HEADER, next toTOOL_ERROR_HEADER). MCP has no field for it, so an MCP agent calls the model again; the Fern MCP guide says so.simple_agentruns the rest of the model response's tool calls and returns the activation without calling the model again.Why
An Environment Server that simulates the user activates the agent once for each turn and sends only the new user message. BIRD-Interact's c-Interact (#5409) needs it: each user reply is a new activation of the same session. #5202 prototyped it. No public issue: the PRs of the BIRD-Interact stack track the work.
The BIRD-Interact ADK ends the agent's run right after
submit_sql: itsbefore_model_callbackanswers the next model call itself. An Environment Server sees only tool calls, so without a signalsimple_agentmade one more model call per turn, which the ADK does not. Rewards were the same, but token counts and trajectories were not, and both are compared with auto-ontology-eval and used for training. #5478 uses the signal.Validation
pytest responses_api_agents/simple_agent/tests/test_app.py tests/unit_tests/test_agent_sessions.pypytest responses_api_agents/simple_agent/tests(review fixes)prompt_token_ids,generation_token_idsandgeneration_log_probsagentic_turn_simulation_agentandlabbench2_vlm_agenttests (SimpleAgentsubclasses)pytest tests/unit_tests/server_runtime(after addingends_activation)ends_activationcarries the header, a call that never ran does notpytest responses_api_agents/simple_agent/tests(after addingends_activation)pre-commit run --fileson the changed filesRollout evidence
The c-Interact smoke run in #5409 uses this continuation: 10 rollouts with
simple_agent, none failed. That run is from before the rebase onto main atdda609f86and the split into two stacks, which changed no behavior here.For
ends_activation: the BIRD-Interact server's five example tasks in c-Interact (SQLite, Docker sandboxes, with #5478's use of the signal), before and after. Before, every turn made one model call aftersubmit_sql: 8 extra calls over 8 turns. After, none: each turn made exactly one model call fewer, and all 5 episodes completed. Details in #5478.Compatibility
Opt-in through the seed. An agent seeded without
continuationbehaves as before.ends_activationdefaults toFalse, so other tools' replies do not change; an agent that ignores the header calls the model again, as before.SimpleAgentsubclasses no longer accept continuation seeds unless they setcontinuation_supported.Team review fixes (2026-11-19)
A team review (the repository's
review-pr-teamskill) found notes only. Fixed in c3167e7:_create_session_episode, as an activation without continuation does, so a subclass's task context applies on every activation (new test).integrate-existing-agents.mdxdescribessimple_agent's continuation;multi-step-tasks.mdxsays which harness can continue in a lent sandbox.Not changed: #6162 adds the same
model_server_cookiesfield with another type; whichever lands second reconciles them.Core coverage fix (2026-11-21)
Core coverage measures
responses_api_agents/simple_agent/app.py, because core tests import it, but counts only core tests. This PR's continuation code is tested in the server's suite, so the stack's core coverage was 94.95%, under the 95% gate. 2160aa8 addstests/unit_tests/server_runtime/test_environment_server_with_simple_agent.py: aBaseEnvironmentServerWithToolsepisode drives a real Simple Agent continuation session. A tool that ends the activation ends the turn with no further model call, the next activation sends the conversation so far, a failed activation stays in the trajectory, and an activation with no new input or changed settings gets a 422 before any model call. Each test fails when the rule it covers is removed. Core suite at the top of the stack: 26,020 passed, coverage 95.09%.Review fixes, third round (2026-11-21)
01d21ec applies ananthsub's third round:
Ending the activation:
simple_agenthonors the header.Session history: with
execute_toolson, a function call cut off before its tools ran is not sent to the next activation.New
simple_agenttests:incomplete,CancelledError);Each test fails when its rule is removed.
simple_agent: 192 passed.