agenta 0.14.11__py3-none-any.whl → 0.14.12a0__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/__init__.py +4 -3
- agenta/client/backend/client.py +8 -6
- agenta/client/backend/types/create_span.py +1 -1
- agenta/sdk/__init__.py +4 -4
- agenta/sdk/agenta_init.py +66 -70
- agenta/sdk/decorators/base.py +10 -0
- agenta/sdk/decorators/llm_entrypoint.py +485 -0
- agenta/sdk/decorators/tracing.py +84 -0
- agenta/sdk/tracing/llm_tracing.py +87 -65
- agenta/sdk/tracing/tasks_manager.py +1 -3
- {agenta-0.14.11.dist-info → agenta-0.14.12a0.dist-info}/METADATA +2 -2
- {agenta-0.14.11.dist-info → agenta-0.14.12a0.dist-info}/RECORD +14 -13
- agenta/sdk/agenta_decorator.py +0 -501
- agenta/sdk/tracing/decorators.py +0 -41
- {agenta-0.14.11.dist-info → agenta-0.14.12a0.dist-info}/WHEEL +0 -0
- {agenta-0.14.11.dist-info → agenta-0.14.12a0.dist-info}/entry_points.txt +0 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# Stdlib Imports
|
|
2
|
+
import os
|
|
3
|
+
from threading import Lock
|
|
2
4
|
from datetime import datetime, timezone
|
|
3
5
|
from typing import Optional, Dict, Any, List, Union
|
|
4
6
|
|
|
@@ -13,10 +15,38 @@ from agenta.client.backend.types.create_span import CreateSpan, SpanKind, SpanSt
|
|
|
13
15
|
from bson.objectid import ObjectId
|
|
14
16
|
|
|
15
17
|
|
|
16
|
-
class
|
|
17
|
-
"""
|
|
18
|
+
class SingletonMeta(type):
|
|
19
|
+
"""
|
|
20
|
+
Thread-safe implementation of Singleton.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
_instances = {} # type: ignore
|
|
24
|
+
|
|
25
|
+
# We need the lock mechanism to synchronize threads \
|
|
26
|
+
# during the initial access to the Singleton object.
|
|
27
|
+
_lock: Lock = Lock()
|
|
28
|
+
|
|
29
|
+
def __call__(cls, *args, **kwargs):
|
|
30
|
+
"""
|
|
31
|
+
Ensures that changes to the `__init__` arguments do not affect the
|
|
32
|
+
returned instance.
|
|
33
|
+
|
|
34
|
+
Uses a lock to make this method thread-safe. If an instance of the class
|
|
35
|
+
does not already exist, it creates one. Otherwise, it returns the
|
|
36
|
+
existing instance.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
with cls._lock:
|
|
40
|
+
if cls not in cls._instances:
|
|
41
|
+
instance = super().__call__(*args, **kwargs)
|
|
42
|
+
cls._instances[cls] = instance
|
|
43
|
+
return cls._instances[cls]
|
|
44
|
+
|
|
18
45
|
|
|
19
|
-
|
|
46
|
+
class Tracing(metaclass=SingletonMeta):
|
|
47
|
+
"""The `Tracing` class is an agent for LLM tracing with specific initialization arguments.
|
|
48
|
+
|
|
49
|
+
__init__ args:
|
|
20
50
|
base_url (str): The URL of the backend host
|
|
21
51
|
api_key (str): The API Key of the backend host
|
|
22
52
|
tasks_manager (TaskQueue): The tasks manager dedicated to handling asynchronous tasks
|
|
@@ -24,18 +54,11 @@ class Tracing(object):
|
|
|
24
54
|
max_workers (int): The maximum number of workers to run tracing
|
|
25
55
|
"""
|
|
26
56
|
|
|
27
|
-
_instance = None
|
|
28
|
-
|
|
29
|
-
def __new__(cls, *args, **kwargs):
|
|
30
|
-
if not cls._instance:
|
|
31
|
-
cls._instance = super().__new__(cls)
|
|
32
|
-
return cls._instance
|
|
33
|
-
|
|
34
57
|
def __init__(
|
|
35
58
|
self,
|
|
36
59
|
base_url: str,
|
|
37
60
|
app_id: str,
|
|
38
|
-
variant_id: str,
|
|
61
|
+
variant_id: Optional[str] = None,
|
|
39
62
|
variant_name: Optional[str] = None,
|
|
40
63
|
api_key: Optional[str] = None,
|
|
41
64
|
max_workers: Optional[int] = None,
|
|
@@ -49,8 +72,8 @@ class Tracing(object):
|
|
|
49
72
|
self.tasks_manager = TaskQueue(
|
|
50
73
|
max_workers if max_workers else 4, logger=llm_logger
|
|
51
74
|
)
|
|
52
|
-
self.active_span =
|
|
53
|
-
self.active_trace =
|
|
75
|
+
self.active_span: Optional[CreateSpan] = None
|
|
76
|
+
self.active_trace: Optional[CreateSpan] = None
|
|
54
77
|
self.recording_trace_id: Union[str, None] = None
|
|
55
78
|
self.recorded_spans: List[CreateSpan] = []
|
|
56
79
|
self.tags: List[str] = []
|
|
@@ -93,41 +116,18 @@ class Tracing(object):
|
|
|
93
116
|
def set_trace_tags(self, tags: List[str]):
|
|
94
117
|
self.tags.extend(tags)
|
|
95
118
|
|
|
96
|
-
def start_parent_span(
|
|
97
|
-
self, name: str, inputs: Dict[str, Any], config: Dict[str, Any], **kwargs
|
|
98
|
-
):
|
|
99
|
-
trace_id = self._create_trace_id()
|
|
100
|
-
span_id = self._create_span_id()
|
|
101
|
-
self.llm_logger.info("Recording parent span...")
|
|
102
|
-
span = CreateSpan(
|
|
103
|
-
id=span_id,
|
|
104
|
-
app_id=self.app_id,
|
|
105
|
-
variant_id=self.variant_id,
|
|
106
|
-
variant_name=self.variant_name,
|
|
107
|
-
inputs=inputs,
|
|
108
|
-
name=name,
|
|
109
|
-
config=config,
|
|
110
|
-
environment=kwargs.get("environment"),
|
|
111
|
-
spankind=SpanKind.WORKFLOW.value,
|
|
112
|
-
status=SpanStatusCode.UNSET.value,
|
|
113
|
-
start_time=datetime.now(timezone.utc),
|
|
114
|
-
)
|
|
115
|
-
self.active_trace = span
|
|
116
|
-
self.recording_trace_id = trace_id
|
|
117
|
-
self.parent_span_id = span.id
|
|
118
|
-
self.llm_logger.info(
|
|
119
|
-
f"Recorded active_trace and setting parent_span_id: {span.id}"
|
|
120
|
-
)
|
|
121
|
-
|
|
122
119
|
def start_span(
|
|
123
120
|
self,
|
|
124
121
|
name: str,
|
|
125
122
|
spankind: str,
|
|
126
123
|
input: Dict[str, Any],
|
|
127
|
-
config: Dict[str, Any] =
|
|
124
|
+
config: Optional[Dict[str, Any]] = None,
|
|
125
|
+
**kwargs,
|
|
128
126
|
) -> CreateSpan:
|
|
129
127
|
span_id = self._create_span_id()
|
|
130
|
-
self.llm_logger.info(
|
|
128
|
+
self.llm_logger.info(
|
|
129
|
+
f"Recording {'parent' if spankind == 'workflow' else spankind} span..."
|
|
130
|
+
)
|
|
131
131
|
span = CreateSpan(
|
|
132
132
|
id=span_id,
|
|
133
133
|
inputs=input,
|
|
@@ -136,47 +136,69 @@ class Tracing(object):
|
|
|
136
136
|
variant_id=self.variant_id,
|
|
137
137
|
variant_name=self.variant_name,
|
|
138
138
|
config=config,
|
|
139
|
-
environment=
|
|
140
|
-
|
|
139
|
+
environment=(
|
|
140
|
+
self.active_trace.environment
|
|
141
|
+
if self.active_trace
|
|
142
|
+
else os.environ.get("AGENTA_LLM_RUN_ENVIRONMENT", "unset")
|
|
143
|
+
),
|
|
141
144
|
spankind=spankind.upper(),
|
|
142
145
|
attributes={},
|
|
143
146
|
status=SpanStatusCode.UNSET.value,
|
|
144
147
|
start_time=datetime.now(timezone.utc),
|
|
148
|
+
outputs=None,
|
|
149
|
+
tags=None,
|
|
150
|
+
user=None,
|
|
151
|
+
end_time=None,
|
|
152
|
+
tokens=None,
|
|
153
|
+
cost=None,
|
|
154
|
+
token_consumption=None,
|
|
155
|
+
parent_span_id=None,
|
|
145
156
|
)
|
|
146
157
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
if span.spankind == SpanKind.WORKFLOW.value:
|
|
159
|
+
self.active_trace = span
|
|
160
|
+
self.parent_span_id = span.id
|
|
161
|
+
self.recording_trace_id = self._create_trace_id()
|
|
162
|
+
else:
|
|
163
|
+
self.active_span = span
|
|
164
|
+
self.active_span = span
|
|
165
|
+
self.span_dict[span.id] = span
|
|
166
|
+
span.parent_span_id = (
|
|
167
|
+
self.parent_span_id
|
|
168
|
+
) # set the parent_span_id to the present span
|
|
169
|
+
self.parent_span_id = span.id # update parent_span_id to active span
|
|
170
|
+
|
|
171
|
+
self.llm_logger.info(f"Recorded span and setting parent_span_id: {span.id}")
|
|
153
172
|
return span
|
|
154
173
|
|
|
155
174
|
def update_span_status(self, span: CreateSpan, value: str):
|
|
156
|
-
|
|
157
|
-
self.active_span =
|
|
158
|
-
|
|
159
|
-
def end_span(self, outputs: Dict[str, Any], span: CreateSpan
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
cost=outputs.get("cost", None),
|
|
165
|
-
tokens=outputs.get("usage"),
|
|
166
|
-
)
|
|
175
|
+
span.status = value
|
|
176
|
+
self.active_span = span
|
|
177
|
+
|
|
178
|
+
def end_span(self, outputs: Dict[str, Any], span: CreateSpan):
|
|
179
|
+
span.end_time = datetime.now(timezone.utc)
|
|
180
|
+
span.outputs = [outputs["message"]]
|
|
181
|
+
span.cost = outputs.get("cost", None)
|
|
182
|
+
span.tokens = outputs.get("usage")
|
|
167
183
|
|
|
168
184
|
# Push span to list of recorded spans
|
|
169
|
-
self.recorded_spans.append(
|
|
185
|
+
self.recorded_spans.append(span)
|
|
170
186
|
self.llm_logger.info(
|
|
171
|
-
f"Pushed {
|
|
187
|
+
f"Pushed {span.spankind} span {span.id} to recorded spans."
|
|
172
188
|
)
|
|
173
189
|
|
|
174
|
-
|
|
175
|
-
|
|
190
|
+
# End tracing if spankind is workflow
|
|
191
|
+
if span.spankind == SpanKind.WORKFLOW.value:
|
|
192
|
+
self.end_recording(span=span)
|
|
193
|
+
|
|
194
|
+
def end_recording(self, span: CreateSpan):
|
|
176
195
|
if self.api_key == "":
|
|
177
196
|
return
|
|
178
197
|
|
|
179
|
-
|
|
198
|
+
if not self.active_trace:
|
|
199
|
+
raise RuntimeError("No active trace to end.")
|
|
200
|
+
|
|
201
|
+
self.llm_logger.info("Preparing to send recorded spans for processing.")
|
|
180
202
|
self.llm_logger.info(f"Recorded spans => {len(self.recorded_spans)}")
|
|
181
203
|
self.tasks_manager.add_task(
|
|
182
204
|
self.active_trace.id,
|
|
@@ -106,9 +106,7 @@ class TaskQueue(object):
|
|
|
106
106
|
future.result()
|
|
107
107
|
except Exception as exc:
|
|
108
108
|
self._logger.error(f"Error running task: {str(exc)}")
|
|
109
|
-
self._logger.error(
|
|
110
|
-
f"Recording trace {task.coroutine_type} status to ERROR."
|
|
111
|
-
)
|
|
109
|
+
self._logger.error(f"Recording {task.coroutine_type} status to ERROR.")
|
|
112
110
|
break
|
|
113
111
|
finally:
|
|
114
112
|
self.tasks.task_done()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: agenta
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.12a0
|
|
4
4
|
Summary: The SDK for agenta is an open-source LLMOps platform.
|
|
5
5
|
Home-page: https://agenta.ai
|
|
6
6
|
Keywords: LLMOps,LLM,evaluation,prompt engineering
|
|
@@ -23,7 +23,7 @@ Requires-Dist: httpx (>=0.24,<0.28)
|
|
|
23
23
|
Requires-Dist: importlib-metadata (>=6.7,<8.0)
|
|
24
24
|
Requires-Dist: ipdb (>=0.13)
|
|
25
25
|
Requires-Dist: posthog (>=3.1.0,<4.0.0)
|
|
26
|
-
Requires-Dist: pydantic (==
|
|
26
|
+
Requires-Dist: pydantic (==1.10.13)
|
|
27
27
|
Requires-Dist: pymongo (>=4.6.3,<5.0.0)
|
|
28
28
|
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
|
29
29
|
Requires-Dist: python-multipart (>=0.0.6,<0.0.10)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
agenta/__init__.py,sha256=
|
|
1
|
+
agenta/__init__.py,sha256=yXks3d7zLmyJCM3D_L5rk4GnFKHZX2NJa6j6wjAJUGQ,661
|
|
2
2
|
agenta/cli/evaluation_commands.py,sha256=fs6492tprPId9p8eGO02Xy-NCBm2RZNJLZWcUxugwd8,474
|
|
3
3
|
agenta/cli/helper.py,sha256=vRxHyeNaltzNIGrfU2vO0H28_rXDzx9QqIZ_S-W6zL4,6212
|
|
4
4
|
agenta/cli/main.py,sha256=Wz0ODhoeKK3Qg_CFUhu6D909szk05tc8ZVBB6H1-w7k,9763
|
|
@@ -10,7 +10,7 @@ agenta/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
10
10
|
agenta/client/api.py,sha256=0u1vd7V2ctFEtY6KeGGiOeoDv6vyeit32u6c6BVyc4w,2434
|
|
11
11
|
agenta/client/api_models.py,sha256=zebfE2-0-SW1SvzyarzmSJMXqyiCLKrX2sHpzoX-RnU,623
|
|
12
12
|
agenta/client/backend/__init__.py,sha256=tkSqI-dciccMpM2diWMe7pF0SjsGXPV_kR-029xNN9w,3853
|
|
13
|
-
agenta/client/backend/client.py,sha256=
|
|
13
|
+
agenta/client/backend/client.py,sha256=LDuJbFQ9wnhBDeldrlJfOt2TsvO102fy1iKbQG4n_fE,73738
|
|
14
14
|
agenta/client/backend/core/__init__.py,sha256=QJS3CJ2TYP2E1Tge0CS6Z7r8LTNzJHQVX1hD3558eP0,519
|
|
15
15
|
agenta/client/backend/core/api_error.py,sha256=TtMtCdxXjd7Tasc9c8ooFg124nPrb2MXG-tKOXV4u9I,440
|
|
16
16
|
agenta/client/backend/core/client_wrapper.py,sha256=kQEqxdm31r7V9x--mMliWOdMujD3dtPZyYBNzxgNdrs,972
|
|
@@ -54,7 +54,7 @@ agenta/client/backend/types/base_output.py,sha256=ynXhDBQKrkR6Lnkx-yv6Q8xW4wXmzX
|
|
|
54
54
|
agenta/client/backend/types/body_import_testset.py,sha256=7dVF3mv3VO0Co8F0qxLAgu4jabqDPjebK4mYvcd_TuA,1061
|
|
55
55
|
agenta/client/backend/types/config_db.py,sha256=P0cSYvVOn0ZxpYMIdvhWpQVjRuBS5APe6qlc69AXaF4,1028
|
|
56
56
|
agenta/client/backend/types/create_app_output.py,sha256=pgnTnfZx35Q-8wZ1yTZBQ0ydYacGzFC9kyLug_UvymM,986
|
|
57
|
-
agenta/client/backend/types/create_span.py,sha256=
|
|
57
|
+
agenta/client/backend/types/create_span.py,sha256=Ldb2zclVtVyBRKxM2Ap3YjE-FP3jbaOya96_ZsYw1cg,1794
|
|
58
58
|
agenta/client/backend/types/create_trace_response.py,sha256=FO-Ii9JEn2AQ1nmZYmjnKRbACsNxRvY_-xn7Ys7Yo8A,1012
|
|
59
59
|
agenta/client/backend/types/docker_env_vars.py,sha256=altCvA1k-zdAkKNYLwaCnmV48HZg9cwe2cHu_BGImac,986
|
|
60
60
|
agenta/client/backend/types/environment_output.py,sha256=dl0GKodeqB7kWK5mH6Y4iBppkpwRzSTmtkXH1II4L6w,1257
|
|
@@ -126,17 +126,18 @@ agenta/docker/docker-assets/entrypoint.sh,sha256=29XK8VQjQsx4hN2j-4JDy-6kQb5y4LC
|
|
|
126
126
|
agenta/docker/docker-assets/lambda_function.py,sha256=h4UZSSfqwpfsCgERv6frqwm_4JrYu9rLz3I-LxCfeEg,83
|
|
127
127
|
agenta/docker/docker-assets/main.py,sha256=7MI-21n81U7N7A0GxebNi0cmGWtJKcR2sPB6FcH2QfA,251
|
|
128
128
|
agenta/docker/docker_utils.py,sha256=5uHMCzXkCvIsDdEiwbnnn97KkzsFbBvyMwogCsv_Z5U,3509
|
|
129
|
-
agenta/sdk/__init__.py,sha256=
|
|
130
|
-
agenta/sdk/
|
|
131
|
-
agenta/sdk/agenta_init.py,sha256=wDfStpe8_3ZXRLtikarwDKI_VpA1YW4eIz_3fXq39is,9044
|
|
129
|
+
agenta/sdk/__init__.py,sha256=Zqst2m-u5HbV_Y6sGcT7suwbP-XanP-5noLpfKlA2nQ,627
|
|
130
|
+
agenta/sdk/agenta_init.py,sha256=KjxMOewpADtlhOAqTbW-T2TQ1oVwKncV1-0ByNwXBpE,8644
|
|
132
131
|
agenta/sdk/client.py,sha256=trKyBOYFZRk0v5Eptxvh87yPf50Y9CqY6Qgv4Fy-VH4,2142
|
|
133
132
|
agenta/sdk/context.py,sha256=q-PxL05-I84puunUAs9LGsffEXcYhDxhQxjuOz2vK90,901
|
|
133
|
+
agenta/sdk/decorators/base.py,sha256=9aNdX5h8a2mFweuhdO-BQPwXGKY9ONPIdLRhSGAGMfY,217
|
|
134
|
+
agenta/sdk/decorators/llm_entrypoint.py,sha256=qU_TyYAbhoj-Cf-SSAKzo11Le9qpH-Z4bA_kKQ6iJk0,18643
|
|
135
|
+
agenta/sdk/decorators/tracing.py,sha256=w8qBj1P8ft2i7K5NoQBIGEHxfAyfNLiSlvgyRB9m0Mo,2446
|
|
134
136
|
agenta/sdk/router.py,sha256=0sbajvn5C7t18anH6yNo7-oYxldHnYfwcbmQnIXBePw,269
|
|
135
137
|
agenta/sdk/tracing/context_manager.py,sha256=HskDaiORoOhjeN375gm05wYnieQzh5UnoIsnSAHkAyc,252
|
|
136
|
-
agenta/sdk/tracing/
|
|
137
|
-
agenta/sdk/tracing/llm_tracing.py,sha256=UiotJ56EFA3VPt7LREkcK2w51D9-0T1QNvBy4zNWEdY,7348
|
|
138
|
+
agenta/sdk/tracing/llm_tracing.py,sha256=CLijhERu9LYbi-UrUTsUT_jyb_0dT5iO_0o2MpjXk1g,8038
|
|
138
139
|
agenta/sdk/tracing/logger.py,sha256=4zG9c51p8xPdKA5SL8MOgBfkpCnBSuV6JfWiXO0A7oc,473
|
|
139
|
-
agenta/sdk/tracing/tasks_manager.py,sha256=
|
|
140
|
+
agenta/sdk/tracing/tasks_manager.py,sha256=ROrWIaqS2J2HHiJtRWiHKlLY8CCsqToP5VeXu7mamck,3748
|
|
140
141
|
agenta/sdk/types.py,sha256=Mn0yBlHh_Yr_5oQXUfsYI3V7sJAVWkJgkxEOBDOOMS0,5852
|
|
141
142
|
agenta/sdk/utils/globals.py,sha256=lpgflY8xovZJtHfJf41dbNCZGwx07YNkG9ldruv6xoI,360
|
|
142
143
|
agenta/sdk/utils/helper/openai_cost.py,sha256=1VkgvucDnNZm1pTfcVLz9icWunntp1d7zwMmnviy3Uw,5877
|
|
@@ -156,7 +157,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
|
|
|
156
157
|
agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
|
|
157
158
|
agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
|
|
158
159
|
agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
|
|
159
|
-
agenta-0.14.
|
|
160
|
-
agenta-0.14.
|
|
161
|
-
agenta-0.14.
|
|
162
|
-
agenta-0.14.
|
|
160
|
+
agenta-0.14.12a0.dist-info/METADATA,sha256=iS-y1oTXaY-6bHnUAIzCa2u7RmDdIJAuY5Kevj75gBI,26466
|
|
161
|
+
agenta-0.14.12a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
162
|
+
agenta-0.14.12a0.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
|
|
163
|
+
agenta-0.14.12a0.dist-info/RECORD,,
|