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.