1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Langgraph Supervisor SDK not storing states

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am developing a langgraph agent ( Python ) using langgraph SDK,langgraph supervisor. My agent has this structure below


    1. Primary Agent ( which will route requests to the appropriate sub-agent )
      1. It doesn’t have any tools

    2. Order Agent ( which will create / update / save Orders ) - Tools below

      1. create_order( source, destination, items ) - This creates an order based on the user's request changes in a dict ( with source, destination, items as keys ) and stores it in shared State


      2. update_order( source,destination,items) - Does something similar to create_order


      3. save_order() - Fetch the dict ( Order ) from state and send to API

    The issue is with the save_order tool. I try to fetch the constructed order from the graph state, but it is always empty. I am updating the Graph state using the Command method in the create & update_order tool.

    # AgentStateSchema

    from langchain.agents import AgentState

    class AgentStateSchema(AgentState):
    draft_order: Annotated[dict, update_dicts] = {}


    # Tools

    from langchain.tools import tool,BaseTool,ToolRuntime

    @tool
    def create_order(# Some order related fields):
    # Redacted the code for brevity
    return Command(
    update={
    "draft_order" : order,
    "messages" : [
    ToolMessage(content="Created a Draft Order",tool_call_id=tool_call_id)
    ]
    }
    )

    @tool
    def update_order(# Some order related fields):
    # Redacted the code for brevity
    return Command(
    update={
    "draft_order" : updated_order,
    "messages" : [
    ToolMessage(content="Updated the Draft Order",tool_call_id=tool_call_id)
    ]
    }
    )

    @tool
    def save_order(runtime: ToolRuntime):
    # Redacted the code for brevity
    draft_order = runtime.state.get("draft_order",{}) ##### The draft_order field is always empty


    # Order Agent

    order_agent = create_agent(
    model=ChatOpenAI(model="gpt-4o",temperature=0,max_completion_tokens=None,max_retries=2),
    tools=[create_order,update_order,save_order],
    system_prompt=prompt.format(),
    name="order_agent"
    )


    # Supervisor

    primary_assistant = create_supervisor(
    agents=[
    order_agent
    ],
    model=primary_assistant_llm,
    prompt=primary_assistant_prompt,
    output_mode="full_history",
    supervisor_name="primary_assistant",
    state_schema=AgentStateSchema
    ).compile(name="primary_assistant")


    I tried to make the state to the sub-agent level, but it still gives the same error

    Continue reading...

Compartilhe esta Página