2026-08-22 09:06:24 +03:00
import { tool , type ToolSet } from "ai" ;
2026-08-31 19:51:17 +03:00
import { askInputSchema , quizInputSchema } from "../core/question-core.ts" ;
2026-08-31 22:16:03 +03:00
import type { ChatStore } from "../core/ports.ts" ;
2026-08-22 09:06:24 +03:00
import { jobTools } from "./tools/jobs.ts" ;
2026-08-31 22:16:03 +03:00
export { jobTools };
2026-08-22 09:06:24 +03:00
import { planTools } from "./tools/plan.ts" ;
2026-08-22 02:18:27 +03:00
/**
2026-08-22 09:06:24 +03:00
* The teacher's tools, composed per request by createTeacherTools.
2026-08-22 02:18:27 +03:00
*
2026-08-22 09:06:24 +03:00
* - questionTools (quiz / ask_user_question): CLIENT-SIDE tools (no `execute`).
* The tool call streams to the browser in `input-available` state; the
* learner answers in the dock; the client grades via question-core and
2026-08-31 19:51:17 +03:00
* sends the verdict with addToolOutput. The input schemas live in
* core/question-core (the question contract) — parameter names mirror
* the prompt docs exactly; keep them in sync.
2026-08-22 09:06:24 +03:00
* - planTools (src/agent/tools/plan.ts): SERVER-SIDE, mutate the chat's plan
* tree (needs the chatId closure — hence the per-request factory).
* - jobTools (src/agent/tools/jobs.ts): CLIENT-SIDE semantics, server-side
* fulfillment by background sub-agents (see src/core/contracts.ts).
2026-08-22 02:18:27 +03:00
*/
export const quizTool = tool ({
description :
"Ask the learner a GRADED question with a known correct answer, then instantly grade and give feedback. " +
"Use it to (1) assess what the learner already understands before teaching, and (2) run tight practice/retrieval loops after explaining. " +
"Options-only: single-select or multi-select, plus an automatic 'I don't know' choice so the learner can signal a genuine gap instead of guessing. " +
2026-09-01 01:47:47 +03:00
"correctAnswer must be the EXACT value (or label) of one of the listed options — a correctAnswer that matches no option fails validation and the call is returned to you to fix. " +
2026-08-22 02:18:27 +03:00
"No free-text answers — for non-graded questions use ask_user_question instead. " +
"Ask exactly one question per tool call; after calling, end your turn and wait for the graded result." ,
inputSchema : quizInputSchema ,
});
export const askUserQuestionTool = tool ({
description :
"Ask the learner a single question and pause until they answer. NOT graded — there is no correct answer. " +
"Use when requirements are ambiguous, preferences are needed, a decision would materially affect the lesson, " +
"or you need an open-ended response. Ask exactly one question per tool call; after calling, end your turn and wait." ,
inputSchema : askInputSchema ,
});
2026-08-22 09:06:24 +03:00
export const questionTools = {
2026-08-22 02:18:27 +03:00
quiz : quizTool ,
ask_user_question : askUserQuestionTool ,
};
2026-08-22 09:06:24 +03:00
export interface TeacherToolContext {
chatId : string ;
2026-08-31 22:16:03 +03:00
/** The storage port plan tools persist through — the composition root
* (chat-handler) injects the wired adapter; the agent layer never
* imports one. */
chatStore : ChatStore ;
2026-08-22 09:06:24 +03:00
}
/**
2026-08-31 22:16:03 +03:00
* Per-request tool registry. Plan tools close over the ctx (chatId + the
* injected ChatStore) for persistence; question and job tools are
* context-free.
2026-08-22 09:06:24 +03:00
*/
export function createTeacherTools ( ctx : TeacherToolContext ) : ToolSet {
return {
... questionTools ,
... planTools ( ctx ),
2026-08-31 22:16:03 +03:00
... jobTools (),
2026-08-22 09:06:24 +03:00
};
}