feat(crewai-tools): add IBM Db2 search tool#5885
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a DB2-native vector search tool: Pydantic schemas and JSON encoder, DB2VectorSearchTool with dynamic driver loading, OpenAI/custom embeddings, parameterized VECTOR_DISTANCE queries (optional metadata filtering), package export updates, README, and MDX user documentation. ChangesDB2 Vector Search Tool for CrewAI
Sequence Diagram(s)sequenceDiagram
participant Agent
participant DB2VectorSearchTool
participant DB2
participant OpenAIEmbeddings
Agent->>DB2VectorSearchTool: call _run(query, filter_by?, filter_value?)
DB2VectorSearchTool->>OpenAIEmbeddings: request embedding (if no custom fn)
OpenAIEmbeddings-->>DB2VectorSearchTool: embedding vector
DB2VectorSearchTool->>DB2: execute PARAMETERIZED VECTOR_DISTANCE query
DB2-->>DB2VectorSearchTool: rows with distances
DB2VectorSearchTool-->>Agent: JSON results (distance + data)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 5
🤖 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/__init__.py`:
- Around line 56-58: Restore the central exports by importing and re-exporting
the missing tool symbols in crewi_tools.tools.__init__: re-enable the
DirectoryReadTool import from
crewi_tools.tools.directory_read_tool.directory_read_tool and add imports for
the DB2 tool classes (e.g., the DB2 tool module(s) under
crewi_tools.tools.db2_*) and include those symbol names in the module's __all__
so consumers can import them from crewi_tools.tools; ensure you import the exact
class/function names from their modules and add them to the exported list (also
apply the same changes to the other affected export block referenced in the
comment).
In `@lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py`:
- Around line 252-255: The except block handling failures from _connect() should
clean up any partially opened resources: if self.connection was created but
cursor setup failed, close the connection (or call the existing cleanup method,
e.g., self._close()) before returning the error JSON; update the try/except to
check for self.connection (and any partially created cursor) and close them on
exception or move cleanup into a finally block so no DB2 connection is leaked
when _connect() raises.
- Around line 37-51: The schema allows one-sided filter inputs; add a Pydantic
validator that enforces filter_by and filter_value are provided together (both
non-None) or both None. Locate the model containing the Field definitions for
filter_by and filter_value and implement either a `@root_validator`(pre=False) or
paired `@validator` methods to raise a ValueError when one is set and the other is
not (referencing the filter_by and filter_value symbols), ensuring the runtime
check aligns with the existing filtering logic that only applies when both are
present.
- Around line 110-115: The package list in the DB2VectorSearchTool model is
missing the DBI package so dependency automation won't install the module
imported in _setup_db2; update the package_dependencies Field (in the
DB2VectorSearchTool declaration) to include "ibm_db_dbi" alongside "ibm_db" and
"openai" so the default db2_dbi_package used in _setup_db2 is available at
runtime. Ensure the string matches the default db2_dbi_package value
("ibm_db_dbi") to avoid mismatches.
In `@lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/README.md`:
- Around line 40-57: Update the README examples to use the public module path
and public API: change the import to crewai_tools.tools.db2_search_tool and
instantiate DB2Config and DB2VectorSearchTool as shown, then call the public
method run(...) instead of the private _run(...); also update any
metadata-filtering example that currently calls _run to call run and pass the
same parameters so examples reference DB2Config, DB2VectorSearchTool, run, and
no longer use _run.
🪄 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: 8ba82584-3681-434d-b317-d49455cf3284
📒 Files selected for processing (5)
docs/en/tools/database-data/db2searchtool.mdxlib/crewai-tools/src/crewai_tools/tools/__init__.pylib/crewai-tools/src/crewai_tools/tools/db2_search_tool/README.mdlib/crewai-tools/src/crewai_tools/tools/db2_search_tool/__init__.pylib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py
| from db2_search_tool import ( | ||
| DB2Config, | ||
| DB2VectorSearchTool, | ||
| ) | ||
|
|
||
| config = DB2Config( | ||
| database="TESTDB", | ||
| hostname="localhost", | ||
| table_name="documents", | ||
| ) | ||
|
|
||
| tool = DB2VectorSearchTool( | ||
| db2_config=config | ||
| ) | ||
|
|
||
| result = tool._run( | ||
| query="What is machine learning?", | ||
| ) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n "from db2_search_tool|\\._run\\(" lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/README.md docs/en/tools/database-data/db2searchtool.mdxRepository: crewAIInc/crewAI
Length of output: 337
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate tool implementation
rg -n "class DB2VectorSearchTool" -S lib/crewai-tools/src/crewai_tools/tools/db2_search_tool || true
rg -n "def (run|_run)\b" -S lib/crewai-tools/src/crewai_tools/tools/db2_search_tool || true
# Find how the module is exported (public import path)
rg -n "DB2Config|DB2VectorSearchTool" -S lib/crewai-tools/src/crewai_tools/tools/db2_search_tool || true
fd -t f "__init__.py" lib/crewai-tools/src/crewai_tools/tools/db2_search_tool -a | head -n 50Repository: crewAIInc/crewAI
Length of output: 1657
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Check any top-level exports that might make `from db2_search_tool import ...` valid
rg -n "from (db2_search_tool|crewai_tools\.tools\.db2_search_tool)" -S lib/crewai-tools/src/crewai_tools || true
rg -n "db2_search_tool" -S lib/crewai-tools/src/crewai_tools | head -n 200Repository: crewAIInc/crewAI
Length of output: 359
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the README around the flagged lines
nl -ba lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/README.md | sed -n '30,90p'Repository: crewAIInc/crewAI
Length of output: 103
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect similar tool READMEs for doc conventions (import path + run vs _run)
fd -t f "README.md" lib/crewai-tools/src/crewai_tools/tools -a | head -n 200
# Pick a couple likely vector-search tools and grep their examples
for f in $(fd -t f "README.md" lib/crewai-tools/src/crewai_tools/tools -a | rg -i "vector|search|database" | head -n 10); do
echo "---- $f ----"
rg -n "from .*db|_run|\.run\(" "$f" || true
doneRepository: crewAIInc/crewAI
Length of output: 7748
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Read the DB2 README with line numbers (cat -n is available)
echo "=== db2_search_tool README (1-120) ==="
cat -n lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/README.md | sed -n '1,120p'
# 2) Inspect DB2 tool implementation around _run
echo
echo "=== db2_search_tool.py (80-320) ==="
sed -n '1,220p' lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py | head -n 220
echo
sed -n '220,340p' lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py | head -n 140
# 3) Find BaseTool definition and run/_run behavior
echo
echo "=== Locate BaseTool ==="
rg -n "class BaseTool" lib/crewai-tools/src -S || true
rg -n "def run\\(" lib/crewai-tools/src -S || true
rg -n "def _run\\(" lib/crewai-tools/src -S | head -n 50 || true
# 4) Inspect BaseTool.run if found
base_tool_file="$(rg -n "class BaseTool" lib/crewai-tools/src -S --files-with-matches | head -n 1 || true)"
echo
echo "=== BaseTool file: ${base_tool_file:-<none>} ==="
if [[ -n "${base_tool_file:-}" ]]; then
sed -n '1,220p' "$base_tool_file" | head -n 220
rg -n "def run\\(" "$base_tool_file" -n -S || true
# print around run if exists
if rg -n "def run\\(" "$base_tool_file" -S >/dev/null; then
line="$(rg -n "def run\\(" "$base_tool_file" -n -S | head -n 1 | cut -d: -f1)"
start=$((line-40))
end=$((line+80))
sed -n "${start},${end}p" "$base_tool_file" | head -n 200
fi
fi
# 5) Compare README conventions with a couple similar tools
echo
echo "=== Check other tool READMEs for import style + _run usage ==="
for f in \
lib/crewai-tools/src/crewai_tools/tools/firecrawl_search_tool/README.md \
lib/crewai-tools/src/crewai_tools/tools/qdrant_vector_search_tool/README.md \
lib/crewai-tools/src/crewai_tools/tools/weaviate_tool/README.md \
lib/crewai-tools/src/crewai_tools/tools/mongodb_vector_search_tool/README.md \
lib/crewai-tools/src/crewai_tools/tools/rag/README.md \
; do
echo "--- $f (import + run/_run lines) ---"
rg -n "^from .* import \\(" "$f" || true
rg -n "_run\\(" "$f" || true
rg -n "\\.run\\(" "$f" || true
doneRepository: crewAIInc/crewAI
Length of output: 19605
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Find BaseTool implementation in the whole repo
rg -n "class BaseTool" . -S --hidden --no-ignore || true
base_tool_file="$(rg -n "class BaseTool" . -S --hidden --no-ignore --files-with-matches | head -n 1 || true)"
echo "BaseTool file: ${base_tool_file:-<none>}"
# 2) If found, inspect around run/_run
if [[ -n "${base_tool_file:-}" ]]; then
sed -n '1,260p' "$base_tool_file" | head -n 260
rg -n "def run\\(" "$base_tool_file" -n -S || true
rg -n "def _run\\(" "$base_tool_file" -n -S || true
# print around def run if present
if rg -n "def run\\(" "$base_tool_file" -n -S >/dev/null; then
line="$(rg -n "def run\\(" "$base_tool_file" -n -S | head -n 1 | cut -d: -f1)"
start=$((line-60)); end=$((line+120))
sed -n "${start},${end}p" "$base_tool_file" | head -n 220
fi
fi
# 3) Inspect db2_search_tool package __init__.py (for export path clues)
echo
echo "=== db2_search_tool __init__.py ==="
cat lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/__init__.py
# 4) Check if there is any top-level module/package named db2_search_tool
echo
echo "=== any top-level db2_search_tool occurrences ==="
fd -t d "db2_search_tool" . --hidden --no-ignore || true
fd -t f "db2_search_tool.py" . --hidden --no-ignore || true
rg -n "from db2_search_tool import" . -S --hidden --no-ignore || true
# 5) Inspect one other README that uses `run()` to see import conventions
echo
echo "=== firecrawl_search_tool README (relevant section) ==="
sed -n '1,120p' lib/crewai-tools/src/crewai_tools/tools/firecrawl_search_tool/README.md
echo
echo "=== qdrant_vector_search_tool README (relevant section) ==="
sed -n '1,120p' lib/crewai-tools/src/crewai_tools/tools/qdrant_vector_search_tool/README.mdRepository: crewAIInc/crewAI
Length of output: 18542
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find where DB2VectorSearchTool is exported publicly
rg -n "DB2VectorSearchTool" lib/crewai-tools/src/crewai_tools -S
# Inspect crewai_tools root __init__ to see public exports
ls -la lib/crewai-tools/src/crewai_tools | head
cat lib/crewai-tools/src/crewai_tools/__init__.py | sed -n '1,220p'
# Also inspect crewai_tools/tools/__init__.py if present
if [[ -f lib/crewai-tools/src/crewai_tools/tools/__init__.py ]]; then
echo "=== crewai_tools/tools/__init__.py ==="
cat lib/crewai-tools/src/crewai_tools/tools/__init__.py | sed -n '1,260p'
fi
# Confirm any documented import paths elsewhere
rg -n "from crewai_tools import .*DB2" -S lib/crewai-tools/src docs || true
rg -n "DB2VectorSearchTool" -S docs lib/crewai-tools/src | head -n 50Repository: crewAIInc/crewAI
Length of output: 23011
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect DB2 docs usage of run/_run and import path
echo "=== db2searchtool.mdx (imports + example blocks) ==="
rg -n "from crewai_tools import DB2VectorSearchTool, DB2Config|tool\\.(run|_run)\\(" docs/en/tools/database-data/db2searchtool.mdx
echo
# Show surrounding lines around each tool.run/_run call
rg -n "tool\\.(run|_run)\\(" docs/en/tools/database-data/db2searchtool.mdx -n --with-filename | cut -d: -f1-3 >/dev/null || true
# Use sed range around the first few matches
line_nums=$(rg -n "tool\\.(run|_run)\\(" docs/en/tools/database-data/db2searchtool.mdx | head -n 10 | cut -d: -f1)
for ln in $line_nums; do
start=$((ln-15)); end=$((ln+15));
echo "---- around line $ln ----"
sed -n "${start},${end}p" docs/en/tools/database-data/db2searchtool.mdx | nl -ba | head -n 80
done
# Inspect crewai_tools top-level exports for DB2VectorSearchTool
echo
echo "=== crewai_tools/__init__.py DB2 exports ==="
rg -n "DB2VectorSearchTool|DB2Config" lib/crewai-tools/src/crewai_tools/__init__.py -n || trueRepository: crewAIInc/crewAI
Length of output: 407
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== crewai_tools/__init__.py (DB2-related lines) ==="
rg -n "DB2VectorSearchTool|DB2Config" lib/crewai-tools/src/crewai_tools/__init__.py -n || true
echo
echo "=== db2searchtool.mdx (around run usage) ==="
sed -n '140,210p' docs/en/tools/database-data/db2searchtool.mdx
echo
echo "=== db2searchtool.mdx (around later example usage) ==="
sed -n '210,270p' docs/en/tools/database-data/db2searchtool.mdxRepository: crewAIInc/crewAI
Length of output: 4265
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "DB2VectorSearchTool" lib/crewai-tools/src/crewai_tools/__init__.py lib/crewai-tools/src/crewai_tools/tools/__init__.py
rg -n "DB2Config" lib/crewai-tools/src/crewai_tools/__init__.py lib/crewai-tools/src/crewai_tools/tools/__init__.pyRepository: crewAIInc/crewAI
Length of output: 42
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Search for DB2 export occurrences anywhere under crewai_tools
rg -n "DB2VectorSearchTool" lib/crewai-tools/src/crewai_tools -S || true
echo "----"
rg -n "db2_search_tool" lib/crewai-tools/src/crewai_tools -S || true
echo "----"
# Inspect root __init__.py export mechanism (look for star imports / __all__)
cat lib/crewai-tools/src/crewai_tools/__init__.py | sed -n '1,260p'
echo "---- (tail) ----"
tail -n 120 lib/crewai-tools/src/crewai_tools/__init__.pyRepository: crewAIInc/crewAI
Length of output: 14900
🏁 Script executed:
rg -n "DB2VectorSearchTool|DB2Config" lib/crewai-tools/src/crewai_tools/__init__.py -S || trueRepository: crewAIInc/crewAI
Length of output: 42
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "DB2VectorSearchTool|DB2Config" lib/crewai-tools/src/crewai_tools/tools/__init__.py -S || true
rg -n "db2_search_tool" lib/crewai-tools/src/crewai_tools/tools/__init__.py -S || trueRepository: crewAIInc/crewAI
Length of output: 42
Fix DB2 README example to use public import path and run()
README uses from db2_search_tool import ... and calls the private tool._run(...). Update the example to import from crewai_tools.tools.db2_search_tool and call tool.run(...) (also update the metadata-filtering snippet that uses _run()).
Suggested fix
-from db2_search_tool import (
+from crewai_tools.tools.db2_search_tool import (
DB2Config,
DB2VectorSearchTool,
)
@@
-result = tool._run(
+result = tool.run(
query="What is machine learning?",
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| from db2_search_tool import ( | |
| DB2Config, | |
| DB2VectorSearchTool, | |
| ) | |
| config = DB2Config( | |
| database="TESTDB", | |
| hostname="localhost", | |
| table_name="documents", | |
| ) | |
| tool = DB2VectorSearchTool( | |
| db2_config=config | |
| ) | |
| result = tool._run( | |
| query="What is machine learning?", | |
| ) | |
| from crewai_tools.tools.db2_search_tool import ( | |
| DB2Config, | |
| DB2VectorSearchTool, | |
| ) | |
| config = DB2Config( | |
| database="TESTDB", | |
| hostname="localhost", | |
| table_name="documents", | |
| ) | |
| tool = DB2VectorSearchTool( | |
| db2_config=config | |
| ) | |
| result = tool.run( | |
| query="What is machine learning?", | |
| ) |
🤖 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/db2_search_tool/README.md` around
lines 40 - 57, Update the README examples to use the public module path and
public API: change the import to crewai_tools.tools.db2_search_tool and
instantiate DB2Config and DB2VectorSearchTool as shown, then call the public
method run(...) instead of the private _run(...); also update any
metadata-filtering example that currently calls _run to call run and pass the
same parameters so examples reference DB2Config, DB2VectorSearchTool, run, and
no longer use _run.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/db2_search_tool/db2_search_tool.py`:
- Around line 53-57: The _validate_filter_pair model validator in DB2ToolSchema
only checks None pairing and allows empty or whitespace-only filter_by which
later gets ignored; update _validate_filter_pair to also reject blank/whitespace
filter_by when filter_value is provided (and vice versa), by treating filter_by
as required to be a non-empty truthy string (e.g., strip() check) whenever
filter_value is not None, and raise ValueError("filter_by and filter_value must
be provided together.") for invalid pairs so the later filtering logic that
checks truthiness behaves correctly.
🪄 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: 66d237cf-253b-46e3-bc2a-e7b8f2935d73
📒 Files selected for processing (1)
lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py (1)
78-80:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winPrevent empty
return_columnsto avoid invalid SQL syntax.If
return_columnsis an empty list, line 290 producescolumn_query="", resulting in malformed SQL (SELECT , VECTOR_DISTANCE...). Add a minimum length constraint.Suggested fix
return_columns: list[str] = Field( - default_factory=lambda: ["content"] + default_factory=lambda: ["content"], + min_length=1, + description="Columns to return from the database. At least one required." )🤖 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/db2_search_tool/db2_search_tool.py` around lines 78 - 80, The return_columns Field is allowed to be an empty list which leads to a malformed SQL fragment when building column_query (e.g., SELECT , VECTOR_DISTANCE...), so add validation on the return_columns Field (or in the class __post_init__/validate method) to ensure its length is >=1; if empty either raise a clear ValueError describing the requirement or coerce it back to the default ["content"]. Update code that builds column_query to assume return_columns is non-empty (or defensively join with a fallback), referencing the return_columns Field and the column_query construction to locate where to add the check.
🤖 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.
Outside diff comments:
In `@lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py`:
- Around line 78-80: The return_columns Field is allowed to be an empty list
which leads to a malformed SQL fragment when building column_query (e.g., SELECT
, VECTOR_DISTANCE...), so add validation on the return_columns Field (or in the
class __post_init__/validate method) to ensure its length is >=1; if empty
either raise a clear ValueError describing the requirement or coerce it back to
the default ["content"]. Update code that builds column_query to assume
return_columns is non-empty (or defensively join with a fallback), referencing
the return_columns Field and the column_query construction to locate where to
add the check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9207b9b7-f5b3-419e-8cf8-a638eacb4a61
📒 Files selected for processing (1)
lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py
|
Fix all unresolved @CodeRabbit comments on this PR |
|
@coderabbitai help |
ChatThere are 3 ways to chat with CodeRabbit:
CodeRabbit commands
Other keywords and placeholders
CodeRabbit configuration file (
|
|
@coderabbitai autofix |
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. An unexpected error occurred while generating fixes: Not Found - https://docs.github.com/rest/git/refs#get-a-reference |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Fetch all review comments by coderabbitai on PR `#5885`
gh pr view 5885 --repo crewAIInc/crewAI --json reviews,comments
echo "=== Review thread comments ==="
gh api repos/crewAIInc/crewAI/pulls/5885/comments --paginate | jq '[.[] | select(.user.login == "coderabbitai") | {id, path, line, body, in_reply_to_id}]'
echo "=== Issue comments ==="
gh api repos/crewAIInc/crewAI/issues/5885/comments --paginate | jq '[.[] | select(.user.login == "coderabbitai") | {id, body}]'
echo "=== All review threads with resolution status ==="
gh api repos/crewAIInc/crewAI/pulls/5885/reviews --paginate | jq '[.[] | select(.user.login == "coderabbitai") | {id, state, body, submitted_at}]'Length of output: 35016 🏁 Script executed: #!/bin/bash
echo "=== __init__.py ==="
cat lib/crewai-tools/src/crewai_tools/tools/__init__.py
echo ""
echo "=== db2_search_tool.py ==="
cat lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py
echo ""
echo "=== README.md ==="
cat lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/README.md
echo ""
echo "=== db2_search_tool __init__.py ==="
cat lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/__init__.pyLength of output: 25056 I've analyzed the current code. Here's what's already fixed vs. still unresolved: Already fixed ✅
Still unresolved ❌ — planning fixes now:
Failed to handle agent chat message. Please try again. |
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. ❌ Failed to clone repository into sandbox. Please try again. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py (3)
335-349: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick winReturn one top-level JSON shape on both success and failure.
Success currently returns a bare list, while failures return an object with
success/error. That forces consumers to branch on JSON type instead of a stable contract for this public tool API. Wrap successful results in the same envelope, e.g.{"success": true, "results": [...]}.🤖 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/db2_search_tool/db2_search_tool.py` around lines 335 - 349, The success path currently returns a bare list (normalized_results) while the exception path returns an envelope with success/error fields; update the success return in the function that produces normalized_results (referencing normalized_results, DB2JSONEncoder, and self._disconnect) to return a top-level envelope like {"success": True, "results": normalized_results} serialized with json.dumps using the same indent and cls=DB2JSONEncoder so both success and failure share a stable JSON shape.
249-257:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winShort-circuit blank queries before calling the embedder.
query=""or whitespace-only input reaches_generate_embedding(), so this can still spend an embedding request and a DB roundtrip on meaningless input. A fast guard here would keep the runtime behavior aligned with the tool's input-validation contract.🤖 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/db2_search_tool/db2_search_tool.py` around lines 249 - 257, Short-circuit blank or whitespace-only queries at the start of _run to avoid calling _generate_embedding and making unnecessary embedding/DB requests: add a guard that checks if query is None or query.strip() == "" and return an early descriptive string/error (consistent with the tool's input-validation contract) before any call to _generate_embedding or DB operations in the _run method.
77-80:⚠️ Potential issue | 🟠 Major | ⚡ Quick winReject empty
return_columns.
DB2Config(return_columns=[])is accepted here, but_run()later turns that intoSELECT , VECTOR_DISTANCE(...), which is invalid SQL after you've already generated an embedding and opened a connection. Fail fast on an empty list in the config layer.🤖 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/db2_search_tool/db2_search_tool.py` around lines 77 - 80, DB2Config currently allows return_columns to be an empty list which later causes invalid SQL in _run() (producing "SELECT , VECTOR_DISTANCE(...)"); validate return_columns in the DB2Config constructor or model (the Field/default_factory for return_columns) to reject empty lists and raise a clear ValueError, or add a pydantic validator on DB2Config that checks return_columns is a non-empty list; ensure the error is raised early (before embedding generation/connection) and reference the return_columns Field and DB2Config/_run() in the message so callers understand the misconfiguration.
🤖 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.
Outside diff comments:
In `@lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py`:
- Around line 335-349: The success path currently returns a bare list
(normalized_results) while the exception path returns an envelope with
success/error fields; update the success return in the function that produces
normalized_results (referencing normalized_results, DB2JSONEncoder, and
self._disconnect) to return a top-level envelope like {"success": True,
"results": normalized_results} serialized with json.dumps using the same indent
and cls=DB2JSONEncoder so both success and failure share a stable JSON shape.
- Around line 249-257: Short-circuit blank or whitespace-only queries at the
start of _run to avoid calling _generate_embedding and making unnecessary
embedding/DB requests: add a guard that checks if query is None or query.strip()
== "" and return an early descriptive string/error (consistent with the tool's
input-validation contract) before any call to _generate_embedding or DB
operations in the _run method.
- Around line 77-80: DB2Config currently allows return_columns to be an empty
list which later causes invalid SQL in _run() (producing "SELECT ,
VECTOR_DISTANCE(...)"); validate return_columns in the DB2Config constructor or
model (the Field/default_factory for return_columns) to reject empty lists and
raise a clear ValueError, or add a pydantic validator on DB2Config that checks
return_columns is a non-empty list; ensure the error is raised early (before
embedding generation/connection) and reference the return_columns Field and
DB2Config/_run() in the message so callers understand the misconfiguration.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4242fd09-330d-47e7-a6f9-5845c35b648f
📒 Files selected for processing (1)
lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py
… and config validation
|
Hi @greysonlalonde, |
37e11be to
468149e
Compare
…viour. 'OpenAI embedding fallback' implied it was optional. Replaced with 'Uses a custom embedding function if supplied, otherwise OpenAI embeddings.'
… and config validation
9655947 to
b22fe41
Compare
…ibm-db2-review-fix # Conflicts: # docs/v1.13.0/en/tools/database-data/db2searchtool.mdx # lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/README.md # lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/__init__.py # lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py
lorenzejay
left a comment
There was a problem hiding this comment.
Review findings from the current head. These should be addressed before merge; I left the PR approval state unchanged.
| return self | ||
|
|
||
| db2_package: ImportString[Any] = Field( | ||
| default="ibm_db", |
There was a problem hiding this comment.
ImportString does not validate default values unless default validation is enabled, so the documented/default construction leaves db2_package and db2_dbi_package as plain strings. _connect() then fails on self.db2_package.connect(...). Please enable default validation, use factories that import the modules, or resolve them explicitly in _connect(), and add a test that does not inject these two fields.
There was a problem hiding this comment.
Totally valid catch. We dropped ImportString from both fields and moved resolution into _connect() via _resolve_db2_packages(), which handles both None defaults and explicit string names like "ibm_db". Also added test_connect_resolves_packages_without_injection — constructs the tool without injecting either field and drives through _connect() to confirm the packages get resolved and the connection comes up.
|
|
||
| ```python | ||
| from crewai import Agent | ||
| from crewai_tools import DB2VectorSearchTool, DB2Config |
There was a problem hiding this comment.
This documented public API does not exist: the PR does not export DB2VectorSearchTool from crewai_tools, and no DB2Config class is implemented or exported. As written, every example fails at import time. Please either implement/export the documented API or update all examples to the actual constructor and make that constructor publicly importable.
There was a problem hiding this comment.
Fixed — DB2Config never existed and DB2VectorSearchTool wasn't exported, so all examples were broken at import. Both DB2VectorSearchTool and DB2ToolSchema are now exported from crewai_tools, and all examples have been updated to use the actual connection_string constructor.
| _ALLOWED_METRICS: ClassVar[set[str]] = { | ||
| "COSINE", | ||
| "EUCLIDEAN", | ||
| "DOT_PRODUCT", |
There was a problem hiding this comment.
These metric names do not match Db2's VECTOR_DISTANCE API. Db2 supports COSINE, EUCLIDEAN, EUCLIDEAN_SQUARED, DOT, HAMMING, and MANHATTAN; DOT_PRODUCT and L2_DISTANCE will be accepted here but fail when the SQL executes. Please align the whitelist and documentation with the Db2 names: https://www.ibm.com/docs/en/db2/12.1.x?topic=functions-vector-distance
There was a problem hiding this comment.
Good catch — DOT_PRODUCT and L2_DISTANCE were incorrect and would have passed the whitelist check before failing silently at SQL execution. We've updated _ALLOWED_METRICS to exactly match the Db2 VECTOR_DISTANCE API: COSINE, EUCLIDEAN, EUCLIDEAN_SQUARED, DOT, HAMMING, and MANHATTAN. The docs have been updated to reflect the same six values with a link to the IBM reference.
| DirectoryReadTool, | ||
| ) | ||
| # from crewai_tools.tools.directory_read_tool.directory_read_tool import ( | ||
| # DirectoryReadTool, |
There was a problem hiding this comment.
This is an unrelated public API regression: it breaks from crewai_tools.tools import DirectoryReadTool. Please restore both this import and the corresponding __all__ entry; adding the Db2 tool should not remove an existing tool export.
There was a problem hiding this comment.
Good catch — DirectoryReadTool was accidentally commented out when the DB2 tool imports were added. We've restored both the import and the all entry, so from crewai_tools import DirectoryReadTool works correctly again.
| @@ -0,0 +1,279 @@ | |||
| --- | |||
There was a problem hiding this comment.
Repository policy treats docs/v*/ as frozen release snapshots managed by devtools. New documentation should be added under docs/edge/en/ and referenced from docs/docs.json when needed, rather than modifying a versioned snapshot.
There was a problem hiding this comment.
The frozen snapshot has been cleaned up — docs/v1.13.0/en/tools/database-data/db2searchtool.mdx was deleted entirely, and the documentation now lives at docs/edge/en/tools/database-data/db2searchtool.mdx with a corresponding entry in docs/docs.json. No versioned snapshot directories were modified.
- Restore DirectoryReadTool export accidentally removed; add DB2VectorSearchTool and DB2ToolSchema to crewai_tools.tools __init__ and __all__ - Align _ALLOWED_METRICS whitelist with Db2 VECTOR_DISTANCE API: replace DOT_PRODUCT/L2_DISTANCE with EUCLIDEAN_SQUARED/DOT/HAMMING/MANHATTAN - Replace ImportString fields for db2_package/db2_dbi_package with plain Any + lazy importlib.import_module in new _resolve_db2_packages() to avoid Pydantic default-validation gap where strings were never resolved at construction time - Move docs from frozen docs/v1.13.0/ snapshot to docs/edge/en/tools/database-data/ and register in docs/docs.json; update examples to match actual API (connection_string constructor, not DB2Config), correct return format, and align documented distance metrics with the whitelist
…-fixes fix(db2-search-tool): address PR review comments
78612aa to
0cf1309
Compare
lorenzejay
left a comment
There was a problem hiding this comment.
Two remaining issues:
|
|
||
| ```python | ||
| from crewai import Agent | ||
| from crewai_tools import DB2VectorSearchTool |
There was a problem hiding this comment.
This import still fails: DB2VectorSearchTool was added to crewai_tools.tools, but not the package-level crewai_tools/__init__.py. Please export it there and add a public-import test.
There was a problem hiding this comment.
Missed this one — DB2VectorSearchTool was only exported from crewai_tools.tools, not from the top-level crewai_tools package, so from crewai_tools import DB2VectorSearchTool would fail at import. Both DB2VectorSearchTool and DB2ToolSchema are now in crewai_tools/init.py and all. Added test_public_import_from_crewai_tools to cover the package-level import explicitly. All 70 tests passing.
| # Installation | ||
|
|
||
| ```bash | ||
| pip install ibm_db ibm_db_dbi openai |
There was a problem hiding this comment.
ibm_db_dbi is bundled with ibm_db, not a separate PyPI package. Please use uv add ibm_db openai.
There was a problem hiding this comment.
ibm_db_dbi is bundled with ibm_db so it doesn't need to be listed separately — removed it. Also switched pip install to uv add to match the repo convention, and updated the example import to use the public from crewai_tools import DB2VectorSearchTool path now that it's properly exported at the package level.
…om package-level crewai_tools
Closes #5925
Overview
This PR introduces a Db2 Vector Search Tool for CrewAI tools, enabling semantic/vector similarity search using Db2 native vector capabilities.
The implementation follows existing CrewAI tools architecture patterns to maintain consistency, extensibility, and maintainability across vector search integrations.
Components Added
DB2VectorSearchTool
Main CrewAI tool implementation providing:
DB2Config
Configuration model for:
DB2ToolSchema
Pydantic-based input schema for:
Features
Vector Search Support
Provides semantic/vector similarity retrieval using Db2 native vector functionality with:
Flexible Embedding Support
Supports:
Validation & Security
Added validation and sanitization support for:
Connection Lifecycle Management
Added support for:
Serialization Handling
Implemented standardized JSON serialization support for Db2-specific response types including:
Current Scope
This implementation currently focuses on:
The following are currently out of scope:
Testing
Completed end-to-end local testing for:
Documentation
Added documentation covering:
Summary by CodeRabbit
New Features
Breaking Changes
Documentation