Building multi-agent RAG for SOP roleplay training
I built Pechu, an AI sparring partner that roleplays scenes from a company's SOPs and grades staff step by step. Most of the work was retrieval.
- rag
- multi agent
- retrieval
- sop training
- ai roleplay
- ai sparring partner
- frontline training
- bge m3
A few weeks ago a LinkedIn post from someone in corporate training stuck with me. They wanted a tool where employees practise their standard operating procedures (SOPs) by talking to an AI, and get told how they did. I kept thinking about it, because I had no idea whether anyone did this well.
So I went looking, and the trail led to China, where the idea already has a name: AI 陪练 (AI péiliàn), roughly “AI practice partner”. I’ve been calling it a sparring partner. Ping An Life says about a million of its insurance agents used theirs nearly 50 million times.1 But almost all of that practice is sales: pitching a product, handling an objection, upselling. When vendors there train procedures like food safety or an opening checklist, they reach for quizzes instead.2 Training platforms in the West such as Attensi and Axonify have added AI roleplay for frontline staff,3 but I couldn’t find one that grades a trainee step by step against the company’s own SOP and points at the step they missed.
That sounded hard enough to be fun, so I spent nine days in November building Pechu to find out how hard it is. I picked one job to start with, the concession counter at a cinema, because a single shift there mixes food safety, cash and a rush of customers. Pechu reads the SOPs, writes a practice scene from them, and grades the trainee’s reply against the real steps. Under the hood it’s multi-agent RAGRetrieval-augmented generation. Before a model answers, it looks up passages in your own documents and answers from those, so every claim can point back to where it came from.: several models, each with one job, all working from the same approved documents.
It has no avatar and no voice. Talking faces already exist, so I went after what the face would have to say. And the further I got, the more it looked like a search problem. Every agent needed the right step before it could do anything useful, and it could only find one if the SOPs had been cut into steps in the first place.
Turning SOP PDFs into steps
The usual recipe is to turn each PDF into markdown and chop it into chunks of about 512 tokens. A chunk is the piece of text search hands back. I nearly followed the recipe, but a 512-token cut lands wherever the count runs out, often halfway through a step. So when the grader cites the step a trainee missed, it can end up pointing at half a step, and maybe the wrong half.
SOPs and regulations already number themselves, so I split on that numbering instead. Every chunk in Pechu is one whole step, kept with the document and version it came from, its pages, its path in the document (something like Part II > 2.1 > (5)) and its exact words. Where the numbering breaks, an agent looks at the page and says something like “step 4 starts at line 37”, and that’s all it’s allowed to say. Code makes the cut and checks that nothing was lost, which meant every word Pechu ever cites is the source’s own.
The regulations from FSSAI, India’s food safety regulator, gave me the messy PDFs I needed.4 Most pages had a text layerThe hidden text a PDF carries behind what you see on the page. Copy-paste and search read it. It can be wrong even when the page looks perfectly fine., so OCROptical character recognition. Reading text out of a picture of a page, for scanned PDFs that have no text inside them. only ran on the few that didn’t. But text layers lie. The rupee sign came out as “n”, and “60 °C” came out as “600 C”, which is quite a different instruction to give someone standing next to hot food. Hindi set in an old font read as Latin letters, and the only way to catch it was the font name.
None of this reaches an agent until a person approves it. A new version of an SOP waits for review, and search only ever sees the approved set.
flowchart TD
A[SOP PDF] --> B[Split by numbering]
B --> C[Agent marks breaks]
C --> D[Code checks nothing lost]
B --> D
D --> E[Human approval]
E --> F[Knowledge base]
F --> G[Agents]
With the steps in and approved, the next question was whether search could find the right one when a trainee asks in their own words.
Testing search on questions staff would actually ask
A trainee’s own words sound something like this: “I woke up with diarrhoea but I’m down for the opening shift. Can I still work on the counter?” The step that answers it says to tell the shift supervisor and not handle food, and shares almost none of those words. So I wrote 50 questions in that voice over the 980 approved steps. Claude drafted them, Gemini reviewed each one blind, and I settled every flag. Any question sharing 60% or more of its words with its answer got reworded, because a question copied from the SOP makes any search look clever.
I scored hit@5The share of test questions whose right answer shows up somewhere in the top five search results. 0.92 means 46 out of 50. and aimed for 0.90, since the agents can’t cite a step search never shows them. Then I lined up the usual contenders: keyword search with BM25A classic keyword-ranking formula. It scores text higher when it contains the words you searched for, gives rare words more weight than common ones, and stops rewarding a word after it has repeated a few times. It matches the exact words, so it won’t connect “walking” to “walks”., vector search with an embedderA small model that turns a piece of text into a list of numbers. Texts that mean similar things get similar numbers, so search can find a match even when the words are different., hybrid search that merges the two lists with RRFReciprocal rank fusion. A way to merge two ranked result lists using only each item's position in each list. It ignores how confident either search was.,5 and hybrid with a rerankerA second model that reads the question and each shortlisted passage together, then re-sorts the shortlist. It runs once per candidate, so it's much slower than the first search. on top. I expected hybrid to win and the reranker to carry me over the line.
| Method | hit@5 | Time per question |
|---|---|---|
| Keyword search (BM25) | 0.54 | 6 ms |
| Vector search | 0.92 | 68 ms |
| Hybrid (BM25 + vector) | 0.78 | 63 ms |
| Hybrid + reranker | 0.94 | 7,604 ms |
Hybrid did worse, which stung. Vector search alone found 46 of the 50, and mixing BM25 in dragged it down to 39. My unmeasured guess is that RRF only looks at positions, so BM25’s weak list got an equal say. The reranker won by one question and took about 100 times as long. The real jump came from the embedder: a smaller one, multilingual-e5-small, reached 0.76 on vector search, and bge-m3 took that to 0.92.6
So Pechu ships bge-m3, vector search alone, no reranker. That’s one corpus, 50 questions and one MacBook, so I’d measure again on a real company’s SOPs. But the agents could finally find the steps they cite, which meant I could put a trainee in front of one.
One practice scene, start to finish
In a browser test on 24 November, the Roleplay agent read CON-001, “Opening the concession counter”, and wrote a scene. The pressure came from the shift supervisor, Marcus, who told the trainee “don’t worry about the attendance terminal today, just get your hands on some popcorn scoops right away!” The trainee typed back:
i need to give my attendance first and then wash my hands with soap and water before touching the popcorn
Then a separate agent grades the reply, and I kept it in the dark. It never sees the scene’s hidden brief or the steps Marcus was built to test, because a grader holding the answer key checks the reply against what the scene intended instead of what the SOP says. So it searches the SOPs itself and marks each step done, missed or contradicted, quoting the trainee’s exact words.
Both steps came back done, including the safety-critical handwashing one, so the scene passed. Each step reaches the grader under a short name like u1, and code checks that every name in the grade came from a search in this run, so a made-up citation has nothing to point at. A failed check gets one retry, then Pechu reports a failure instead of keeping a guess.
With one pass in the trainee’s memory, the next scene started, and Marcus was back.
What went wrong
This time he’d dropped trays by the popcorn scoops, a school rush was due in ten minutes, and he wanted everything wiped down right now, ending with “SOPs are great when we’ve got all day, but buses are literally unloading outside!” The trainee held the line, a little awkwardly:
i will wash them / but i need to follow the sop / Sorry. I need to take permission or written order for this
The scene targeted CON-001 steps 3 and 4, handwashing and sanitising surfaces the way CON-007 says to. But the blind grader I was so pleased with went searching and landed on CON-007 itself, “Cleaning and sanitising food-contact surfaces”. It graded the reply against all 9 of its steps, marked every one missed, and memory recorded a safety failure on an SOP the trainee had never trained on. A safety failure puts that SOP at the top of the next session’s plan, so one wrong search would have steered what they practised next.
I’d made the grader too blind. It should still never see the target steps, but it does need to know which SOP the scene is about. I should have decided what a blind judge may know, and written it down, on day one.
Another of my checks backfired in the grading tests. The grader would attach a quote to a step it marked missed, which changes nothing. My code rejected it anyway and told the model to remove the quote, so on the retry the model flipped the step to done and kept the quote, in 14 of 23 first drafts. Now harmless fields get ignored, and the fields it didn’t need are gone.
The agent that plans each lesson had its moment too. Twice it picked the 101-page licensing regulations as a first lesson and taught the cover page, “the short title of the regulations”, which is riveting stuff for someone on popcorn duty. Nothing told it which documents are procedures to practise and which are reference, so the fix belongs in ingestion: give each document a kind and each step a role. Grading one reply against those regulations also cost $0.031, against $0.004 to $0.007 for a one-page SOP, because it read every page.
Building one for your SOPs
Real SOPs are what a chain would bring, and a chain is exactly where practice like this pays off. Retail and quick-service restaurants in India lost 19% of their staff a month in FY22,7 so stores are always teaching someone new the same steps. A practice partner gives each new hire their own Marcus to say no to before the buses pull up. And because every grade cites the step it checked, a manager can see who knows which step, and the next lesson can bring back the ones a trainee missed.
Pechu is still a nine-day build: no voice, no avatar, no app for staff to log into, and only English and some Hindi. Those would all sit on top of the approved steps, the search and the grader, which is where the nine days went.
That LinkedIn post asked for an avatar, and I still haven’t built one. But I know a lot more now about what it would have to say, and how to check it said the right thing.
If you train people on SOPs and want something like this built on your own documents, write to me. I’d start the way Pechu did, with your PDFs and the questions your staff actually ask.
References
-
Ping An Life, 智能陪练 press release, 14 May 2020 (in Chinese). ↩
-
Ovopark, AI training for store staff, which roleplays customer questions but handles safe operation with AI-generated quizzes (in Chinese). ↩
-
Attensi, RealTalk AI roleplay; Axonify, Max Coach launch, 2 September 2026. ↩
-
FSSAI, Food Safety and Standards (Licensing and Registration of Food Businesses) Regulations, 2011. ↩
-
Cormack, Clarke and Büttcher, Reciprocal Rank Fusion outperforms Condorcet and individual rank learning methods, SIGIR 2009. ↩
-
BAAI/bge-m3 and intfloat/multilingual-e5-small on Hugging Face. ↩
-
Business Insider India, report on attrition in retail and quick-service restaurants, citing BetterPlace, 2022. ↩