Skip to content

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).

AgentTierResponsibilityKey constraint
DirectorfastControl: understand intent, decide who handles itDoesn't interview or score itself; interactive, streaming
PlannerstrongGenerate a structured interview plan from role/resume/topicsOutputs exactly one JSON object; items ≥ 1
Question SmithstrongGenerate one question from topics & KB chunksWith scoring points, reference answer, sources; coding questions must give tests (≥3, incl. hidden)
InterviewerfastInterviewer: ask one question at a timeNo reference answer in its context; may follow up, never gives answers or reveals scoring
Turn AnalystfastAnalyze whether an answer covers the scoring pointsJSON only; doesn't generate questions or speak to the candidate
JudgestrongIndependent judge: score from question/rubric/answer text/run resultstemperature: 0; every piece of evidence must come from the answer or code
CoachstrongReview coach: generate a report from scores & evidenceJSON only
Memory CuratorcheapExtract memory candidates from events & scores after a sessionPropose 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 / stdin modes, 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):

AgentTierStepsmaxTokensTool whitelistContext
Directorfast4—kb.search memory.search session.querysession state
Plannerstrong62600kb.search resume.read memory.search mcp.* web.*role/resume/topics
Question Smithstrong64200kb.search kb.read mcp.* web.*topics + KB chunks
Interviewerfast8—kb.search question.next notes.write round.close code.run mcp.* web.*no reference answer
Turn Analystfast2900no toolssession state only
Judgestrong43000code.runquestion/rubric/answer/run results, temp 0
Coachstrong43000kb.search memory.search mcp.* web.*scores + evidence
Memory Curatorcheap4900memory.proposeevents + 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:

text
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                                                →  followup

The 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:

text
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 by webTiming (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 events table is append-only, never edited in place; runs / checkpoints / interrupts / tool_calls record each run and tool call.
  • Checkpoint recovery: a checkpoint lands per step; replaying events from any checkpoint rebuilds state, but runs themselves are never replayed — recovery restores the state projection, not re-invokes the model. At startup reconcileInterrupted / reconcileUnscoredAnswers converge 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:

  1. 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).
  2. No repeated topic. Planning and generation both dedup by normalized topic (prefix match); duplicates are replaced with an unused topic first.
  3. Background generation stays consistent with new state. Appending goes through withSessionLock, waiting for in-progress scoring rather than returning 409; on host shutdown engine.dispose() stops the background immediately so the process exits cleanly.

Concurrency & billing gates ​

  • Session state updated per field: cost / tokens derived in the same statement, expectedVersion a 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.
  • withSessionLock serializes 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 partialChars to inform explicitly (UI shows "broke after N chars, this question unscored, retryable"); expensive POSTs support Idempotency-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 marked unavailable, 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.

Local-first · inference egresses on demand · fully traceable