Back to Blog
Original

How We Use Twenty CRM and GraphQL to Run AI Agent Pipelines

We replaced Salesforce with Twenty CRM, an open source alternative, and use its GraphQL API to power our entire AI agent pipeline. Here is how GraphQL makes CRM agents possible, why self-hosting matters, and what we learned deploying it for lead management.

12 April 202614 min read
How We Use Twenty CRM and GraphQL to Run AI Agent Pipelines

Last Updated: April 12, 2026

Most CRM integrations are painful. You wrestle with REST APIs that return too much data, make too many requests, and still do not give you exactly what you need. Then you try to connect an AI agent to that mess and wonder why everything feels brittle.

At Flowtivity, we self-host Twenty CRM, the open source alternative to Salesforce, and use its GraphQL API to power our entire TenderFlow lead pipeline. AI agents read leads, update stages, create companies, enrich contacts, and draft outreach emails, all through a single GraphQL endpoint. Here is why this combination works so well and what we learned along the way.

Why Did We Choose Twenty CRM?

Twenty CRM is an open source, GPL-licensed CRM backed by Y Combinator. It provides the standard CRM features you expect: companies, contacts, opportunities, tasks, notes, pipeline views, email sync, and permissions. But three things set it apart for AI agent workflows.

It is self-hosted. We run Twenty on our own VPS using Docker Compose. Our lead data, contact details, and pipeline information never leave our infrastructure. For an AI automation agency that advocates owning your stack, using a SaaS CRM would be hypocritical. Twenty lets us practice what we preach.

It has a native GraphQL API. Every CRM action, creating records, updating fields, querying relationships, filtering lists, is available through a single GraphQL endpoint. This is not a bolted-on API layer. GraphQL is how Twenty works internally. The API is the product.

It is fully customisable. Custom objects, custom fields, custom views. We extended Twenty with a TenderFlow pipeline that has 11 custom opportunity stages, from initial research through to active, lost, and excluded. No vendor approval needed. No feature request backlog. We just added it.

What Is GraphQL and Why Does It Matter for CRM Agents?

If you have not worked with GraphQL before, think of it as a query language for APIs. Instead of making multiple REST calls to different endpoints (GET /companies, GET /contacts, GET /opportunities), you send a single query that specifies exactly what you need and get back exactly that.

Here is a real example from our pipeline. An AI agent needs to find all opportunities in the OUTREACH_READY stage, along with the associated company and contact details:

query GetOutreachReadyOpps {
  opportunities(
    filter: { stage: { eq: "OUTREACH_READY" } }
    orderBy: [createdAt_DESC]
  ) {
    edges {
      node {
        id
        name
        stage
        amount
        company {
          id
          name
          domainName
        }
        pointOfContact {
          id
          firstName
          lastName
          email
        }
      }
    }
  }
}

One request. All the data. No over-fetching, no under-fetching, no joining results from five different API calls in your code.

This matters for AI agents for three specific reasons.

Token efficiency. Every API call an AI agent makes consumes tokens in its context window. REST APIs often return bloated responses with fields you do not need. GraphQL returns exactly what you ask for. Over hundreds of pipeline operations per day, this saves significant context window space.

Fewer round trips. An AI agent checking pipeline status with a REST API might need three calls: one for opportunities, one for companies, one for contacts. With GraphQL, it gets everything in one call. Fewer calls means faster execution, lower latency, and fewer chances for something to break.

Schema introspection. GraphQL APIs publish their schema, which means AI agents can discover what types, fields, and operations are available without reading documentation. The agent knows what it can query and how. This is incredibly powerful for autonomous agents that need to adapt to different data models.

How Does Our TenderFlow Pipeline Use Twenty?

Our TenderFlow pipeline is a daily AI-driven process that researches, qualifies, and reaches out to potential clients. Twenty CRM is the system of record. Here is how the pieces fit together.

Lead research. Each morning, an AI agent researches new companies that match our target profile: established businesses with 20 to 500 employees in construction, allied health, professional services, or trades. The agent finds the company website, LinkedIn presence, recent contracts, and identifies the decision maker.

CRM record creation. For each qualified lead, the agent creates three records in Twenty via GraphQL mutations: a Company record with the business details, a Person record with the decision maker's name, title, and enriched email, and an Opportunity record named "Company Name - TenderFlow" with an initial stage of RESEARCH.

