← Back to blog
INTEGRATION8 min read

Coordinate LangChain Agents with NoLag

HB
Henco Burger
August 2, 2026

LangChain is excellent at building a single agent: prompts, tools, memory, and chains. What it does not give you is the layer above a single agent, where several agents and humans coordinate: dispatching work, sharing state, and gating actions. That is what NoLag provides. This guide connects a LangChain worker to a NoLag room so you can fan work out and collect results in realtime.

The shape

  • A dispatcher publishes tasks to a tasks topic.
  • One or more workers, each wrapping a LangChain chain, subscribe to tasks, run the chain, and publish to results.
  • Anything can watch results: a UI, a supervisor agent, or a human.

Two platform rules shape the code below. A publishing actor never receives its own messages, so the dispatcher and each worker connect with their own actor token. And every subscriber to a topic receives every message unless it opts into load balancing, so workers that should share a queue join a load-balance group.

1. Install

pip install nolag langchain langchain-openai

2. A LangChain worker on a NoLag room

import asyncio
from nolag import NoLag, NoLagOptions
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

# Build the LangChain agent (a simple summariser here)
llm = ChatOpenAI(model="gpt-4o-mini")
prompt = ChatPromptTemplate.from_template("Summarise this in one sentence:\n\n{input}")
chain = prompt | llm

async def main():
    # Every worker in the "summarisers" group shares the queue: each task
    # goes to one of them instead of all of them.
    client = NoLag(WORKER_TOKEN, NoLagOptions(
        load_balance=True,
        load_balance_group="summarisers",
    ))
    await client.connect()

    # Create the app and the "workflow" room first; the slug you get back
    # has a random suffix and that suffixed slug is what set_app() takes.
    room = client.set_app(APP_SLUG).set_room("workflow")
    await room.subscribe("tasks")

    def on_task(data, meta):
        async def run():
            result = await chain.ainvoke({"input": data["input"]})
            await room.emit("results", {
                "task_id": data["task_id"],
                "output": result.content,
            })
        asyncio.create_task(run())

    room.on("tasks", on_task)

    # Keep the worker alive
    await asyncio.Event().wait()

asyncio.run(main())

Start this process on as many machines as you like. Each instance is another member of the summarisers group, and the broker hands each task to one of them. Leave load_balance off and every instance would run every task.

3. Dispatch work

Any authorised client can publish a task. Use a different actor token from the workers, or the dispatcher will never see the results it is waiting for:

from nolag import NoLag

client = NoLag(DISPATCHER_TOKEN)
await client.connect()
room = client.set_app(APP_SLUG).set_room("workflow")

await room.subscribe("results")
room.on("results", lambda data, meta: print("done:", data["task_id"], data["output"]))

await room.emit("tasks", {
    "task_id": "t-001",
    "input": "NoLag is realtime messaging infrastructure with a coordination layer for agents.",
})

Results arrive on the results topic for anyone subscribed, so a dashboard or a supervising agent can react as they land.

Keeping a human in the loop

For steps that need sign-off, NoLag's coordination patterns include approval gates: an agent publishes a proposed action, a human approves or rejects it from a UI, and the agent proceeds only on approval. The AI agents guide covers approval gates, shared blackboard state, and observability in depth. For higher-level Python ergonomics, the nolag-agents package wraps these patterns so you do not hand-roll the topics.

Why coordinate over pub/sub

Direct orchestration, where one process calls each agent in sequence, is easy to start and hard to scale: it couples your agents together and hides what is happening. A realtime coordination layer decouples dispatch from execution, lets you add workers freely, and gives you a single stream to observe every decision. LangChain builds the agent; NoLag coordinates the system.

Next steps