Repository navigation
One agent abstraction: environments, Direct in Layer 1, ReAct hooks, supports and needs - #111
Merged
Merged
Conversation
…supports and needs
Where an agent works is now an environment given with each call, never a setting:
hermit/agent/environment/ holds Environment (workspace, limits, isolation; exec, upload,
download, path) and Local, Sandboxed and Container (the old base/container.py is
environment/docker.py). BaseAgent.run(prompt, environment=..., tools, session, roles)
replaces run(prompt, workspace=, limits=); a path is a Local. The CLI Base Agents read
their isolation from the environment and refuse isolation, sandbox or container given as
settings; the isolation code paths themselves are unchanged.
A single model call is Layer 1: Direct moves to hermit/agent/model/direct.py and returns a
Reply; make("direct") is refused with the new place.
react gains hooks (call_model, before_tool, after_tool, stopped) and step-by-step driving
with external tools. ReactAgent is the class a benchmark subclasses: @tool methods (the
schema read from the signature), environment_for, and task hooks.
An acting agent declares what it takes of an adapter (supports); a method lists what it
needs (evolver.yaml needs: MWM tools, ASPIRE and ReHarness context_tool, AHE skills,
agents, hooks); hermit check and training refuse a run whose agent lacks one.
Docs (agent-layers, custom-evolver), AGENTS.md, the general PR checklist and the PR
template say so. No config compatibility is kept: every caller moves to the new API.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alls, capability checks Five rounds of review (this session and an independent Codex review) on the one-agent refactor; every confirmed finding fixed, each with a test that fails without it. - cli_endpoint chose a container only when no log directory was given: a Trainer-logged llm.isolation: container ran its CLI on the host. Placement is now chosen apart from logging. - Environment.exec keeps the environment's limits: its timeout_s by default, readable mounts linked (Local, a stale link replaced, the workspace's own file refused) or bound (Sandboxed); hidden paths and a limited network refused where they cannot be kept (checked against everything the sandbox shows, its allowed hosts, proxy, ports and sockets, and a fallback that ran without bubblewrap). A timed-out command's whole process tree is killed and its output read for a few seconds at most. upload and download keep links as links. - ReAct's external calls go through before_tool, and React.give applies tool_result_chars and after_tool; the calls after an external one wait behind it, and the turn's ends (stopped, the caps) are judged after the last result. - supports: Harbor's from its acting agent (a CLI all, the answer agent its context and context tool, Harbor's own none), read from params merged as the runner merges them; ServeLearnBench takes no context tool; a supports that is a property counts as undeclared. A test walks every shipped config of a method with adapter needs. - @tool schemas: runtime and postponed unions, and a list's items. - ChatEndpoint.start() is idempotent: cli_endpoint returns a started endpoint that callers enter with `with`, which started a second serving loop; it outlived close() and spun on the closed socket, slowing the whole process (found as two timeout tests failing only in the full suite). - Tests that still passed isolation as settings (RRSI, mini-swe-agent, AHE) or a stand-in with the old run(prompt, workspace) (Harness² on Pi). - Docs: Direct is Layer 1 everywhere (the interactive diagram too), the Environments section says what is not implemented yet, the needs check's scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, sandbox cwd, moved paths - Environment.upload of a folder wrote through a link the workspace already had (a file outside the workspace was overwritten): entries are copied one by one and a link at a target is replaced, never written through. - ReactAgent counted its client's totals: a subclass whose call_model uses another client had those calls left out of tokens, cost and the budget. The run's usage is now what its loop recorded, plus the answer-tag follow-up. - The answer tag was looked for in answer()'s output, so a subclass that strips it triggered a follow-up whose reply skipped answer(): the tag is looked for in the model's reply, and answer() shapes the follow-up too. - Sandboxed.exec started bubblewrap in the command's cwd on this machine, which fails for a folder only the sandbox shows (a mount's target): it starts from the workspace and sets the cwd inside. - hermit.agent.base.direct and hermit.agent.base.container forward to their new modules for one release (hermit._moved, as earlier moves did); CHANGELOG's Breaking section and the agent-layers table say what changed. - Docs: docker/README.md's module path, cli.py's "Local", the needs check's message for an agent that takes no adapter export. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Change
One agent abstraction, the first step of the refactor in the design doc (Hermit agent and benchmark refactor). Every
agent stays inside the three layers, with three things made explicit:
hermit/agent/environment/:Environment(workspace, limits, isolation;
exec,upload,download,path) and its implementationsLocal(isolationnone),
Sandboxed(the run's bubblewrap sandbox) andContainer(a Docker container; the oldhermit/agent/base/container.py, nowenvironment/docker.py).BaseAgent.run(prompt, environment=..., tools=, session=, roles=)replacesrun(prompt, workspace=, limits=); a path is aLocal. The CLI Base Agents take theirisolation from the environment and refuse
isolation,sandboxorcontainergiven as settings (a session thattook them for settings would have run without its isolation). The isolation code paths (bubblewrap wrap, container
run) are unchanged; only where they read their choice from changed.
placed(path, sandbox)is an Evolver'ssessions' environment (
Sandboxedwhen the run's sandbox is on). The interface follows Harbor's environments, forthe follow-up that runs any agent in a Harbor environment.
Directmoves tohermit/agent/model/direct.pyand returns aReply;make("direct")is refused with the new place.ctx.agent, the local endpoint and the benchmark loops useit as before.
react(hermit/agent/base/react.py) gains hooks (call_model,before_tool,after_tool,stopped) and step-by-step driving (start,step, external tools that wait inloop.pendingforagent.give(loop, ...), in the order the model asked). The actingReactAgentis the class a benchmark subclasses in its example folder:tools as methods marked
@tool, anenvironment_for, and task hooks (system_prompt,user_message,tools,answer) besides the loop's.@toolalone reads the description from the docstring and the schema from thesignature.
supports(the adapter exports it givesits session:
context,context_tool,tools,skills,agents,hooks); a method lists what it needs of themin its
evolver.yamlneeds(MWMtools, ASPIRE and ReHarnesscontext_tool, AHEskills, agents, hooks). A runwhose acting agent does not take one is refused at
hermit checkand before training (adapter_needs_errors).Built-in agents and host pipelines are checked; a task's class that runs only in its sandbox is not imported to
check it. The check compares declared needs, not template exports: MWM exports roles that CL-Bench's host never
used, and an export-based check would refuse its shipped configs.
Core changes:
hermit/agent/environment/(new),hermit/agent/base/{interface,cli,react,endpoint}.py,hermit/agent/model/direct.py(moved),hermit/agent/acting/{agent,react,tools,workspace}.py, the Evolver sessionsthat set isolation (
agent.py, AHE debugger, EvoSafe roles, Harness² channel, MWM, RRSI),hermit/trainer/trainer.py(
adapter_needs_errors),hermit/agent/evolver/loader.py(the adapter needs),hermit/harbor/{runner,tools}.py.No sandbox change.
Not in this PR (follow-ups in the design doc): one Harbor bridge for every agent; a bwrap executor for Harbor-format
tasks; benchmarks moved to Harbor's task format, with
benchmark.yaml's default agent; the robotics changes; theLIBERO-90 to LIBERO-Pro Long experiment. The benchmark loops that come from a benchmark or a paper (CL-Bench,
ServeLearnBench, OfficeQA's SkillOpt rollout, AgentDyn) stay as they are, conforming to the interfaces: replacing
them with the core ReAct would change what reaches the model, and each needs its own parity check.
Docs and checklists:
docs/framework/agent-layers.md(Layer 1'sDirect, Environments, the ReAct hooks,supportsandneeds, rules 7 and 8, a before/now table),docs/framework/custom-evolver.md,AGENTS.md, thegeneral PR checklist (an Agent layers item) and the PR template.
No config compatibility is kept, by decision: code that passed
workspace=/limits=or isolation settings ischanged here (every caller in
hermit/,examples/andtests/).Validation
Run on Linux (RHEL 9, x86_64) with bubblewrap, as a non-root user, against
mainata6f39ea1.Requests unchanged. A script records what each kind of agent sends, with a stand-in at the edge: the ReAct
agent's chat requests (a task tool and an adapter), a single
Directcall, and the Codex and Claude Code Base Agents(argv, environment, stdin, the home's and workspace's files; Codex also inside the run's bubblewrap sandbox). Recorded
on
mainand on this branch after each step: byte for byte identical (paths under the scenario's root normalised).Real runs, GLM 5.3 Flash on Fireworks,
mainagainst this branch (same configs, same data):examples/claude_subscription's), test 3 × 3 repeatsTrajectories: in E1 both versions classify correctly, but ACE's playbook makes the model append
bullet_idsafterthe JSON, which the strict judge scores 0 (the same on
main). In E2 both learners wrote the same rule (exactly{"label": ...}, with what each label means). E2's and E3's learner sessions ran in the run's sandbox on this branch(
sandbox/learner-1.json: enforced, network isolated, probe passed, the data and judge absent). In E3 every MWMreview was adopted in both versions.
Tests.
python -m pytest --changed --base origin/main(shared code: every group, plus the examples' own tests),in a venv with the optional groups CI installs (
.[test,mini-swe-agent], gepa, skillopt, harness2, rrsi, she): 1983passed, 187 skipped, 0 failed on
b6932693.main(a6f39ea1) in the same venv: 1882 passed, 165 skipped, 0 failed;the 123 more collected here are the examples' tests (94) and the new ones. The skips are optional CLIs and opt-ins
(the pi CLI,
--integration, official AgentDojo, metaworld, clbench, Docker).git merge-treeagainstmain: clean.The parity script was rerun after every review round: still byte for byte identical to
main.New tests:
tests/core/test_environment.py(28: environments and their limits, the CLI's refusal of isolationsettings,
Directin Layer 1, the ReAct hooks and external calls, aReactAgentsubclass with@toolmethods,@tool's schema, the adapter needs on every shipped config, Harbor's supports, an endpoint entered after it started),and one in
test_ahe_debugger.py(each attempt in the run's sandbox). Each review fix's test fails without its fix.Not verified: macOS; Docker-isolated CLI sessions (no
officeqa-codeximage here: the container path's code isunchanged, only where it reads its settings from); the Pi CLI (not installed); Harbor trials.
Review
unisolated; an unknown pending call is refused; a method's need an agent lacks stops the run before it starts.
gpt-6.1-solreview at higheffort, each round a fresh session); see Review rounds below.
Review rounds
What was fixed (all in
b6932693, each with a test):cli_endpointchose a container only without a log directory, so a Trainer-loggedllm.isolation: containerran its CLI on the host.
Environment.execkeeps its limits: timeout, mounts (a stale link replaced), hidden paths and a limited networkrefused where the sandbox shows them or lets the network through (allowed hosts, a proxy, ports, sockets, a run
without bubblewrap); a timed-out command's process tree killed, its output drained a few seconds at most; links kept
as links on upload and download.
before_tool/after_tooland the result cut; later calls of the same message waitbehind them;
stoppedand the caps judged after the last result.supports: Harbor's by acting agent (answer: context and context tool) from params merged as the runner mergesthem; ServeLearnBench without
context_tool; a property counts as undeclared.@toolschemas: unions and listitems (a provider refuses an array without them).
ChatEndpoint.start()idempotent:with cli_endpoint(...)started a second serving loop that outlivedclose()and spun on the closed socket; it slowed the whole test process tenfold and failed two timeout tests in the full
suite only (the pattern predates this PR).
Directis Layer 1 everywhere,the interactive diagram, what is not implemented yet, the needs check's scope).
A later review (after the dual review) found four more, all fixed in
99ea6f24with tests that fail without thefixes: a folder upload wrote through a link already in the workspace;
ReactAgentcounted its client's totals, so asubclass's
call_modelon another client went uncounted;answer()was skipped on the answer-tag follow-up;Sandboxed.execcould not start in a folder only the sandbox shows. The two moved modules forward for one release,and CHANGELOG says what changed. Full suite on that tree (CI venv): 1987 passed, 185 skipped, 1 failed
(
test_selection: the forwards'hermit/_moved.pywas not marked shared), fixed in the same commit and rerun.Left, with the reason: in a
Localenvironment, a process that detached itself and whose parent already exitedsurvives a timeout (a subreaper would be needed;
Sandboxedis contained by bubblewrap's PID namespace; nothing inHermit calls
execyet). The docstring says so.🤖 Generated with Claude Code