feat: add requireLogicNodes() on-chain agent verification helper#5955
feat: add requireLogicNodes() on-chain agent verification helper#5955cmdenney wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds a new helper module ChangesLogicNodes Registration Check
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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: 2
🤖 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 `@src/crewai/utilities/logicnodes_helper.py`:
- Around line 14-15: Update the example import path to the package-qualified
module so examples succeed when installed: replace bare "from logicnodes_helper
import requireLogicNodes" with the proper package import (e.g., "from
crewai.utilities.logicnodes_helper import requireLogicNodes") wherever it
appears (references to requireLogicNodes in the examples around the top of the
file and the occurrence at line ~58) so the documented import matches the
module's package structure.
- Around line 22-23: requireLogicNodes currently trusts the registry response
from the caller-provided rpc_url without verifying the chain, so first check the
chain matches the module-level CHAIN_ID (8453) by creating the web3 instance
used in requireLogicNodes and asserting w3.eth.chain_id == CHAIN_ID (raise a
clear error if it mismatches) before calling isRegistered; also update the
docstring/example import to use from crewai.utilities.logicnodes_helper import
requireLogicNodes to reflect the actual module path.
🪄 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: 4c778a30-383f-4a7a-8a95-9fa526ec7813
📒 Files selected for processing (1)
src/crewai/utilities/logicnodes_helper.py
| from logicnodes_helper import requireLogicNodes | ||
| requireLogicNodes(agent_address="0xYourAgent...") |
There was a problem hiding this comment.
Fix example import path in module docs.
The examples use from logicnodes_helper import requireLogicNodes, which will fail for the packaged module path in this repo.
📝 Suggested fix
- from logicnodes_helper import requireLogicNodes
+ from crewai.utilities.logicnodes_helper import requireLogicNodes
...
- from logicnodes_helper import requireLogicNodes
+ from crewai.utilities.logicnodes_helper import requireLogicNodesAlso applies to: 58-58
🤖 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 `@src/crewai/utilities/logicnodes_helper.py` around lines 14 - 15, Update the
example import path to the package-qualified module so examples succeed when
installed: replace bare "from logicnodes_helper import requireLogicNodes" with
the proper package import (e.g., "from crewai.utilities.logicnodes_helper import
requireLogicNodes") wherever it appears (references to requireLogicNodes in the
examples around the top of the file and the occurrence at line ~58) so the
documented import matches the module's package structure.
| CHAIN_ID = 8453 | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Identify the file and show the relevant parts around CHAIN_ID / requireLogicNodes
FILE="src/crewai/utilities/logicnodes_helper.py"
echo "== File existence =="
ls -l "$FILE" || true
echo
echo "== Lines 1-120 =="
nl -ba "$FILE" | sed -n '1,120p'
echo
echo "== Search for CHAIN_ID usage =="
rg -n "CHAIN_ID" "$FILE" || true
echo
echo "== Search for requireLogicNodes definition and body =="
rg -n "def requireLogicNodes|requireLogicNodes\s*\(" "$FILE" || true
echo
echo "== Lines around requireLogicNodes (entire function) =="
# Print a bit more aggressively around the function definition
START=$(rg -n "def requireLogicNodes" "$FILE" | cut -d: -f1 | head -n1)
if [ -n "${START:-}" ]; then
START=$((START-10))
END=$((START+140))
nl -ba "$FILE" | sed -n "${START},${END}p"
fi
echo
echo "== Search for docstring example imports =="
rg -n "from .*logicnodes_helper import requireLogicNodes|logicnodes_helper import requireLogicNodes|requireLogicNodes.*logicnodes_helper" "$FILE" || true
echo
echo "== Search for HTTPProvider / chain_id comparisons =="
rg -n "HTTPProvider|eth\.chain_id|chain_id" "$FILE" || trueRepository: crewAIInc/crewAI
Length of output: 253
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="src/crewai/utilities/logicnodes_helper.py"
echo "== File existence =="
ls -l "$FILE" || true
echo
echo "== Lines 1-160 (with line numbers) =="
awk '{printf "%5d %s\n", NR, $0}' "$FILE" | sed -n '1,160p'
echo
echo "== Search for CHAIN_ID usage =="
rg -n "CHAIN_ID" "$FILE" || true
echo
echo "== Search for requireLogicNodes definition =="
rg -n "def requireLogicNodes" "$FILE" || true
echo
echo "== Lines around requireLogicNodes body =="
LINE=$(rg -n "def requireLogicNodes" "$FILE" | head -n1 | cut -d: -f1 || true)
if [ -n "${LINE:-}" ]; then
START=$((LINE-10))
END=$((LINE+200))
awk '{printf "%5d %s\n", NR, $0}' "$FILE" | sed -n "${START},${END}p"
fi
echo
echo "== Search for docstring example imports =="
rg -n "from .*logicnodes_helper import requireLogicNodes|logicnodes_helper import requireLogicNodes" "$FILE" || true
echo
echo "== Search for chain_id checks in file =="
rg -n "HTTPProvider|eth\.chain_id|chain_id" "$FILE" || trueRepository: crewAIInc/crewAI
Length of output: 6360
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# List nearby package files to see how module is exposed
echo "== Files under src/crewai/utilities =="
find src/crewai/utilities -maxdepth 1 -type f -print | sed 's#^./##' || true
echo
echo "== Search for requireLogicNodes imports/usages =="
rg -n "requireLogicNodes" src || true
echo
echo "== Search for logicnodes_helper import patterns =="
rg -n "logicnodes_helper" src || true
echo
echo "== Check for __init__.py in relevant directories =="
find src/crewai -maxdepth 3 -type f -name "__init__.py" -print | sed 's#^./##' || true
echo
echo "== Contents of src/crewai/utilities/__init__.py (if exists) =="
if [ -f src/crewai/utilities/__init__.py ]; then
sed -n '1,200p' src/crewai/utilities/__init__.py
else
echo "(no src/crewai/utilities/__init__.py)"
fiRepository: crewAIInc/crewAI
Length of output: 1181
Enforce Base chain ID in requireLogicNodes before trusting isRegistered.
CHAIN_ID (8453) is defined but never checked; requireLogicNodes() calls the registry using the caller-provided rpc_url without verifying w3.eth.chain_id, so responses from the wrong chain/RPC can yield misleading results (lines 22-23, ~66-73).
🔧 Suggested fix
w3 = Web3(Web3.HTTPProvider(rpc_url))
+ if w3.eth.chain_id != CHAIN_ID:
+ msg = f"Unexpected chain ID {w3.eth.chain_id}; expected {CHAIN_ID} (Base mainnet)."
+ if strict:
+ raise RuntimeError(msg)
+ return False
+
contract = w3.eth.contract(
address=Web3.to_checksum_address(registry),
abi=_REGISTRY_ABI,
)Docstring example imports from logicnodes_helper import requireLogicNodes, but the module is located at src/crewai/utilities/logicnodes_helper.py; update the example to from crewai.utilities.logicnodes_helper import requireLogicNodes (lines ~14, ~58).
🤖 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 `@src/crewai/utilities/logicnodes_helper.py` around lines 22 - 23,
requireLogicNodes currently trusts the registry response from the
caller-provided rpc_url without verifying the chain, so first check the chain
matches the module-level CHAIN_ID (8453) by creating the web3 instance used in
requireLogicNodes and asserting w3.eth.chain_id == CHAIN_ID (raise a clear error
if it mismatches) before calling isRegistered; also update the docstring/example
import to use from crewai.utilities.logicnodes_helper import requireLogicNodes
to reflect the actual module path.
LogicNodes Integration Helper
This PR adds
logicnodes_helper.py— a lightweight utility that lets agents verify their on-chain registration status before executing tasks.What is LogicNodes?
LogicNodes is a decentralized agent coordination protocol on Base mainnet. Agents register their capabilities on-chain, enabling:
Usage
Registry Details
0x4c60B817beeD72aa570B964243eE6DD463faaE22No new dependencies required
The helper uses
web3.pywhich is already in scope for most agent frameworks. Network errors are handled gracefully — the function returnsFalserather than crashing if the RPC is unreachable.This helper is provided by the LogicNodes team. Issues / questions: https://logicnodes.io
Summary by CodeRabbit