-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
langgraph: add structured output to create_react_agent (#2848)
```python class WeatherResponse(BaseModel): """Respond to the user with this""" temperature: float = Field(description="The temperature in fahrenheit") wind_direction: str = Field( description="The direction of the wind in abbreviated form" ) wind_speed: float = Field(description="The speed of the wind in mph") @tool def get_weather(city: Literal["nyc", "sf"]): """Use this to get weather information.""" if city == "nyc": return "It is cloudy in NYC, with 5 mph winds in the North-East direction and a temperature of 70 degrees" elif city == "sf": return "It is 75 degrees and sunny in SF, with 3 mph winds in the South-East direction" else: raise AssertionError("Unknown city") model = ChatOpenAI() tools = [get_weather] agent_with_structured_output = create_react_agent(model, tools, response_format=WeatherResponse) agent_with_structured_output.invoke({"messages": [("user", "what's the weather in nyc?")]}) ``` ```pycon { 'messages': [...], 'structured_response': WeatherResponse(temperature=70.0, wind_directon='NE', wind_speed=5.0) } ```
- Loading branch information
Showing
3 changed files
with
163 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters