How to Integrate CrewAI for retail banking with FastAPI for multi-agent systems

By Cyprian AaronsUpdated 2026-04-22
crewai-for-retail-bankingfastapimulti-agent-systems

Combining CrewAI for retail banking with FastAPI gives you a clean way to expose multi-agent workflows as production APIs. In practice, that means you can take banking tasks like customer onboarding, transaction dispute triage, loan pre-screening, or account servicing and wrap them behind HTTP endpoints your internal systems can call.

FastAPI handles request validation, auth, and response shaping. CrewAI handles orchestration across specialized agents, so your API can coordinate multiple banking-focused roles instead of stuffing everything into one monolithic model call.

Prerequisites

  • Python 3.10+
  • fastapi
  • uvicorn
  • crewai
  • pydantic
  • An LLM provider configured for CrewAI:
    • OpenAI API key or another supported provider
  • Basic understanding of:
    • FastAPI path operations
    • Pydantic models
    • CrewAI Agent, Task, and Crew
  • A working virtual environment

Install the dependencies:

pip install fastapi uvicorn crewai pydantic

Set your model key:

export OPENAI_API_KEY="your-api-key"

Integration Steps

1) Define your retail banking agents

Start by separating responsibilities. For retail banking, a common split is:

  • Customer service agent
  • Compliance agent
  • Product specialist agent

Use CrewAI’s Agent class to define each role clearly.

from crewai import Agent

customer_service_agent = Agent(
    role="Retail Banking Customer Service Agent",
    goal="Resolve customer questions about accounts, cards, and basic banking services.",
    backstory="You handle retail banking support with a focus on clarity and accuracy.",
    verbose=True,
)

compliance_agent = Agent(
    role="Banking Compliance Agent",
    goal="Review responses for policy violations, regulatory risk, and unsafe recommendations.",
    backstory="You ensure all banking guidance follows internal policy and regulatory constraints.",
    verbose=True,
)

2) Create tasks that map to the bank workflow

Tasks are where you define the actual work. In multi-agent systems, each task should be narrow and measurable.

from crewai import Task

customer_support_task = Task(
    description=(
        "Analyze the customer's request about retail banking services and draft a helpful response. "
        "If the request involves sensitive topics like disputes, lending decisions, or KYC issues, flag it."
    ),
    expected_output="A concise support response with any escalation flags.",
    agent=customer_service_agent,
)

compliance_review_task = Task(
    description=(
        "Review the drafted banking response for compliance risk. "
        "Check for disallowed advice, privacy issues, or claims that require human approval."
    ),
    expected_output="A compliance-approved response or a list of required edits.",
    agent=compliance_agent,
)

3) Assemble the CrewAI crew

Now connect the agents and tasks into a single workflow using Crew. This is the unit your API will call.

from crewai import Crew, Process

banking_crew = Crew(
    agents=[customer_service_agent, compliance_agent],
    tasks=[customer_support_task, compliance_review_task],
    process=Process.sequential,
    verbose=True,
)

For retail banking, sequential processing is usually the right default. You want support output generated first, then reviewed before anything leaves your API.

4) Expose the workflow through FastAPI

Wrap the crew in a FastAPI endpoint. Use Pydantic models for request/response validation so downstream consumers get predictable contracts.

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="Retail Banking Multi-Agent API")

class BankingRequest(BaseModel):
    customer_query: str

class BankingResponse(BaseModel):
    result: str

@app.post("/banking/support", response_model=BankingResponse)
def banking_support(payload: BankingRequest):
    result = banking_crew.kickoff(
        inputs={"customer_query": payload.customer_query}
    )
    return BankingResponse(result=str(result))

This is the main integration point. FastAPI receives the request, CrewAI runs the multi-agent workflow, and your endpoint returns a structured response.

5) Run the API and wire it into your internal system

Use Uvicorn to serve the app locally or in your container runtime.

uvicorn main:app --reload --host 0.0.0.0 --port 8000

If you want to harden this for production bank workloads:

  • Add authentication middleware
  • Add rate limiting
  • Log request IDs and agent outputs
  • Put timeouts around long-running calls
  • Store redacted traces only

Testing the Integration

Send a test request with curl or Python requests.

import requests

response = requests.post(
    "http://localhost:8000/banking/support",
    json={"customer_query": "Can I increase my debit card limit for online purchases?"}
)

print(response.status_code)
print(response.json())

Expected output will look similar to this:

{
  "result": "The customer wants to increase their debit card limit for online purchases..."
}

If you want a quick health check during development, add a simple endpoint too:

@app.get("/health")
def health():
    return {"status": "ok"}

Then verify it:

curl http://localhost:8000/health

Expected output:

{"status":"ok"}

Real-World Use Cases

  • Customer service triage

    • Route account access issues, card problems, fee questions, and branch inquiries through specialized agents before escalating to humans.
  • Compliance-aware responses

    • Use one agent to draft answers and another to check policy constraints before returning anything related to lending, disputes, or identity verification.
  • Loan pre-screening workflows

    • Accept applicant data through FastAPI, let one agent summarize eligibility signals, and another flag missing documents or risk indicators.

The pattern is simple: FastAPI gives you an API boundary; CrewAI gives you orchestration. That combination is what turns a set of prompts into something you can actually put behind a bank-facing service contract.


Keep learning

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

Related Guides