GenAI & Agents · Personal

Building an Autonomous Browser Agent with Hard Limits and a State Log

A reference design for an agent that drives a signed-in browser to shortlist opportunities and submit tailored proposals, kept safe by explicit caps, a persistent state log and a facts-only profile.

  • Claude agents
  • Browser automation
  • Python
  • JSON state log
  • Guardrails
  • Prompt design
  • Cron

// Why this matters

An autonomous browser agent with guardrails is the difference between a useful assistant and an expensive liability. Letting a model click through a signed-in session and submit forms on your behalf saves hours, but every submit can spend money, send text under your name or create commitments. The interesting engineering is not getting the agent to act, it is bounding what it can do when it is wrong.

I built a proposal agent for my own freelance pipeline as a low-stakes proving ground. The same ideas apply to any agent that takes real-world actions: ticket triage, access requests, or the pull-request agents described in Agentic SRE: MCP Servers and Workflow Agents for Change and Observability.

// The problem

Left unconstrained, a browsing agent fails in predictable ways. It re-applies to the same listing because it does not remember the last run. It spends a metered resource faster than you intended because each action looks reasonable in isolation. It embellishes: models will happily describe a certification as current when it lapsed, or claim a skill that only appears in a neighbouring bullet.

Prompt-only rules such as never spend more than N are weak, because they depend on the model counting correctly across a long session. You need the limits to be enforced by something that cannot be talked out of them.

// The solution

The design separates judgement from enforcement. The model judges fit and writes the draft. A small wrapper script owns the config and state: it provides the shortlist rules, checks every candidate against hard limits and refuses the submit step if any limit trips. The model receives only the items that pass.

State is a JSON lines file of item ids with the decision, a timestamp and a short reason. Before the model sees a listing the wrapper drops any id already in the log. That single mechanism gives idempotency, makes a crashed pass safe to rerun, and doubles as the audit trail.

Facts come from a profile document, a plain markdown file with roles, skills, dated certifications and rates. The drafting prompt says: use only statements supported by the profile; if a requirement is not covered, say nothing about it. Expiry dates are written next to each credential so a lapsed one cannot be called current.

Each invocation is one pass with a quota, for example at most three submissions, then the process exits. Scheduling is external cron or a task runner, so you can pause the whole system by disabling one entry. I rejected a continuous loop because failures compound and nobody notices a runaway process.

How it flows flow1. Start pass → 2. Scan feed → 3. Filter → 4. Score fit → 5. Gate: hard limits → 6. Draft → 7. Submit → 8. Record → 9. Stop01Start pass02Scan feed03Filter04Score fit05 · GATEGate: hard limits06Draft07Submit08Record09Stop
How it flows. End-to-end flow. Dashed pink nodes are gates: points where a human or a check must pass before the next stage runs.
  1. Start passload config, profile and state log
  2. Scan feedread the newest listings in the signed-in browser
  3. Filterdrop seen ids, wrong type, too short or over budget
  4. Score fitcompare each remaining item to the profile
  5. Gate: hard limits gatecost cap, rate and quota checked in code
  6. Draftwrite a tailored proposal using only profile facts
  7. Submitfill the form and send through the browser
  8. Recordappend id, decision and reason to the state log
  9. Stopend the pass; a scheduler runs the next one
SchedulerWrapperAgentBrowserState logrun passload seen idsconfig, profile, unseen candidatesopen listing, read detailspropose draft and costsubmit only if limits passappend decision and reason
One pass of the agent. The wrapper enforces limits; the model only judges and drafts.

// Before you start

  • Python 3.11 or newer
  • An agent runtime that can drive a browser session you are already signed in to (for example a browser extension toolset)
  • A written profile document you are willing to stand behind
  • A scheduler (cron, systemd timer or a hosted task runner)
  • Clarity on your limits: rate, per-item cost cap and per-pass quota

// Step-by-step implementation

  1. 01 Step 1. Write the limits as configuration

    Put every number the agent must respect in one file the wrapper reads, and keep it out of the prompt. Changing behaviour is then a reviewed config change. Include a kill switch.

  2. 02 Step 2. Create the facts-only profile

    The profile is the single source of truth for claims. Write dates next to anything that expires, and add a short list of things that must never be asserted.

  3. 03 Step 3. Build the state log

    Use append-only JSON lines. Reading it into a set is cheap, and an append is atomic enough for a single-process agent. Record the reason so you can see why the agent skipped things.

  4. 04 Step 4. Enforce limits in code, before the submit

    The gate is a pure function. The agent proposes an action; the wrapper approves or rejects it. Because it is plain code you can unit test it, which you cannot do with a prompt.

  5. 05 Step 5. Write the drafting prompt that forbids invention

    Give the model the profile and the listing, and state the rules plainly. Ask for a structured response so the wrapper can inspect it before anything is typed into a form.

  6. 06 Step 6. Orchestrate one bounded pass

    The wrapper ties it together: load, filter, hand the agent only the unseen candidates, gate each proposed action and log everything, including rejections. Exit when the quota is reached.

  7. 07 Step 7. Schedule it and keep a way to stop it

    Run the pass on a timer and write output to a log. Pausing the system is then a one-line change: disable the cron entry or set enabled to false.

// How to verify it works

  • Run the pass twice in a row; the second run logs zero new candidates for the same feed because ids are in the state file.
  • Set max_submissions_per_pass: 0 and confirm nothing is submitted and every candidate is logged as skipped with the quota reason.
  • Feed the gate a listing just over the cost cap; it must reject with the cost reason.
  • Read a draft and check each entry in its claims array against the profile; any claim not in the profile is a failure.
  • Set enabled: false and confirm the wrapper exits immediately.

// Design decisions and trade-offs

  • Limits live in code and config, not only in the prompt: rate, per-item cost cap and a per-pass quota are checked before the submit action.
  • A state log of seen item ids makes each pass idempotent, so the agent never touches the same item twice.
  • A single profile document is the only source of claims; anything absent from it may not be stated.
  • One bounded pass per invocation, scheduled externally, instead of a long-running loop.
  • Time-sensitive facts such as expiring credentials carry dates so they are never described as current when stale.

// Pitfalls and lessons learned

  • Putting limits only in the prompt. The model miscounts over a long session; enforce in code.
  • No idempotency. Without the state log a crash mid-pass leads to duplicates on the rerun.
  • Undated credentials. The model will call a lapsed certification current unless the status is explicit text.
  • Letting the agent negotiate. A fixed rate in config removes a whole class of surprises.
  • Unbounded loops. A forever process hides failures; prefer short passes and an external scheduler.
  • Logging decisions without reasons, which makes tuning guesswork.

// Frequently asked questions

How do I add guardrails to an autonomous browser agent?

Enforce caps, quotas and allow-lists in a wrapper script that approves each action, persist a state log for idempotency, and ground generation in a facts-only profile.

How do I stop an agent repeating the same action?

Keep an append-only log of processed item ids and filter candidates against it before the model sees them.

Can an LLM be trusted to respect a spending limit?

Not on its own. Treat the model as untrusted for enforcement and check limits in deterministic code before any irreversible step.

How do I keep an agent from inventing facts?

Provide a single profile document, require the model to list every claim it used, and review or programmatically check that list.

// The outcome

A repeatable agent that works through a feed in a signed-in browser within strict budgets, leaves an auditable log, and can be stopped or tuned by editing a config file.

// Where to take it next

// Keep reading