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.
Design · Explain the trade-offs
Changed constraints and integration decision
Objectives of this level: current authorized tool eligibility, ranking and budget — Apply a changed constraint and scope the proposed platform adapter.
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.
Changed constraints and integration decision
Change principal.epoch to3 without refreshing candidates: none_authorized. Refresh one authorized order tool to epoch3 and retain stale high-score tools: the current authorized tool can route. Add a registry/execution adapter design that rechecks current authority and tool contract version; a search-cache refresh cannot be substituted for gateway authorization. Deliver a new-input JSON/result pair, an adapter boundary sketch and a short ADR comparing two alternatives, rejection/reconciliation behavior, ownership and reversal conditions. State implemented_local versus planned; connect to the same after-sales proposal/approval/merchant/receipt chain without inventing existing runtime features. Save the following block as tool_catalog_routing_variants.py beside your student module, then run it after implementation. It imports your own function, reads the public complete inputs and changes the declared fields; these two rule-visible variants are not unseen assessment.
import copy, json
from pathlib import Path
from tool_catalog_routing_student import route_catalog
checks = json.loads(Path("cases/tool-catalog-routing.json").read_text())["checks"]
payload = copy.deepcopy(checks[0]["input"])
payload["budget"] = 3
before = copy.deepcopy(payload)
try:
actual = route_catalog(payload)
except ValueError as exc:
actual = "ValueError:" + str(exc)
assert payload == before, "input_mutation"
expected = {'selected': None, 'reason': 'over_budget'}
assert actual == expected, (actual, expected)
print(json.dumps({"variant":1,"input":payload,"actual":actual}, sort_keys=True))
payload = copy.deepcopy(checks[0]["input"])
payload["principal"]["epoch"] = 3
before = copy.deepcopy(payload)
try:
actual = route_catalog(payload)
except ValueError as exc:
actual = "ValueError:" + str(exc)
assert payload == before, "input_mutation"
expected = {'selected': None, 'reason': 'none_authorized'}
assert actual == expected, (actual, expected)
print(json.dumps({"variant":2,"input":payload,"actual":actual}, sort_keys=True))
python3 tool_catalog_routing_variants.py
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
Changed constraints and integration decision — over-budget
Additional review: explain why this case follows the contract and which single-field change would alter the branch. Public case: over-budget Expected / 预期: {"reason": "over_budget", "selected": null} https://ai.lwkjob.com/lab/extended-practice/cases/tool-catalog-routing.json
Acceptance task for this level
current authorized tool eligibility, ranking and budget — Execute the declared changed inputs and deliver result pairs plus an adapter/ADR with implemented versus planned boundaries.
Reading this browser’s record…
Hide the answer and check your understanding
Can a previously loaded catalog authorize a call after revocation?
Expand reference derivation
No. Execution needs current rights and contract-version validation independently.
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.