Stage progression. As the pipeline progresses, the AI agent updates the opportunity stage through the CRM. RESEARCH becomes CONTACT_FOUND_NO_EMAIL. After email enrichment via Dropcontact, it becomes PROTOTYPE_BUILT. After QA validation, OUTREACH_READY. After sending the email, ACTIVE. If two follow-ups go unanswered, LOST.

Email drafting. The agent stores draft outreach emails as CRM notes attached to the opportunity. When AJ reviews and approves, the email is sent and the interaction is logged back to the CRM.

Daily QA. Another agent runs a daily validation check: query all OUTREACH_READY opportunities, verify the prototype URL returns HTTP 200, check that all four tabs work, confirm the email draft exists in the notes, and ensure the contact email is not a generic info@ address.

All of this runs through GraphQL. A single API endpoint handles every read and write operation for the entire pipeline.

What GraphQL Operations Do We Use Most?

Here are the key operations our AI agents perform daily.

Querying opportunities by stage. The most common operation. The agent needs to know what is in each pipeline stage to decide what action to take next. GraphQL filtering makes this a single query.

Creating companies and people. When a new lead enters the pipeline, the agent creates the records with all enriched data: company name, domain, industry, employee count, contact name, title, and email.

Updating opportunity stages. As leads progress through the pipeline, stages update. This is a simple mutation that also triggers downstream logic in our daily reports.

Adding notes. Outreach email drafts, research summaries, and QA results are stored as notes on the opportunity. The agent can read these later to understand context without re-researching.

Filtering and sorting. GraphQL's built-in filtering and pagination means the agent can ask specific questions: "Show me all opportunities updated in the last 48 hours that are in OUTREACH_READY stage, sorted by creation date." One query, precise results.

What Did We Learn Deploying Twenty CRM?

We have been running Twenty CRM on a Contabo VPS for several months now. Here are the practical lessons.

Docker Compose is the way to go. Twenty provides a Docker Compose setup that includes the app, PostgreSQL, and Redis. Deploying was straightforward. We run PostgreSQL on port 5433 to avoid conflicts, and the entire stack sits behind Caddy as a reverse proxy with automatic SSL.

The GraphQL rate limit is real. Twenty enforces a rate limit of 100 GraphQL tokens per 60 seconds. For human use this is never an issue. For AI agents making rapid queries, it is. We added a 0.75-second delay between API calls to stay within limits. If you are building CRM agents, plan for this from day one.

Custom stages require database access. Adding custom opportunity stages is not yet a first-class UI feature. We modified the stage enum directly in PostgreSQL and updated the field metadata in Twenty's core.fieldMetadata table. It works, but it requires database access and careful JSON handling. This will likely improve in future Twenty releases.

The REST metadata endpoint is handy. Twenty exposes a REST endpoint at /rest/metadata/fields that returns all field definitions. This is useful for AI agents that need to understand the data model without introspecting the full GraphQL schema.

Self-hosting means self-maintaining. Updates, backups, monitoring. These are your responsibility. We use automated backups of the PostgreSQL database and monitor the VPS with basic uptime checks. The tradeoff is worth it for data sovereignty, but be honest about the operational overhead.

Why Is GraphQL Better Than REST for AI Agents?

Having worked with both REST and GraphQL APIs in AI agent workflows, the difference is significant.

Schema discovery. A REST API requires external documentation. You read the docs, figure out which endpoints exist, what parameters they accept, and what they return. GraphQL publishes its schema. An AI agent can introspect the schema and know exactly what is available. This is the difference between reading a manual and having a conversation.

Flexible queries. REST endpoints return fixed data structures. If you need a different shape, you need a different endpoint or query parameters. GraphQL lets the agent specify the exact shape of the response. This flexibility is invaluable when agents need different data for different tasks.

Relationship traversal. CRM data is inherently relational. Companies have contacts. Contacts have email addresses. Opportunities have notes. In REST, traversing these relationships means multiple API calls. In GraphQL, you nest the relationships in a single query. For an AI agent that needs to understand the full context of a lead, this is dramatically more efficient.

Mutation consistency. Creating, updating, and deleting records in REST often means different endpoints with different request formats. GraphQL mutations follow a consistent pattern. Once an agent understands one mutation, it understands the pattern for all of them.

Error handling. GraphQL returns structured errors with specific fields and messages. REST error handling varies by implementation. For AI agents that need to parse and recover from errors programmatically, GraphQL's consistent error format is much easier to work with.

