espnet3.bin.atlas.agents.session.StudySessionAgentClient
espnet3.bin.atlas.agents.session.StudySessionAgentClient
class espnet3.bin.atlas.agents.session.StudySessionAgentClient(delegate, state, study_id: str, study_dir: Path, recipe_dir: Path, configured_session_id=None)
Bases: object
Wrap an agent client to reuse one resumable agent session per study.
Every call injects instructions to re-read the study’s mutable files (objective, knowledge pack, trial history, config) rather than trust resumed-session memory, and persists the session id to state (via a file lock, so concurrent node runs across CPU/GPU jobs do not race). If the agent’s reply violates its output schema, this writes a STOP file, marks the study "stopped", and raises InvalidAgentResponseError rather than letting a corrupted response silently continue.
Wrap delegate with study-scoped session reuse.
- Parameters:
- delegate – The underlying agent client (e.g.
CliAgent) that actually invokes Codex/Claude Code. - state – The study’s
StateStore, used to persist the shared session id. - study_id – Study this session belongs to.
- study_dir – Study directory (for the session lock file and the paths listed in the injected context).
- recipe_dir – Recipe directory, listed in the injected context.
- configured_session_id – A session id explicitly set in config (
atlas.agent.session_id), taking priority over any session id already persisted in state, orNoneto use whatever is persisted.
- delegate – The underlying agent client (e.g.
lock_session()
Hold the study’s agent-session lock and refresh self.session_id.
Serializes access to the shared agent session across concurrent CPU and GPU jobs: while held, re-reads the persisted session id (in case another job set it since this instance was created) and, if a configured_session_id was given and differs, persists it as the new shared session id.
- Parameters:None.
- Returns: Context manager yielding the current (possibly just-refreshed) session id.
- Return type:Iterator[str | None]
Example
>>> with client.lock_session() as session_id:
... passrun(request: AgentRequest, artifact_dir=None) → AgentResponse
Run one request through the shared session, persisting and validating it.
Overrides request.resume_thread_id with the study’s shared session id (if any), replaces the request’s objective with instructions to re-read study files fresh, and clears knowledge/repo_context/trial_history_csv (the agent is told to read those files itself instead). After the delegate call, persists a newly created session id, and raises InvalidAgentResponseError (after writing STOP and marking the study stopped) if the response reports an invalid structured reply.
- Parameters:
- request – The task to run; its session/objective/context fields are overridden as described above.
- artifact_dir – Directory the agent may write output artifacts under, passed through to the delegate.
- Returns: The delegate’s response.
- Return type:AgentResponse
- Raises:InvalidAgentResponseError – If the agent’s reply violated the request’s output schema.
Example
>>> response = client.run(request)
>>> response.status
'success'