Closed fatih-sarioglu closed 1 week ago
@fatih-sarioglu the issue is in how you're defining the pydantic model for structured output -- see below how to fix:
class RouteResponse(BaseModel):
# next_agent: Literal[*options] <-- this won't work unless you change the `AgentState` and rest of the code to use "next_agent" field
next: Literal[*options] # <-- this is the correct way to define it to make the example work
the reason why the code is breaking is because each graph node needs to write an update to at least one of the state keys ("messages" / "next"). in this case, and the supervisor agent node should return a dictionary with the key "next" (i.e. structured output based on RouteResponse
)
def supervisor_agent(state):
supervisor_chain = prompt | llm.with_structured_output(RouteResponse)
return supervisor_chain.invoke(state) # <-- this should return {"next": <agent name>}
hope this helps!
Oh, it's a silly mistake of mine. Your solution works. Thank you, man.
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
My code is 90 percent same as the LangGraph's Supervisor code. I just want to build a simple supervisor based agentic workflow, but I got this error. I couldn't find a solution on other issues. Please help me!
System Info
annotated-types==0.7.0 anyio==4.6.0 asttokens==2.4.1 certifi==2024.8.30 charset-normalizer==3.4.0 colorama==0.4.6 comm==0.2.2 debugpy==1.8.7 decorator==5.1.1 distro==1.9.0 executing==2.1.0 h11==0.14.0 httpcore==1.0.6 httpx==0.27.2 idna==3.10 ipykernel==6.29.5 ipython==8.28.0 jedi==0.19.1 jiter==0.6.1 jsonpatch==1.33 jsonpointer==3.0.0 jupyter_client==8.6.3 jupyter_core==5.7.2 langchain-core==0.3.12 langchain-openai==0.2.3 langgraph==0.2.35 langgraph-checkpoint==2.0.1 langsmith==0.1.132 matplotlib-inline==0.1.7 msgpack==1.1.0 nest-asyncio==1.6.0 openai==1.52.0 orjson==3.10.7 packaging==24.1 parso==0.8.4 platformdirs==4.3.6 prompt_toolkit==3.0.48 psutil==6.1.0 pure_eval==0.2.3 pydantic==2.9.2 pydantic_core==2.23.4 Pygments==2.18.0 pypdf==5.0.1 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 pywin32==308 PyYAML==6.0.2 pyzmq==26.2.0 regex==2024.9.11 requests==2.32.3 requests-toolbelt==1.0.0 six==1.16.0 sniffio==1.3.1 stack-data==0.6.3 tenacity==8.5.0 tiktoken==0.8.0 tornado==6.4.1 tqdm==4.66.5 traitlets==5.14.3 typing_extensions==4.12.2 urllib3==2.2.3 wcwidth==0.2.13