Loading the notebook…
Loading the notebook…
Notebooks · Autopilot · 37
Autopilot is the long-running, goal-driven, budget-gated runner. It wraps GoalAgent + PersistentAgent with:
Its imports and arguments are checked against shipit-agent 3.0. The outputs were saved when it was written, for an earlier release.
from pathlib import Path
import sys
# Resolve the repo root whether this cell is running from ./notebooks
# or from the repo root — mirrors the existing 01–36 notebook series.
ROOT = (
Path.cwd().resolve().parent
if Path.cwd().name == "notebooks"
else Path.cwd().resolve()
)
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from examples.run_multi_tool_agent import build_llm_from_env
# Bedrock Llama 4 Scout is the default model this library ships with
# (see `shipit_agent/config.py`). No model name required — the helper
# reads `AWS_REGION` / credentials from env and returns an adapter that
# works with every Autopilot / Agent class.
llm = build_llm_from_env("bedrock")
print("Bedrock LLM ready:", type(llm).__name__)A Goal is an objective plus a list of success criteria. Autopilot stops iterating the moment every criterion is satisfied OR a budget trips — whichever comes first.
from shipit_agent.deep import Goal
goal = Goal(
objective="Summarize the three most common Python dict gotchas and show a working snippet for each.",
success_criteria=[
"At least 3 gotchas explained in prose",
"Each gotcha has a Python snippet that reproduces it",
"A one-line fix or avoidance is shown for each",
],
)
goalBudgetPolicy has conservative defaults (30 min, 100 tool calls, $5). For this demo we cap harder so it finishes quickly.
from shipit_agent.autopilot import Autopilot, BudgetPolicy, default_heartbeat_stderr
autopilot = Autopilot(
llm=llm,
goal=goal,
budget=BudgetPolicy(
max_seconds=600, # 10 min cap for the demo
max_tool_calls=20,
max_iterations=8,
max_tokens=300_000,
max_dollars=2.0,
),
heartbeat_every_seconds=30,
on_heartbeat=default_heartbeat_stderr,
)
print("Autopilot ready — budget:", autopilot.budget)run(run_id=...)run() drains the goal loop and returns an AutopilotResult. Pass a stable run_id so the checkpoint is resumable later.
result = autopilot.run(run_id="py-dict-gotchas-v1")
print(f"status: {result.status}")
print(f"iterations: {result.iterations}")
print(
f"criteria met: {sum(1 for c in result.criteria_met if c)} / {len(result.criteria_met)}"
)
print(f"halt reason: {result.halt_reason}")
print()
print(result.output[:800])Autopilot writes one JSON file per run to ~/.shipit_agent/checkpoints/<run_id>.json. That file is enough to resume on another machine.
import json
from pathlib import Path
cp = Path.home() / ".shipit_agent" / "checkpoints" / "py-dict-gotchas-v1.json"
if cp.exists():
data = json.loads(cp.read_text())
print(json.dumps({k: data[k] for k in ("run_id", "iterations", "usage")}, indent=2))
else:
print("(no checkpoint — run cell 3 first)")statuscompleted — every criterion passed.partial — some criteria passed; run halted because of budget.halted — budget tripped before any criterion could be verified.failed — an exception aborted the run; the checkpoint captures what was known at crash time.You can call autopilot.resume(run_id=...) to pick up any non-completed run.