Review the prerequisites
Suitable for: Backend developers learning Agent applications.
- Separate discovery from execution in large tool catalogs
- Choosing the right tool requires first discovering the applicable capabilities and then calling it based on the complete contract. The discovery layer is responsible for candidate coverage, and the execution layer is responsible for permissions and parameters; error hiding tools can improve selection, but they cannot replace the server's rejection of unauthorized actions.
How does the mechanism work?
Step-by-step explanation
- What should I do if the correct tool is missed in dynamic tool retrieval?
Correct calls depend on discovering the right capability, so locate the stage where a failure occurs.
- How to score when multiple tools can accomplish it?
Tool evaluation should measure capabilities and constraints, rather than require one unique call path.
- Do directory description changes require regression?
The catalog itself is model input, so wording changes can alter the execution path.
Foundation · Understand the concepts
Mechanism before code
Objectives of this level: current authorized tool eligibility, ranking and budget — Derive eligibility and the exact branch order from concrete inputs.
Visual guide · Discover first, authorize again
A catalog snapshot finds candidates; it grants no later execution. Current registry metadata and the full tool contract must reach the execution boundary. Select the figure to open it at full size.
Mechanism before code
The after-sales task needs lookup_order, not the similarly named policy_search. A catalog is a discovery snapshot: eligibility must be established before score or cost. Stable tool identity and current authority metadata come from the registered fixture, not a description claiming read-only.
An unauthorized high-score item is not an acceptable alternative. A discoverability miss differs from a budget failure. At equal declared quality, lower cost wins; a score difference precedes cost under this declared policy. A loaded directory cannot authorize a later execution after revocation. Write a branch trace for the three inputs and create one additional legal/negative input yourself before completing the function.
Starting point and evidence
Download the source-only ZIP, extract it, and work in extended-agent-practice-v1 with lab_runner.py beside cases/. Python3.9+ standard library; no model, cloud, network or business request is made. Scaffold once in a fresh directory; it refuses overwrite. Reuse your module in later tracks. The empty template must exit1 on grade; scaffold exits0, overwrite exits2. Grade exits0 only when every fixed case passes and otherwise exits1.
- https://ai.lwkjob.com/downloads/extended-agent-practice-v1.zip
- https://ai.lwkjob.com/lab/extended-practice/lab_runner.py
- https://ai.lwkjob.com/lab/extended-practice/cases/tool-catalog-routing.json
python3 lab_runner.py scaffold --course tool-catalog-routing --out tool_catalog_routing_student.py
python3 lab_runner.py grade --course tool-catalog-routing --module tool_catalog_routing_student.py --out tool_catalog_routing_before.json
This course has12 public fixed cases. Each calls your route_catalog(payload), records input/expected/actual/error, strict JSON types, input immutability and no output-container aliases, plus module/runner/cases SHA and Python version. Inputs are complete JSON fixtures. Unknown or missing keys, null outside explicitly allowed fields, wrong types, duplicate IDs/list members where uniqueness is required raise ValueError:input_shape; booleans are not integers. Exceptions match exact class:message. Return fresh JSON values without mutating input.
Trusted identity, approvals, receipts and policy/index metadata are fixtures assembled by the exercise. In a real service the server must obtain them from authenticated/current authority sources; accepting client JSON with these labels does not authenticate it. The function is a decision over that trusted snapshot, not the adapter or race-proof enforcement.
Local function contract
payload exactly principal/request/budget/candidates. principal={tenant:nonempty str,epoch:strict positive int,enabled:strict bool}; request={tenant:nonempty str,capability:nonempty str}; budget strict nonnegative int. candidates is a list, possibly empty, with exactly id/tenant/capability(nonempty str),epoch(strict positive int),cost/score(strict nonnegative int),enabled(strict bool); IDs are globally unique. Shape errors first. Return selected=None and reason tenant_mismatch or principal_disabled first. Filter candidate tenant=current principal,epoch=current epoch,enabled=True,capability=requested. No eligible candidates gives none_authorized; eligible but none affordable(cost<=budget) gives over_budget. Rank affordable candidates by score descending,cost ascending,id ascending; return selected tool ID/reason routed. Costs/scores are fictional integers, not real prices or model confidence.
def route_catalog(payload):
raise NotImplementedError("Implement the public local contract")
Three reviewable inputs
capability-not-description
{
"principal": {
"tenant": "acme",
"epoch": 2,
"enabled": true
},
"request": {
"tenant": "acme",
"capability": "lookup_order"
},
"budget": 4,
"candidates": [
{
"id": "order_api",
"tenant": "acme",
"epoch": 2,
"capability": "lookup_order",
"cost": 4,
"score": 80,
"enabled": true
},
{
"id": "policy_search",
"tenant": "acme",
"epoch": 2,
"capability": "search_policy",
"cost": 1,
"score": 99,
"enabled": true
}
]
}
Expected / 预期: {"reason": "routed", "selected": "order_api"}
foreign-high-score
{
"principal": {
"tenant": "acme",
"epoch": 2,
"enabled": true
},
"request": {
"tenant": "acme",
"capability": "lookup_order"
},
"budget": 4,
"candidates": [
{
"id": "order_api",
"tenant": "acme",
"epoch": 2,
"capability": "lookup_order",
"cost": 4,
"score": 80,
"enabled": true
},
{
"id": "policy_search",
"tenant": "acme",
"epoch": 2,
"capability": "search_policy",
"cost": 1,
"score": 99,
"enabled": true
},
{
"id": "foreign",
"tenant": "other",
"epoch": 2,
"capability": "lookup_order",
"cost": 0,
"score": 100,
"enabled": true
}
]
}
Expected / 预期: {"reason": "routed", "selected": "order_api"}
over-budget
{
"principal": {
"tenant": "acme",
"epoch": 2,
"enabled": true
},
"request": {
"tenant": "acme",
"capability": "lookup_order"
},
"budget": 3,
"candidates": [
{
"id": "order_api",
"tenant": "acme",
"epoch": 2,
"capability": "lookup_order",
"cost": 4,
"score": 80,
"enabled": true
},
{
"id": "policy_search",
"tenant": "acme",
"epoch": 2,
"capability": "search_policy",
"cost": 1,
"score": 99,
"enabled": true
}
]
}
Expected / 预期: {"reason": "over_budget", "selected": null}
Responsibility and limits
Junior codes deterministic catalog routing and explains failures. Intermediate separates candidate recall, selection, parameter errors and business completion, with bounded rediscovery and budget records. Senior owns registry version rollout, permission revocation, cache invalidation and per-tenant budgets. This fixture ranks declared records; no model discovery or actual tool execution was measured. The four tracks are learning activities, not job ranks. Fixed authored examples and known repairs cannot prove independent diagnosis, real-world security or hiring readiness. Keep source, initial failure, personal diff, same-input rerun and a declared changed-condition result. A reviewer-new complete contract and observed personal work are separate; disclose assistance. The five-second worker guard is not a performance SLO or hostile-code sandbox.
code example
Mechanism before code — capability-not-description
Additional review: explain why this case follows the contract and which single-field change would alter the branch. Public case: capability-not-description Expected / 预期: {"reason": "routed", "selected": "order_api"} https://ai.lwkjob.com/lab/extended-practice/cases/tool-catalog-routing.json
Acceptance task for this level
current authorized tool eligibility, ranking and budget — Submit three branch traces and two personal payloads; distinguish trusted fixture fields from client/model data.
Reading this browser’s record…
Hide the answer and check your understanding
Why does policy_search fail despite score99?
Expand reference derivation
Its registered capability is search_policy, while this request is lookup_order.
Further explanations and practice
When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.
All linked explanations and exercises (1 )
Sources and verification scope
The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.