Agent Kernel & Session Lifecycle
InterviewForge doesn't use "one giant prompt for everything". It's a custom Kernel: 8 single-responsibility agents + 16 zod-validated tools + an append-only event log + checkpoints + interrupts + provenance. No fake UI or preset values — every number comes from a real run.
Orchestration overview
The 8 agents
Each agent has its own system prompt, tool whitelist, context flags, step cap and model tier (fast / strong / cheap).
| Agent | Tier | Responsibility | Key constraint |
|---|---|---|---|
| Director | fast | Control: understand intent, decide who handles it | Doesn't interview or score itself; interactive, streaming |
| Planner | strong | Generate a structured interview plan from role/resume/topics | Outputs exactly one JSON object; items ≥ 1 |
| Question Smith | strong | Generate one question from topics & KB chunks | With scoring points, reference answer, sources; coding questions must give tests (≥3, incl. hidden) |
| Interviewer | fast | Interviewer: ask one question at a time | No reference answer in its context; may follow up, never gives answers or reveals scoring |
| Turn Analyst | fast | Analyze whether an answer covers the scoring points | JSON only; doesn't generate questions or speak to the candidate |
| Judge | strong | Independent judge: score from question/rubric/answer text/run results | temperature: 0; every piece of evidence must come from the answer or code |
| Coach | strong | Review coach: generate a report from scores & evidence | JSON only |
| Memory Curator | cheap | Extract memory candidates from events & scores after a session | Propose add/update/invalidate/ignore after comparing with existing memory |
A few deliberate designs:
- The Interviewer can't see the reference answer — prevents leaking questions; scoring and asking are fully separated.
- The Judge keeps only
code.run: scoring needs the answer text and code-run results, not the corpus; a lean tool whitelist keeps the judge focused on evidence and emitting JSON reliably. - Question Smith's coding questions support
function/class/stdinmodes, restricted to locally available runtimes; cpp/java are stdin-only.
Runtime specs
Each agent's step cap, output-token cap, tool whitelist and context injection are declarative (agents.ts):
| Agent | Tier | Steps | maxTokens | Tool whitelist | Context |
|---|---|---|---|---|---|
| Director | fast | 4 | — | kb.search memory.search session.query | session state |
| Planner | strong | 6 | 2600 | kb.search resume.read memory.search mcp.* web.* | role/resume/topics |
| Question Smith | strong | 6 | 4200 | kb.search kb.read mcp.* web.* | topics + KB chunks |
| Interviewer | fast | 8 | — | kb.search question.next notes.write round.close code.run mcp.* web.* | no reference answer |
| Turn Analyst | fast | 2 | 900 | no tools | session state only |
| Judge | strong | 4 | 3000 | code.run | question/rubric/answer/run results, temp 0 |
| Coach | strong | 4 | 3000 | kb.search memory.search mcp.* web.* | scores + evidence |
| Memory Curator | cheap | 4 | 900 | memory.propose | events + scores |
ui.present exists in the tool registry but no agent whitelists it — frontend presentation is engine-driven, not left to the model's discretion.
Follow-up decisions are deterministic
After each answer a fixed decision graph (graph.ts) runs, not model free-form:
coding question and the candidate has not run any code → followup (explicitly asks to implement and click "Run Code" first)
action === 'next' or coverage ≥ threshold → next
followUps ≥ follow-up cap → next
otherwise → followupThe coverage threshold and follow-up cap come from the interviewer style (roundPolicy): calm 0.55 / 2, standard 0.62 / 2, sharp 0.75 / 3 — style only swaps constants; the guarantee that "one question is never followed up forever" is unchanged. Difficulty (1–5) applies on the generation side: low difficulty tests direct implementation and basic edges; high difficulty demands better complexity, hidden stress cases, and more edge-case traps.
The 16 tools
All zod-validated, authorized per agent whitelist:
kb.search kb.read resume.read session.query
memory.search memory.propose notes.write
question.next round.close code.run
web.search web.fetch mcp.list mcp.call
ui.present delegate- Retrieval (
kb.search/kb.read/memory.search/resume.read) goes through the retrieval pipeline. - Code (
code.run) goes through the sandbox. - Web (
web.search/web.fetch) is forced allow/deny bywebTiming(off / prepare / live / auto). - MCP (
mcp.list/mcp.call) connects external MCP servers, with tool toggles, approval and audit. - Session control (
question.next/round.close/notes.write/session.query/ui.present) drives the state machine and frontend presentation.
The tool runtime (ToolRuntime) has three guards: an idempotency cache (repeat calls with the same args return the first result), a 20 s timeout, and skipping a tool repeated > 3 times — preventing the model from looping on tools and burning budget.
Event sourcing & checkpoints
Session state isn't "a mutable object" but a projection of an append-only event log:
- The
eventstable is append-only, never edited in place;runs/checkpoints/interrupts/tool_callsrecord each run and tool call. - Checkpoint recovery: a checkpoint lands per step; replaying events from any checkpoint rebuilds state, but
runsthemselves are never replayed — recovery restores the state projection, not re-invokes the model. At startupreconcileInterrupted/reconcileUnscoredAnswersconverge interrupts and unscored answers to a consistent state. - Interrupts: user or system can interrupt at any step, with state persisted consistently.
- Provenance: every model and tool call is written to the provenance ledger; every conclusion leads back to its source.
Session lifecycle
Three design guarantees:
- The first question doesn't wait for all questions. The first question goes up front and the rest fill in in the background, so the user enters the interview immediately without waiting for full preparation (full preparation with a real model takes 26–42 s).
- No repeated topic. Planning and generation both dedup by normalized topic (prefix match); duplicates are replaced with an unused topic first.
- Background generation stays consistent with new state. Appending goes through
withSessionLock, waiting for in-progress scoring rather than returning 409; on host shutdownengine.dispose()stops the background immediately so the process exits cleanly.
Concurrency & billing gates
- Session state updated per field:
cost/tokensderived in the same statement,expectedVersiona real CAS (compare-and-swap), bounded retry on conflict — concurrent writes to different fields don't overwrite each other. - Budget enforced at billing time, not estimated up front.
IFG_MAX_CONCURRENT_SESSIONS(default 4) limits cross-session concurrency, a second gate beyond budget;IFG_PREPARE_CONCURRENCY(default 3) limits background question-fill concurrency.withSessionLockserializes writes within a session: polls every 2 s up to 120 s, waiting for in-progress scoring rather than returning 409.- Per-phase timeouts: 240 s per question preparation, 180 s per answer, 12 s for planning — a slow model never hangs a session forever.
- Conservative stream-break handling: a provider break carries
partialCharsto inform explicitly (UI shows "broke after N chars, this question unscored, retryable"); expensive POSTs supportIdempotency-Key, replay returns the first result without re-answering or re-billing. True continuation still needs provider-level support.
Single entries for scoring & reports
- Per-question scoring has one entry,
scoring.ts: the judge panel (1–3 judges, default 1) takes the median; failed runs are markedunavailable, never faking a score. Rubric, dimensions and report signing are covered in Scoring & Reports. - Reports have one assembly point,
report-builder.ts: shared by first score and rescore, filling derived fields before computing hash + HMAC.
This guarantees "the same score uses the same algorithm regardless of path", and gives citation verification a definite anchor.