Skip to content

Commit 0d95ed5

Browse files
authored
revert "(fix): AgentOps is only instantiated if an api key is passed (#22)" (#24)
1 parent 8ad78c5 commit 0d95ed5

File tree

2 files changed

+15
-47
lines changed

2 files changed

+15
-47
lines changed

src/multion/client.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# this is used as the default value for optional parameters
1616
OMIT = typing.cast(typing.Any, ...)
1717

18-
record_function = lambda *args, **kwargs: lambda fn: fn
19-
2018

2119
class MultiOn(BaseMultiOn):
2220
"""
@@ -54,37 +52,25 @@ def __init__(
5452
agentops_api_key: typing.Optional[str] = os.getenv("AGENTOPS_API_KEY"),
5553
**kwargs
5654
):
57-
5855
super().__init__(*args, **kwargs)
59-
self._agentops_api_key = agentops_api_key
60-
61-
self.sessions = WrappedSessionsClient(
62-
client_wrapper=self._client_wrapper, use_agentops=self._agentops_api_key is not None)
63-
64-
if self._agentops_api_key is not None:
56+
self.sessions = WrappedSessionsClient(client_wrapper=self._client_wrapper)
57+
if agentops_api_key is not None:
6558
agentops.init(
6659
api_key=agentops_api_key,
6760
parent_key=os.getenv("AGENTOPS_PARENT_KEY"),
6861
auto_start_session=False,
6962
)
70-
# Redefine the record_function globally
71-
global record_function
72-
record_function = agentops.record_function
73-
# Apply the decorator at runtime
74-
self.browse = record_function(event_name="browse")(self.browse)
75-
self.retrieve = record_function(
76-
event_name="retrieve")(self.retrieve)
7763

64+
@agentops.record_function(event_name="browse") # type: ignore
7865
@wraps_function(BaseMultiOn.browse)
7966
def browse(self, *args, **kwargs) -> BrowseOutput:
80-
if self._agentops_api_key is not None:
81-
agentops.start_session(tags=["multion-sdk"])
67+
agentops.start_session(tags=["multion-sdk"])
8268
return super().browse(*args, **kwargs)
8369

70+
@agentops.record_function(event_name="retrieve") # type: ignore
8471
@wraps_function(BaseMultiOn.retrieve)
8572
def retrieve(self, *args, **kwargs) -> RetrieveOutput:
86-
if self._agentops_api_key is not None:
87-
agentops.start_session(tags=["multion-sdk"])
73+
agentops.start_session(tags=["multion-sdk"])
8874
return super().retrieve(*args, **kwargs)
8975

9076

@@ -125,31 +111,22 @@ def __init__(
125111
**kwargs
126112
):
127113
super().__init__(*args, **kwargs)
128-
self._agentops_api_key = agentops_api_key
129-
self.sessions = WrappedAsyncSessionsClient(client_wrapper=self._client_wrapper,
130-
use_agentops=self._agentops_api_key is not None)
114+
self.sessions = WrappedAsyncSessionsClient(client_wrapper=self._client_wrapper)
131115
if agentops_api_key is not None:
132116
agentops.init(
133117
api_key=agentops_api_key,
134118
parent_key=os.getenv("AGENTOPS_PARENT_KEY"),
135119
auto_start_session=False,
136120
)
137-
# If agentops is set, we need to wrap the record function
138-
global record_function
139-
record_function = agentops.record_function
140-
141-
record_function = agentops.record_function
142121

143-
@record_function(event_name="browse") # type: ignore
122+
@agentops.record_function(event_name="browse") # type: ignore
144123
@wraps_function(AsyncBaseMultiOn.browse)
145124
async def browse(self, *args, **kwargs) -> BrowseOutput:
146-
if self._agentops_api_key is not None:
147-
agentops.start_session(tags=["multion-sdk"])
125+
agentops.start_session(tags=["multion-sdk"])
148126
return await super().browse(*args, **kwargs)
149127

150-
@record_function(event_name="retrieve") # type: ignore
128+
@agentops.record_function(event_name="retrieve") # type: ignore
151129
@wraps_function(BaseMultiOn.retrieve)
152130
async def retrieve(self, *args, **kwargs) -> RetrieveOutput:
153-
if self._agentops_api_key is not None:
154-
agentops.start_session(tags=["multion-sdk"])
131+
agentops.start_session(tags=["multion-sdk"])
155132
return await super().retrieve(*args, **kwargs)

src/multion/sessions/wrapped_client.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from ..wrappers import wraps_function
21
from multion.sessions.client import AsyncSessionsClient, SessionsClient
32
import agentops # type: ignore
43
from agentops import ActionEvent, LLMEvent, ErrorEvent # type: ignore
@@ -12,16 +11,13 @@
1211
# this is used as the default value for optional parameters
1312
OMIT = typing.cast(typing.Any, ...)
1413

14+
from ..wrappers import wraps_function
1515

16-
class WrappedSessionsClient(SessionsClient):
17-
def __init__(self, use_agentops: bool = False, *args, **kwargs):
18-
super().__init__(*args, **kwargs)
19-
self.use_agentops = use_agentops
2016

17+
class WrappedSessionsClient(SessionsClient):
2118
@wraps_function(SessionsClient.create) # type: ignore
2219
def create(self, *args, **kwargs) -> SessionCreated:
23-
if self.use_agentops:
24-
agentops.start_session(tags=["multion-sdk"])
20+
agentops.start_session(tags=["multion-sdk"])
2521
try:
2622
return super().create(*args, **kwargs)
2723
except Exception as e:
@@ -72,14 +68,9 @@ def close(self, *args, **kwargs) -> SessionsCloseResponse:
7268

7369

7470
class WrappedAsyncSessionsClient(AsyncSessionsClient):
75-
def __init__(self, use_agentops: bool = False, *args, **kwargs):
76-
super().__init__(*args, **kwargs)
77-
self.use_agentops = use_agentops
78-
7971
@wraps_function(AsyncSessionsClient.create) # type: ignore
8072
async def create(self, *args, **kwargs) -> SessionCreated:
81-
if self.use_agentops:
82-
agentops.start_session(tags=["multion-sdk"])
73+
agentops.start_session(tags=["multion-sdk"])
8374
try:
8475
return await super().create(*args, **kwargs)
8576
except Exception as e:

0 commit comments

Comments
 (0)