WfAi Agents

Multi-Agent Code Generation System

Challenge

AlphaCom's büro+ ERP users needed to write Workflow+ automation scripts—a task requiring knowledge of hundreds of proprietary commands with specialized syntax. The learning curve was steep, script development took hours or days, and errors were frequent.

Solution

I architected and built a multi-agent AI system where a dynamic supervisor orchestrates specialized worker agents in parallel. The system searches documentation, retrieves pattern examples, and inspects database schemas on-demand. An evidence-only validation layer ensures generated code can only use commands that have been verified through documentation search, catching hallucinations before they reach the user. Pinned file state and context-anchored editing solve the persistent problems of LLM memory drift and line number miscounting.

Result

Script generation dropped from hours to minutes. The optimized search architecture significantly reduces LLM API calls by caching and reusing search results. The evidence validation system catches hallucinations by only allowing commands found in documentation. A continuous learning pipeline captures user corrections and extracts generalizable patterns, meaning the system improves with use. The project runs in production with full observability via OpenTelemetry, Prometheus, and Grafana dashboards.

Key Highlights

  • Multi-Agent Orchestration

    A dynamic supervisor analyzes requests and spawns specialized workers in parallel—documentation search, example retrieval, and schema inspection—synthesizing results into coherent responses.

  • Intelligent Search Architecture

    Dual-layer search combining BM25 full-text and vector embeddings with Reciprocal Rank Fusion. HyDE generates hypothetical documentation for better recall, while tiered escalation and a 1000-entry embedding cache reduce API calls by ~50%.

  • Semantic Self-Verification

    A small LLM semantically extracts command calls from generated code—understanding structure rather than pattern matching. Catches ~80% of hallucinated commands that regex would miss.

  • Context-Anchored Editing

    Eliminates line number drift by using code block anchors for surgical edits. The agent provides target and replacement blocks rather than line numbers, enabling precise modifications.

  • Pinned File State

    The physical script file is read from disk on every turn, solving the LLM memory problem. The AI never relies on stale conversation memory for code state.

  • Real-Time Streaming

    SignalR WebSocket delivers tokens as generated with phase progress events. A streaming filter separates internal reasoning from user output—clean responses with full debugging capability.

  • Continuous Learning

    User corrections flow through a pipeline: capture, validation, pattern extraction, and confidence scoring. The system retrieves relevant patterns for future queries via semantic search.

  • Resilient Architecture

    Full circuit breaker pattern with state transitions and failure tracking. Per-endpoint rate limiting with multiple algorithms, LangSmith tracing for debugging, and adaptive sampling under load.

Architecture diagram of WfAi Agents multi-agent code generation system

Technology Stack

Backend
.NET 9.0
C# 12
ASP.NET Core
SignalR
Dapper
SQLite
AI
OpenAI GPT-5
Semantic Kernel
sqlite-vec
LangSmith
Frontend
Blazor
WebView2
Highlight.js
Markdown-it
Architecture
Multi-Agent Orchestration
Circuit Breaker
Rate Limiting
Event Streaming
Observability
OpenTelemetry
Prometheus
Grafana
Adaptive Sampling