Whetstone.
Build agentsBuild agents
Focus area: Build22 min

Build agents

The Build domain is create_agent, deep agents, and middleware, the high-level surface that sits on top of the LangGraph runtime. Ten questions.

Practice

Try it yourself

Quiz

The create_agent import

Which import gives you the high-level agent constructor in LangChain 1.0?

  1. Afrom langchain.agents import create_agent
  2. Bfrom langchain.experimental import create_agent_executor
  3. Cfrom langsmith import create_agent
  4. Dfrom langgraph.graph import StateGraph
Show answer

Correct answer: A — from langchain.agents import create_agent

create_agent lives in langchain.agents in LangChain 1.0; StateGraph is the lower-level LangGraph API it compiles down to. Docs: docs.langchain.com/oss/python/langchain (Build).

Quiz

Structured output

You want the agent to return a validated Pydantic object instead of free text. Which parameter do you set, and where do you read the result?

  1. Astructured=True, read result["data"]
  2. Bresponse_format=<schema>, read result["structured_response"]
  3. Cformat="json", read result["json"]
  4. Doutput_schema=<schema>, and read the parsed object at result["output"]
Show answer

Correct answer: B — response_format=<schema>, read result["structured_response"]

response_format=<schema> validates output, and you read it at result["structured_response"]. Docs: docs.langchain.com/oss/python/langchain (Build).

Quiz

What an agent is

In the create_agent mental model, what is an "agent"?

  1. AA deployment revision that has been bound to a conversation thread
  2. BA single LLM call paired with a fixed system prompt and no tools
  3. CA model calling tools in a loop until the task is complete
  4. DA LangSmith dataset combined with one or more evaluators
Show answer

Correct answer: C — A model calling tools in a loop until the task is complete

The core definition: an agent is a model calling tools in a loop until the task is complete. Docs: docs.langchain.com/oss/python/langchain (Build).

Quiz

The messages field

Which statement about the built-in messages field of AgentState is correct?

  1. AIt only exists after a checkpointer has been attached to the agent
  2. BIt stores the reference outputs that evaluators compare against
  3. CIt is overwritten with a fresh list on each and every model call
  4. DIt is append-only: new messages are added, never replaced
Show answer

Correct answer: D — It is append-only: new messages are added, never replaced

messages is append-only; new messages are added and existing ones are never replaced. Docs: docs.langchain.com/oss/python/langchain (Build).

Quiz

Once per invocation

A middleware hook that must run exactly once before the agent starts (not once per model call) is:

  1. Abefore_agent
  2. Bafter_model
  3. Cbefore_model
  4. Dwrap_model_call
Show answer

Correct answer: A — before_agent

before_agent runs once per invocation, whereas before_model runs before each model call. Docs: docs.langchain.com/oss/python/langchain/middleware (Build).

Quiz

Why wrap_model_call

What makes wrap_model_call more powerful than before_model / after_model?

  1. AIt runs on the LangSmith server rather than in your local process
  2. BIt can call the handler zero, one, or many times (short-circuit, normal, or retry)
  3. CIt is the only middleware hook that is permitted to read and also mutate the agent state
  4. DIt automatically provisions a durable checkpointer for the agent
Show answer

Correct answer: B — It can call the handler zero, one, or many times (short-circuit, normal, or retry)

Wrap hooks control the handler: calling it zero times short-circuits, once is normal, and many times retries. Docs: docs.langchain.com/oss/python/langchain/middleware (Build).

Quiz

Human approval of tools

You need a human to approve certain tool calls before they execute. Which built-in middleware, and how is it targeted?

  1. APIIMiddleware, matched by a regular expression evaluated over each message's content
  2. BSummarizationMiddleware, matched once the history passes a token count
  3. CHumanInTheLoopMiddleware, matched against each tool's .name via interrupt_on
  4. DToolRetryMiddleware, matched by the configured retry count per tool
Show answer

Correct answer: C — HumanInTheLoopMiddleware, matched against each tool's .name via interrupt_on

HumanInTheLoopMiddleware uses interrupt_on, matched against each tool's .name. Docs: docs.langchain.com/oss/python/langchain/middleware (Build).

Quiz

SummarizationMiddleware

The primary purpose of SummarizationMiddleware is:

  1. AGuardrails, by detecting and redacting PII from messages
  2. BDeployment, by bundling revisions of a graph for release
  3. CFault tolerance, by retrying model calls that fail transiently
  4. DContext management, compressing history so it fits the window
Show answer

Correct answer: D — Context management, compressing history so it fits the window

SummarizationMiddleware is a context-management primitive that compresses history. Docs: docs.langchain.com/oss/python/langchain/middleware (Build).

Quiz

Deep agent capabilities

Which are the four capabilities create_deep_agent adds on top of create_agent?

  1. APlanning (todo), a virtual filesystem, subagents, and memory
  2. BDatasets, evaluators, experiments, and dataset splits
  3. CAssistants, threads, runs, and deployment revisions
  4. DTracing, alerting, cost dashboards, and long-term data retention windows
Show answer

Correct answer: A — Planning (todo), a virtual filesystem, subagents, and memory

Deep agents add planning (a todo list), a virtual filesystem, subagents, and memory. Docs: docs.langchain.com/oss/python/deepagents (Build).

Quiz

thread_id vs context

What is the difference between passing thread_id and passing context to an agent invocation?

  1. Acontext persists across every run, whereas thread_id never does
  2. BThey are simply two aliases for the same invocation argument, and either one may be used interchangeably in every case
  3. Cthread_id scopes the persisted conversation/checkpoints; context carries per-run data read at invocation time
  4. Dthread_id is only for deployment while context is only for local runs
Show answer

Correct answer: C — thread_id scopes the persisted conversation/checkpoints; context carries per-run data read at invocation time

thread_id scopes the persisted conversation and its checkpoints; context is per-run data read at invocation time. Docs: docs.langchain.com/oss/python/langchain (Build).

Sign in to track your progress →