SB
Soban Bin NadeemAI ENGINEER
INDEX // ALL PROJECTS
PRODUCTION SPECIFICATION
AI Engineering / Multi-Agent OrchestrationFeatured AI Architecturegit: main

ONE AI

↳ Repository:Legacy AI

An AI agent platform built around FastAPI, MongoDB, Redis, Celery, LangGraph, custom Python orchestration, and human-in-the-loop workflows.

Repository: [LEGACY_AI_REPOSITORY_URL]@Nabos23 ↗
SYSTEM TELEMETRY & SPECIFICATIONProduction Architecture
RoleLead AI Systems Engineer
Primary FocusDynamic Multi-Agent Orchestration & HITL
Integrations
LangGraphFastAPICeleryRedisMongoDBDocker
01 // THE CHALLENGE

The Problem Context

Most AI applications are architected as static, single-track pipelines (Prompt → Agent → Tool → Response). This brittle approach collapses when business requirements demand multi-step reasoning, conditional routing based on dynamic intermediate states, parallel branch execution, or human sign-off before committing state changes.

⚠WHY THIS WAS TECHNICALLY DIFFICULT:
  • ›Static workflows cannot adapt when intermediate tools yield unexpected data formats or require alternate reasoning strategies.
  • ›Managing workflow state across asynchronous background workers (Celery) and real-time API clients requires rigorous persistence and state hydration.
  • ›Parallel branch execution introduces race conditions and complex merge semantics when multiple agents produce interdependent context.
  • ›Human-in-the-loop (HITL) checkpoints require pausing execution indefinitely without blocking thread pools or losing execution state.
02 // THE SOLUTION

Engineering Architecture

Engineered a proprietary Python-based dynamic orchestration layer where workflow routing logic is decoupled from individual agent definitions and persisted in MongoDB. Instead of relying solely on LangGraph for full-pipeline coordination, the custom engine evaluates runtime execution state, selects appropriate agent combinations dynamically, branches into parallel workers when appropriate, and halts for human approval before critical operations.

Execution Sequence:

STEP 1Incoming request is validated by FastAPI and registered as an active execution graph in MongoDB.
STEP 2The Python Orchestration Engine evaluates the initial state against registered graph rules to determine agent sequencing.
STEP 3Tasks requiring heavy computation or multi-step tool calls are offloaded to Celery workers backed by Redis.
STEP 4When dynamic conditions require multi-domain reasoning, parallel worker branches execute concurrently and merge their context into the shared state.
STEP 5Critical decision nodes trigger HITL state halts, dispatching notification webhooks and awaiting human approval before proceeding.
03 // SYSTEM TOPOLOGY

Interactive Architecture & Data Flow

The custom Python Orchestration Engine coordinates database-backed workflow state, dynamic agent transitions, parallel branches, and human approvals.

one-ai // dynamic-orchestrator-graph.v2
INBOUND EVENT:FastAPI Workflow Ingestion
hydrate state
CORE ENGINECustom Python Dynamic Orchestrator
STATUS: ACTIVE ROUTING

Decoupled transition evaluator reads dynamic step metadata from MongoDB, resolves next-hop agent dependencies, and dispatches asynchronous tasks.

MongoDBWorkflow Graph DB
RedisMessage Broker & Lock
Celery QueueDistributed Workers
dynamic agent dispatch
Agent Alpha
Intent & Guardrails
LangGraph Sub-Graph
Agent Beta
Multi-Tool Retrieval
Vector & API Query
Agent Gamma
Synthesis & Drafting
Structured Pydantic
fork: parallel execution
BRANCH #1 (CELERY ASYNC)THREAD 1
Heavy LLM Multi-Doc Reasoning & Fact Verification
BRANCH #2 (CELERY ASYNC)THREAD 2
Live Third-Party API Sync & Database Constraint Checks
barrier join & validate
HUMAN-IN-THE-LOOP (HITL) GATE
Execution suspended: awaiting operator cryptographic signature
SUSPENDED [202 ACCEPTED]
✓Committed State & Streaming Response Complete
01User / API Request

FastAPI endpoint captures request and initializes workflow session.

02Dynamic Orchestrator

Custom Python routing engine inspects current task state and selects required agents.

03Workflow State DB

MongoDB stores graph state, execution histories, and branch dependencies.

04Dynamic Agent Execution

Agents A, B, and C execute in sequence or parallel depending on state evaluation.

05Parallel Branching & Merge

Celery-backed workers run independent sub-graphs simultaneously and reconcile outputs.

06Human Approval Gate

Optional HITL suspension node pauses execution until authorized via API.

04 // ENGINEERING DEEP-DIVE

Key Technical Challenges

CHALLENGE 01

Static Workflows Are Too Restrictive

Problem:Hardcoded agent graphs cannot reconfigure themselves when real-world API responses require detour strategies.

✓ Engineering Solution:Decoupled agent execution logic from orchestration topology, storing transition rules and state schemas in MongoDB so the orchestrator can resolve next hops at runtime.
CHALLENGE 02

Dynamic Multi-Agent Routing

Problem:Determining whether one or multiple specialized agents must handle a step without cascading latency.

✓ Engineering Solution:Implemented an intent and state evaluator that determines agent dispatch arrays dynamically, supporting both sequential chaining and broadcast execution.
CHALLENGE 03

Multi-Branch & Parallel Execution

Problem:Allowing independent task components to execute simultaneously without data races.

✓ Engineering Solution:Built a Celery-based fork-join mechanism that spawns isolated tasks with unique branch identifiers and atomically merges results upon barrier completion in Redis.
CHALLENGE 04

Resilient Human-in-the-Loop (HITL)

Problem:Pausing workflows awaiting human review without keeping open socket connections or consuming active worker threads.

✓ Engineering Solution:Serializing full graph state into MongoDB with status 'AWAITING_APPROVAL', freeing workers completely until an approval API payload triggers workflow resumption.
05 // STACK & LIBRARIES

Verified Technology Stack

Languages & Core
PythonFastAPI
Backend Services
MongoDBRedisCelery
AI & Orchestration
LangGraphAI AgentsLLM APIsHuman-in-the-LoopDynamic Routing
Infrastructure
DockerLinuxGit
06 // ARCHITECTURAL TRADE-OFFS

Design Decisions & Rationales

Custom Python Orchestration alongside LangGraph

LangGraph provides strong primitives for localized graph execution, but high-level enterprise state management, multi-agent dispatch, and distributed worker queues required custom business logic.

FastAPI + Celery + Redis separation of concerns

FastAPI handles rapid request validation and response delivery, while Celery handles resource-intensive LLM tool iterations asynchronously.

07 // PRODUCTION OUTCOME

Technical Results

  • ✓Engineered an end-to-end multi-agent orchestration platform with dynamic agent sequencing.
  • ✓Implemented database-driven routing with persistent workflow state.
  • ✓Delivered parallel branch execution with reliable barrier synchronization.
  • ✓Integrated asynchronous human-in-the-loop review nodes with webhook triggers.

Lessons Learned

  • •State persistence and serialization discipline are far more important in multi-agent systems than prompt tweaking.
  • •Separating agent reasoning from orchestrator routing prevents prompt degradation as workflows scale in complexity.

Future Improvements

  • •Add interactive visual workflow canvas for non-technical operators to build custom branch rules.
  • •Implement automatic checkpoint replay for single-node failure recovery without re-running parent nodes.

Have questions about this architecture?

Let's discuss multi-agent systems, backend scaling, or custom integrations.