agenta 0.19.1a0__py3-none-any.whl → 0.19.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of agenta might be problematic. Click here for more details.
- agenta/sdk/agenta_init.py +4 -12
- agenta/sdk/tracing/llm_tracing.py +33 -4
- {agenta-0.19.1a0.dist-info → agenta-0.19.3.dist-info}/METADATA +1 -1
- {agenta-0.19.1a0.dist-info → agenta-0.19.3.dist-info}/RECORD +6 -6
- {agenta-0.19.1a0.dist-info → agenta-0.19.3.dist-info}/WHEEL +0 -0
- {agenta-0.19.1a0.dist-info → agenta-0.19.3.dist-info}/entry_points.txt +0 -0
agenta/sdk/agenta_init.py
CHANGED
|
@@ -26,16 +26,6 @@ class AgentaSingleton:
|
|
|
26
26
|
cls._instance = super(AgentaSingleton, cls).__new__(cls)
|
|
27
27
|
return cls._instance
|
|
28
28
|
|
|
29
|
-
@property
|
|
30
|
-
def client(self):
|
|
31
|
-
"""API Backend client.
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
34
|
-
AgentaAPI: instance of agenta api backend
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
return AgentaApi(base_url=self.host + "/api", api_key=self.api_key)
|
|
38
|
-
|
|
39
29
|
def init(
|
|
40
30
|
self,
|
|
41
31
|
app_id: Optional[str] = None,
|
|
@@ -95,7 +85,7 @@ class AgentaSingleton:
|
|
|
95
85
|
|
|
96
86
|
|
|
97
87
|
class Config:
|
|
98
|
-
def __init__(self, base_id: str, host: str, api_key: str = ""):
|
|
88
|
+
def __init__(self, base_id: str, host: str, api_key: Optional[str] = ""):
|
|
99
89
|
self.base_id = base_id
|
|
100
90
|
self.host = host
|
|
101
91
|
|
|
@@ -103,7 +93,9 @@ class Config:
|
|
|
103
93
|
self.persist = False
|
|
104
94
|
else:
|
|
105
95
|
self.persist = True
|
|
106
|
-
self.client = AgentaApi(
|
|
96
|
+
self.client = AgentaApi(
|
|
97
|
+
base_url=self.host + "/api", api_key=api_key if api_key else ""
|
|
98
|
+
)
|
|
107
99
|
|
|
108
100
|
def register_default(self, overwrite=False, **kwargs):
|
|
109
101
|
"""alias for default"""
|
|
@@ -178,7 +178,7 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
178
178
|
span.status = value
|
|
179
179
|
|
|
180
180
|
def _update_span_cost(self, span: CreateSpan, cost: Optional[float]):
|
|
181
|
-
if
|
|
181
|
+
if cost is not None and isinstance(cost, float):
|
|
182
182
|
if span.cost is None:
|
|
183
183
|
span.cost = cost
|
|
184
184
|
else:
|
|
@@ -187,7 +187,7 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
187
187
|
def _update_span_tokens(self, span: CreateSpan, tokens: Optional[dict]):
|
|
188
188
|
if isinstance(tokens, LlmTokens):
|
|
189
189
|
tokens = tokens.dict()
|
|
190
|
-
if
|
|
190
|
+
if tokens is not None and isinstance(tokens, dict):
|
|
191
191
|
if span.tokens is None:
|
|
192
192
|
span.tokens = LlmTokens(**tokens)
|
|
193
193
|
else:
|
|
@@ -218,7 +218,6 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
218
218
|
|
|
219
219
|
self.active_span.end_time = datetime.now(timezone.utc)
|
|
220
220
|
self.active_span.outputs = [outputs.get("message", "")]
|
|
221
|
-
|
|
222
221
|
if self.active_span.spankind in [
|
|
223
222
|
"LLM",
|
|
224
223
|
"RETRIEVER",
|
|
@@ -230,15 +229,45 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
230
229
|
self.pending_spans.append(self.active_span)
|
|
231
230
|
|
|
232
231
|
active_span_parent_id = self.active_span.parent_span_id
|
|
232
|
+
if (
|
|
233
|
+
self.active_span.status == SpanStatusCode.ERROR.value
|
|
234
|
+
and active_span_parent_id is not None
|
|
235
|
+
):
|
|
236
|
+
self.record_exception_and_end_trace(span_parent_id=active_span_parent_id)
|
|
233
237
|
|
|
234
238
|
if active_span_parent_id is None:
|
|
235
239
|
self.end_trace(parent_span=self.active_span)
|
|
240
|
+
|
|
236
241
|
else:
|
|
237
242
|
parent_span = self.span_dict[active_span_parent_id]
|
|
238
243
|
self._update_span_cost(parent_span, self.active_span.cost)
|
|
239
244
|
self._update_span_tokens(parent_span, self.active_span.tokens)
|
|
240
245
|
self.active_span = parent_span
|
|
241
246
|
|
|
247
|
+
def record_exception_and_end_trace(self, span_parent_id: str):
|
|
248
|
+
"""
|
|
249
|
+
Record an exception and end the trace.
|
|
250
|
+
|
|
251
|
+
Args:
|
|
252
|
+
span_parent_id (str): The ID of the parent span.
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
None
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
parent_span = self.span_dict.get(span_parent_id)
|
|
259
|
+
if parent_span is not None:
|
|
260
|
+
# Update parent span of active span
|
|
261
|
+
parent_span.outputs = self.active_span.outputs # type: ignore
|
|
262
|
+
parent_span.status = "ERROR"
|
|
263
|
+
parent_span.end_time = datetime.now(timezone.utc)
|
|
264
|
+
|
|
265
|
+
# Push parent span to list of recorded spans and end trace
|
|
266
|
+
self.pending_spans.append(parent_span)
|
|
267
|
+
self.end_trace(parent_span=parent_span)
|
|
268
|
+
|
|
269
|
+
# TODO: improve exception logic here.
|
|
270
|
+
|
|
242
271
|
def end_trace(self, parent_span: CreateSpan):
|
|
243
272
|
"""
|
|
244
273
|
Ends the active trace and sends the recorded spans for processing.
|
|
@@ -256,7 +285,7 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
256
285
|
if self.api_key == "":
|
|
257
286
|
return
|
|
258
287
|
|
|
259
|
-
if self.active_trace_id
|
|
288
|
+
if not self.active_trace_id:
|
|
260
289
|
raise RuntimeError("No active trace to end.")
|
|
261
290
|
|
|
262
291
|
self.llm_logger.info("Preparing to send recorded spans for processing.")
|
|
@@ -127,7 +127,7 @@ agenta/docker/docker-assets/lambda_function.py,sha256=h4UZSSfqwpfsCgERv6frqwm_4J
|
|
|
127
127
|
agenta/docker/docker-assets/main.py,sha256=7MI-21n81U7N7A0GxebNi0cmGWtJKcR2sPB6FcH2QfA,251
|
|
128
128
|
agenta/docker/docker_utils.py,sha256=5uHMCzXkCvIsDdEiwbnnn97KkzsFbBvyMwogCsv_Z5U,3509
|
|
129
129
|
agenta/sdk/__init__.py,sha256=cF0de6DiH-NZWEm0XvPN8_TeC1whPBnDf1WYYE1qK2g,762
|
|
130
|
-
agenta/sdk/agenta_init.py,sha256=
|
|
130
|
+
agenta/sdk/agenta_init.py,sha256=zhMYCH6QMDzQADrOmFBaqZRvAYrA6CC35XsePY7IMxg,9789
|
|
131
131
|
agenta/sdk/client.py,sha256=trKyBOYFZRk0v5Eptxvh87yPf50Y9CqY6Qgv4Fy-VH4,2142
|
|
132
132
|
agenta/sdk/context.py,sha256=q-PxL05-I84puunUAs9LGsffEXcYhDxhQxjuOz2vK90,901
|
|
133
133
|
agenta/sdk/decorators/base.py,sha256=9aNdX5h8a2mFweuhdO-BQPwXGKY9ONPIdLRhSGAGMfY,217
|
|
@@ -137,7 +137,7 @@ agenta/sdk/router.py,sha256=0sbajvn5C7t18anH6yNo7-oYxldHnYfwcbmQnIXBePw,269
|
|
|
137
137
|
agenta/sdk/tracing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
138
138
|
agenta/sdk/tracing/callbacks.py,sha256=8XYcGC4EZQ0lBn2IWmtPH_yC5Hu6Yu-NkdZRuY7CoTw,6816
|
|
139
139
|
agenta/sdk/tracing/context_manager.py,sha256=HskDaiORoOhjeN375gm05wYnieQzh5UnoIsnSAHkAyc,252
|
|
140
|
-
agenta/sdk/tracing/llm_tracing.py,sha256=
|
|
140
|
+
agenta/sdk/tracing/llm_tracing.py,sha256=fHtc1tKgdR2CDnFMrfDIxSvyjwFW3Qk2RE8P-y_tCM0,11361
|
|
141
141
|
agenta/sdk/tracing/logger.py,sha256=GfH7V-jBHcn7h5dbdrnkDMe_ml3wkXFBeoQiqR4KVRc,474
|
|
142
142
|
agenta/sdk/tracing/tasks_manager.py,sha256=ROrWIaqS2J2HHiJtRWiHKlLY8CCsqToP5VeXu7mamck,3748
|
|
143
143
|
agenta/sdk/types.py,sha256=KMnQUOdjaHSWctDLIiMHnk0o3c-C47Vm4Mn2kIZ88YI,5740
|
|
@@ -159,7 +159,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
|
|
|
159
159
|
agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
|
|
160
160
|
agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
|
|
161
161
|
agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
|
|
162
|
-
agenta-0.19.
|
|
163
|
-
agenta-0.19.
|
|
164
|
-
agenta-0.19.
|
|
165
|
-
agenta-0.19.
|
|
162
|
+
agenta-0.19.3.dist-info/METADATA,sha256=QBW7Cr2PSwdij3Ayk1dqTLWMDlwcmi8eH3blszBa7Fs,26458
|
|
163
|
+
agenta-0.19.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
164
|
+
agenta-0.19.3.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
|
|
165
|
+
agenta-0.19.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|