Skip to content

Agent & Tools

deepbuilder/agent/core/runtime/agent.py defines DeepAgent, the composition point for a shared agent used by REPL sessions, data preparation, and LNR workers. Each run executes on InquiryCraft’s AgentRuntime; DeepBuilder supplies the policies and hooks around it. Behavior is divided by responsibility rather than duplicated across solver modes.

Area Current responsibility
agent/session/ Builds one InquiryCraft AgentRuntime session per run (execution/runtime.py): LLM/tool rounds, turn routing and round-limit handling (execution/turn.py), tool execution hooks (execution/tool_result.py), and context projection (coordination/context.py).
agent/core/runtime/run_policy.py Auto-continue policy, text-only retry, and result recovery when the round budget is exhausted.
agent/factory/ Role-aware DeepAgent construction, including tool selection and prompts.
Streaming and retry Configured in agent/session/execution/runtime.py on InquiryCraft’s StreamOutputGuard (output cap, repetition detection) and SameRoundRetryPolicy.
runtime/safety/execution/agent_runtime/ Read-before-edit guard (edit_guard.py) and tool-bundle scheduling (tool_bundle_policy.py): single, sequential, parallel bash, or parallel read-only; multi-call bundles containing write or edit are blocked.
research/solver/lnr/orchestration/agent_hooks.py LNR hook adapter: round-start runtime-context injection and round-complete guard messages.
research/quality/fullrun/ Optional embedded full-run handling and unified final-candidate evaluation.
research/state/knowledge/memory/agent/ Tool-memory compression, reasoning replay, and resource-feedback folding.
runtime/observability/agent_io/ Human-readable interaction logs and logging policy.

Paths in the table are relative to the deepbuilder/ package.


create_tool_collection in deepbuilder/runtime/safety/execution/agent_runtime/tool_composition.py builds the tool surface from InquiryCraft file tools plus DeepBuilder’s own bash, skill, and resource_wait. The agent always receives bash, read, grep, glob, and ls; write and edit depend on the tool preset, and skill and resource_wait are added only when a skill registry or resource observer is supplied.

Tool Role Controls
bash Run code, training, evaluation, and file-changing commands. Sandbox and path guards, timeout, output shaping, command classification, process tracking, resource observation.
read / grep / glob / ls Inspect workspace and permitted read-only roots. Path guards, result caps, overlap protection, and parallel read-only scheduling.
write / edit Legacy structured file changes. Omitted in bash-write mode, which LNR main agents and data preparation always use and the REPL uses under its default repl.repl_tool_preset: bash_write; the REPL write_edit preset enables them. Snapshots, syntax-oriented feedback, size limits, and edit diagnostics.
skill List and read Markdown skills from a loaded registry. Mode/category filtering, visibility limit, aliases, and priority.
resource_wait Wait on a resource-runtime token until an unlock condition changes. Registered only with a resource observer; without a valid wait_token it returns RESOURCE_WAIT_NOT_AVAILABLE.

BashTool (deepbuilder/runtime/safety/tooling/bash/core/tool.py, exported from deepbuilder.runtime.safety.tooling.bash) is more than a shell wrapper. It classifies commands, normalizes selected package-install invocations, registers long jobs with the resource observer, streams compact interaction logs, parses DEEPBUILDER_HB heartbeats and metric history, detects artifact updates, enforces visible GPU boundaries, and returns bounded feedback.

Supporting code is split into:

  • runtime/safety/tooling/bash/core/: request building, preflight, and admission
  • runtime/safety/tooling/bash/monitor/: output streaming, progress projection, resource guards, and termination effects
  • runtime/safety/tooling/bash/process/: process start and lifecycle
  • runtime/safety/tooling/bash/policy/: admission and output policy
  • runtime/safety/tooling/workspace/: shell guards (shell_guards.py) and heartbeat/progress parsing (progress.py)
  • runtime/safety/tooling/resource_management/: resource classification, spawn and timeout feedback, and resource_wait

Resource value judgments do not belong in the tool facade; they are made by the task-local resource runtime.


  • Sliding-window projection prioritizes task and recent execution context.
  • Tool output is capped, deduplicated, summarized, or stored as an artifact reference.
  • Repeated resource feedback is folded by capability state rather than appended as a live summary stream.
  • File snapshots can remain latest-only in the model-visible memory.
  • Compaction: LNR may trigger context-hygiene compaction (research/solver/lnr/support/context_hygiene.py) after stage count, code churn, repeated large files, low cache efficiency, or large tool output.

Path guards constrain file tools to the workspace and explicitly allowed read-only roots. The REPL and LNR profiles can maintain a lightweight workspace Git baseline for source and Markdown files (repl_workspace_git_* and workspace_git_* keys; deepbuilder/research/state/workspace/storage/git.py), while generated data, snapshots, submissions, and runtime logs are excluded from source checkpointing.