Skip to content

feat(crewai-tools): add Comply54ComplianceTool for African regulatory enforcement#6623

Open
kingztech2019 wants to merge 2 commits into
crewAIInc:mainfrom
kingztech2019:feat/comply54-compliance-tool
Open

feat(crewai-tools): add Comply54ComplianceTool for African regulatory enforcement#6623
kingztech2019 wants to merge 2 commits into
crewAIInc:mainfrom
kingztech2019:feat/comply54-compliance-tool

Conversation

@kingztech2019

Copy link
Copy Markdown

Description

Adds Comply54ComplianceTool, Comply54GuardedTool, and comply54_guard_tools() to lib/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):

from crewai_tools import Comply54ComplianceTool
from comply54.sectors import NigeriaFintechCompliance

tool = Comply54ComplianceTool(compliance=NigeriaFintechCompliance())
agent = Agent(role="Fintech Agent", tools=[transfer_funds_tool, tool], ...)

Pattern 2 — Automatic pre-execution guard (transparent to agent):

from crewai_tools import comply54_guard_tools
from comply54.sectors import NigeriaFintechCompliance

guarded = comply54_guard_tools(
    NigeriaFintechCompliance(),
    [transfer_funds_tool, approve_payment_tool],
    context={"kyc_tier": 3},
)
agent = Agent(role="Fintech Agent", tools=guarded, ...)

Pattern 3 — Output-level task guardrail (blocks PII leakage before delivery):

from comply54.crewai import Comply54TaskGuardrail
task = Task(..., guardrail=Comply54TaskGuardrail(NigeriaFintechCompliance()), agent=agent)

Type of Change

  • New feature (non-breaking change which adds functionality)

Files changed

File Change
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py New tool implementation
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/__init__.py Package init
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md Usage docs
lib/crewai-tools/src/crewai_tools/tools/__init__.py Export 3 new symbols
lib/crewai-tools/pyproject.toml Add comply54 optional extra
lib/crewai-tools/tool.specs.json Add Comply54ComplianceTool spec entry
lib/crewai-tools/tests/tools/test_comply54_tool.py Unit tests (all mocked, no real Rego)

Checklist

  • Tool lives under lib/crewai-tools/src/crewai_tools/tools/comply54_tool/
  • Class ends with Tool and subclasses BaseTool
  • Precise args_schema with Pydantic field descriptions and validation
  • No env_vars (comply54 requires no API key)
  • package_dependencies = ["comply54"] declared
  • Lazy import with clear ImportError message pointing to pip install crewai-tools[comply54]
  • Optional extra added in pyproject.toml
  • tool.specs.json entry added manually (auto-generator requires internal PR secrets)
  • Unit tests added — all mocked, deterministic, no network calls
  • Tool README.md with usage patterns and all three integration examples

Links

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.

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
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7d2b32f9-ec77-4090-9031-749cc016b946

📥 Commits

Reviewing files that changed from the base of the PR and between 3057af8 and c5228f5.

📒 Files selected for processing (4)
  • lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py
  • lib/crewai-tools/tests/tools/test_comply54_tool.py
  • lib/crewai-tools/tool.specs.json
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/crewai-tools/tool.specs.json
  • lib/crewai-tools/tests/tools/test_comply54_tool.py
  • lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py
  • lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md

📝 Walkthrough

Walkthrough

Adds optional Comply54 support to crewai-tools, including standalone compliance checks, pre-execution guarded tools, public exports, tool specifications, documentation, and mocked tests for allow, deny, and escalate decisions.

Changes

Comply54 integration

Layer / File(s) Summary
Package and tool contracts
lib/crewai-tools/pyproject.toml, lib/crewai-tools/src/crewai_tools/tools/..., lib/crewai-tools/tool.specs.json
Adds the optional comply54 dependency, defines input schemas and tool specifications, and exposes the new compliance APIs.
Compliance execution and guarding
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py
Implements dependency validation, standalone checks, result serialization, guarded execution, deny/escalate blocking, and multi-tool wrapping.
Usage documentation and validation
lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md, lib/crewai-tools/tests/tools/test_comply54_tool.py
Documents installation, supported policy packs, and integration patterns while testing decisions, import handling, metadata preservation, and context propagation.

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
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is clearly related to the change, though it names only one of several new tools added.
Description check ✅ Passed The description matches the PR and accurately explains the new tools, docs, specs, dependency, and tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🔵 Trivial

Duplicated comply54 availability check across both constructors.

Comply54ComplianceTool.__init__ and Comply54GuardedTool.__init__ both contain an identical try/except block importing comply54.sectors._base.SectorCompliance and raising the same ImportError message. 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

📥 Commits

Reviewing files that changed from the base of the PR and between b14d36b and 3057af8.

📒 Files selected for processing (7)
  • lib/crewai-tools/pyproject.toml
  • lib/crewai-tools/src/crewai_tools/tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/comply54_tool/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/comply54_tool/comply54_tool.py
  • lib/crewai-tools/tests/tools/test_comply54_tool.py
  • lib/crewai-tools/tool.specs.json

Comment on lines +9 to +17
| 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 |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Comment thread lib/crewai-tools/src/crewai_tools/tools/comply54_tool/README.md
Comment thread lib/crewai-tools/tests/tools/test_comply54_tool.py
Comment thread lib/crewai-tools/tests/tools/test_comply54_tool.py
Comment thread lib/crewai-tools/tool.specs.json Outdated
}
},
{
"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).",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant