Changes in langchain and langgraph v1
What new things have been introduced in the v1 of langgraph and langchain? Read further to discover them and learn how to use it
The langchain team released langgraph and langchain v1 last week. Here are 5 new things.
1. The new create_agent
primitive
New helper function that allows to create the agent with the tools, model and prompt.
agent = create_agent( model=ChatOpenAI(model="gpt-4o"), tools=tool_node, prompt="You are a financial assistant." )
- Middleware API.
They also added a new middleware that can be added before/after a model execution or to modify the request to a model. Doesn’t seem that intuitive at first glance, would be nice to see how they use in some of their os repos.
from langchain.agents import create_agent
from langchain.agents.middleware import SummarizationMiddleware
agent = create_agent(
model="openai:gpt-4o",
tools=[weather_tool, calculator_tool],
middleware=[
SummarizationMiddleware(
model="openai:gpt-4o-mini",
max_tokens_before_summary=4000, # Trigger summarization at 4000 tokens
messages_to_keep=20, # Keep last 20 messages after summary
summary_prompt="Custom prompt for summarization...", # Optional
),
],
)
- New structured output logic.
Now, instead of assigning the structured output to the instance of the llm, this can be specified for each tool in the agent. Like this.
def create_agent(…,
response_format: Union[
ToolStrategy[StructuredResponseT],
ProviderStrategy[StructuredResponseT],
type[StructuredResponseT],
]
New docs
Imho so far the biggest highlight of the release, much more clear and structured than before.
New Standard content blocks on messages.
Also pretty useful! Before to display a message list like Toolmessage we saw a lot of noise like multiple ids or other data that it wasn’t that relevant . This will display just the type and content. Sounds good to just debug and see things with much more clarity.
Conclusion
Very nice to see the updates of the langchain community, it seems they are giving much more focus on the tool functionalities and how to work with them.
Haven’t seen yet anything on best practices to connect nodes, which for me was one of the biggest discoveries when looking at their repos, but let’s see maybe it comes in future releases.
Related Posts
Create a chatbot: Part 4 - Adding memory
In this part we'll see how to make the chatbot to remember things in our langgraph chatbot, this will be useful so our chatbot can remember a conversation
Create a chatbot: Part 2 - Creating the FastApi endpoints
How to use langgraph to create a chatbot that is wrapped around by a fastapi istance and displayed in the frontend with React. This second part explains how to use fastapi to create the endpoints that will be accessed from the frontend
Create a chatbot: Part 1 - Creating the graph with langgraph
How to use langgraph to create a chatbot that is wrapped around by a fastapi istance and displayed in the frontend with React. This first part explains how to set up the project
Let's connect !!
Get in touch if you want updates, examples, and insights on how AI agents, Langchain and more are evolving and where they’re going next.