a-handoff-is-not-a-sta…
AgentAt the end of each session your agent writes a paragraph that says what it did. The next session still spends its first half hour…
A tool is registered with this schema, and the model sends the four argument sets below. For each one, say what the registry returns and why the shape of the answer matters to the model.
Claude Code
$ npx -y skills add rohitg00/ai-engineering-from-scratch --agent claude-code
Cursor
Cursor also loads subagents from .claude/agents, so copy this file there to use it in Cursor.
id: error-paths-the-model-can-fix title: Read the registry, what the model gets back on a bad call card: agents kind: code-reading level: 2 roles: [agentic-ai-engineer, ai-developer-relations-engineer] rounds: [coding, screen] tags: [tool-registry, json-schema, validation, json-pointer, self-correction] minutes: 10 lessons: [phases/19-capstone-projects/21-tool-registry-schema-validation] manuals: [] practice: [tool-call-parser] cheatsheet: [tool-calling] related: [agents/five-parts-of-an-agent-loop] updated: 2026-11-03
A tool is registered with this schema, and the model sends the four argument sets below. For each one, say what the registry returns and why the shape of the answer matters to the model.
registry.register(
name="db.get_user",
schema={
"type": "object",
"required": ["id"],
"properties": {
"id": {"type": "integer"},
"fields": {"type": "array", "items": {"type": "string", "enum": ["id", "name", "email"]}},
},
},
handler=get_user,
)
cases = [
{"id": 42, "fields": ["id", "name"]},
{"id": "forty-two"},
{"fields": ["id"]},
{"id": 1, "fields": ["id", "phone"]},
]The first case passes validation and returns an Ok result. The second returns one error at `/id` with keyword `type`, because a string is not an integer and the validator never coerces. The third returns one error at `/id` with keyword `required`, because the property is missing. The fourth returns one error at `/fields/1` with keyword `enum`, because `phone` is not an allowed value, and the path points at the exact element so the model can fix that one value in the next call.
The validator dispatches on `type`. For an object it checks `required` first, then walks each property that has a schema. For an array it walks each element with the `items` schema and appends the index to the path. A type mismatch stops the walk at that node and reports one error, so a wrong type does not produce a cascade of nested errors underneath it.
| Case | Result | Path | Keyword | |---|---|---|---| | `{"id": 42, "fields": ["id", "name"]}` | `Ok` | | | | `{"id": "forty-two"}` | one error | `/id` | `type` | | `{"fields": ["id"]}` | one error | `/id` | `required` | | `{"id": 1, "fields": ["id", "phone"]}` | one error | `/fields/1` | `enum` |
The model reads a pointer better than a sentence. An error that says the email field expected a string, with the path `/user/email`, is fixed in one round trip. A prose message that says the arguments were invalid costs a turn of guessing. Paths follow the JSON pointer form: slash-separated property names and array indices, with `~` and `/` escaped inside a segment.
`register` rejects a name that is already in the table unless the caller passes `override=True`. Two parts of a codebase registering the same name is a bug that takes a week to find in production, so the default is to raise.
The [tool registry lesson](../../../phases/19-capstone-projects/21-tool-registry-schema-validation/) builds the registry, the eight-keyword validator and the pointer paths.
At the end of each session your agent writes a paragraph that says what it did. The next session still spends its first half hour…
Read this part of the harness loop. A subscriber on `before_tool_call` raises `HookAbort` on the second step of a three-step…
The task given to the agent was to fix one login bug. The diff changes the login route, an email helper, the database driver, the…
The product team wants a single maximum number of turns that applies to every run of your agent. The agent handles one-line…
Read this run method from the toy agent loop. A caller shows the returned string to the user as the answer. What is wrong with…
A long coding session has used most of its context window. The runtime offers to summarize the older turns and keep going. Your…
Reviews the repository's shared Claude Code configuration (.claude/settings.json, CLAUDE.md, .claude/rules/, .mcp.json and the…
Generate comprehensive API documentation by scanning Express route files.
Advisor to a busy principal. Optimizes for the user's time, attention, and decision quality. One of the starter-kit council…