feat(crewai-tools): add Comply54ComplianceTool for African regulatory enforcement#6623
feat(crewai-tools): add Comply54ComplianceTool for African regulatory enforcement#6623kingztech2019 wants to merge 2 commits into
Conversation
Adds pre-execution African financial and data-protection compliance enforcement for CrewAI agents via the comply54 library (Apache 2.0). Three integration patterns: - Comply54ComplianceTool — explicit self-check BaseTool the agent calls before a regulated action; returns JSON allow/deny/escalate/audit with exact regulatory citation and stable audit ID - Comply54GuardedTool — wraps any existing BaseTool and enforces compliance transparently before each execution; preserves the wrapped tool's name, description, and args_schema unchanged - comply54_guard_tools() — convenience helper to wrap a list of tools at once (e.g. all tools in a fintech agent) Jurisdiction coverage (21 policy packs, 12 African countries): Nigeria (CBN NIP Framework, NDPA 2023, NIIRA 2025, NFIU AML, BVN/NIN), Kenya (KDPA 2019), South Africa (POPIA), Ghana, Rwanda, Egypt, Tanzania, Uganda, Ethiopia, Mauritius. No API key or OPA binary required — comply54 evaluates Rego policies fully in-process via regopy (zero subprocess, works offline). Optional dependency: pip install crewai-tools[comply54] Closes crewAIInc#6392
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds optional Comply54 support to ChangesComply54 integration
Sequence Diagram(s)sequenceDiagram
participant Agent
participant Comply54GuardedTool
participant Comply54
participant InnerTool
Agent->>Comply54GuardedTool: invoke action with parameters
Comply54GuardedTool->>Comply54: check action and context
Comply54-->>Comply54GuardedTool: allow, deny, or escalate
alt denied or blocked escalation
Comply54GuardedTool-->>Agent: return structured blocked response
else allowed
Comply54GuardedTool->>InnerTool: delegate action
InnerTool-->>Comply54GuardedTool: return tool result
Comply54GuardedTool-->>Agent: return delegated result
end
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Checkov (3.3.8)lib/crewai-tools/tool.specs.jsonTraceback (most recent call last): Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py (1)
113-122: 📐 Maintainability & Code Quality | 🔵 TrivialDuplicated
comply54availability check across both constructors.
Comply54ComplianceTool.__init__andComply54GuardedTool.__init__both contain an identical try/except block importingcomply54.sectors._base.SectorComplianceand raising the sameImportErrormessage. Extract into a shared helper to avoid drift if the install message or import path changes.♻️ Proposed refactor
+def _ensure_comply54_installed() -> None: + try: + from comply54.sectors._base import SectorCompliance # noqa: F401 + except ImportError as exc: + raise ImportError( + "Missing optional dependency 'comply54'. Install with:\n" + " pip install crewai-tools[comply54]\n" + "or\n" + " pip install comply54" + ) from exc + + class Comply54ComplianceTool(BaseTool): ... def __init__(self, compliance: Any, **kwargs: Any) -> None: - try: - from comply54.sectors._base import SectorCompliance # noqa: F401 - except ImportError as exc: - raise ImportError( - "Missing optional dependency 'comply54'. Install with:\n" - " pip install crewai-tools[comply54]\n" - "or\n" - " pip install comply54" - ) from exc + _ensure_comply54_installed()Apply the same substitution in
Comply54GuardedTool.__init__.Also applies to: 204-212
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py` around lines 113 - 122, Extract the duplicated optional-dependency validation from Comply54ComplianceTool.__init__ and Comply54GuardedTool.__init__ into a shared helper that imports SectorCompliance and raises the existing installation guidance on ImportError. Replace both constructor-local try/except blocks with calls to this helper, preserving the current error message and dependency behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py`:
- Around line 231-236: Update Comply54GuardedTool._run so its
self.compliance.check call includes the required output="" argument, matching
Comply54ComplianceTool._run while preserving the existing action, params, and
context values.
In `@lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md`:
- Around line 9-17: Reconcile the jurisdiction table in the README with the
coverage statement near the “12 jurisdictions” claim: add the two omitted
supported countries to the table if they are part of the 12-country, 21-pack
integration, or revise the claim to match the listed countries. Ensure the
documented coverage is consistent and does not imply unsupported jurisdictions.
- Around line 105-116: Add the missing Task import to the standalone
Comply54TaskGuardrail example so Task is defined when the snippet is copied
independently; leave the guardrail setup and task construction unchanged.
In `@lib/crewai-tools/tests/tools/test_comply54_tool.py`:
- Around line 112-123: The compliance tool tests currently omit the documented
audit decision. Add a behavior-focused test alongside
test_deny_decision_returns_json that creates an audit compliance result, runs
Comply54ComplianceTool._run, deserializes the JSON, and asserts the expected
overall value, blocked status, and audit ID fields.
- Around line 152-168: Strengthen the guarded-tool tests around _make_guarded:
spy on inner._run and assert it is not called for deny or escalate decisions,
proving blocking occurs before execution. In
test_allow_passes_through_to_inner_tool, assert compliance.check receives the
tool name, submitted parameters, and KYC context via guard_context, while
preserving the existing successful result assertions; apply the same coverage to
the related test cases.
In `@lib/crewai-tools/tool.specs.json`:
- Line 2910: Verify the jurisdiction coverage represented by the tool
specification description against the PR’s stated 12-country scope, then update
the description accordingly. Keep the named jurisdictions accurate and change “5
more” to the correct remainder, or add the missing jurisdiction if the named
list is incomplete.
---
Nitpick comments:
In `@lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py`:
- Around line 113-122: Extract the duplicated optional-dependency validation
from Comply54ComplianceTool.__init__ and Comply54GuardedTool.__init__ into a
shared helper that imports SectorCompliance and raises the existing installation
guidance on ImportError. Replace both constructor-local try/except blocks with
calls to this helper, preserving the current error message and dependency
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9dda7c10-58df-4743-89d1-5c3a1345ec2c
📒 Files selected for processing (7)
lib/crewai-tools/pyproject.tomllib/crewai-tools/src/crewai_tools/tools/__init__.pylib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.mdlib/crewai-tools/src/crewai_tools/tools/comply54_tool/__init__.pylib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.pylib/crewai-tools/tests/tools/test_comply54_tool.pylib/crewai-tools/tool.specs.json
| | Country | Regulations | | ||
| |---|---| | ||
| | Nigeria | CBN NIP Framework, NDPA 2023, NIIRA 2025, NFIU AML, BVN/NIN | | ||
| | Kenya | KDPA 2019 | | ||
| | South Africa | POPIA | | ||
| | Ghana | Ghana DPA 2012 | | ||
| | Rwanda | Rwanda DPA 2021 | | ||
| | Egypt | Egypt PDPL No. 151/2020 | | ||
| | Tanzania, Uganda, Ethiopia, Mauritius | Jurisdiction-specific packs | |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Reconcile the jurisdiction coverage list.
The table lists 10 countries, but line 128 says 12 jurisdictions. List the missing two countries or revise the coverage claim so users do not infer unsupported compliance coverage.
Based on PR objectives, the integration covers 21 packs across 12 countries.
Also applies to: 128-128
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md` around lines
9 - 17, Reconcile the jurisdiction table in the README with the coverage
statement near the “12 jurisdictions” claim: add the two omitted supported
countries to the table if they are part of the 12-country, 21-pack integration,
or revise the claim to match the listed countries. Ensure the documented
coverage is consistent and does not imply unsupported jurisdictions.
| } | ||
| }, | ||
| { | ||
| "description": "Check whether an agent action complies with applicable African regulatory requirements before executing it. Returns a JSON decision: allow / deny / escalate / audit \u2014 with the triggered rule and exact regulatory citation. Covers Nigeria (CBN, NDPA 2023, NIIRA 2025, NFIU AML), Kenya (KDPA), South Africa (POPIA), Ghana, Rwanda, Egypt, and 5 more African jurisdictions. No API key required \u2014 evaluation runs fully offline via in-process Rego (regopy).", |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Jurisdiction count in description doesn't match PR's stated coverage.
The description lists 6 named jurisdictions (Nigeria, Kenya, South Africa, Ghana, Rwanda, Egypt) plus "5 more" = 11 total, but the PR objectives state coverage across 12 African countries. Verify the actual count and correct the description text (likely "6 more" instead of "5 more", or the named list is missing an entry).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@lib/crewai-tools/tool.specs.json` at line 2910, Verify the jurisdiction
coverage represented by the tool specification description against the PR’s
stated 12-country scope, then update the description accordingly. Keep the named
jurisdictions accurate and change “5 more” to the correct remainder, or add the
missing jurisdiction if the named list is incomplete.
- Extract duplicated import guard into _ensure_comply54_installed() helper - Add missing output="" to Comply54GuardedTool._run compliance.check call, matching the contract of Comply54ComplianceTool._run - Fix jurisdiction count: 10 countries (not 12); expand README table to list all 10 rows with individual regulation names - Add missing `from crewai import Task` to Pattern 3 README example - Add test for `audit` decision in TestComply54ComplianceTool - Strengthen guarded-tool tests: assert inner._run not called on deny/ escalate-blocked decisions; assert compliance.check receives tool name, params, output="", and guard_context on allow - Fix tool.specs.json description: name all 10 countries, remove "5 more"
Description
Adds
Comply54ComplianceTool,Comply54GuardedTool, andcomply54_guard_tools()tolib/crewai-tools/— pre-execution African financial and data-protection compliance enforcement for CrewAI agents.Why now: Nigeria's CBN issued an AI-in-AML mandate in March 2026 requiring banks and fintechs to enforce compliance controls on AI agent actions. There is currently no crewAI tool addressing African regulatory requirements, which represent a fast-growing developer market.
What it does:
Returns a structured JSON decision —
allow/deny/escalate/audit— with the triggered rule, exact regulatory citation (document, section, authority, year), and a stable audit ID before the agent executes any regulated action.Jurisdiction coverage: 21 policy packs across 12 African countries — Nigeria (CBN NIP Framework, NDPA 2023, NIIRA 2025, NFIU AML, BVN/NIN), Kenya (KDPA 2019), South Africa (POPIA), Ghana, Rwanda, Egypt, Tanzania, Uganda, Ethiopia, Mauritius.
No API key required. Evaluation runs fully offline via in-process Rego (regopy). No OPA binary, no subprocess, no network call.
Three integration patterns
Pattern 1 — Explicit self-check (agent decides when to call):
Pattern 2 — Automatic pre-execution guard (transparent to agent):
Pattern 3 — Output-level task guardrail (blocks PII leakage before delivery):
Type of Change
Files changed
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.pylib/crewai-tools/src/crewai_tools/tools/comply54_tool/__init__.pylib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.mdlib/crewai-tools/src/crewai_tools/tools/__init__.pylib/crewai-tools/pyproject.tomlcomply54optional extralib/crewai-tools/tool.specs.jsonComply54ComplianceToolspec entrylib/crewai-tools/tests/tools/test_comply54_tool.pyChecklist
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/Tooland subclassesBaseToolargs_schemawith Pydantic field descriptions and validationenv_vars(comply54 requires no API key)package_dependencies = ["comply54"]declaredImportErrormessage pointing topip install crewai-tools[comply54]pyproject.tomltool.specs.jsonentry added manually (auto-generator requires internal PR secrets)README.mdwith usage patterns and all three integration examplesLinks
Attribution
Implemented by @kingztech2019.
AI Assistance
Claude (Anthropic) was used to assist with code generation and review.
IP
The comply54 library is original work by the contributor (Apache 2.0). No third-party IP is included.