All B-Agent apps Home
Case study · B-Agent

B-Agent Roleplay

Practise sales conversations with an AI customer first.

Joined a team-built Next.js front end, then wrote the Python Azure Functions API and its v2 rewrite with roles and tenant isolation, added voice calls and took the app to production.

5roles, from trainee to super admin
32API tests
0–100score on every practice call
~4 scold start removed with an always-ready instance
The problem

Sales teams practise objections and difficult customers on real customers, which is costly and stressful. Managers had no consistent way to build practice scenarios or to score how a conversation went.

The approach

An AI persona plays the customer, in text or by live voice, using current product facts for that brand. After the call, a second pass scores the transcript against the scenario's criteria and writes a coaching note.

How it works

From request to answer, step by step.

  1. 01Microsoft sign-inEntra ID; API tokens kept only in HttpOnly cookies
  2. 02Scenario and personaWizard sets the customer's profile, behaviour and scoring criteria
  3. 03Product knowledgeCatalogue text synced from the brand's site or uploaded files
  4. 04Text or voiceChat turns, or WebRTC to an Azure OpenAI realtime model
  5. 05Transcript savedEvery line from text and voice stored for feedback
  6. 06AI feedbackScore from 0 to 100, strengths, improvements and next steps

What it does

  • Pick a scenario, like a price objection or a security-minded IT manager, and talk to an AI customer.
  • Talk face to face with an avatar that listens and answers out loud in Turkish, or practise by voice or text, against the clock.
  • Get a score and a coaching note: strengths, what to improve, next steps.
  • Managers build scenarios with a 5-step wizard, or let AI fill it in from one paragraph.

Under the hood

  • Talking avatars from Azure AI Speech over WebRTC: Turkish speech-to-text in, the scenario's character answers, the avatar says it with lip-sync. 15 faces to choose from.
  • The AI customer knows current product facts, synced from the brand's website and uploaded files.
  • Real-time voice over WebRTC to an Azure OpenAI realtime model, with short-lived secrets.
  • Each company's data is kept apart, with 5 roles. Tokens live only in HttpOnly cookies.
Hard problems

What took real engineering.

Problem 1

Sessions that expired mid-practice

People kept seeing a "token missing or invalid" error because a 60-minute API token lived in a one-day browser cookie, and server routes forwarded it without refreshing. I moved both tokens into HttpOnly cookies behind a proxy that refreshes them on demand, so browser code never sees a token. A per-user token version lets an admin revoke every session at once.

Problem 2

Live voice without exposing keys

Voice calls run over WebRTC straight from the browser to an Azure OpenAI realtime model. The API builds the persona prompt and asks Azure for a short-lived client secret bound to it, so the browser never holds the resource key or the prompt text. The persona speaks first when the call opens, so it feels like a real phone call.

Built with
Next.jsReactTypeScriptTailwindPythonPostgreSQLAzure OpenAI