DEV Community

RagLeap
RagLeap

Posted on

How We Built a True Agentic AI Loop in Django (ReAct Pattern)

Everyone's building "AI agents." Very few are implementing the actual ReAct pattern correctly.

Here's the core loop we use in RagLeap — and why each step matters:

# RagLeap ReAct Loop (simplified)
plan = agent.think(task, memory)       # REASON: build multi-step plan
result = agent.act(plan, workspace)    # ACT: execute real tool calls
ok = agent.verify(result, plan)        # OBSERVE: did it actually work?

if not ok:
    healed = agent.heal(result)        # HEAL: analyse what broke
    if not healed.success:
        retry_plan = agent.think(      # RE-REASON: new plan with error context
            {**task, 'error': result.message}
        )
        agent.act(retry_plan, workspace)  # RE-ACT: try again differently
Enter fullscreen mode Exit fullscreen mode

The key insight: the re-plan step injects the previous error as context. The agent doesn't just retry — it reasons about WHY it failed and builds a different plan.

What most implementations get wrong:

  1. No verification step — they assume the action succeeded
  2. Retry = same plan again (useless)
  3. No memory between attempts

Our stack:

  • Django + Celery for async agent tasks
  • Neo4j for knowledge graph / memory
  • 194 registered tool functions (email, CRM, database, voice)
  • 3-layer observability: AgentTrace DB + Guardrails + Live Dashboard

The hardest part wasn't the LLM calls — it was the adaptation loop and making sure tool calls actually executed (not just "said" they did).

Full architecture writeup: ragleap.com/blog/true-agentic-ai/
Platform: ragleap.com/agentic-ai-platform/

What's the trickiest part of your agent implementation?

Top comments (0)