Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b1b500a
Add SmoLAgents instrumentation
Dwij1704 May 15, 2025
216328c
Merge branch 'main' into smolagents-instrumentation
Dwij1704 May 15, 2025
0cad666
Merge branch 'main' of github.com:AgentOps-AI/agentops into smolagent…
Dwij1704 May 30, 2025
d8dd43a
Remove deprecated instrumentor definitions from `__init__.py` to stre…
Dwij1704 May 30, 2025
184584e
Add SmoLAgents instrumentation
Dwij1704 May 30, 2025
70c4204
Refactor multi_smolagents_system notebook to streamline agent managem…
Dwij1704 May 30, 2025
67d508d
Add a blank line for improved readability in `__init__.py`
Dwij1704 May 30, 2025
c4ae09b
Refactor SmoLAgents instrumentation for improved clarity and consiste…
Dwij1704 May 30, 2025
835a1e3
Merge branch 'main' into smolagents-instrumentation
Dwij1704 Jun 3, 2025
2676c56
Merge branch 'main' into smolagents-instrumentation
bboynton97 Jun 6, 2025
633f57b
Merge branch 'main' into smolagents-instrumentation
Dwij1704 Jun 12, 2025
17d821a
feat: Add multi-agent system notebook example
Dwij1704 Jun 12, 2025
ac323f4
fix: Update execution counts and correct session ending method in mul…
Dwij1704 Jun 12, 2025
eb0eb7e
fix: Correct markdown formatting and remove deprecated multi-agent ex…
Dwij1704 Jun 12, 2025
ca56c44
feat: Add Smolagents integration documentation and examples
Dwij1704 Jun 12, 2025
a4c5ad7
Merge branch 'main' into smolagents-instrumentation
Dwij1704 Jun 12, 2025
bd606b2
fix: Add missing newline before InstrumentorLoader class definition
Dwij1704 Jun 12, 2025
2dae98c
feat: Add smolagents integration card to examples documentation
Dwij1704 Jun 12, 2025
de7338c
feat: Update examples and introduction documentation to include Smola…
Dwij1704 Jun 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions agentops/instrumentation/common/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,27 @@
attributes[CoreAttributes.PARENT_ID] = parent_id

return attributes


def extract_token_usage(response: Any) -> Dict[str, int]:
"""Extract token usage information from a response.

Args:
response: The response object to extract token usage from

Returns:
Dictionary containing token usage information
"""
usage = {}

Check warning on line 266 in agentops/instrumentation/common/attributes.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/common/attributes.py#L266

Added line #L266 was not covered by tests

# Try to extract token counts from response
if hasattr(response, "usage"):
usage_data = response.usage
if hasattr(usage_data, "prompt_tokens"):
usage["prompt_tokens"] = usage_data.prompt_tokens
if hasattr(usage_data, "completion_tokens"):
usage["completion_tokens"] = usage_data.completion_tokens
if hasattr(usage_data, "total_tokens"):
usage["total_tokens"] = usage_data.total_tokens

Check warning on line 276 in agentops/instrumentation/common/attributes.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/common/attributes.py#L269-L276

Added lines #L269 - L276 were not covered by tests

return usage

Check warning on line 278 in agentops/instrumentation/common/attributes.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/common/attributes.py#L278

Added line #L278 was not covered by tests
88 changes: 88 additions & 0 deletions agentops/instrumentation/smolagents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# SmoLAgents Instrumentation

This module provides OpenTelemetry instrumentation for the SmoLAgents framework. It captures telemetry data from model operations, agent executions, and tool usage.

## Features

- Model operation tracking
- Text generation
- Token usage
- Streaming responses
- Latency metrics

- Agent execution monitoring
- Step-by-step execution
- Planning phases
- Tool usage
- Execution time

- Tool usage analytics
- Tool call patterns
- Success/failure rates
- Execution time
- Error tracking

## Usage

```python
from agentops import init
from agentops.instrumentation.smolagents import SmoLAgentsInstrumentor

# Initialize AgentOps with your API key
init(api_key="your-api-key")

# The instrumentation will be automatically activated
# All SmoLAgents operations will now be tracked
```

## Metrics Collected

1. Token Usage
- Input tokens
- Output tokens
- Total tokens per operation

2. Timing Metrics
- Operation duration
- Time to first token (streaming)
- Tool execution time
- Planning phase duration

3. Agent Metrics
- Step counts
- Planning steps
- Tools used
- Success/failure rates

4. Error Tracking
- Generation errors
- Tool execution errors
- Parsing errors

## Architecture

The instrumentation is built on OpenTelemetry and follows the same pattern as other AgentOps instrumentors:

1. Attribute Extractors
- Model attributes
- Agent attributes
- Tool call attributes

2. Wrappers
- Method wrappers for sync operations
- Stream wrappers for async operations
- Context propagation handling

3. Metrics
- Histograms for distributions
- Counters for events
- Custom attributes for filtering

## Contributing

When adding new features or modifying existing ones:

1. Follow the established pattern for attribute extraction
2. Maintain context propagation
3. Add appropriate error handling
4. Update tests and documentation
8 changes: 8 additions & 0 deletions agentops/instrumentation/smolagents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""SmoLAgents instrumentation for AgentOps."""

LIBRARY_NAME = "smolagents"
LIBRARY_VERSION = "1.16.0"

Check warning on line 4 in agentops/instrumentation/smolagents/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/smolagents/__init__.py#L3-L4

Added lines #L3 - L4 were not covered by tests

from agentops.instrumentation.smolagents.instrumentor import SmolAgentsInstrumentor # noqa: E402

Check warning on line 6 in agentops/instrumentation/smolagents/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/smolagents/__init__.py#L6

Added line #L6 was not covered by tests

__all__ = ["SmolAgentsInstrumentor"]

Check warning on line 8 in agentops/instrumentation/smolagents/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/smolagents/__init__.py#L8

Added line #L8 was not covered by tests
Loading
Loading