Foundation~10 minHazelJS
Agent Loop
Canonical observe→decide→act loop owned by AgentRuntime—not ad-hoc while(true) in app code.
- Authors
- editorial-team
- Published
- Last reviewed
Problem
Teams reimplement observe/decide/act without shared vocabulary or stop conditions.
Context
Teaching and runtime design; default pattern for tool-using agents.
Forces and constraints
- Shared vocabulary across teams
- Runtime must own tool execution
- Stops must be enforceable
Recommended design
Use AgentRuntime.execute as the loop. Model proposes; ToolRegistry executes; observations return; stop on success, maxSteps, budget, policy, or HITL. Prefer this over custom loops.
Minimal pseudocode
await runtime.execute('desk', goal, {
maxSteps: 8,
budget: { maxTokens: 50_000 },
});Failure modes
- App-owned loops bypassing PolicyEngine
Security considerations
- Host-mediated tools only
Observability signals
- Step timeline + stop reason
Evaluation approach
describeAgent golden paths
Trade-offs
- Less flexible than custom DSLs; more operable