Context scoping
The rule of scoping: do not show context the LLM does not need right now. The clearest case is tool scoping: decide dynamically which tools are required for this call, and include only those, not all of them.
Why
Every tool schema costs tokens, and tools the step does not need are noise. Anthropic’s guidance on tools says more tools do not always lead to better outcomes, and that too many or overlapping tools can distract an agent from efficient strategies. Each extra tool is another wrong turn the model can take.
In LangChain
Middleware edits the request just before each model call. Here a user who is not an admin only sees tools whose name starts with read_. The decision uses the runtime context (who is asking), and the result is a shorter tool list. State, or the detected intent (see the dynamic expert agentThe dynamic expert agentPersonalize with what the agent knows about the user, then assemble the right expert for the question.Opens in a new tab), can drive the same choice.
from typing import Callablefrom langchain.agents.middleware import wrap_model_call, ModelRequest, ModelResponse @wrap_model_calldef scope_tools( request: ModelRequest, handler: Callable[[ModelRequest], ModelResponse],) -> ModelResponse: role = request.runtime.context.user_role if role != "admin": tools = [t for t in request.tools if t.name.startswith("read_")] request = request.override(tools=tools) return handler(request)Beyond tools
The same rule applies to data. A tool should return a slice, not the table: Anthropic suggests pagination, range selection, filtering or truncation, with sensible defaults. Scoping also limits what a misbehaving agent can do. A tool that is not offered cannot be called, which is why it doubles as a capability guardrail (see guardrailsLLM guardrailsChecks around the model, so a bad input or a bad output is caught by something that does not rely on the model behaving.Opens in a new tab).
Sources
- Context engineering in agents, LangChain Docs · accessed October 5, 2026
- Writing effective tools for agents, Anthropic Engineering · accessed October 5, 2026