How to Build a transaction monitoring Agent Using CrewAI in Python for wealth management
A transaction monitoring agent in wealth management watches client activity for patterns that need human review: unusual transfers, rapid movement across accounts, structuring, or behavior that conflicts with the client profile. It matters because you need to catch risk early without flooding compliance teams with false positives, and every decision has to be explainable for audit and regulatory review.
Architecture
- •Transaction ingestion layer
- •Pulls trades, cash movements, wire transfers, journal entries, and account metadata from your internal systems.
- •Risk enrichment layer
- •Adds KYC profile data, expected activity bands, jurisdiction, PEP/sanctions flags, account tenure, and advisor notes.
- •CrewAI analyst agent
- •Uses a structured prompt to classify transactions, summarize anomalies, and produce a clear rationale.
- •Compliance reviewer agent
- •Validates the first pass against policy rules and escalates cases that meet alert thresholds.
- •Case output layer
- •Writes alerts into your case management system with evidence, timestamps, and model reasoning.
- •Audit and observability layer
- •Stores prompts, outputs, tool calls, and final decisions for exam readiness and internal QA.
Implementation
1) Install dependencies and define the transaction schema
You want strict input shapes before you hand anything to an LLM. In wealth management, sloppy payloads create bad alerts and weak audit trails.
pip install crewai pydantic
from pydantic import BaseModel
from typing import List, Optional
class Transaction(BaseModel):
transaction_id: str
account_id: str
client_name: str
amount: float
currency: str
txn_type: str
counterparty_country: str
booking_country: str
kyc_risk_rating: str
expected_monthly_volume: float
is_pep: bool = False
is_sanctioned_jurisdiction: bool = False
notes: Optional[str] = None
class Alert(BaseModel):
transaction_id: str
risk_level: str
reason: str
recommended_action: str
2) Create a monitoring tool for policy checks
CrewAI agents work better when you give them deterministic tools for hard rules. Use tools for threshold checks and reserve the LLM for judgment and narrative explanation.
from crewai.tools import tool
@tool("policy_check")
def policy_check(amount: float, expected_monthly_volume: float,
counterparty_country: str, booking_country: str,
is_pep: bool, is_sanctioned_jurisdiction: bool) -> str:
flags = []
if amount > expected_monthly_volume * 3:
flags.append("amount exceeds expected monthly volume by >3x")
if counterparty_country != booking_country:
flags.append("cross-border movement detected")
if is_pep:
flags.append("PEP client")
if is_sanctioned_jurisdiction:
flags.append("sanctioned jurisdiction involved")
return " | ".join(flags) if flags else "no hard-rule violations"
3) Build the CrewAI agents and task pipeline
This is the core pattern. One agent performs triage; another reviews escalation logic. The output should be structured enough to feed a case management workflow.
from crewai import Agent, Task, Crew, Process
transaction_monitor = Agent(
role="Transaction Monitoring Analyst",
goal="Detect suspicious or unusual wealth management transactions with concise explanations",
backstory=(
"You review client transactions for AML/CTF risk in a regulated wealth management environment. "
"You must be precise, conservative, and explain every alert in plain language."
),
tools=[policy_check],
verbose=True,
)
compliance_reviewer = Agent(
role="Compliance Reviewer",
goal="Validate whether the transaction should be escalated for manual review",
backstory=(
"You apply wealth management compliance standards. "
"You prefer false negatives over noisy alerts only when supported by policy."
),
verbose=True,
)
monitor_task = Task(
description=(
"Review this transaction:\n"
"{transaction}\n\n"
"Use the policy_check tool first. Then assess whether this should be escalated. "
"Return a short JSON-like summary with risk_level, reason, recommended_action."
),
expected_output="A concise escalation recommendation with rationale.",
agent=transaction_monitor,
)
review_task = Task(
description=(
"Review the analyst output for compliance quality. "
"Confirm whether the alert is justified under wealth management monitoring standards."
"\n\nAnalyst output:\n{analyst_output}"
),
expected_output="A final compliance disposition.",
agent=compliance_reviewer,
)
crew = Crew(
agents=[transaction_monitor, compliance_reviewer],
tasks=[monitor_task, review_task],
)
4) Run the crew on a real transaction payload
Keep the transaction object serialized cleanly so it can be logged verbatim. That gives you reproducibility during audits and model tuning.
sample_txn = Transaction(
transaction_id="TXN-100045",
account_id="ACC-77881",
client_name="A. Kumar",
amount=250000.0,
currency="USD",
txn_type="wire_transfer",
counterparty_country="AE",
.booking_country="US",
kyc_risk_rating="medium",
expected_monthly_volume=50000.0,
is_pep=False,
is_sanctioned_jurisdiction=False,
notes="Transfer to newly added external beneficiary"
)
result = crew.kickoff(inputs={"transaction": sample_txn.model_dump_json()})
print(result)
Production Considerations
- •Data residency
- •Keep client PII and transaction logs in-region. If your firm operates across jurisdictions, route EU client data through EU-hosted infrastructure and avoid sending raw identifiers to external services unless policy explicitly allows it.
- •Auditability
- •Persist every prompt, tool call result, task output, and final disposition with timestamps and versioned prompts. Regulators will ask why an alert fired; “the model said so” is not acceptable.
- •Guardrails
- •Add deterministic thresholds before LLM review. In wealth management you need rule-based filters for sanctions exposure, PEP status, velocity checks, and unusual counterparties.
- •Operational monitoring
- •Track alert rates by advisor team, region, client segment, and product type. A sudden spike usually means either a process change or a broken prompt.
Common Pitfalls
- •
Letting the LLM decide without rules
- •Avoid pure free-text classification. Use tools like
policy_checkso obvious violations are handled consistently.
- •Avoid pure free-text classification. Use tools like
- •
Ignoring client context
- •A $250k transfer means something different for a UHNW family office than for a retail brokerage account. Include expected volume, risk rating, account tenure, and beneficiary history.
- •
Producing unstructured outputs
- •If your agent returns prose only, downstream case systems become brittle. Force structured fields like
risk_level,reason, andrecommended_action.
- •If your agent returns prose only, downstream case systems become brittle. Force structured fields like
- •
Skipping human review boundaries
- •The agent should recommend escalation; it should not auto-close or auto-file regulatory reports without policy approval. Wealth management firms need clear human sign-off paths for high-risk cases.
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