State is not being copied between sub-graphs

I’m experiencing some weird behavior.

My architecture is as follow:
I created an AI assistant that talks with the user and helps him complete a task.
For that I created 5 Sub-graphs, each responsible for a different part of the task, and they usually run sequentally.
Each sub-graph has an agent node, and tool nodes which iteratively uses them.
I also have a shared state for all the sub-graphs, lets take this for simplification:

class BaseAgenticState(MessagesState):
elements: Elements | None

So the messages, and some additional params.

The way I move between subgraphs, is once the agent decides it finishes the job, it calls a tool, which then uses COMMAND like this:

return Command(
graph=Command.PARENT,
goto=next_agent,
update=update_data,
)

Where update_data contains the updates to the state (last AI and tool message and additional items)

Now to the behavior I’m experiencing.

There are two scenarios:
Good scenario - When the agent ASKS the user if everything is ok before calling the finish tool, the entire state is being projected into the next agent. I assume this happens because I invoke the stream graph again, loading the state from the last checkpoint, which holds the entire information, and the COMMAND adds the last data to it.

Bad scenario - When the agent iteratively does the work, and decide on the same stream to call the finish tool it self without leaving the stream, then the entire state updates that happened since the stream began until the tool call just disappears, and is not projected back to the main/sub graphs, only what appears inside the COMMAND
I see the updates works inside the current subgraph, but when the COMMAND executes, we move to the next subgraph with messages and items missing from the state.

Is the normal behavior?
If so, how do I work around it? I need the entire state to be projected every time I move to another subgraph, and I don’t want to “hope” my agent will always ask the user before calling the tool.

Hi @sagi.l

imho that is a normal behavior.

Within a single execution step, state only crosses a subgraph boundary via what your node returns. When you goto a node in the parent with Command.PARENT, the parent only receives the update you include in the Command(update=...) payload. The full, in‑memory subgraph state is not implicitly copied up to the parent unless it has already been persisted at a checkpoint boundary (e.g., after an interrupt/resume or at the end of a step).

In your “finish” tool, include the full messages (and any other needed fields like elements) in Command.update before goto to the parent, or split the logic so the step ends (creating a checkpoint) before issuing the handoff.

btw, if you shared your graph, it would be easier to understand what actually happens there :slight_smile:

1 Like