How to Integrate CrewAI for wealth management with FastAPI for multi-agent systems
Combining CrewAI for wealth management with FastAPI gives you a clean way to expose multi-agent financial workflows as production APIs. You get CrewAI handling the orchestration of specialist agents, while FastAPI gives you a typed, async-friendly interface for clients, internal systems, or downstream services.
This is useful when you need an API that can route tasks like portfolio review, risk checks, and client communication through separate agents without turning your backend into a pile of ad hoc scripts.
Prerequisites
- •Python 3.10+
- •
fastapi - •
uvicorn - •
crewai - •Access to the CrewAI wealth management package or your configured CrewAI agent setup
- •An LLM provider key configured in environment variables
- •Basic understanding of REST APIs and async Python
Install the dependencies:
pip install fastapi uvicorn crewai pydantic
Set your environment variables:
export OPENAI_API_KEY="your-key"
Integration Steps
- •Define your wealth management agents
Start by creating agents for the specific responsibilities in your workflow. In wealth management, that usually means a planner, a risk analyst, and a client communication agent.
from crewai import Agent
portfolio_analyst = Agent(
role="Portfolio Analyst",
goal="Analyze portfolio allocation and identify concentration risk",
backstory="You review holdings for diversification and exposure issues.",
verbose=True,
)
risk_analyst = Agent(
role="Risk Analyst",
goal="Assess client risk profile against proposed actions",
backstory="You ensure recommendations match suitability constraints.",
verbose=True,
)
client_advisor = Agent(
role="Client Advisor",
goal="Summarize recommendations in plain language for clients",
backstory="You translate technical findings into concise client updates.",
verbose=True,
)
- •Create tasks that map to each agent
CrewAI works best when each agent has a narrow task. Keep the task inputs explicit so your API layer can pass structured data without guesswork.
from crewai import Task
portfolio_task = Task(
description=(
"Review this portfolio: {portfolio_data}. "
"Identify concentration risk, asset class imbalance, and any obvious issues."
),
expected_output="A concise analysis with risks and observations.",
agent=portfolio_analyst,
)
risk_task = Task(
description=(
"Given client profile {client_profile} and portfolio analysis {analysis}, "
"determine whether the recommendation fits the client's risk tolerance."
),
expected_output="A suitability assessment with pass/fail reasoning.",
agent=risk_analyst,
)
advisor_task = Task(
description=(
"Summarize {analysis} and {suitability} into a client-ready response."
),
expected_output="A short client-friendly summary.",
agent=client_advisor,
)
- •Assemble the crew execution pipeline
This is where the multi-agent system comes together. The crew runs tasks in sequence so each step can consume the previous output.
from crewai import Crew, Process
wealth_crew = Crew(
agents=[portfolio_analyst, risk_analyst, client_advisor],
tasks=[portfolio_task, risk_task, advisor_task],
process=Process.sequential,
verbose=True,
)
- •Expose the workflow through FastAPI
Create an endpoint that accepts portfolio and client data, then invokes the crew. Keep request/response models strict so your API remains predictable.
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Dict, Any
app = FastAPI(title="Wealth Management Multi-Agent API")
class WealthReviewRequest(BaseModel):
portfolio_data: Dict[str, Any]
client_profile: Dict[str, Any]
class WealthReviewResponse(BaseModel):
analysis: str
suitability: str
summary: str
@app.post("/wealth/review", response_model=WealthReviewResponse)
async def review_portfolio(payload: WealthReviewRequest):
result = wealth_crew.kickoff(
inputs={
"portfolio_data": payload.portfolio_data,
"client_profile": payload.client_profile,
}
)
return WealthReviewResponse(
analysis=str(result),
suitability="See crew output for suitability assessment",
summary="See crew output for client-facing summary",
)
- •Run FastAPI with Uvicorn
Keep deployment simple first. Once this works locally, wrap it with auth, logging, retries, and request tracing.
# save as main.py
# then run:
# uvicorn main:app --reload --host 0.0.0.0 --port 8000
If you want cleaner separation between API concerns and orchestration logic, move crew creation into a service module:
# services/wealth_service.py
def run_wealth_review(portfolio_data, client_profile):
return wealth_crew.kickoff(
inputs={
"portfolio_data": portfolio_data,
"client_profile": client_profile,
}
)
Then call that from your route handler instead of instantiating logic inline.
Testing the Integration
Use FastAPI’s test client to verify the endpoint returns a response and the crew executes end-to-end.
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_wealth_review():
response = client.post(
"/wealth/review",
json={
"portfolio_data": {
"equities": 65,
"bonds": 25,
"cash": 10
},
"client_profile": {
"risk_tolerance": "moderate",
"investment_horizon_years": 10
}
},
)
assert response.status_code == 200
print(response.json())
test_wealth_review()
Expected output:
{
"analysis": "...crew output...",
"suitability": "See crew output for suitability assessment",
"summary": "See crew output for client-facing summary"
}
If you want more deterministic tests in CI, mock wealth_crew.kickoff() and assert only on request validation plus response shape.
Real-World Use Cases
- •Portfolio review API: Accept holdings data from a CRM or advisor portal and return concentration risk plus rebalancing guidance.
- •Suitability checks: Run a multi-agent approval flow where one agent analyzes products and another validates against KYC/risk profiles.
- •Client update generation: Turn analyst findings into compliant plain-English summaries for relationship managers or automated email drafts.
The pattern here is straightforward: FastAPI owns transport and validation, CrewAI owns orchestration. That separation keeps your wealth management system maintainable when you add more agents later for compliance review, tax impact analysis, or document generation.
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