Multi-agent supervisor gives json related error #328

Closed
opened 2026-02-20 17:36:44 -05:00 by yindo · 4 comments
Owner

Originally created by @sfallahpour on GitHub (Nov 29, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

https://colab.research.google.com/drive/1QszbxpiFJkhWWYhBpSmDCX_3MMMeHVdd?usp=sharing#scrollTo=UiWxjTxDNNOe


    class RouteResponse(TypedDict):
        """Worker to route to next. If no workers needed, route to FINISH."""
        next: Union[Literal["FINISH"], Literal["Rag_agent"], Literal["Sql_agent"]]

Error Message and Stack Trace (if applicable)

OutputParserException: Function RouteResponse arguments:

     {
       next: "Rag_agent"
     }


     are not valid JSON. Received JSONDecodeError Expecting property name enclosed in double quotes: 
     line 2 column 3 (char 4)
     For troubleshooting, visit: 
     https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE
     For troubleshooting, visit: 
     https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE

Description

i used the multi agent supervisor code: https://github.com/langchain-ai/langgraph/discussions/683

and i created similar agentic workflow with two agents (rag and sql agent). My code is here:
https://colab.research.google.com/drive/1QszbxpiFJkhWWYhBpSmDCX_3MMMeHVdd?usp=sharing#scrollTo=XbyYy3HU3J--

and i get the error related to RouteResponse argument not generating in a json format.
even the

 class Router(TypedDict):
       """Worker to route to next. If no workers needed, route to FINISH."""
       next: Literal[*options]

gives me syntax error because of asterisk (*) which i had to replace it with

 class RouteResponse(TypedDict):
      """Worker to route to next. If no workers needed, route to FINISH."""
      next: Union[Literal["FINISH"], Literal["Rag_agent"], Literal["Sql_agent"]]

i replicated the github code as is and i got same error. So the router function instead of generating next action in json like

{'supervisor': {'next': 'Rag_agent'}})

It generates {'next': 'Rag_agent'} which is a non json format

image

System Info

langchain 0.3.7
langchain-anthropic 0.3.0
langchain-community 0.3.7
langchain-core 0.3.19
langchain-experimental 0.3.3
langchain-openai 0.2.9
langchain-text-splitters 0.3.2
langgraph 0.2.52
langgraph-checkpoint 2.0.4
langgraph-sdk 0.1.36
langsmith 0.1.143

Originally created by @sfallahpour on GitHub (Nov 29, 2024). ### Checked other resources - [x] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python https://colab.research.google.com/drive/1QszbxpiFJkhWWYhBpSmDCX_3MMMeHVdd?usp=sharing#scrollTo=UiWxjTxDNNOe class RouteResponse(TypedDict): """Worker to route to next. If no workers needed, route to FINISH.""" next: Union[Literal["FINISH"], Literal["Rag_agent"], Literal["Sql_agent"]] ``` ### Error Message and Stack Trace (if applicable) ```shell OutputParserException: Function RouteResponse arguments: { next: "Rag_agent" } are not valid JSON. Received JSONDecodeError Expecting property name enclosed in double quotes: line 2 column 3 (char 4) For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE ``` ### Description i used the multi agent supervisor code: https://github.com/langchain-ai/langgraph/discussions/683 and i created similar agentic workflow with two agents (rag and sql agent). My code is here: https://colab.research.google.com/drive/1QszbxpiFJkhWWYhBpSmDCX_3MMMeHVdd?usp=sharing#scrollTo=XbyYy3HU3J-- and i get the error related to RouteResponse argument not generating in a json format. even the class Router(TypedDict): """Worker to route to next. If no workers needed, route to FINISH.""" next: Literal[*options] gives me syntax error because of asterisk (*) which i had to replace it with class RouteResponse(TypedDict): """Worker to route to next. If no workers needed, route to FINISH.""" next: Union[Literal["FINISH"], Literal["Rag_agent"], Literal["Sql_agent"]] i replicated the github code as is and i got same error. So the router function instead of generating next action in json like {'supervisor': {'next': 'Rag_agent'}}) It generates {'next': 'Rag_agent'} which is a non json format ![image](https://github.com/user-attachments/assets/43b3b852-86b3-44b8-b49b-e0418a30d6a1) ### System Info langchain 0.3.7 langchain-anthropic 0.3.0 langchain-community 0.3.7 langchain-core 0.3.19 langchain-experimental 0.3.3 langchain-openai 0.2.9 langchain-text-splitters 0.3.2 langgraph 0.2.52 langgraph-checkpoint 2.0.4 langgraph-sdk 0.1.36 langsmith 0.1.143
yindo closed this issue 2026-02-20 17:36:44 -05:00
Author
Owner

@danielmartinscabanas commented on GitHub (Dec 3, 2024):

I think you also need to pass the arguments of the state object in the returning object of your supervisor_node, try this version below:

def supervisor_node(state: AgentState) -> AgentState:
    messages = [
        {"role": "system", "content": system_prompt},
    ] + state["messages"]
    response = llm.with_structured_output(RouteResponse).invoke(messages)
    next_ = response["next"]
    if next_ == "FINISH":
        next_ = END

    return {**state, "next": next_} # Added the `**state` here
@danielmartinscabanas commented on GitHub (Dec 3, 2024): I think you also need to pass the arguments of the state object in the returning object of your `supervisor_node`, try this version below: ``` def supervisor_node(state: AgentState) -> AgentState: messages = [ {"role": "system", "content": system_prompt}, ] + state["messages"] response = llm.with_structured_output(RouteResponse).invoke(messages) next_ = response["next"] if next_ == "FINISH": next_ = END return {**state, "next": next_} # Added the `**state` here ```
Author
Owner

@vbarda commented on GitHub (Dec 7, 2024):

@sfallahpour try replacing

class RouteResponse(TypedDict):
      """Worker to route to next. If no workers needed, route to FINISH."""
      next: Union[Literal["FINISH"], Literal["Rag_agent"], Literal["Sql_agent"]]

with

 class RouteResponse(TypedDict):
      """Worker to route to next. If no workers needed, route to FINISH."""
      next: Literal["FINISH", "Rag_agent", "Sql_agent"]

think the schema might not be created correctly with unions here

@vbarda commented on GitHub (Dec 7, 2024): @sfallahpour try replacing ```python class RouteResponse(TypedDict): """Worker to route to next. If no workers needed, route to FINISH.""" next: Union[Literal["FINISH"], Literal["Rag_agent"], Literal["Sql_agent"]] ``` with ```python class RouteResponse(TypedDict): """Worker to route to next. If no workers needed, route to FINISH.""" next: Literal["FINISH", "Rag_agent", "Sql_agent"] ``` think the schema might not be created correctly with unions here
Author
Owner

@vbarda commented on GitHub (Dec 7, 2024):

@danielmartinscabanas this is actually not necessary -- returns from the node functions are the state updates, so you don't need to manually add current state to the returned update

@vbarda commented on GitHub (Dec 7, 2024): @danielmartinscabanas this is actually not necessary -- returns from the node functions are the state updates, so you don't need to manually add current state to the returned update
Author
Owner

@vbarda commented on GitHub (Dec 17, 2024):

Will close this due to inactivity, but please let me know if this is still an issue

@vbarda commented on GitHub (Dec 17, 2024): Will close this due to inactivity, but please let me know if this is still an issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#328