liveBook · Manning

Shared lock

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

A shared lock is a synchronization mechanism that permits only one concurrent participant at a time to access a protected resource.

A shared lock lets one participant at a time access a protected resource. For subagents sharing a console, it serializes human-input requests and helps keep responses organized and correctly attributed. section 9.3

In SharedConsoleHumanInputTool, the lock coordinates concurrent prompts:

  • A class-level asyncio.Lock is shared across tool instances. section 9.3
  • The asynchronous tool acquires the lock before prompting the human. section 9.3
  • An agent_name label identifies which subagent is requesting input. section 9.3
Figure 9.9 SharedConsoleHumanInputTool introduces a shared lock so subagent tool-calls don’t race to use the shared console

Shows how a shared lock prevents subagents from racing to use the console. section 9.3

Two subagents request input

A Hailstone subagent asks for a starting number while a greeter asks for a name. Both tasks run concurrently, but their console prompts are handled one at a time. section 9.3

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

How deep it goes
Implements serialization with a class-level asyncio.Lock acquired around prompting in an asynchronous tool.
Examples
Demonstrates a Hailstone agent requesting a starting number alongside a greeter requesting a name.
What you can do after
Apply it via SharedConsoleHumanInputTool to serialize concurrent subagent requests for human input.
How it connects
Connects asyncio locks with asynchronous tools, subagents, and human-in-the-loop interaction.

Also explained in

Compare how 2 books explain shared lock →

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.