Build agents
The Build domain is create_agent and its parameters, the middleware catalogue, and deep agents. This second set covers the model argument, custom state, the built-in middleware for PII, retries, tool selection, and model fallback, and the deep-agent surface (subagents, skills versus memory, sandboxes). Ten questions.
Try it yourself
Specifying the model
How do you tell create_agent which model to use?
Show answer
Correct answer: A — Pass a "provider:model" string such as "openai:gpt-5.5", or an initialized model instance
The model argument accepts a "provider:model" string (e.g. "openai:gpt-5.5") or an initialized model instance. Docs: docs.langchain.com/oss/python/langchain/agents (Build).
Custom state fields
You need the agent to track a custom field (say a call_count) that middleware can read and update across the run. What do you do?
Show answer
Correct answer: D — Subclass AgentState to add the field and pass the subclass via state_schema
To carry custom state fields, subclass AgentState and pass the subclass via state_schema; context is read-only per-run data, not mutable state. Docs: docs.langchain.com/oss/python/langchain/agents (Build).
Relationship to LangGraph
How does an agent built with create_agent relate to LangGraph?
Show answer
Correct answer: B — It compiles to a LangGraph graph and can be embedded as a node in a larger StateGraph
create_agent compiles to a LangGraph graph and its middleware hooks run inside that compiled graph, so the agent can be dropped into a larger StateGraph as a node or subgraph. Docs: docs.langchain.com/oss/python/langchain/middleware (Build).
Handling PII
Which built-in middleware detects sensitive values like emails or credit-card numbers, and how do you control what happens to a match?
Show answer
Correct answer: C — PIIMiddleware, with a strategy such as redact, mask, block, or hash
PIIMiddleware detects PII (email, credit_card, ip, and others) and its strategy chooses the handling: block, redact, mask, or hash. Docs: docs.langchain.com/oss/python/langchain/middleware/built-in (Build).
Retrying a flaky tool
A tool fails intermittently on transient errors and you want it retried automatically with exponential backoff. Which middleware fits?
Show answer
Correct answer: A — ToolRetryMiddleware, which retries a failed tool call with a growing backoff delay
ToolRetryMiddleware retries failed tool calls with exponential backoff (max_retries, backoff_factor, initial_delay). Docs: docs.langchain.com/oss/python/langchain/middleware/built-in (Build).
Narrowing many tools
Your agent is bound to sixty tools and the model sometimes picks poorly. You want to narrow the candidates before the main model call. Which middleware?
Show answer
Correct answer: B — LLMToolSelectorMiddleware, which uses an LLM to pick the relevant tools first
LLMToolSelectorMiddleware uses an LLM with structured output to select the relevant tools before the main model call (max_tools, always_include). Docs: docs.langchain.com/oss/python/langchain/middleware/built-in (Build).
Failing over to another model
Your primary model provider has an outage partway through a run and you want the agent to try a different model automatically. Which middleware, and how does it differ from retrying?
Show answer
Correct answer: C — ModelFallbackMiddleware, which tries alternate models when the primary fails
ModelFallbackMiddleware tries one or more alternate models when the primary call fails; ModelRetryMiddleware retries the same model, so fallback is the one that changes models. Docs: docs.langchain.com/oss/python/langchain/middleware/built-in (Build).
What a subagent sees
A deep agent delegates a subtask to a subagent. What does that subagent work with, and what comes back?
Show answer
Correct answer: D — It gets its own isolated context and returns one final report to the main agent
Each subagent invocation creates a new agent instance with its own context; it is stateless and returns a single final report to the main agent, quarantining the heavy subtask. Docs: docs.langchain.com/oss/python/deepagents (Build).
Skills versus memory files
In a deep agent, how does loading a SKILL.md skill differ from an AGENTS.md memory file?
Show answer
Correct answer: A — The skill''s full body loads only when a task needs it, while memory files are always loaded
A deep agent reads SKILL.md frontmatter at startup and the full skill content only when a task needs it (progressive disclosure), whereas AGENTS.md memory files are always loaded. Docs: docs.langchain.com/oss/python/deepagents (Build).
What a sandbox backend adds
You add a sandbox backend to a deep agent. What capability does that add beyond the standard filesystem tools?
Show answer
Correct answer: C — An execute tool that runs shell commands in an isolated environment
Sandbox backends expose an execute tool for running shell commands in an isolated environment; the planning tool, durable state, and self-evaluation are separate features. Docs: docs.langchain.com/oss/python/deepagents (Build).