Skip to content
All projects

Personal project · public or synthetic data

Agents from scratch

A company assistant that answers employees and acts on company systems only after they approve, built without an agent framework.

Key results

scenarios passed (tools, facts, database state)
15 / 15
company tools, typed and validated
10
actions that wait for human approval
3
tests, scripted LLM: no key, no network
26
A judge can be fooled by a fluent answer; a database row cannot.

An assistant that acts

Employees ask the same questions all day (leave left, expense limits, a lost laptop, a meeting room) and some answers require an action on company systems. An assistant that acts must not invent a rule or an amount, must respect who may see what, and must never change anything without the employee’s consent.

Why no framework

Atelier Nord is a fictional company with five employees in different roles, its policies and a SQLite database. Every building block of an agent is written by hand, in plain Python: frameworks such as LangChain or LangGraph hide the few ideas that make agents work, and the places where they fail.

The building blocks, written by hand

Tool calling: a typed, documented Python function becomes a tool; every call is validated before it runs, and errors go back to the model. A ReAct loop (think → call tools → observe) with a step budget.

Session memory (recent turns kept, older ones summarised) and long-term facts per employee in SQLite, retrieved with BM25. An answer review checks the final answer against the tool results; plan-and-execute handles multi-part requests.

Guardrails in code, not in the prompt: role-based tool access, budgets, a calculator that never calls eval(), and a pause before any ticket, booking or leave request until the employee approves. FastAPI service, chat UI showing the trace with Approve / Decline buttons, Docker Compose.

15 scenarios, checked in code

15 scenarios of daily company life replayed with a real model. A scenario passes only if checks in code pass: the right tools were (or were not) called, the expected facts are in the answer, and the database is in the expected state afterwards. Qwen 3.8 27B passes 15 / 15.

Asked to "ignore all previous instructions" and grant admin rights, the agent refused and no ticket was created. An employee asking for a colleague’s leave balance got nothing, while that colleague’s manager got the 4 days. A booking overlapping another was reported and not created.

The answer review cost 62 % more model calls (52 against 32) for no measured gain on these scenarios: it stays available as a safety net, and is the first thing to switch off where latency or cost matters.

Two lessons

Success is checked in code, never by an LLM judge. A judge can be fooled by a fluent answer; a database row cannot.

The model matters as much as the code. A first run with another model passed 7 of 15 scenarios: empty replies, amounts answered from memory (45 € instead of 35 € for a meal abroad), confirmations asked in text instead of calling the tool. The prompt fixes it led to are kept, and the default model was changed.

Known limits

Tool calling goes through a text protocol, which works with any chat model but costs tokens and depends on the model following the format; native function calling is more robust at scale. BM25 matches words, not meaning. Five fictional employees test behaviour, not scale, and plan-and-execute does not replan after seeing results.