How Could Other Businesses Use This Pattern?

The Twenty CRM plus GraphQL plus AI agent pattern is not specific to our use case. Any business that manages contacts, leads, or customers could benefit.

Recruitment agencies could use AI agents to source candidates, enrich profiles, and track placement pipelines. GraphQL queries would pull candidate details, job requirements, and match scores in a single call.

Real estate agencies could track property inquiries, buyer preferences, and inspection schedules. AI agents could match buyers to properties and draft personalised follow-ups.

Professional services firms could manage client engagements, track deliverables, and automate status reporting. AI agents could query project status and generate client updates without human involvement.

Healthcare practices could manage patient intake, appointment scheduling, and follow-up workflows. AI agents could handle routine communications and flag cases that need human attention.

The pattern is the same: Twenty CRM as the system of record, GraphQL as the API layer, and AI agents as the workforce that keeps the pipeline moving.

What Does the Future Hold for CRM Agents?

We are early in this space, but the direction is clear. CRM agents will become standard. Not as chatbots that answer questions about your pipeline, but as autonomous workers that actively manage it.

Proactive pipeline management. Agents that notice a lead has not been contacted in five days and send a follow-up without being asked. Agents that detect a high-value opportunity stalling and escalate it to a human.

Cross-system intelligence. Agents that combine CRM data with email analytics, website behaviour, and financial data to prioritise leads by genuine buying intent rather than arbitrary stage labels.

Natural language CRM operations. Instead of writing GraphQL queries, you tell your agent "show me all construction companies in Queensland that we have not contacted in two weeks" and it translates that into the right query, executes it, and presents the results.

Automated reporting. Agents that generate weekly pipeline reports, identify trends, and surface insights without anyone asking. "Your response rate from allied health leads dropped 15% this week. Here is why."

Twenty CRM's GraphQL API makes all of this possible today. The tools exist. The API is open. The agents are ready.

Getting Started with Twenty CRM and GraphQL

If you want to explore this stack:

Self-host Twenty. Clone the repository, run Docker Compose, and you have a full CRM running on your own infrastructure in minutes.

Explore the GraphQL playground. Twenty includes a built-in GraphQL playground (typically at /graphql) where you can write and test queries interactively. Start with simple queries and build up.

Connect an AI agent. Use any agent framework (we use OpenClaw) to make authenticated GraphQL requests. Start with read-only queries to understand the data model, then add mutations for writes.

Build your pipeline. Define your custom stages, create your opportunity flow, and let the agents start managing it.

The official Twenty CRM repository is at github.com/twentycrm/twenty. It is GPL-licensed, actively maintained, and backed by a growing community.


Frequently Asked Questions

What is Twenty CRM?

Twenty CRM is an open source CRM platform licensed under GPL. It provides standard CRM features including companies, contacts, opportunities, tasks, notes, email sync, and pipeline management. Unlike Salesforce or HubSpot, Twenty is designed to be self-hosted, giving businesses full control over their customer data. It is backed by Y Combinator and built with a native GraphQL API as its primary interface.

Why is GraphQL better than REST for CRM integrations?

GraphQL lets you specify exactly what data you need in a single request. REST requires multiple calls to different endpoints and often returns more data than necessary. For AI agents that need to traverse relationships (companies to contacts to opportunities to notes), GraphQL's nested query structure is dramatically more efficient in terms of round trips, latency, and token consumption.

Can AI agents autonomously manage a CRM pipeline?

Yes. Using Twenty CRM's GraphQL API, AI agents can query pipeline status, create and update records, move opportunities between stages, draft notes, and trigger outreach workflows. We run a daily pipeline where agents research leads, enrich contacts, build prototypes, draft emails, and manage follow-ups, all through a single GraphQL endpoint.

How do you self-host Twenty CRM?

Twenty CRM runs via Docker Compose, which includes the application, PostgreSQL database, and Redis. You deploy it on any VPS, configure a reverse proxy (we use Caddy) with SSL, and connect your domain. The entire setup takes under an hour. You are responsible for updates, backups, and monitoring.

What rate limits does Twenty CRM's GraphQL API have?

Twenty CRM enforces a rate limit of approximately 100 GraphQL tokens per 60 seconds. For normal human use this is never an issue. For AI agents making rapid automated queries, you need to add delays between requests (we use 0.75 seconds) to stay within limits.

Want AI insights for your business?

Get a free AI readiness scan and discover automation opportunities specific to your business.