AI User-Story Assistant for CRM
Built an AutoGen business-analyst agent that turns requirement notes into schema-conformant CRM user stories, with token streaming over WebSockets, hot/cold session persistence in Cosmos DB and tool-driven Word export.
- Role
- Backend engineer · agent, persistence & export
- Year
- 2025
- Type
- Multi-agent
- Stack
- AutoGen AgentChat · Azure OpenAI · Azure Cosmos DB · Python · FastAPI · WebSockets · React · TypeScript · python-docx · Material UI
The problem
Business analysts at an IT services company wrote detailed CRM user stories by hand from workshop notes and transcripts, so quality depended on the author. The team had a strict house table template and needed a tool that applied it consistently and asked for missing context instead of inventing it.
Architecture
- 01
Input
Requirement notes pasted or uploaded, with attachments converted to text before they reach the agent.
- 02
Auth
JWT access and refresh tokens validated on the WebSocket connection before any agent traffic flows.
- 03
Agent
A cached per-session RoundRobinGroupChat runs a streaming AssistantAgent with a 25-message buffered context and name-based termination.
- 04
Stream
ModelClientStreamingChunkEvents forwarded token by token over the WebSocket and rendered progressively with throttled React updates.
- 05
Export
The export_stories tool parses Markdown tables from agent output and builds a formatted Word grid table.
- 06
Persist
On session switch or disconnect, history and team state flush to Cosmos DB in a single transactional batch.
Engineering highlights
01
Hot/cold session persistence
Active sessions live in local files; on switch or disconnect, Q&A pairs and a session header commit to Cosmos DB in one transactional batch on a hierarchical user/assistant/session partition key, with idempotent persisted flags.
02
Concurrency-safe team management
A TeamManager caches one AutoGen team per user, assistant and session behind its own lock, per-session asyncio locks guard persistence, and a ConnectionRegistry broadcasts to multiple sockets on the same session.
03
Resumable agent state
Reopening a session rehydrates the saved AutoGen team state from a dedicated Cosmos DB container, so the agent resumes with its earlier conversational context rather than merely replaying old messages.
04
Schema-constrained generation
A prompt-defined story schema (MoSCoW priority, actors, business rules, main and exception flows) packs numbered sub-lists into single Markdown table cells, and forces a clarifying-question step before any story is generated.
05
Markdown-to-Word conversion
The export tool parses tables from agent output and maps inline strong, em and br tags to Word bold, italic and line breaks, producing a shareable grid-table document with no manual reformatting.