I’m running into a confusing issue with LangGraph. When I try to use the response_format
parameter in the create_react_agent
function, I get this error:
TypeError: create_react_agent() got an unexpected keyword argument 'response_format'
This is strange because the documentation clearly shows this parameter should work. Has anyone else encountered this problem? I’m wondering if there’s a version mismatch or something I’m missing.
Here’s my code that’s causing the issue:
from pydantic import BaseModel, Field
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from typing import Literal
from dotenv import load_dotenv
load_dotenv()
llm = ChatOpenAI(model="gpt-4o")
class StockResponse(BaseModel):
"""Format for stock price responses."""
price: str = Field(description="Current stock price")
trend: str = Field(description="Price trend direction")
@tool
def check_stock_price(symbol: Literal["AAPL", "GOOGL"]):
"""Tool to check stock prices."""
if symbol == "AAPL":
return "Apple stock is at $150, trending up"
elif symbol == "GOOGL":
return "Google stock is at $2800, trending down"
else:
raise ValueError("Unsupported stock symbol")
prompt = "Check stock prices for the requested company."
available_tools = [check_stock_price]
agent = create_react_agent(
llm,
tools=available_tools,
response_format=StockResponse,
state_modifier=prompt
)
query = {"messages": [("user", "What's Apple's current stock price?")]}
result = agent.invoke(query)
print('result:', result)
Any ideas what might be wrong here?