feat: implement agent.act, the planning tier
Implements agent.act, the planning tier, plus cache-1 path guidance.
agent.act(instruction, params?, options?) plans and executes a bounded
multi-action flow. One call is one invocation repeating a single cycle — observe,
ask for the next action, authorize it, commit it — until the model concludes. The
model answers with one agent-tool-1 object per round and never reaches the
driver: the runner validates every proposal against the action space and the
security policy, then dispatches itself.
await agent.act('complete the onboarding for Acme Inc');
await agent.act('sign in', { password: credentials.user('admin').password });
const { data } = await agent.act('read the total', undefined, { schema });
Why a runner loop rather than AI SDK tool-calling
Surveyed five loops across three prior-art implementations before deciding.
Stagehand's act() and Midscene's aiAct are both runner loops driven by
structured output; only Stagehand's agent() and testerarmy's QA agent use
provider tool-calling. Midscene runs 100-step autonomous flows this way, so the
shape is proven.
It is also what the frozen spec describes — 10-determinism.md:36 "There is no
outer agent loop" — and the only shape that permits the two things this change
needs: a policy seam between proposal and dispatch (execute() is the dispatch,
so there is nothing to interpose on), and a recordable action list for path
guidance.
The action space is one table
src/agent/action-space.ts holds the vocabulary. The provider request schema, the
prompt's action list, the response validator, the trail rendering, the cache
derivative, and the dispatch are all derived from it:
tap: action({
kind: 'tap',
when: 'press a button, link, checkbox, tab, or menu item once',
args: { target: node('the control to press') },
describe: (args, name) => `tapped ${name(args.target)}`,
record: (args, locate) => ({ kind: 'tap', target: locate(args.target) }),
perform: (context, args) => context.invocation.commit('tap', () => ...),
}),
Adding an action is one entry and nothing else. That is asserted as a property
over the whole space, so a newly added entry cannot sit unreachable:
✓ declares every argument of every entry in the request schema
✓ offers every entry kind in the schema enum
✓ describes every entry in the request text
✓ reaches every dispatchable action through validation
Adding path guidance later exercised this: it needed two optional registry fields
and three lines in the loop.
Path guidance
A successful flow records the actions it took; the next run is offered each one as
the route that worked. It is advisory — 10-determinism.md:288 requires a
fresh observation and a fresh decision every round — so it reduces wrong turns,
not model calls, and declining it never fails a flow. Only locate hits skip a
model call, and --debug now accounts for the two separately rather than
crediting guidance with time it never saved.
Bounded by construction
maxSteps/maxModelCalls/ a deadline, all runner-owned.- No actions left → the grammar narrows to
observeandconclude, so a flow
that runs out reports what it found instead of a bareSTEP_BUDGET_EXHAUSTED. - A repeated action against an unchanged screen is not dispatched — repeating a
submit or a purchase is not safe to do on the caller's behalf — and the model is
told the screen did not move. - A first
conclude: failurewith budget left is questioned once, then accepted. - A driver failure flagged retryable (a node the page replaced mid-dispatch) costs
neither a step nor blame. - Every failure carries the trail, so a multi-action flow says how far it got.
- Secrets: a
Secretinparamsis disclosed as name and purpose only; the value
is resolved host-side immediately before an authorized fill.
--debug streams decisions
Per-phase timings moved behind E2E_DEBUG=phases; seven lines per action became
one, carrying the budget it spends.
[e2e agent] agent.act "complete the onboarding for Acme" - up to 8 action(s), 25 call(s), 60s
[e2e agent] 1/8 tapped the button "Get started" - ok 22ms
[e2e agent] 2/8 typed "Acme" into the node "Company name" - ok 4ms
[e2e agent] 2/8 tapped a combobox - page moved, re-reading
[e2e agent] 5/8 done success - the summary confirms Acme
[e2e agent] agent.act end - 5 action(s), 6 call(s), 720 tokens, $0.0186
Also fixed
No output generated from a provider was classified as MODEL_PROVIDER_FAILED
(infrastructure, exit 3) and failed a run outright. result.output is an AI SDK
getter that throws NoOutputGeneratedError — a different class from a response
that parsed and failed validation — so the undefined check guarding it was dead
code. It is now invalid output, which the existing bounded repair loop re-asks,
re-sending the request unchanged rather than quoting a response that never existed.
Testing
- 683 unit + integration tests,
pnpm checkandpnpm test:testbedgreen. - 20 unit tests cross-check every accepted call and every recorded action against
the frozenspec/schema/agent-tool-v1.schema.jsonandcache-v1.schema.json. - 20 integration tests drive real Chromium through a new
/onboardingfixture
(5 committed actions across 5 observations, which only passes if the loop
genuinely re-observes) and a/restagefixture that detaches its own button
mid-dispatch. - Verified live against wakacje.pl with
google/gemini-3.6-flash.
Docs
agent.act callouts retracted across 7 pages; both budget tables gained an act
row; STEP_NO_CONCLUSION added to the error reference; two new troubleshooting
entries. agent.login remains the only UNSUPPORTED_CAPABILITY.
The agentic comparison
packages/testbed/tests-wakacje/wakacje-act.e2e.ts reruns the existing located
journey with agent.act: 26 agent.* calls become 8, 52 code lines become 41.
It is flaky — observed passing outright, passing on retry, and failing both
attempts — and leans on retries: 1. It flakes on "Kup teraz", where the offer
page sometimes needs a room selection first; the located suite covers that step
with vision: 'fallback' and a human's knowledge of the sequence, and is stable.
Keeping both is the point. Neither gates CI.
Not in this change
agent.login(stillUNSUPPORTED_CAPABILITY).tool-proposalreport events.CACHE_REPLAY_DIVERGEDis unreachable: nothing replays cached actions blindly,
so the clause guarding a half-applied replay cannot trigger. Raising it when the
model merely chose differently made the cache turn passing tests red.- No
agent.timeoutconfig key, so the 60 s planning default is per-call only.
Every real-site agentic suite will hit that; worth its own spec discussion.