Wave A: pi-native tool layer — delete LhTool/toPiTool, TypeBox everywhere, terminate on questions
- src/agent/lh-tool.ts deleted: the zod-wrapped LhTool + toPiTool bridge (z.toJSONSchema per call, clientQuestion flag, hand-rolled result mapping) is gone. Tools are pi-agent-core native AgentTools now. - New src/agent/tool-execute.ts owns what the wrapper added: the abort guard (runWithAbortGuard: run signal + 30s per-call timeout + 250ms grace, 'Operation aborted' / timeout wording preserved), ToolInputError (the retryable '- problem at path' format), result mapping (string verbatim / object JSON / image parts, details rides the record's tool part output), and questionResult() — placeholder + terminate:true (owner Option A: belt of terminate + slim makeQuestionStopper with the clean-question rule; maxTurns deleted from the teaching turn entirely per owner). - All 11 tool files + tools.ts registries converted to TypeBox parameters (typebox@1.3.7, pinned to pi-agent-core's copy). zod refinements (quizInputProblems, askOptionProblems, live-nodeId) moved from schemas into execute — the model sees the same retryable error shape. - question-core + contracts/probe TypeBox-authored (single source shared with the UI); tool-parts parse seam runs the boundary's full chain (Convert → Check → Clean → refinement), fixing the live-smoke lockout: pi's boundary Value.Converts correctAnswer: 17 → '17' but the record keeps raw args, so a parse without Convert rejected a posed quiz (invisible pending question, turn ended). Pinned with the real smoke emission shape. - Subagents converted: demo-builder/researcher AgentTool-native, visual-maker/pdf-reader declaration-only pi-ai Tools with local execute fns, extraction submit schemas re-authored in TypeBox (owner option 2: zod defaults → Type.Optional + fill at the submit seam). - Accepted delta, flagged: TypeBox-native schemas skip pi's JSON-Schema primitive coercion fast path... (boundary still Value.Converts), and prober-quiz unknown keys ride through (Value.Clean strips at display). - Tests: 988 passing (was 967 at the recon baseline); tool-abort and read-tool rewritten against the native seams; question-core/question- tools/tool-parts/demos/web-search/graph-tools/plan-tree/probe-done/ tool-toggles converted to Value.Check/execute pins. Live smoke (PORT=3004, real model): native ls turn streams end-to-end; a real quiz pose (first attempt missing correctAnswer → tool-input-error → model retry → posed) terminates the turn cleanly and persists pending.
This commit is contained in:
+34
-32
@@ -15,7 +15,7 @@
|
||||
* the learner's edge sits.
|
||||
*/
|
||||
|
||||
import { z } from "zod";
|
||||
import { Type, type Static } from "typebox";
|
||||
|
||||
/** One dependency strand the planned lesson will rest on. */
|
||||
export interface ProbeStrand {
|
||||
@@ -38,41 +38,43 @@ export interface ProbeDoneInput {
|
||||
assessment: ProbeAssessment;
|
||||
}
|
||||
|
||||
// The zod schema of that input — SINGLE SOURCE OF TRUTH, lived by the tool
|
||||
// (src/agent/tools/probe.ts) and by the UI parse seam (src/core/tool-parts.ts):
|
||||
// The TypeBox schema of that input — SINGLE SOURCE OF TRUTH, lived by the
|
||||
// tool (src/agent/tools/probe.ts) and by the UI parse seam (src/core/tool-parts.ts):
|
||||
// the boundary validation and the consumer parse run literally the same
|
||||
// schema, so "schema-valid at the boundary" ⇔ "parseable by a consumer" is
|
||||
// structural, not a convention. (Live crash 2026-09-12: the model sent
|
||||
// `assessment` as a STRING; the card cast it and died on `.strands.map`.)
|
||||
export const probeDoneInputSchema = z
|
||||
.object({
|
||||
assessment: z
|
||||
.object({
|
||||
strands: z
|
||||
.array(
|
||||
z.object({
|
||||
strand: z
|
||||
.string()
|
||||
.describe(
|
||||
"The dependency strand (e.g. 'the derivative as a limit') — a name the plan can hang a node on.",
|
||||
),
|
||||
assessment: z
|
||||
.string()
|
||||
.describe(
|
||||
"Where his edge sits on this strand: the floor (what he reliably gets right), the ceiling (where it runs out), " +
|
||||
"misconceptions found, and what the lesson should build from.",
|
||||
),
|
||||
}),
|
||||
)
|
||||
.min(1)
|
||||
.describe("Every strand the planned lesson will depend on, each with your read of his edge on it."),
|
||||
summary: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Optional overall synthesis: his apparent goal and where the teaching should enter."),
|
||||
})
|
||||
.describe("The learner assessment — the probe's distilled output."),
|
||||
}) satisfies z.ZodType<ProbeDoneInput>;
|
||||
export const probeDoneInputSchema = Type.Object({
|
||||
assessment: Type.Object(
|
||||
{
|
||||
strands: Type.Array(
|
||||
Type.Object({
|
||||
strand: Type.String({
|
||||
description:
|
||||
"The dependency strand (e.g. 'the derivative as a limit') — a name the plan can hang a node on.",
|
||||
}),
|
||||
assessment: Type.String({
|
||||
description:
|
||||
"Where his edge sits on this strand: the floor (what he reliably gets right), the ceiling (where it runs out), " +
|
||||
"misconceptions found, and what the lesson should build from.",
|
||||
}),
|
||||
}),
|
||||
{ minItems: 1, description: "Every strand the planned lesson will depend on, each with your read of his edge on it." },
|
||||
),
|
||||
summary: Type.Optional(
|
||||
Type.String({
|
||||
description: "Optional overall synthesis: his apparent goal and where the teaching should enter.",
|
||||
}),
|
||||
),
|
||||
},
|
||||
{ description: "The learner assessment — the probe's distilled output." },
|
||||
),
|
||||
});
|
||||
|
||||
/** Schema ↔ interface lock (the old `satisfies z.ZodType` guarantee): the
|
||||
* declaration and ProbeDoneInput can never drift apart — this only compiles
|
||||
* when the schema's static shape IS the interface. */
|
||||
export const probeDoneSchemaLock = (v: Static<typeof probeDoneInputSchema>): ProbeDoneInput => v;
|
||||
|
||||
/** probe_done tool output. */
|
||||
export interface ProbeDoneResult {
|
||||
|
||||
Reference in New Issue
Block a user