Compare commits

..

6 Commits

Author SHA1 Message Date
Devin AI
7e38e09307 Fix import sorting in test_span_creation function
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-14 10:39:13 +00:00
Devin AI
ae88b56f9c Add span creation test and documentation for version constraints
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-14 10:37:49 +00:00
Devin AI
2d07504b96 Fix import sorting issues in test file
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-14 10:33:51 +00:00
Devin AI
92e2d9491e Enhance tests and refine OpenTelemetry version constraints
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-14 10:32:05 +00:00
Devin AI
e60ad726b9 Fix import sorting in test file
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-14 10:29:30 +00:00
Devin AI
7f55f830a0 Fix #2372: Update OpenTelemetry version constraints for compatibility with newer versions
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-14 10:27:58 +00:00
12 changed files with 128 additions and 112 deletions

View File

@@ -106,7 +106,6 @@ Here is a list of the available tools and their descriptions:
| Tool | Description |
| :------------------------------- | :--------------------------------------------------------------------------------------------- |
| **ApifyActorsTool** | A tool that integrates Apify Actors with your workflows for web scraping and automation tasks. |
| **BrowserbaseLoadTool** | A tool for interacting with and extracting data from web browsers. |
| **CodeDocsSearchTool** | A RAG tool optimized for searching through code documentation and related technical documents. |
| **CodeInterpreterTool** | A tool for interpreting python code. |

View File

@@ -115,7 +115,6 @@
"concepts/testing",
"concepts/cli",
"concepts/tools",
"concepts/event-listener",
"concepts/langchain-tools",
"concepts/llamaindex-tools"
]
@@ -155,7 +154,6 @@
"group": "Tools",
"pages": [
"tools/aimindtool",
"tools/apifyactorstool",
"tools/bravesearchtool",
"tools/browserbaseloadtool",
"tools/codedocssearchtool",
@@ -222,4 +220,4 @@
"linkedin": "https://www.linkedin.com/company/crewai-inc",
"youtube": "https://youtube.com/@crewAIInc"
}
}
}

View File

