Inspiration

Real-world AI agents wait. They wait for human approvals, vendor replies, API responses, and scheduled tasks. But what happens when an agent crashes while waiting? It loses everything—the analysis it performed, the emails it drafted, the context it gathered.

We were inspired by the challenge of building agents with memories that last. In finance, invoice processing often requires back-and-forth negotiations that span hours or days. An agent that can't survive a server restart is useless in production.

MemMachine's persistent memory and Neo4j's graph reasoning gave us the perfect toolkit to solve this problem.

What it does

LedgerLoop is an AI-powered invoice anomaly detection system that:

  1. Detects Price Anomalies - Uses Neo4j to query historical invoice data and identify price surges (e.g., 50% above average)

  2. Drafts Negotiation Emails - Automatically creates professional vendor communications when anomalies are detected

  3. Hibernates Mid-Task - When waiting for vendor responses, the agent saves its complete state to MemMachine and stops execution

  4. Survives Server Restarts - Kill the server, restart it—the agent's checkpoint is still there, ready to resume

  5. Resumes with Full Context - Wake the agent with the vendor's reply, and it continues exactly where it left off

Demo Scenario: Dragon Steel Trading invoices Stainless Steel 304 at $1,800/ton. Historical data shows 5 invoices at $1,200/ton. Agent detects 50% anomaly → drafts email → hibernates → survives restart → processes vendor reply → saves $3,000.

How we built it

Architecture:

  • Frontend: Next.js + TypeScript + Tailwind CSS
  • Backend: FastAPI (Python)
  • Agent: LangGraph with 6-node workflow (Ingest → Query → Detect → Draft → Hibernate → Resume)
  • Graph Database: Neo4j for vendor/product/invoice relationships and price history queries
  • Memory: MemMachine for persistent agent state and episodic memory

Key Implementation:

  1. Neo4j Schema: Created nodes (Vendor, Product, Invoice, Department) with relationships (SUPPLIES, CONTAINS, ISSUED_BY) and seeded 25 historical invoices

  2. LangGraph Agent: Built a 6-node stateful workflow where the await_vendor node triggers hibernation and process_reply handles resumption

  3. MemMachine Integration: Implemented hibernate() to serialize and persist agent state, wake() to restore it, and add_memory() for episodic learning

  4. Frontend UI: Created an interactive demo with "Load Demo Invoice" button, real-time status updates, and pre-written vendor reply options

Challenges we ran into

  1. LangGraph Routing Changes - Newer versions of LangGraph changed how conditional edges work with the END constant. We had to update our routing logic to use explicit path mapping instead of string returns.

  2. State Serialization - Ensuring the complete agent state (including analysis results, drafted emails, and negotiation context) could be serialized and restored perfectly required careful design of our state schema.

  3. Cloud Deployment - Cloud Run containers can't connect to localhost Neo4j. We had to design the system to work both locally (Docker Neo4j) and in production (Neo4j AuraDB).

  4. Demo Flow Design - Creating a demo that clearly shows the value of persistent memory required careful UX design—the "kill server, restart, checkpoint survives" moment needed to be dramatic and clear.

Accomplishments that we're proud of

  • True Hibernation/Wake Cycle - The agent genuinely survives server restarts with complete context preservation

  • Production-Ready Architecture - Clean separation between agent logic, memory operations, and API layer

  • Beautiful Demo UI - The frontend clearly visualizes the hibernation concept with status badges, analysis cards, and pre-written reply buttons

  • Real Graph Reasoning - Neo4j queries across vendor-product-invoice relationships provide genuine historical context, not just mock data

  • $3,000 Savings Demo - The demo tells a compelling story with concrete business value

What we learned

  1. Memory Persistence is Essential - Real agents need to survive interruptions. In-memory state is a liability in production.

  2. Graph Databases Excel at Historical Analysis - Neo4j's Cypher queries made price history lookups natural and fast. SQL would have been painful.

  3. LangGraph Simplifies Complex Workflows - The graph-based agent model is intuitive for multi-step processes with conditional branching.

  4. Demo Design Matters - A good demo isn't just working code—it's a story that shows the problem, the solution, and the impact.

What's next for LedgerLoop

  • LLM-Powered Invoice Parsing - Extract data from PDF/image invoices using vision models

  • Multi-Vendor Negotiations - Handle parallel negotiations with multiple vendors simultaneously

  • Slack/Email Integration - Send negotiation emails directly and receive replies via webhooks

  • Predictive Analytics - Use historical negotiation outcomes to predict vendor behavior

  • Risk Scoring - Enhance vendor risk scores based on negotiation history and payment patterns

  • Production Deployment - Deploy with Neo4j AuraDB for fully cloud-native operation

Built With

Share this project:

Updates