Research Companion Agent
Retrieval-augmented academic assistant built on a multi-agent graph
- role
- Full-stack
- stack
- FastAPI · LangGraph · PostgreSQL · pgvector · Next.js · shadcn/ui
- status
- Internal deployment
- year
- 2026

the problem
Students repeatedly ask the same procedural questions about thesis work, internships, course material, and campus processes, and the answers are spread across official PDF documentation.

the agent graph
Two LangGraph graphs share one state schema and one Postgres checkpointer, so either can read or write any thread. The general graph is three nodes: a context manager, the model, and a tool node that loops back until no tool calls remain. The academic graph adds a router that classifies each message into one of five writing specialists and writes that choice into state, where it becomes the single source of truth for every conditional edge, including the return path out of the tool node.

five specialists
The router dispatches to a writing assistant for drafting and rewriting, a research advisor for methodology and structure, a critic for reviewing text the student wrote, a format checker for margins, pagination and bibliography rules, and a grammar specialist for Indonesian academic register. Only the research advisor gets web search and the lecturer directory; the other four share a narrower tool set. Splitting them this way keeps each prompt and tool surface smaller than a single general assistant could hold at once.
picking a mode
A thread set to auto runs a top-level classifier on every turn to choose between the two graphs. It sees a compact transcript rather than just the newest message, so a short follow-up like "make it shorter" stays on the academic graph instead of being misread as a fresh general question. Both routers fall back to a safe default when classification fails.
retrieval and citations
An answer is only worth having if the student can check it, and three decisions follow from that. Chunks are searched small and read large: a short child chunk is what the index matches, but the model receives the parent section around it, so retrieval stays precise without starving the answer of context. Semantic and keyword search run as parallel passes whose rankings are then fused, because embeddings alone miss exact wording and keyword matching alone misses anything paraphrased. And every citation resolves to a page verified against the document's own content, so following one lands on the source of the claim rather than on a filename and a guess.

grounding rules
Institutional rules are never answered from the model's own memory. They are retrieved and cited, or declared unavailable. Tool output and web results are fenced as data rather than instructions, and citations may only be minted from retrieval identifiers and used verbatim. The caller's identity is read from the run configuration rather than from the model, so a tool cannot be argued into fetching another person's records.