Skip to content

Commit e47b894

Browse files
authored
fix-a-lot (#830)
Fixes #827 Fixes #787 Fixes #783 --- Restores `start_session` from legacy SDK ``` import openai import agentops agentops.start_session() response = openai.chat.completions.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Write a one-line joke"}] ) ``` <img width="279" alt="image" src="https://github.com/user-attachments/assets/5b339e41-19bd-4a84-b981-25f971f5b329" /> --- Implements correct decorator nesting and traces context. ``` uv run examples/sdk/basic.py ``` <img width="347" alt="image" src="https://github.com/user-attachments/assets/1408689b-4bb0-43aa-abdf-25dd2d03f5e9" /> Signed-off-by: Teo <[email protected]>
1 parent d0b8f8a commit e47b894

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1680
-9844
lines changed

agentops/__init__.py

Lines changed: 15 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from typing import Dict, List, Optional, Union, Any
1+
from typing import Any, Dict, List, Optional, Union
2+
3+
from agentops.legacy import ErrorEvent, ToolEvent, end_session, start_session
24

35
from .client import Client
4-
from .sdk.commands import record as sdk_record, start_span as sdk_start_span, end_span as sdk_end_span
5-
from .semconv.span_kinds import SpanKind
6-
import agentops.legacy as legacy
7-
from agentops.legacy import ErrorEvent, ToolEvent
86

97
# Client global instance; one per process runtime
108
_client = Client()
@@ -126,110 +124,21 @@ def configure(**kwargs):
126124

127125
_client.configure(**kwargs)
128126

127+
# For backwards compatibility and testing
129128

130-
def start_session(**kwargs):
131-
"""Start a new session for recording events.
132-
133-
Args:
134-
tags (List[str], optional): Tags that can be used for grouping or sorting later.
135-
e.g. ["test_run"]
136-
137-
Returns:
138-
Optional[Session]: Returns Session if successful, None otherwise.
139-
"""
140-
return _client.start_session(**kwargs)
141-
142-
143-
def end_session(span, token):
144-
"""
145-
End a previously started AgentOps session.
146-
147-
This function ends the session span and detaches the context token,
148-
completing the session lifecycle.
149-
150-
Args:
151-
span: The span returned by start_session
152-
token: The token returned by start_session
153-
"""
154-
legacy.end_session(span, token)
155-
156-
157-
def start_span(
158-
name: str = "manual_span",
159-
span_kind: str = SpanKind.OPERATION,
160-
attributes: Optional[Dict[str, Any]] = None,
161-
version: Optional[int] = None,
162-
):
163-
"""
164-
Start a new span manually.
165-
166-
This function creates and starts a new span, which can be used to track
167-
operations. The span will remain active until end_span is called with
168-
the returned span and token.
169-
170-
Args:
171-
name: Name of the span
172-
span_kind: Kind of span (defaults to SpanKind.OPERATION)
173-
attributes: Optional attributes to set on the span
174-
version: Optional version identifier for the span
175-
176-
Returns:
177-
A tuple of (span, token) that should be passed to end_span
178-
"""
179-
return sdk_start_span(name, span_kind, attributes, version)
180-
181-
182-
def end_span(span, token):
183-
"""
184-
End a previously started span.
185-
186-
This function ends the span and detaches the context token,
187-
completing the span lifecycle.
188-
189-
Args:
190-
span: The span returned by start_span
191-
token: The token returned by start_span
192-
"""
193-
sdk_end_span(span, token)
194-
195-
196-
def record(message: str, attributes: Optional[Dict[str, Any]] = None):
197-
"""
198-
Record an event with a message within the current session.
199-
200-
This function creates a simple operation span with the provided message
201-
and attributes, which will be automatically associated with the current session.
202-
203-
Args:
204-
message: The message to record
205-
attributes: Optional attributes to set on the span
206-
"""
207-
sdk_record(message, attributes)
208-
209-
210-
def add_tags(tags: List[str]):
211-
"""
212-
Append to session tags at runtime.
213-
214-
TODO: How do we retrieve the session context to add tags to?
215-
216-
Args:
217-
tags (List[str]): The list of tags to append.
218-
"""
219-
raise NotImplementedError
220129

130+
def get_client() -> Client:
131+
"""Get the singleton client instance"""
132+
return _client
221133

222-
def set_tags(tags: List[str]):
223-
"""
224-
Replace session tags at runtime.
225134

226-
Args:
227-
tags (List[str]): The list of tags to set.
228-
"""
229-
raise NotImplementedError
230135

136+
from agentops.legacy import * # type: ignore
231137

232-
# For backwards compatibility and testing
233-
def get_client() -> Client:
234-
"""Get the singleton client instance"""
235-
return _client
138+
__all__ = [
139+
"init",
140+
"configure",
141+
"get_client",
142+
"start_session",
143+
"end_session",
144+
]

agentops/cli.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)