Urgent.News

What's breaking now, across hundreds of outlets.

AI

How to build an agent loop with SurrealDB: a task graph for AI agents

An agent loop is a cycle where an AI agent picks up a task, does the work, records the result and asks for the next task, until nothing is left. To run one safely you need a shared task list that knows what depends on what. In SurrealDB that list is a graph, and the database itself enforces the rules. Why should you care about agent loops? A single prompt gets you a single answer. An agent loop…

An agent loop is a cycle where an AI agent tackles a task, completes the work, documents the result, and then requests the next task until none remain. To run such a loop safely, you require a shared task list that understands dependencies. In SurrealDB, this list exists as a graph, and the database itself enforces the rules. Understanding agent loops is important because they turn a single prompt into a finished product, from feature specification to testing and documentation.

For engineering leaders, AI transformation experts, or product organizations, this approach separates a demo from a process-ready outcome. The loop's reliability hinges on four key questions: who is working on what, what can start now, what happened, and who approved it. SurrealDB's task graph ensures the loop is trustworthy, with each step leaving a record you can review later.

While SQL isn't necessary to grasp these answers, sharing this article with your team can help them implement agent loops. To make an agent loop reliable, the database must provide the task list. SurrealDB fits this role perfectly because tasks and their dependencies form a directed acyclic graph (DAG), allowing easy determination of what's ready and what might be blocked.

Claiming a task is a simple write operation, preventing multiple agents from working on the same task. The progress log on each task creates a comprehensive audit trail. The model starts with a single table, but it can expand to include agents, runs, and artefacts as needs grow. Tasks are defined with status, priority, assignee, progress log, and blockers—tasks that must be completed first.

The dependency graph is bidirectional thanks to the REFERENCE feature, which maintains consistency. The example project illustrates how various components depend on each other, from the API needing the data model to the release depending on tests and documentation. To determine the next task, agents query for ready tasks: those whose blockers are completed or cancelled, prioritized by urgency and creation time.

The ready queue is a dynamic query, not a static table. Agents claim tasks by updating the status to "in_progress" in a single statement, provided they still meet the "todo" criteria. SurrealDB prevents agents from taking the same task again by rejecting deletion attempts on tasks with dependent claims. To maintain the integrity of the graph, two events enforce rules: one prevents cyclic dependencies, and the other stops work with open blockers.

If an agent attempts to skip necessary steps, it receives an error, ensuring the release remains complete. For human oversight, agents mark tasks as "review," where approvals are required before downstream tasks can begin. SurrealDB's events further enforce these rules, ensuring the loop follows the defined constraints without the need for prompt-based supervision.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

Why 4h Funding Rollovers Break Cross-Exchange Perp Arbitrage Bots (and a Pure-Python Fix)

In cross-exchange perpetual funding rate arbitrage, the strategy looks deceptively simple on paper: go delta-neutral by longing the venue with the lower funding rate and shorting the venue with the higher funding rate, then collect the spread every 1, 4, or 8 hours.

  • Arbitrage bots exploit funding rate differentials between exchanges.
  • Bug silently eats taker fees at rollover points when spreads evaluated naively.
  • Fix separates full-market quotes from filtered pairs, adds exit hysteresis.

More from Tuesday 24 November →