Sharing state

Once multiple agents are working together, messages alone are not always enough. Some information needs to be visible to more than one agent at the same time. This lesson exists to orient us to how shared state fits into multi-agent systems, and why making that state explicit matters when agents must coordinate reliably over time.

Deciding what state should be shared

Not all state belongs everywhere. Shared state should be limited to information that multiple agents genuinely need in order to coordinate their behavior. This often includes progress indicators, task assignments, or shared resources, but not an agent’s private reasoning or internal bookkeeping.

The goal is clarity. If state affects more than one agent’s decisions, it should be a candidate for sharing. If it only affects one agent, keeping it local usually makes the system easier to reason about.

Representing shared state explicitly

Shared state works best when it is represented as plain, structured data. Dictionaries, lists, and simple objects are common choices because they are easy to inspect and update. What matters is that the structure makes the meaning of the data obvious.

For example, a shared task registry might be represented as a dictionary keyed by task identifier, with values describing status and ownership. This makes it clear what is shared and how other agents should interpret it.

shared_state = {
    "tasks": {
        "generate-mars-page": {
            "status": "in_progress",
            "worker": "content_agent"
        }
    }
}

Reading shared state safely

When multiple agents can see the same state, they must treat it as a source of truth, not a suggestion. Agents should read shared state before making decisions that depend on it, rather than assuming they already know the current situation.

This usually means treating shared state as read-only during decision-making. An agent first observes what is there, then decides whether an update is needed. This mental separation helps avoid accidental conflicts.

Updating shared state without corruption

Updating shared state is where coordination can break down. Changes should be deliberate, minimal, and easy to understand. An agent should update only the parts of state it is responsible for, and only when its work has reached a clear outcome.

Rather than rewriting large structures, agents typically update a small, well-defined portion of the shared state. This reduces the risk of overwriting information another agent depends on.

shared_state["tasks"]["generate-mars-page"]["status"] = "complete"

Using shared state to coordinate behavior

Once shared state is in place, agents can use it to guide their actions. A manager agent might scan shared state to see which tasks are complete. A worker agent might check whether a task is already claimed before starting work.

The shared state becomes a coordination surface. It allows agents to remain loosely coupled while still behaving as a coherent system.

Conclusion

At this point, we are oriented to why shared state exists in multi-agent systems and how it is used. We have seen how to decide what to share, how to represent it clearly, and how agents can read and update shared state without stepping on each other. With these ideas in place, shared state becomes a practical tool for coordination rather than a hidden source of complexity.