How to Integrate CrewAI for insurance with FastAPI for multi-agent systems
Combining CrewAI for insurance with FastAPI gives you a clean way to expose multi-agent workflows as production APIs. In practice, that means you can take an insurance intake, route it through specialized agents for claims, underwriting, and policy lookup, then return a structured response your core systems can consume.
This pattern is useful when you want agent orchestration behind a standard HTTP interface. FastAPI handles request validation, auth, and observability; CrewAI handles task decomposition and agent collaboration.
Prerequisites
- •Python 3.10+
- •
fastapi - •
uvicorn - •
crewai - •
pydantic - •API keys or credentials for any LLM provider your CrewAI setup uses
- •A basic understanding of:
- •FastAPI request/response models
- •CrewAI
Agent,Task, andCrewobjects - •Async vs sync execution in Python
Install the packages:
pip install fastapi uvicorn crewai pydantic
Integration Steps
- •Define your insurance agents and tasks
Start by modeling the work as specialized agents. For insurance workflows, keep agents narrow: one for intake classification, one for policy reasoning, one for claims summarization.
from crewai import Agent, Task, Crew, Process
intake_agent = Agent(
role="Insurance Intake Agent",
goal="Classify incoming insurance requests and extract key fields",
backstory="You handle policy questions, claims intake, and triage for insurance operations.",
verbose=True,
)
claims_agent = Agent(
role="Claims Review Agent",
goal="Summarize claim details and identify missing information",
backstory="You review claims submissions and prepare them for adjuster review.",
verbose=True,
)
policy_agent = Agent(
role="Policy Analysis Agent",
goal="Check policy-related questions and return a structured answer",
backstory="You help interpret policy terms and coverage constraints.",
verbose=True,
)
triage_task = Task(
description=(
"Classify this insurance request into one of: policy_question, claim_intake, "
"billing_issue, or escalation. Extract customer name, policy number if present, "
"and a short summary."
),
expected_output="A JSON-like summary with category, customer_name, policy_number, and summary.",
agent=intake_agent,
)
crew = Crew(
agents=[intake_agent, claims_agent, policy_agent],
tasks=[triage_task],
process=Process.sequential,
)
- •Wrap the CrewAI workflow in a service function
Keep the orchestration logic outside your FastAPI route. That makes it easier to test and swap models later.
from typing import Dict
def run_insurance_workflow(payload: Dict) -> str:
customer_message = payload["message"]
triage_task.description = (
f"Classify this insurance request: {customer_message}. "
"Return category, customer_name if present, policy_number if present, and summary."
)
result = crew.kickoff()
return str(result)
Crew.kickoff() is the core execution method here. In production you would usually pass richer context through task inputs or build tasks dynamically per request.
- •Expose the workflow through FastAPI
Now create a typed API endpoint that accepts the user message and returns the agent output.
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(title="Insurance Multi-Agent API")
class InsuranceRequest(BaseModel):
message: str
class InsuranceResponse(BaseModel):
result: str
@app.post("/insurance/triage", response_model=InsuranceResponse)
def triage_insurance_request(request: InsuranceRequest):
output = run_insurance_workflow(request.model_dump())
return InsuranceResponse(result=output)
This keeps your HTTP layer thin. FastAPI handles validation with Pydantic, while CrewAI handles the multi-agent reasoning.
- •Add async-safe execution if your crew calls are slow
CrewAI runs can take time depending on model latency and task complexity. If you expect concurrent traffic, push the work into a threadpool or background queue.
from fastapi.concurrency import run_in_threadpool
@app.post("/insurance/triage/async", response_model=InsuranceResponse)
async def triage_insurance_request_async(request: InsuranceRequest):
output = await run_in_threadpool(run_insurance_workflow, request.model_dump())
return InsuranceResponse(result=output)
This is the safer default for API workloads. It prevents long-running LLM calls from blocking the event loop.
- •Run the service locally
Use Uvicorn to serve the FastAPI app.
uvicorn main:app --reload --host 0.0.0.0 --port 8000
If you need production behavior behind a load balancer or container platform, remove --reload and set proper worker counts at deployment time.
Testing the Integration
Hit the endpoint with a simple payload using curl or Python requests.
import requests
payload = {
"message": "Hi, I'm Sarah Chen. My car was damaged in an accident yesterday. Policy number is PC-88219."
}
response = requests.post("http://localhost:8000/insurance/triage", json=payload)
print(response.status_code)
print(response.json())
Expected output will vary by model/provider, but it should look like this:
{
"result": "category: claim_intake\ncustomer_name: Sarah Chen\npolicy_number: PC-88219\nsummary: Customer reported vehicle damage from an accident yesterday and needs claim assistance."
}
If you get a valid JSON response with structured triage data back from the crew through FastAPI, the integration is working.
Real-World Use Cases
- •
Claims intake API
- •Accept FNOL submissions from web or mobile apps.
- •Use one agent to classify urgency and another to extract missing claim fields before routing to adjusters.
- •
Policy servicing assistant
- •Let one agent answer coverage questions while another checks exclusions or rider context.
- •Expose it as an internal API for call center tools or broker portals.
- •
Underwriting pre-screening
- •Run applicant data through multiple agents for risk summarization.
- •Return a structured recommendation that underwriters can review before manual approval.
The main pattern here is simple: keep CrewAI responsible for reasoning and coordination, keep FastAPI responsible for transport and contracts. That separation makes the system testable, deployable, and much easier to extend when your insurance workflows grow beyond one agent.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit