cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Core loop › Tool call › Which tools it sees

Agent Harness Tutorial · End to end · Zoom level 3

Which tools the model sees

The model can only ask for tools it has been shown. So the safest place to stop a forbidden action is to never show the tool at all.

Rohan's tokenclaims:readclaims:writeget_policyreadlist_policiesreadget_claimreadlist_claimsreadregister_claimwritesubmit_documentwritewithdraw_claimwriterequest_payoutwrite, waitsissue_payoutstaff only → never shown to Rohan
Seven tools come from the claims system over MCP. request_payout is a local tool in the harness that starts an approval.

Before the first trip, the harness asks the claims system for its tools and keeps only those whose required scope is in Rohan's token. The model sees 8. The one that actually pays money, issue_payout, needs a staff scope, so the model can't even ask for it. A payout can only start through request_payout, which waits for a person above ₹25,000.

The list is kept in a stable order so the model provider can cache it. It is about 500 tokens of the prompt.

Code view: input, process, output, the call stack, the classes

Goes inThe signed-in customer's identity
What happensThe claims system lists its tools, each tool's metadata becomes a spec, and only the tools this identity's scopes allow are kept and shown to the model
Comes outA scope-filtered tool registry, and the tool definitions in each model request
CALL STACK · START TO FINISHGOES IN → COMES OUT1Open the source: agent_harness/loop/__init__.py:95run(goal, *, identity, llm, tools, ...)agent_harness/loop/__init__.py:95in: the customer's goal and identityout: an Ended for the turn2Open the source: agent_harness/tools/__init__.py:106GatedTools.list_tools(identity)agent_harness/tools/__init__.py:106in: the identity and its scopesout: ToolRegistry inside an agent.tools.list span3Open the source: agent_harness/tools/mcp.py:118MCPTransport.advertised()agent_harness/tools/mcp.py:118in: nothing; sends MCP tools/listout: (specs, rejected) or ToolUnavailable4Open the source: agent_harness/tools/mcp.py:65_spec_from(tool)agent_harness/tools/mcp.py:65in: one listed tool with its metaout: ToolSpec, or ToolRejected5Open the source: agent_harness/contracts/ids.py:86Identity.may(scope)agent_harness/contracts/ids.py:86in: a tool's required_scopeout: True if the identity holds that scope6Open the source: agent_harness/loop/__init__.py:203_Run.step(step)agent_harness/loop/__init__.py:203in: the step numberout: None to continue, or an Ended7Open the source: agent_harness/loop/__init__.py:244_Run._ask(step_span)agent_harness/loop/__init__.py:244in: the run's transcript and registryout: a ModelResponse, or an Ended8Open the source: agent_harness/context/__init__.py:251model_tools(registry)agent_harness/context/__init__.py:251in: the filtered registry plus local toolsout: function definitions, in registry order9Open the source: agent_harness/llm/pydantic_ai.py:232PydanticAIClient.complete(request)agent_harness/llm/pydantic_ai.py:232in: ModelRequest with messages and toolsout: ModelResponse (text or tool calls)10Open the source: agent_harness/tools/__init__.py:124GatedTools.call(name, arguments, identity, idemp…agent_harness/tools/__init__.py:124in: a tool name the model choseout: a result, or UnknownTool if not offered11Open the source: agent_harness/contracts/tools.py:110ToolRegistry.get(name)agent_harness/contracts/tools.py:110in: the requested tool nameout: its ToolSpec, or None
Read top to bottom: each box is one function call, indented under the function that called it; the dark box is where it starts. Click a box to open its source file.
Dashed boxes are protocols (the ports) or enums; grey boxes are data models; white boxes are classes with behaviour. A dashed arrow means "implements". Click a class to open its source.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

agent_harness/tools/__init__.py:106Keep only the tools the token's scopes allow
    async def list_tools(self, identity: Identity) -> ToolRegistry:
        """The action surface for this identity.

        MCP permits `tools/list` to vary by the authorization presented, so a
        scope-filtered surface is protocol-legal rather than a local invention.
        """
        with tel.span("agent.tools.list") as span:
            specs, rejected = await self._transport.advertised()
            visible = tuple(
                s for s in specs if not s.required_scope or identity.may(s.required_scope)
            )
            self.rejected = rejected
            span.set_attribute("agent.tools.count", len(visible))
            for offered in visible:  # AACP-0026: a tool on the surface nobody calls
                tel.counters.tools_offered.add(1, {"tool": offered.name})
            span.set_attribute("agent.tools.rejected", len(rejected))
            return ToolRegistry(tools=visible)