pip install langchain langchain-openai★langchain(v1 agent API) pulls inlangchain-core. Add one provider package per backend:langchain-anthropic,langchain-google-genai, etc.export OPENAI_API_KEY="sk-..." # or ANTHROPIC_API_KEY, ...Provider packages read their own*_API_KEYenv var. Python 3.10–3.14 supported.from langchain.agents import create_agent from langchain.tools import tool from langchain.messages import HumanMessage, AIMessage★The v1 surface is small & flat:langchain.agents,langchain.tools,langchain.messages,langchain.chat_models.pip install "langchain[anthropic]"Extras install a matching provider package in one shot — handy for the model string"anthropic:...".
agent = create_agent( model="openai:gpt-4o", tools=[get_weather], system_prompt="You are a helpful assistant.")★The standard way to build an agent in v1: a model + tools + instructions. Replaces the oldAgentExecutorandlanggraph.prebuilt.create_react_agent.result = agent.invoke( {"messages": [{"role":"user", "content":"Weather in NYC?"}]})★State is a dict with amessageslist. The agent runs the model→tool loop until the model stops calling tools.result["messages"][-1].contentFinal answer is the last message. The full trajectory (tool calls + results) is inresult["messages"].create_agent(model, tools, system_prompt, middleware=[...], response_format=..., checkpointer=...)Key params:middleware(customize the loop),response_format(structured output),checkpointer(memory),context_schema(typed runtime context).