Skip to content

Commit fe5b2d5

Browse files
authored
Add CrewAI instrumentor (#33)
* Add CrewAI instrumentor * Add crewAI instrumentor * Add CrewAI information and tests * fix tests * fix crewai tests * fix crewai tests
1 parent d94a1c7 commit fe5b2d5

File tree

14 files changed

+3195
-9
lines changed

14 files changed

+3195
-9
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install package and test deps
2828
run: |
2929
pip install -e .
30-
pip install pytest pytest-cov pydantic-ai
30+
pip install pytest pytest-cov pydantic-ai crewai
3131
3232
- name: Run unit tests with coverage
3333
run: |

AGENTS.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Agent Guidelines
2+
3+
## Running Tests
4+
5+
**IMPORTANT:** Always run tests after making code changes to verify they work correctly.
6+
7+
### Running Tests
8+
9+
```bash
10+
# Activate the virtual environment first
11+
source /Users/tgillam/code/gradient-adk/env/bin/activate
12+
13+
# Run all tests
14+
python -m pytest tests/ -v
15+
16+
# Run a specific test file
17+
python -m pytest tests/runtime/test_crewai/crewai_instrumentor_test.py -v
18+
19+
# Run a specific test
20+
python -m pytest tests/runtime/test_crewai/crewai_instrumentor_test.py::test_install_sets_installed_flag -v
21+
22+
# Run tests without coverage (faster)
23+
python -m pytest tests/ -v --no-cov
24+
```
25+
26+
### Test Directory Naming
27+
28+
**CRITICAL:** Test directories must NOT have the same name as Python packages being tested.
29+
30+
For example:
31+
- BAD: `tests/runtime/crewai/` - This shadows the real `crewai` package!
32+
- GOOD: `tests/runtime/test_crewai/` - This doesn't conflict with the real package.
33+
34+
When pytest runs, it adds test directories to `sys.path`. If a test directory has the same name as an installed package, Python will import the test directory instead of the real package, causing import errors like "No module named 'package.submodule'".
35+
36+
### Dependencies
37+
38+
Some tests require optional dependencies:
39+
- `crewai` - For CrewAI instrumentor tests
40+
- `pydantic-ai` - For PydanticAI instrumentor tests
41+
42+
Install optional test dependencies:
43+
```bash
44+
pip install crewai pydantic-ai
45+
```
46+
47+
### Environment Variables for Integration Tests
48+
49+
Some integration tests require environment variables:
50+
- `RUN_E2E_TESTS=1` - Enable E2E tests
51+
- `RUN_DEPLOY_TESTS=1` - Enable deployment tests
52+
- `GRADIENT_MODEL_ACCESS_KEY` - For LLM API calls
53+
- `SERPER_API_KEY` - For search tool tests

gradient_adk/digital_ocean_api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ToolSpanDetails,
66
RetrieverSpanDetails,
77
WorkflowSpanDetails,
8+
AgentSpanDetails,
89
Span,
910
Trace,
1011
CreateTracesInput,
@@ -48,6 +49,7 @@
4849
"ToolSpanDetails",
4950
"RetrieverSpanDetails",
5051
"WorkflowSpanDetails",
52+
"AgentSpanDetails",
5153
"Span",
5254
"Trace",
5355
"CreateTracesInput",

gradient_adk/digital_ocean_api/models.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ class WorkflowSpanDetails(BaseModel):
7171
spans: List["Span"] = Field(default_factory=list, description="Nested sub-spans")
7272

7373

74+
class AgentSpanDetails(BaseModel):
75+
"""Agent span containing nested sub-spans for LLM and tool calls."""
76+
77+
model_config = ConfigDict(populate_by_name=True, extra="allow")
78+
79+
common: Optional[SpanCommon] = None
80+
spans: List["Span"] = Field(default_factory=list, description="Nested sub-spans")
81+
82+
7483
class Span(BaseModel):
7584
"""
7685
Represents a span within a trace (e.g., LLM call, retriever, tool, workflow).
@@ -99,10 +108,14 @@ class Span(BaseModel):
99108
workflow: Optional[WorkflowSpanDetails] = Field(
100109
None, description="Workflow span with nested sub-spans"
101110
)
111+
agent: Optional[AgentSpanDetails] = Field(
112+
None, description="Agent span with nested sub-spans"
113+
)
102114

103115

104-
# Update forward reference for WorkflowSpanDetails
116+
# Update forward references for nested span details
105117
WorkflowSpanDetails.model_rebuild()
118+
AgentSpanDetails.model_rebuild()
106119

107120

108121
class Trace(BaseModel):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""CrewAI instrumentation for Gradient ADK."""
2+
3+
from .crewai_instrumentor import CrewAIInstrumentor
4+
5+
__all__ = ["CrewAIInstrumentor"]

0 commit comments

Comments
 (0)