Agentic chat
The planner, sequential tool executor, evidence gate, citations, and SSE response.
POST /api/chat persists a user turn, plans retrieval work, executes tools, and streams the result as Server-Sent Events.
Request lifecycle
- Prepare. Validate the request and persist the user message with its conversation.
- Plan. Keyword routing handles common intents. The optional LLM planner can decompose a question into tool calls. Plans are capped at six deduplicated steps; invalid or unavailable model output falls back to hybrid search.
- Execute. Tool steps run sequentially. Each trace entry records the tool, arguments, result, citations, error state, and elapsed time. A tool failure is recorded instead of discarding other step results.
- Collect evidence. Successful citable passages are combined and deduplicated by chunk ID. Graph facts without source passages are not presented to the generator as citable text.
- Generate and gate. The generator decides whether evidence supports an answer before answer prose is streamed. An unsupported question can be declined without emitting token events.
- Persist. The assistant turn, citations, confidence, and tool attribution are saved before the final event.
SSE event sequence
A successful stream commonly contains stage, plan, one or more step, citations, one or more token, and done. A decline can contain no token events and report supported: false. That is a refusal due to evidence, not an execution error.
Each frame has an event name and JSON data. Network reads can split a frame across multiple chunks, so clients must buffer until a complete SSE frame is available. The frontend parser in src/lib/chat.ts handles arbitrary byte boundaries.
Planner modes
PLANNER=keyword uses local routing without an LLM planning request. PLANNER=llm enables model-based decomposition with keyword rules as fallback. Both paths return a bounded sequence of tool specifications.
Follow-up detection uses conversation history for short fragments such as “what else?” or “why?”. Questions with their own substantive topic can be planned as standalone requests.
Tools and memory
The available tool surface includes hybrid search and structured college lookups for faculty, courses, facilities, timetables, and departments, as well as memory operations. Web search is a disabled stub until a provider is implemented.
The tool trace is intentionally sequential. It keeps order and evidence attribution explicit and avoids parallel load on shared local model and graph services.