Inspiration

Every business signs contracts and then mostly forgets about them. Two things quietly go wrong: silent auto-renewal clauses lock companies into another year of unfavorable terms because nobody's tracking the notice deadline, and when a business does want to renegotiate, someone has to manually dig up the PDF, draft new language by hand, chase approvals over email, and separately chase a signature. It's slow and error-prone, and it doesn't scale past a handful of contracts.

Foxit's challenge — "Your Agent Shouldn't Sign That" — gave us the perfect lens to solve this properly. Their brief was clear: build an agent that goes from a plain prompt to a signed document, but keep signing itself outside the agent's toolset, gated behind a real human. That constraint became the whole design center of our project.

What it does

Contract Guardian is an AI agent that manages the ongoing lifecycle of a signed contract, not just a one-time drafting task.

You upload a signed contract PDF. The agent reads it — extracting party names, fee, term dates, renewal and termination clauses, and every other material section with its original numbering — and separately tracks the fields that matter for renewal risk (expiry date, auto-renewal, notice period) on a dedicated Notify dashboard, so nothing silently auto-renews unnoticed.

When you want to renegotiate, you type a plain-language request — even a multi-part one, like "extend through 2027 and move to quarterly billing." The agent drafts a real commercial-style amendment: title block, recitals, one numbered section per change citing the exact original clause being amended, ratification and signature blocks — not just a paragraph of text pasted into a PDF.

Before anything is final, you see a structured before/after diff and a full live preview of the amendment, editable Word-style, right in the browser. Only after you click Approve does the agent convert the (possibly edited) document to a real PDF and call Foxit's separate eSign API to send it to the actual signer for a legally binding signature.

How we built it

  • LangGraph orchestrates the whole pipeline as a stateful graph: extract → draft → diff → pause → route to signature. The pause is a real interrupt(), not a UI trick — execution genuinely halts and the graph's entire state is persisted to Postgres, so an approval can happen minutes or weeks later, even across a server restart.
  • Foxit's MCP server handles every reversible document operation — text extraction, PDF generation from HTML, document conversion — all called as tools by the agent.
  • Foxit's eSign API, deliberately separate from the MCP toolset, is called directly from exactly one place in the codebase: the node that only runs after a human clicks Approve.
  • Gemini does the semantic work throughout — reading raw contract text into structured fields, drafting formal amendment language into a strict template (not freeform prose), and comparing before/after states into a clean diff.
  • Next.js + Supabase for the app itself: auth, file storage, and a relational schema (contracts, amendments, agent_runs, signature_requests, contract_notifications) all protected by Row Level Security.

Challenges we ran into

  • Idempotency. Foxit's own docs warn that the eSign folder-creation endpoint isn't safe to retry — a naive retry could email a real signer a duplicate signature request. We built an explicit guard that checks for an existing signature request before ever calling the API a second time for the same amendment, and verified it holds even under a manual forced-retry test.
  • Making the pause survive real time. An in-memory checkpointer works for a demo but breaks the moment a server restarts — a real problem for something a human might approve hours or days later. Swapping to a Postgres-backed checkpointer, and proving a paused run genuinely survives a full server restart, was essential.
  • Not letting the agent overreach. Our biggest design decision was making sure the agent's autonomy stops exactly at the boundary of anything irreversible. Document drafting, comparison, even editing — all agent-assisted, zero permission needed. The moment a real signature request would go out, the code path is architecturally incapable of proceeding without a human's explicit click.
  • Generalizing beyond a toy example. Early testing on a simple sample contract worked well; testing against a denser, real-world-style vendor agreement exposed how much a rigid four-field extraction schema misses. We're honest that this is an area for continued work, not something we're pretending is solved.

Accomplishments that we're proud of

  • A genuinely working pause/resume agent, backed by real persistence, not a simulated demo.
  • A duplicate-signature-request guard that we could actually test and prove works.
  • An editable, real-time preview of the exact document that gets signed — so what you approve is guaranteed to be what gets sent.

What we learned

How much of "responsible AI agent design" comes down to where you draw irreversibility boundaries in code, not just in a policy document — and how much infrastructure (persistence, idempotency, state management) that boundary actually requires to hold up under real-world conditions like restarts and retries.

What's next for Contract Guardian

Moving from a fixed extraction schema to an open-ended clause model that generalizes to arbitrary contract types, and closing the loop on the Notify dashboard with proactive renewal-deadline alerts.

Built With

  • foxit-esign-api
  • foxit-pdf-api
  • gemini-2.5-flash
  • google-gemini
  • langchain
  • langgraph
  • mcp
  • nextjs
  • postrgresql
  • react
  • supabase
  • typescript
Share this project:

Updates

Submission history