{
  "id": 21593365,
  "title": "How to build an agent loop with SurrealDB: a task graph for AI agents",
  "url": "https://urgent.news/2026/11/24/how-to-build-an-agent-loop-with-surrealdb-a-task-graph-for-ai-agents",
  "topic": "ai",
  "section": "AI",
  "published": "2026-11-24T12:39:45.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/martinschaer/how-to-build-an-agent-loop-with-surrealdb-a-task-graph-for-ai-agents-4e1b"
  },
  "original_language": "en",
  "account": "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.",
  "summary": "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…",
  "key_points": [
    "Agent loop consists of task, completion, documentation, and task request cycle",
    "SurrealDB enforces task dependencies via directed acyclic graph (DAG)",
    "Agents claim tasks by updating status to \"inprogress\" in a single statement"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}