liveBook · Manning

Concurrency

As explained in Build a Multi-Agent System (from Scratch)

Concurrency is the coordination of multiple tasks whose execution can overlap in time.

Concurrency allows multiple tasks to make progress with overlapping execution. Asynchronous tools are useful for external API calls: while one waits for a result, other application code can run. section 2.1.3

In Python, an async method returns a coroutine. Await it from asynchronous code, or use asyncio.run() from synchronous code. An agent can also return an awaitable TaskHandler, allowing submitted tasks to run in the background while other work continues. section 2.1.3 section 4.2.3

These mechanisms support overlapping work at two levels:

  • An asynchronous tool call can yield while waiting for an external result. section 2.1.3
  • An agent can submit multiple tasks without blocking, and asyncio.gather can execute multiple tool calls in a step. section 4.2.3 section 4.2.3

An asynchronous tool call

A Hailstone tool implemented with AsyncBaseTool is called with await. The same non-blocking approach suits a tool that waits for weather data from an external API. section 2.1.3 section 2.1.3

Figure 2.9 Comparing synchronous and asynchronous tool executions.

Compare blocking synchronous tool execution with non-blocking asynchronous execution. section 2.1.3

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Explains asynchronous tool interfaces, coroutine and await mechanics, and agent task handling through implementation details.
Examples
Uses a weather API tool, an awaited Hailstone call, multiple tool calls, and concurrent agent tasks.
What it assumes
Introduces Python async functions, coroutines, await, and asyncio.run rather than assuming those mechanisms.
What you can do after
Apply it via Python async/await and asyncio to run waiting tool calls and agent tasks without blocking.
How it connects
Connects asynchronous programming with coroutines, event loops, asyncio, tool calls, and agent task handlers.

Also explained in

Compare how 31 books explain concurrency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Multi-Agent System (from Scratch). The section links point to the parts of the book it draws on.