liveBook · Manning

Task loop

As explained in AI Agents in Action, Second Edition

A task loop is a repeated sequence of task execution attempts that continues until a completion condition or stopping condition is reached.

A task loop repeatedly takes work from a defined queue, processes one item, records progress, and continues until the queue is empty or a stopping condition fires. Unlike a research loop, it handles known work items sequentially rather than exploring an open-ended question. section 9.2.8

Think of it as a checklist with an agent assigned to each line: the queue and decision flow remain outside the agent, while tools perform the current task. This external state supports longer workflows without requiring one internal cycle to hold everything. section 9.1.2 section 9.2.8

A reliable task loop makes these controls explicit:

  • Track completed, failed, and pending items so progress is inspectable. section 9.6
  • Retry transient failures, feed previous errors into retries, and preserve permanently failed items for review. section 9.5 section 9.6
  • Layer hard iteration and budget limits with goal, quality, and stagnation conditions. section 9.5 section 9.6
  • Use parallel processing only when items are independent, while checking rate limits. section 9.5 section 9.6

Batch-processing files

Create a queue of files, process one file per iteration with filesystem and search tools, record its result, and stop when the queue is empty or a termination condition is met. The same pattern applies to invoices, endpoint tests, document transformations, and record migrations. section 9.2.8

Figure 9.5 Workflow of a repetitive task loop agent. The agent pulls items from a task queue, processes each one using tools from MCP servers, records the result, and tracks progress until the queue is empty or a stop condition fires.

Use the workflow diagram to follow the queue-to-processing-to-result-to-progress cycle and see where termination occurs. section 9.2.8

How AI Agents in Action, Second Edition covers it

How deep it goes
Explains external queues, progress tracking, retries, termination layers, and parallelism, but not implementation internals in detail.
Examples
Uses invoice batches, document transformations, endpoint tests, file processing, retries, and sequential-versus-parallel exercises.
What it assumes
Assumes basic familiarity with agents and tools while introducing external queues, state, decisions, retries, and termination controls.
What you can do after
Build it from scratch with queued items, explicit status tracking, termination limits, retry handling, and optional parallel iteration.
How it connects
Connects task queues with agents, external state, termination conditions, retries, parallel processing, MCP servers, and orchestrator loops.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.