Inspiration

When a senior procurement manager leaves a company, they don't just take their laptop they take five years of negotiation patterns, vendor risk profiles, and contract clause precedent locked in their head. Most organizations have no systematic way to preserve this expertise. I built ProcureMind to solve this by making CockroachDB the persistent memory layer for a multi-agent AI procurement system.

What it does

ProcureMind runs a six-agent procurement workflow — Discovery, Quote Comparison, Contract Reader, Negotiation Planner, Risk, and Approval — where every thought, decision, and contract clause is persisted in CockroachDB Cloud. Unlike traditional agent systems that lose context between sessions, ProcureMind agents read from and write to six distinct memory types: semantic (vector-embedded contract clauses), episodic (procurement history), working (crash-recovery checkpoints), vendor (performance scores), quote (pricing), and audit (compliance logging).

The Contract Reader agent is the standout feature: it embeds contract clauses using all-MiniLM-L6-v2 into 384-dimensional vectors, stores them in CockroachDB with a distributed vector index, and retrieves semantically similar language from past deals, not keyword matches, meaning matches. These clauses come from the real CUAD dataset: 510 commercial contracts labeled by legal experts from the Atticus Project.

I also integrated the official CockroachDB Cloud Managed MCP Server, allowing natural language questions like "Which vendors do we have?" to be translated into live SQL against the cluster.

How we built it

  • Backend: FastAPI with SQLAlchemy connecting to CockroachDB Cloud (ap-south-1)
  • Database: CockroachDB Cloud v26.2.5 with VECTOR(384) columns and vector indexes
  • AI/LLM: Ollama running llama3.1:8b locally for zero-cost agent reasoning
  • Embeddings: sentence-transformers (all-MiniLM-L6-v2)
  • Data: CUAD dataset (real commercial contract clauses) + synthetic vendor/episode seed data
  • AWS: Amazon S3 wired into the Contract Reader agent for contract analysis artifact storage
  • MCP: Official CockroachDB Cloud MCP Server for natural language database queries

The architecture is designed so every agent checkpoint is written to agent_working_memory after each step. If an agent process dies, a new instance can recover from the exact row in CockroachDB and resume mid-task.

Challenges we ran into

The biggest challenge was wiring the official CockroachDB Cloud MCP Server. The endpoint returns Server-Sent Events (SSE: event: message\ndata: {...}), but my initial client tried to parse it as raw JSON and crashed with JSONDecodeError. I had to rewrite the HTTP client to handle SSE framing, correct the tool argument schema (database + query instead of just sql), and add the MCP API key to the Pydantic settings model so the app would boot with the key in .env.

Another challenge was the CUAD dataset integration. The raw data is structured for question-answering research, not database seeding. I wrote a transformer that maps CUAD's 41 clause-type labels into my schema, deduplicates by text similarity, generates embeddings, and bulk-loads into CockroachDB with vector index rebuilds.

Accomplishments that we're proud of

  1. Real legal data, not synthetic text. The Contract Reader searches actual liability, warranty, and termination clauses from 510 real commercial agreements. When it flags a clause as risky, it's analyzing language that real lawyers wrote.

  2. Crash recovery that actually works. I can kill the Contract Reader mid-analysis, spin up a new instance, and it resumes from clause 17 of 50 with all partial results intact — because the checkpoint is in CockroachDB, not in-memory.

  3. Official MCP Server integration. I didn't build a custom proxy. I use the managed CockroachDB Cloud MCP Server (cockroachlabs.cloud/mcp) with a service account key, and it handles SQL generation, execution, and read-only safety.

  4. Vector search that finds meaning. Searching "liability caps" returns clauses about limitation of liability even if they don't contain the word ""caps" because CockroachDB's vector index compares embeddings, not keywords.

What we learned

I learned that treating a distributed SQL database as unified agent memory is genuinely powerful. Most agent frameworks use Redis or in-memory stores for "memory." By using CockroachDB, I get persistence, global distribution, vector search, and ACID transactions in one system. I also learned that SSE parsing and JSON-RPC over HTTP are finicky but manageable with proper error handling.

What's next for ProcureMind

  • Swap Ollama for Amazon Bedrock (Claude 3.5 Sonnet) in production by changing one environment variable
  • Deploy the FastAPI app to AWS Lambda with API Gateway for a public demo URL
  • Add multi-region CockroachDB replication so procurement teams in EU and US share the same memory
  • Integrate real-time SAM.gov API for live federal procurement data

Built With

Share this project:

Updates

Submission history