Compare commits

...

6 Commits

Author SHA1 Message Date
Greyson LaLonde
4068fa3cfd ci: diff explicit base...head shas to match files-changed 2026-06-17 17:04:16 -07:00
Greyson LaLonde
474496f928 Merge branch 'main' into ci/python-pr-size-gate 2026-06-17 17:01:11 -07:00
iris-clawd
9d70553515 Use safe expression parser in calculator tool example (#6211)
* Replace eval with safe expression parser in calculator tool example

Update the calculator tool example in the CLI template to use
ast.parse instead of eval for expression evaluation.

Co-authored-by: Vinicius Brasil <vini@hey.com>

* Replace calculator example with practical file reader tool

* Use word count example - safe, no file/eval risk

---------

Co-authored-by: Vinicius Brasil <vini@hey.com>
2026-06-17 16:59:26 -07:00
Greyson LaLonde
c2d28b932a ci: scope job permissions and use immutable base sha 2026-06-17 16:53:02 -07:00
Greyson LaLonde
3fcbc38280 ci: fail PRs over 1500 lines of python changes 2026-06-17 16:46:36 -07:00
Gabe Milani
0a577b7d05 fix: remove duplicated Exa tool (#6205)
Some checks failed
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Check Documentation Broken Links / Check broken links (push) Has been cancelled
Vulnerability Scan / pip-audit (push) Has been cancelled
Build uv cache / build-cache (3.10) (push) Has been cancelled
Build uv cache / build-cache (3.11) (push) Has been cancelled
Build uv cache / build-cache (3.12) (push) Has been cancelled
Build uv cache / build-cache (3.13) (push) Has been cancelled
Nightly Canary Release / Check for new commits (push) Has been cancelled
Nightly Canary Release / Build nightly packages (push) Has been cancelled
Nightly Canary Release / Publish nightly to PyPI (push) Has been cancelled
* fix: remove duplicated Exa tool

* fix tests
2026-06-17 14:41:44 -07:00
7 changed files with 68 additions and 228 deletions

View File

@@ -29,4 +29,30 @@ jobs:
lib/crewai/src/crewai/cli/templates/**
**/*.json
**/test_durations/**
**/cassettes/**
**/cassettes/**
python-diff-size:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
- name: Enforce Python diff size limit
env:
MAX: "1500"
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
# Three-dot base...head == merge-base(base, head)..head: matches GitHub's
# "Files changed" diff and ignores the synthetic merge commit at HEAD.
# Sum added + deleted lines across changed .py files; skip binaries ("-").
total=$(git diff --numstat "$BASE_SHA...$HEAD_SHA" -- '*.py' \
| awk '$1 != "-" && $2 != "-" { sum += $1 + $2 } END { print sum + 0 }')
echo "Python churn: $total lines (limit $MAX)"
if [ "$total" -gt "$MAX" ]; then
echo "::error::Python changes total $total lines, over the $MAX-line limit. Split into smaller PRs."
git diff --numstat "$BASE_SHA...$HEAD_SHA" -- '*.py' | sort -rn
exit 1
fi

View File

@@ -767,10 +767,11 @@ class CustomSearchTool(BaseTool):
```python
from crewai.tools import tool
@tool("Calculator")
def calculator(expression: str) -> str:
"""Evaluates a mathematical expression and returns the result."""
return str(eval(expression))
@tool("WordCount")
def word_count(text: str) -> str:
"""Counts the number of words in the given text."""
count = len(text.split())
return f"Word count: {count}"
```
### Built-in Tools (install with `uv add crewai-tools`)

View File

@@ -32,6 +32,8 @@ class ToolSpecExtractor:
if name.endswith("Tool") and name not in self.processed_tools:
obj = getattr(tools, name, None)
if inspect.isclass(obj) and issubclass(obj, BaseTool):
if getattr(obj, "is_deprecated_alias", False):
continue
self.extract_tool_info(obj)
self.processed_tools.add(name)
return self.tools_spec

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
from builtins import type as type_
import os
from typing import Any, TypedDict
from typing import Any, ClassVar, TypedDict
import warnings
from crewai.tools import BaseTool, EnvVar
@@ -160,6 +160,8 @@ class ExaSearchTool(BaseTool):
class EXASearchTool(ExaSearchTool):
"""Deprecated alias for :class:`ExaSearchTool`. Kept for backwards compatibility."""
is_deprecated_alias: ClassVar[bool] = True
name: str = "ExaSearchTool"
def __init__(self, *args: Any, **kwargs: Any) -> None:

View File

@@ -1,3 +1,4 @@
import builtins
import json
from unittest import mock
@@ -7,6 +8,19 @@ from pydantic import BaseModel, Field
import pytest
def _getattr_for(tool_name, tool_cls):
"""Build a getattr side_effect that resolves the patched tool name to
``tool_cls`` while delegating every other lookup (e.g. the
``is_deprecated_alias`` check) to the real builtin."""
def _getattr(obj, name, *default):
if name == tool_name:
return tool_cls
return builtins.getattr(obj, name, *default)
return _getattr
class MockToolSchema(BaseModel):
query: str = Field(..., description="The query parameter")
count: int = Field(5, description="Number of results to return")
@@ -84,7 +98,10 @@ def test_unwrap_schema(extractor):
def mock_tool_extractor(extractor):
with (
mock.patch("crewai_tools.generate_tool_specs.dir", return_value=["MockTool"]),
mock.patch("crewai_tools.generate_tool_specs.getattr", return_value=MockTool),
mock.patch(
"crewai_tools.generate_tool_specs.getattr",
side_effect=_getattr_for("MockTool", MockTool),
),
):
extractor.extract_all_tools()
assert len(extractor.tools_spec) == 1
@@ -223,7 +240,7 @@ def test_intermediate_base_fields_preserved_for_derived_tool(extractor):
),
mock.patch(
"crewai_tools.generate_tool_specs.getattr",
return_value=MockDerivedTool,
side_effect=_getattr_for("MockDerivedTool", MockDerivedTool),
),
):
extractor.extract_all_tools()
@@ -253,7 +270,10 @@ def test_future_base_tool_field_auto_excluded(extractor):
by checking that ONLY non-BaseTool fields appear."""
with (
mock.patch("crewai_tools.generate_tool_specs.dir", return_value=["MockTool"]),
mock.patch("crewai_tools.generate_tool_specs.getattr", return_value=MockTool),
mock.patch(
"crewai_tools.generate_tool_specs.getattr",
side_effect=_getattr_for("MockTool", MockTool),
),
):
extractor.extract_all_tools()
tool_info = extractor.tools_spec[0]

View File

@@ -111,3 +111,11 @@ def test_exasearchtool_alias_is_deprecated():
with pytest.warns(DeprecationWarning, match="ExaSearchTool"):
tool = EXASearchTool(api_key="test_api_key")
assert isinstance(tool, ExaSearchTool)
def test_deprecated_alias_excluded_from_tool_specs():
from crewai_tools.generate_tool_specs import ToolSpecExtractor
names = {tool["name"] for tool in ToolSpecExtractor().extract_all_tools()}
assert "ExaSearchTool" in names
assert "EXASearchTool" not in names

View File

@@ -9622,225 +9622,6 @@
"type": "object"
}
},
{
"description": "Search the web with Exa, the fastest and most accurate web search API.",
"env_vars": [
{
"default": null,
"description": "API key for Exa services",
"name": "EXA_API_KEY",
"required": false
},
{
"default": null,
"description": "API url for the Exa services",
"name": "EXA_BASE_URL",
"required": false
}
],
"humanized_name": "ExaSearchTool",
"init_params_schema": {
"$defs": {
"EnvVar": {
"properties": {
"default": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Default"
},
"description": {
"title": "Description",
"type": "string"
},
"name": {
"title": "Name",
"type": "string"
},
"required": {
"default": true,
"title": "Required",
"type": "boolean"
}
},
"required": [
"name",
"description"
],
"title": "EnvVar",
"type": "object"
}
},
"description": "Deprecated alias for :class:`ExaSearchTool`. Kept for backwards compatibility.",
"properties": {
"api_key": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "API key for Exa services",
"required": false,
"title": "Api Key"
},
"base_url": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"description": "API server url",
"required": false,
"title": "Base Url"
},
"client": {
"anyOf": [
{},
{
"type": "null"
}
],
"default": null,
"title": "Client"
},
"content": {
"anyOf": [
{
"type": "boolean"
},
{
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"default": false,
"title": "Content"
},
"highlights": {
"anyOf": [
{
"type": "boolean"
},
{
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"default": true,
"title": "Highlights"
},
"summary": {
"anyOf": [
{
"type": "boolean"
},
{
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"default": false,
"title": "Summary"
},
"type": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": "auto",
"title": "Type"
}
},
"required": [],
"title": "EXASearchTool",
"type": "object"
},
"name": "EXASearchTool",
"package_dependencies": [
"exa_py"
],
"run_params_schema": {
"properties": {
"end_published_date": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "End date for the search",
"title": "End Published Date"
},
"include_domains": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"description": "List of domains to include in the search",
"title": "Include Domains"
},
"search_query": {
"description": "Mandatory search query you want to use to search the internet",
"title": "Search Query",
"type": "string"
},
"start_published_date": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Start date for the search",
"title": "Start Published Date"
}
},
"required": [
"search_query"
],
"title": "ExaBaseToolSchema",
"type": "object"
}
},
{
"description": "Search the web with Exa, the fastest and most accurate web search API.",
"env_vars": [