Skip to content
Merged

0.4.4 #848

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5bcd062
0.4.4
teocns Mar 14, 2025
ad76782
Merge branch 'main' into 0.4.4
teocns Mar 14, 2025
bfa20ef
Client.init() | auto_start_session | forward tags
teocns Mar 14, 2025
7f0c932
client: recreate Config on init()
teocns Mar 14, 2025
e1ce7a5
mock_req: /v3/auth/token to return { project_id, token, api_key }
teocns Mar 14, 2025
dc465d0
cleanup dirty files
teocns Mar 14, 2025
693205b
Isolate telemetry setup (`setup_telemetry`)
teocns Mar 14, 2025
aaefaba
core shutdown: remove redundant initialized check
teocns Mar 14, 2025
f1ece39
Simplify core shutdown (flush SynchronousSpanProcessor instead of ite…
teocns Mar 14, 2025
c656613
Improved TracingCore Config
teocns Mar 15, 2025
d5ed7cb
tests: couple instrumentation tester with TracingCore's lifecycle
teocns Mar 15, 2025
3b55098
Base for test_session_legacy
teocns Mar 15, 2025
2eec70c
uv lock
teocns Mar 15, 2025
3eba3f3
tests/benchmark/benchmark_init.py
teocns Mar 15, 2025
1449e9b
Merge branch 'dev' into 0.4.4
teocns Mar 15, 2025
78bc6bd
Remove deprecated SDK tests - favor test_decorators
teocns Mar 15, 2025
d03a3c2
Merge branch 'dev' into 0.4.4
teocns Mar 15, 2025
7125039
update `openai` dep and `uv.lock` file
dot-agi Mar 15, 2025
77f05a8
fix: display session url when using `agentops.init` (#856)
dot-agi Mar 15, 2025
c024b7d
Merge branch 'dev' into 0.4.4
teocns Mar 15, 2025
b45e096
`auto_start_session` must be `False` by default
dot-agi Mar 15, 2025
ab39c96
Merge branch 'dev' into 0.4.4
teocns Mar 16, 2025
c920575
Merge branch 'main' into 0.4.4
dot-agi Mar 16, 2025
f0d74b8
Legacy session support on `end_session`. Backwards-compatible `record…
tcdent Mar 16, 2025
9915d29
CrewAI compat tests. track_tool decorator for compat.
tcdent Mar 16, 2025
60661e4
Use valid type.
tcdent Mar 16, 2025
02338e3
I don't think Event ever passed type checks.
tcdent Mar 16, 2025
e3cf1ad
Type checking runs clean. Fix import.
tcdent Mar 16, 2025
078afee
Auto start sessions.
tcdent Mar 17, 2025
5038a1e
track_agent noop should be a decorator
tcdent Mar 17, 2025
df3f269
Handle trace lifecycle in legacy with backwards
tcdent Mar 17, 2025
f6fa7d4
drop session export delay to one second and expose it as a public con…
tcdent Mar 17, 2025
9511139
Clean up docstrings in legacy
tcdent Mar 17, 2025
dfdec66
type checking
tcdent Mar 17, 2025
ecd2c4f
agentops.config: dataclass -slots | compat 3.9
teocns Mar 17, 2025
0890462
deps: py3.9 backward compat | constraints | resolver
teocns Mar 17, 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
22 changes: 21 additions & 1 deletion agentops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
from typing import Any, Dict, List, Optional, Union

from agentops.legacy import ErrorEvent, ToolEvent, end_session, start_session
from agentops.legacy import ActionEvent, ErrorEvent, ToolEvent, start_session, end_session

from .client import Client

# Client global instance; one per process runtime
_client = Client()

def record(event):
"""
Legacy function to record an event. This is kept for backward compatibility.

In the current version, this simply sets the end_timestamp on the event.

Args:
event: The event to record
"""
from agentops.helpers.time import get_ISO_time

# TODO: Manual timestamp assignment is a temporary fix; should use proper event lifecycle
if event and hasattr(event, 'end_timestamp'):
event.end_timestamp = get_ISO_time()

return event


def init(
api_key: Optional[str] = None,
Expand Down Expand Up @@ -139,6 +156,9 @@ def get_client() -> Client:
"init",
"configure",
"get_client",
"record",
"start_session",
"end_session",
"track_agent",
"track_tool",
]
12 changes: 11 additions & 1 deletion agentops/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
self.config = Config()

def init(self, **kwargs):
# Recreate the Config object to parse environment variables at the time of initialization
self.config = Config()
self.configure(**kwargs)

if not self.config.api_key:
Expand Down Expand Up @@ -56,10 +58,18 @@

self.initialized = True

# Start a session if auto_start_session is True
session = None
if self.config.auto_start_session:
from agentops.legacy import start_session

start_session()
# Pass default_tags if they exist
if self.config.default_tags:
session = start_session(tags=list(self.config.default_tags))

Check warning on line 68 in agentops/client/client.py

View check run for this annotation

Codecov / codecov/patch

agentops/client/client.py#L68

Added line #L68 was not covered by tests
else:
session = start_session()

return session

def configure(self, **kwargs):
"""Update client configuration"""
Expand Down
26 changes: 22 additions & 4 deletions agentops/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
api_key: Optional[str]
endpoint: Optional[str]
max_wait_time: Optional[int]
export_flush_interval: Optional[int]
max_queue_size: Optional[int]
default_tags: Optional[List[str]]
instrument_llm_calls: Optional[bool]
Expand All @@ -32,7 +33,7 @@
prefetch_jwt_token: Optional[bool]


@dataclass(slots=True)
@dataclass
class Config:
api_key: Optional[str] = field(
default_factory=lambda: os.getenv("AGENTOPS_API_KEY"),
Expand All @@ -48,6 +49,11 @@
default_factory=lambda: get_env_int("AGENTOPS_MAX_WAIT_TIME", 5000),
metadata={"description": "Maximum time in milliseconds to wait for API responses"},
)

export_flush_interval: int = field(
default_factory=lambda: get_env_int("AGENTOPS_EXPORT_FLUSH_INTERVAL", 1000),
metadata={"description": "Time interval in milliseconds between automatic exports of telemetry data"},
)

max_queue_size: int = field(
default_factory=lambda: get_env_int("AGENTOPS_MAX_QUEUE_SIZE", 512),
Expand All @@ -65,7 +71,7 @@
)

auto_start_session: bool = field(
default_factory=lambda: get_env_bool("AGENTOPS_AUTO_START_SESSION", False),
default_factory=lambda: get_env_bool("AGENTOPS_AUTO_START_SESSION", True),
metadata={"description": "Whether to automatically start a session when initializing"},
)

Expand All @@ -85,7 +91,7 @@
)

log_level: Union[str, int] = field(
default_factory=lambda: os.getenv("AGENTOPS_LOG_LEVEL", "WARNING"),
default_factory=lambda: os.getenv("AGENTOPS_LOG_LEVEL", "INFO"),
metadata={"description": "Logging level for AgentOps logs"},
)

Expand Down Expand Up @@ -119,6 +125,7 @@
api_key: Optional[str] = None,
endpoint: Optional[str] = None,
max_wait_time: Optional[int] = None,
export_flush_interval: Optional[int] = None,
max_queue_size: Optional[int] = None,
default_tags: Optional[List[str]] = None,
instrument_llm_calls: Optional[bool] = None,
Expand Down Expand Up @@ -147,6 +154,9 @@

if max_wait_time is not None:
self.max_wait_time = max_wait_time

if export_flush_interval is not None:
self.export_flush_interval = export_flush_interval

Check warning on line 159 in agentops/config.py

View check run for this annotation

Codecov / codecov/patch

agentops/config.py#L159

Added line #L159 was not covered by tests

if max_queue_size is not None:
self.max_queue_size = max_queue_size
Expand All @@ -170,7 +180,14 @@
self.env_data_opt_out = env_data_opt_out

if log_level is not None:
self.log_level = log_level
if isinstance(log_level, str):
log_level_str = log_level.upper()
if hasattr(logging, log_level_str):
self.log_level = getattr(logging, log_level_str)

Check warning on line 186 in agentops/config.py

View check run for this annotation

Codecov / codecov/patch

agentops/config.py#L183-L186

Added lines #L183 - L186 were not covered by tests
else:
self.log_level = logging.INFO

Check warning on line 188 in agentops/config.py

View check run for this annotation

Codecov / codecov/patch

agentops/config.py#L188

Added line #L188 was not covered by tests
else:
self.log_level = log_level

Check warning on line 190 in agentops/config.py

View check run for this annotation

Codecov / codecov/patch

agentops/config.py#L190

Added line #L190 was not covered by tests

if fail_safe is not None:
self.fail_safe = fail_safe
Expand All @@ -195,6 +212,7 @@
"api_key": self.api_key,
"endpoint": self.endpoint,
"max_wait_time": self.max_wait_time,
"export_flush_interval": self.export_flush_interval,
"max_queue_size": self.max_queue_size,
"default_tags": self.default_tags,
"instrument_llm_calls": self.instrument_llm_calls,
Expand Down
2 changes: 1 addition & 1 deletion agentops/instrumentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
import importlib

from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore

from agentops.logging import logger
from agentops.sdk.core import TracingCore
Expand Down
Loading
Loading