Agentic AI

LangChain v1: agents, tools and middleware

LangChain 1.x: create_agent, model integrations, tools, messages, structured output and middleware.

LangChain 1.x is built around agents. This module assembles one from its parts: a chat model created for any provider with one function, the messages it reads and writes, tools it can ask for, the loop that create_agent runs, answers in a schema you define, and middleware that summarises long conversations or pauses for a person's approval before a risky tool runs. Lesson 9.8, An agent in one script, puts everything together in one file with Gemini. The agent loop itself is explained in lesson 8.1; the classic chains of modules 06 and 07 still work alongside. Run the notebook cells in order, and try each practice task before you open its solution.

Lessons

  1. 1Chat models in LangChain v1What changed in LangChain v1 and the parts of an agent, init_chat_model and its model strings, OpenAI, Gemini and Groq models side by side, reasoning models and their hidden tokens, streaming, batching, and how to choose a model for an agent.
  2. 2MessagesText prompts and message lists, the four message types, what a system prompt changes, names and IDs, a conversation written by hand, token usage, a tool call and its result, the other formats LangChain accepts, and standard content blocks.
  3. 3Tools and tool callingTurning a function into a tool with @tool, the schema a model receives, bind_tools and tool_choice, reading tool_calls, one round of the tool loop by hand, how tool calling works across providers, designing tools, interview questions and two practice tasks.
  4. 4Agents with create_agentCreating an agent from a model, tools and a system prompt, the graph it builds, reading the messages it returns, string input, memory with a checkpointer and thread IDs, recursion limits, what happens when tools fail, what a run costs, interview questions and two practice tasks.
  5. 5Structured outputwith_structured_output with Pydantic models, what it builds and its three methods, keeping the raw reply, nested data, TypedDict and its traps, model profiles, structured output from an agent with Pydantic, TypedDict or a dataclass, provider and tool strategies, interview questions and two practice tasks.
  6. 6Middleware and summarisationWhat middleware is for, the six hooks and their order, the built-in middleware, SummarizationMiddleware triggered by messages, tokens or a fraction of the context window, how it counts and what it keeps, summarising versus trimming, interview questions and a practice task.
  7. 7Human approval with middlewareHumanInTheLoopMiddleware: gating a tool, the interrupt the agent returns, resuming with Command to approve, edit or reject, what the model is told in each case, the respond decision, conditional gates and per-call mode, designing approval steps, interview questions and a practice task.
  8. 8An agent in one scriptA complete agent in one script: model, tools, system prompt, summarisation and approval middleware, checkpointer, and a chat loop that resumes after each decision; how to run it, which line changes for each alternative, and practice tasks.