@@ -1,99 +0,0 @@
---
title: Apify Actors
description: "`ApifyActorsTool` lets you call Apify Actors to provide your CrewAI workflows with web scraping, crawling, data extraction, and web automation capabilities."
# hack to use custom Apify icon
icon: "); -webkit-mask-image: url('https://upload.wikimedia.org/wikipedia/commons/a/ae/Apify.svg');/*"
---
# `ApifyActorsTool`
Integrate [Apify Actors](https://apify.com/actors) into your CrewAI workflows.
## Description
The `ApifyActorsTool` connects [Apify Actors](https://apify.com/actors), cloud-based programs for web scraping and automation, to your CrewAI workflows.
Use any of the 4,000+ Actors on [Apify Store](https://apify.com/store) for use cases such as extracting data from social media, search engines, online maps, e-commerce sites, travel portals, or general websites.
For details, see the [Apify CrewAI integration](https://docs.apify.com/platform/integrations/crewai) in Apify documentation.
## Steps to get started
<Steps>
<Step title="Install dependencies">
Install `crewai[tools]` and `langchain-apify` using pip: `pip install 'crewai[tools]' langchain-apify`.
</Step>
<Step title="Obtain an Apify API token">
Sign up to [Apify Console](https://console.apify.com/) and get your [Apify API token](https://console.apify.com/settings/integrations)..
</Step>
<Step title="Configure environment">
Set your Apify API token as the `APIFY_API_TOKEN` environment variable to enable the tool's functionality.
</Step>
</Steps>
## Usage example
Use the `ApifyActorsTool` manually to run the [RAG Web Browser Actor](https://apify.com/apify/rag-web-browser) to perform a web search:
```python
from crewai_tools import ApifyActorsTool
# Initialize the tool with an Apify Actor
tool = ApifyActorsTool(actor_name="apify/rag-web-browser")
# Run the tool with input parameters
results = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5})
# Process the results
for result in results:
print(f"URL: {result['metadata']['url']}")
print(f"Content: {result.get('markdown', 'N/A')[:100]}...")
```
### Expected output
Here is the output from running the code above:
```text
URL: https://www.example.com/crewai-intro
Content: CrewAI is a framework for building AI-powered workflows...
URL: https://docs.crewai.com/
Content: Official documentation for CrewAI...
```
The `ApifyActorsTool` automatically fetches the Actor definition and input schema from Apify using the provided `actor_name` and then constructs the tool description and argument schema. This means you need to specify only a valid `actor_name`, and the tool handles the rest when used with agents—no need to specify the `run_input`. Here's how it works:
```python
from crewai import Agent
from crewai_tools import ApifyActorsTool
rag_browser = ApifyActorsTool(actor_name="apify/rag-web-browser")
agent = Agent(
role="Research Analyst",
goal="Find and summarize information about specific topics",
backstory="You are an experienced researcher with attention to detail",
tools=[rag_browser],
)
```
You can run other Actors from [Apify Store](https://apify.com/store) simply by changing the `actor_name` and, when using it manually, adjusting the `run_input` based on the Actor input schema.
For an example of usage with agents, see the [CrewAI Actor template](https://apify.com/templates/python-crewai).
## Configuration
The `ApifyActorsTool` requires these inputs to work:
- **`actor_name`**
The ID of the Apify Actor to run, e.g., `"apify/rag-web-browser"`. Browse all Actors on [Apify Store](https://apify.com/store).
- **`run_input`**
A dictionary of input parameters for the Actor when running the tool manually.
- For example, for the `apify/rag-web-browser` Actor: `{"query": "search term", "maxResults": 5}`
- See the Actor's [input schema](https://apify.com/apify/rag-web-browser/input-schema) for the list of input parameters.
## Resources
- **[Apify](https://apify.com/)**: Explore the Apify platform.
- **[How to build an AI agent on Apify](https://blog.apify.com/how-to-build-an-ai-agent/)** - A complete step-by-step guide to creating, publishing, and monetizing AI agents on the Apify platform.
- **[RAG Web Browser Actor](https://apify.com/apify/rag-web-browser)**: A popular Actor for web search for LLMs.
- **[CrewAI Integration Guide](https://docs.apify.com/platform/integrations/crewai)**: Follow the official guide for integrating Apify and CrewAI.

View File

@@ -1,6 +1,6 @@
[project]
name = "crewai"
version = "0.108.0"
version = "0.105.0"
description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks."
readme = "README.md"
requires-python = ">=3.10,<3.13"
@@ -17,9 +17,11 @@ dependencies = [
"pdfplumber>=0.11.4",
"regex>=2024.9.11",
# Telemetry and Monitoring
"opentelemetry-api>=1.22.0",
"opentelemetry-sdk>=1.22.0",
"opentelemetry-exporter-otlp-proto-http>=1.22.0",
# Version constraints ensure compatibility with various OpenTelemetry versions
# while preventing installation of incompatible versions (issue #2372)
"opentelemetry-api>=1.22.0,<1.32.0",
"opentelemetry-sdk>=1.22.0,<1.32.0",
"opentelemetry-exporter-otlp-proto-http>=1.22.0,<1.32.0",
# Data Handling
"chromadb>=0.5.23",
"openpyxl>=3.1.5",

View File

@@ -14,7 +14,7 @@ warnings.filterwarnings(
category=UserWarning,
module="pydantic.main",
)
__version__ = "0.108.0"
__version__ = "0.105.0"
__all__ = [
"Agent",
"Crew",

View File

@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
authors = [{ name = "Your Name", email = "you@example.com" }]
requires-python = ">=3.10,<3.13"
dependencies = [
"crewai[tools]>=0.108.0,<1.0.0"
"crewai[tools]>=0.105.0,<1.0.0"
]
[project.scripts]

View File

@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
authors = [{ name = "Your Name", email = "you@example.com" }]
requires-python = ">=3.10,<3.13"
dependencies = [
"crewai[tools]>=0.108.0,<1.0.0",
"crewai[tools]>=0.105.0,<1.0.0",
]
[project.scripts]

View File

@@ -5,7 +5,7 @@ description = "Power up your crews with {{folder_name}}"
readme = "README.md"
requires-python = ">=3.10,<3.13"
dependencies = [
"crewai[tools]>=0.108.0"
"crewai[tools]>=0.105.0"
]
[tool.crewai]

View File

View File

@@ -0,0 +1,116 @@
from importlib import import_module
import pytest
def test_opentelemetry_imports():
"""Test that all required OpenTelemetry modules can be imported.
This test verifies that all necessary OpenTelemetry modules can be imported
correctly with the current version constraints, ensuring compatibility
between different OpenTelemetry packages.
"""
try:
# Test basic imports
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
OTLPSpanExporter,
)
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.trace import Span, Status, StatusCode
# Verify that the imports are from the expected modules
assert trace.__name__ == 'opentelemetry.trace'
assert OTLPSpanExporter.__module__ == 'opentelemetry.exporter.otlp.proto.http.trace_exporter'
assert Resource.__module__ == 'opentelemetry.sdk.resources'
assert TracerProvider.__module__ == 'opentelemetry.sdk.trace'
assert BatchSpanProcessor.__module__ == 'opentelemetry.sdk.trace.export'
assert Span.__module__ == 'opentelemetry.trace.span'
assert Status.__module__ == 'opentelemetry.trace.status'
assert StatusCode.__module__ == 'opentelemetry.trace.status'
except ImportError as e:
pytest.fail(f"Failed to import OpenTelemetry modules: {e}")
def test_telemetry_class_initialization():
"""Test that the Telemetry class can be initialized with current OpenTelemetry versions.
This test verifies that the Telemetry class can be properly initialized and
that its core attributes are set correctly. It also tests the set_tracer method
to ensure it works as expected with the current OpenTelemetry versions.
"""
try:
from src.crewai.telemetry.telemetry import Telemetry
# Create an instance of the Telemetry class
telemetry = Telemetry()
# Check if the telemetry instance is initialized correctly
assert hasattr(telemetry, 'ready')
assert hasattr(telemetry, 'trace_set')
assert telemetry.trace_set is False # Should be False initially
# Try to set the tracer
telemetry.set_tracer()
# After setting the tracer, trace_set should be True if ready is True
if telemetry.ready:
assert telemetry.trace_set is True
except ImportError as e:
pytest.fail(f"Failed to import Telemetry class: {e}")
def test_telemetry_configuration():
"""Test that the Telemetry class can be configured with different options.
This test verifies that the Telemetry class respects environment variables
for disabling telemetry collection.
"""
import os
from src.crewai.telemetry.telemetry import Telemetry
# Test with telemetry disabled via environment variable
os.environ["OTEL_SDK_DISABLED"] = "true"
telemetry = Telemetry()
assert telemetry.ready is False
# Reset environment variable
os.environ.pop("OTEL_SDK_DISABLED", None)
def test_span_creation():
"""Test that spans can be created with the current OpenTelemetry versions.
This test verifies that the Telemetry class can create spans using the
OpenTelemetry tracer, which is a core functionality for telemetry.
"""
import os
from opentelemetry import trace
from src.crewai.telemetry.telemetry import Telemetry
# Ensure telemetry is enabled for this test
if "OTEL_SDK_DISABLED" in os.environ:
old_value = os.environ.pop("OTEL_SDK_DISABLED")
try:
telemetry = Telemetry()
telemetry.set_tracer()
# Only test span creation if telemetry is ready
if telemetry.ready and telemetry.trace_set:
tracer = trace.get_tracer("crewai.telemetry.test")
if tracer:
with tracer.start_as_current_span("test_operation") as span:
assert span is not None
assert span.is_recording()
except Exception as e:
pytest.fail(f"Failed to create span: {e}")
finally:
# Restore environment variable if it was set
if "old_value" in locals():
os.environ["OTEL_SDK_DISABLED"] = old_value

2
uv.lock generated
View File

@@ -619,7 +619,7 @@ wheels = [
[[package]]
name = "crewai"
version = "0.108.0"
version = "0.105.0"
source = { editable = "." }
dependencies = [
{ name = "appdirs" },