agenta 0.14.12a2__py3-none-any.whl → 0.14.13__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 +3 -5
- agenta/client/backend/client.py +6 -8
- agenta/client/backend/types/create_span.py +1 -1
- agenta/docker/docker-assets/Dockerfile.cloud.template +1 -1
- agenta/docker/docker-assets/Dockerfile.template +1 -1
- agenta/sdk/__init__.py +4 -4
- agenta/sdk/agenta_decorator.py +501 -0
- agenta/sdk/agenta_init.py +71 -67
- agenta/sdk/tracing/decorators.py +41 -0
- agenta/sdk/tracing/llm_tracing.py +65 -87
- agenta/sdk/tracing/tasks_manager.py +3 -1
- {agenta-0.14.12a2.dist-info → agenta-0.14.13.dist-info}/METADATA +1 -1
- {agenta-0.14.12a2.dist-info → agenta-0.14.13.dist-info}/RECORD +15 -16
- agenta/sdk/decorators/base.py +0 -10
- agenta/sdk/decorators/llm_entrypoint.py +0 -485
- agenta/sdk/decorators/tracing.py +0 -80
- {agenta-0.14.12a2.dist-info → agenta-0.14.13.dist-info}/WHEEL +0 -0
- {agenta-0.14.12a2.dist-info → agenta-0.14.13.dist-info}/entry_points.txt +0 -0
agenta/sdk/agenta_init.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import logging
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
|
|
5
|
+
from .utils.globals import set_global
|
|
4
6
|
|
|
5
|
-
from agenta.sdk.utils.globals import set_global
|
|
6
7
|
from agenta.client.backend.client import AgentaApi
|
|
8
|
+
from agenta.sdk.tracing.llm_tracing import Tracing
|
|
7
9
|
from agenta.client.exceptions import APIRequestError
|
|
8
10
|
|
|
9
11
|
|
|
@@ -11,6 +13,18 @@ logger = logging.getLogger(__name__)
|
|
|
11
13
|
logger.setLevel(logging.DEBUG)
|
|
12
14
|
|
|
13
15
|
|
|
16
|
+
BACKEND_URL_SUFFIX = os.environ.get("BACKEND_URL_SUFFIX", "api")
|
|
17
|
+
CLIENT_API_KEY = os.environ.get("AGENTA_API_KEY")
|
|
18
|
+
CLIENT_HOST = os.environ.get("AGENTA_HOST", "http://localhost")
|
|
19
|
+
|
|
20
|
+
# initialize the client with the backend url and api key
|
|
21
|
+
backend_url = f"{CLIENT_HOST}/{BACKEND_URL_SUFFIX}"
|
|
22
|
+
client = AgentaApi(
|
|
23
|
+
base_url=backend_url,
|
|
24
|
+
api_key=CLIENT_API_KEY if CLIENT_API_KEY else "",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
14
28
|
class AgentaSingleton:
|
|
15
29
|
"""Singleton class to save all the "global variables" for the sdk."""
|
|
16
30
|
|
|
@@ -23,16 +37,6 @@ class AgentaSingleton:
|
|
|
23
37
|
cls._instance = super(AgentaSingleton, cls).__new__(cls)
|
|
24
38
|
return cls._instance
|
|
25
39
|
|
|
26
|
-
@property
|
|
27
|
-
def client(self):
|
|
28
|
-
"""Builds sdk client instance.
|
|
29
|
-
|
|
30
|
-
Returns:
|
|
31
|
-
AgentaAPI: instance of agenta api backend
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
return AgentaApi(base_url=self.host + "/api", api_key=self.api_key)
|
|
35
|
-
|
|
36
40
|
def init(
|
|
37
41
|
self,
|
|
38
42
|
app_name: Optional[str] = None,
|
|
@@ -45,51 +49,53 @@ class AgentaSingleton:
|
|
|
45
49
|
) -> None:
|
|
46
50
|
"""Main function to initialize the singleton.
|
|
47
51
|
|
|
48
|
-
Initializes the singleton with the given `app_name`, `base_name`, and `host`.
|
|
49
|
-
|
|
50
|
-
in environment variables.
|
|
52
|
+
Initializes the singleton with the given `app_name`, `base_name`, and `host`. If any of these arguments are not provided,
|
|
53
|
+
the function will look for them in environment variables.
|
|
51
54
|
|
|
52
55
|
Args:
|
|
53
|
-
app_name (Optional[str]): Name of the application. Defaults to None.
|
|
54
|
-
base_name (Optional[str]): Base name for the setup. Defaults to None.
|
|
55
|
-
|
|
56
|
-
base_id (Optional[str]): Base ID for the setup. Defaults to None.
|
|
57
|
-
app_id (Optional[str]): App ID. Defaults to None.
|
|
58
|
-
host (Optional[str]): Host name of the backend server. Defaults to "http://localhost".
|
|
56
|
+
app_name (Optional[str]): Name of the Agenta application. Defaults to None. If not provided, will look for "AGENTA_APP_NAME" in environment variables.
|
|
57
|
+
base_name (Optional[str]): Base name for the Agenta setup. Defaults to None. If not provided, will look for "AGENTA_BASE_NAME" in environment variables.
|
|
58
|
+
host (Optional[str]): Host name of the backend server. Defaults to None. If not provided, will look for "AGENTA_HOST" in environment variables.
|
|
59
59
|
kwargs (Any): Additional keyword arguments.
|
|
60
60
|
|
|
61
61
|
Raises:
|
|
62
|
-
ValueError: If `app_name`, `base_name`, or `host` are not specified either as arguments
|
|
63
|
-
or in the environment variables.
|
|
62
|
+
ValueError: If `app_name`, `base_name`, or `host` are not specified either as arguments or in the environment variables.
|
|
64
63
|
"""
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
self.app_id = self.get_app(self.app_name)
|
|
81
|
-
self.base_id = self.get_app_base(self.app_id, self.base_name)
|
|
82
|
-
except Exception as ex:
|
|
83
|
-
raise APIRequestError(
|
|
84
|
-
f"Failed to get base id and/or app_id from the server with error: {ex}"
|
|
64
|
+
if app_name is None:
|
|
65
|
+
app_name = os.environ.get("AGENTA_APP_NAME")
|
|
66
|
+
if base_name is None:
|
|
67
|
+
base_name = os.environ.get("AGENTA_BASE_NAME")
|
|
68
|
+
if api_key is None:
|
|
69
|
+
api_key = os.environ.get("AGENTA_API_KEY")
|
|
70
|
+
if base_id is None:
|
|
71
|
+
base_id = os.environ.get("AGENTA_BASE_ID")
|
|
72
|
+
if host is None:
|
|
73
|
+
host = os.environ.get("AGENTA_HOST", "http://localhost")
|
|
74
|
+
|
|
75
|
+
if base_id is None:
|
|
76
|
+
if app_name is None or base_name is None:
|
|
77
|
+
print(
|
|
78
|
+
f"Warning: Your configuration will not be saved permanently since app_name and base_name are not provided."
|
|
85
79
|
)
|
|
80
|
+
else:
|
|
81
|
+
try:
|
|
82
|
+
app_id = self.get_app(app_name)
|
|
83
|
+
base_id = self.get_app_base(app_id, base_name)
|
|
84
|
+
except Exception as ex:
|
|
85
|
+
raise APIRequestError(
|
|
86
|
+
f"Failed to get base id and/or app_id from the server with error: {ex}"
|
|
87
|
+
)
|
|
86
88
|
|
|
89
|
+
self.base_id = base_id
|
|
90
|
+
self.host = host
|
|
91
|
+
self.app_id = os.environ.get("AGENTA_APP_ID") if app_id is None else app_id
|
|
87
92
|
self.variant_id = os.environ.get("AGENTA_VARIANT_ID")
|
|
88
93
|
self.variant_name = os.environ.get("AGENTA_VARIANT_NAME")
|
|
89
|
-
self.
|
|
94
|
+
self.api_key = api_key
|
|
95
|
+
self.config = Config(base_id=base_id, host=host)
|
|
90
96
|
|
|
91
97
|
def get_app(self, app_name: str) -> str:
|
|
92
|
-
apps =
|
|
98
|
+
apps = client.apps.list_apps(app_name=app_name)
|
|
93
99
|
if len(apps) == 0:
|
|
94
100
|
raise APIRequestError(f"App with name {app_name} not found")
|
|
95
101
|
|
|
@@ -97,7 +103,7 @@ class AgentaSingleton:
|
|
|
97
103
|
return app_id
|
|
98
104
|
|
|
99
105
|
def get_app_base(self, app_id: str, base_name: str) -> str:
|
|
100
|
-
bases =
|
|
106
|
+
bases = client.bases.list_bases(app_id=app_id, base_name=base_name)
|
|
101
107
|
if len(bases) == 0:
|
|
102
108
|
raise APIRequestError(f"No base was found for the app {app_id}")
|
|
103
109
|
return bases[0].base_id
|
|
@@ -113,26 +119,14 @@ class AgentaSingleton:
|
|
|
113
119
|
|
|
114
120
|
|
|
115
121
|
class Config:
|
|
116
|
-
def __init__(self, base_id
|
|
122
|
+
def __init__(self, base_id, host):
|
|
117
123
|
self.base_id = base_id
|
|
118
124
|
self.host = host
|
|
119
|
-
self.api_key = api_key
|
|
120
|
-
|
|
121
125
|
if base_id is None or host is None:
|
|
122
126
|
self.persist = False
|
|
123
127
|
else:
|
|
124
128
|
self.persist = True
|
|
125
129
|
|
|
126
|
-
@property
|
|
127
|
-
def client(self):
|
|
128
|
-
"""Builds sdk client instance.
|
|
129
|
-
|
|
130
|
-
Returns:
|
|
131
|
-
AgentaAPI: instance of agenta api backend
|
|
132
|
-
"""
|
|
133
|
-
|
|
134
|
-
return AgentaApi(base_url=self.host + "/api", api_key=self.api_key)
|
|
135
|
-
|
|
136
130
|
def register_default(self, overwrite=False, **kwargs):
|
|
137
131
|
"""alias for default"""
|
|
138
132
|
return self.default(overwrite=overwrite, **kwargs)
|
|
@@ -163,7 +157,7 @@ class Config:
|
|
|
163
157
|
if not self.persist:
|
|
164
158
|
return
|
|
165
159
|
try:
|
|
166
|
-
|
|
160
|
+
client.configs.save_config(
|
|
167
161
|
base_id=self.base_id,
|
|
168
162
|
config_name=config_name,
|
|
169
163
|
parameters=kwargs,
|
|
@@ -174,9 +168,7 @@ class Config:
|
|
|
174
168
|
"Failed to push the configuration to the server with error: " + str(ex)
|
|
175
169
|
)
|
|
176
170
|
|
|
177
|
-
def pull(
|
|
178
|
-
self, config_name: str = "default", environment_name: Optional[str] = None
|
|
179
|
-
):
|
|
171
|
+
def pull(self, config_name: str = "default", environment_name: str = None):
|
|
180
172
|
"""Pulls the parameters for the app variant from the server and sets them to the config"""
|
|
181
173
|
if not self.persist and (
|
|
182
174
|
config_name != "default" or environment_name is not None
|
|
@@ -187,12 +179,12 @@ class Config:
|
|
|
187
179
|
if self.persist:
|
|
188
180
|
try:
|
|
189
181
|
if environment_name:
|
|
190
|
-
config =
|
|
182
|
+
config = client.configs.get_config(
|
|
191
183
|
base_id=self.base_id, environment_name=environment_name
|
|
192
184
|
)
|
|
193
185
|
|
|
194
186
|
else:
|
|
195
|
-
config =
|
|
187
|
+
config = client.configs.get_config(
|
|
196
188
|
base_id=self.base_id,
|
|
197
189
|
config_name=config_name,
|
|
198
190
|
)
|
|
@@ -233,8 +225,20 @@ def init(app_name=None, base_name=None, **kwargs):
|
|
|
233
225
|
app_name: _description_. Defaults to None.
|
|
234
226
|
base_name: _description_. Defaults to None.
|
|
235
227
|
"""
|
|
236
|
-
|
|
237
228
|
singleton = AgentaSingleton()
|
|
238
|
-
|
|
239
229
|
singleton.init(app_name=app_name, base_name=base_name, **kwargs)
|
|
240
230
|
set_global(setup=singleton.setup, config=singleton.config)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def llm_tracing(max_workers: Optional[int] = None) -> Tracing:
|
|
234
|
+
"""Function to start llm tracing."""
|
|
235
|
+
|
|
236
|
+
singleton = AgentaSingleton()
|
|
237
|
+
return Tracing(
|
|
238
|
+
base_url=singleton.host,
|
|
239
|
+
app_id=singleton.app_id, # type: ignore
|
|
240
|
+
variant_id=singleton.variant_id, # type: ignore
|
|
241
|
+
variant_name=singleton.variant_name,
|
|
242
|
+
api_key=singleton.api_key,
|
|
243
|
+
max_workers=max_workers,
|
|
244
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Stdlib Imports
|
|
2
|
+
import inspect
|
|
3
|
+
from functools import wraps
|
|
4
|
+
|
|
5
|
+
# Own Imports
|
|
6
|
+
import agenta as ag
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def span(type: str):
|
|
10
|
+
"""Decorator to automatically start and end spans."""
|
|
11
|
+
|
|
12
|
+
tracing = ag.llm_tracing()
|
|
13
|
+
|
|
14
|
+
def decorator(func):
|
|
15
|
+
@wraps(func)
|
|
16
|
+
async def wrapper(*args, **kwargs):
|
|
17
|
+
result = None
|
|
18
|
+
span = tracing.start_span(
|
|
19
|
+
name=func.__name__,
|
|
20
|
+
input=kwargs,
|
|
21
|
+
spankind=type,
|
|
22
|
+
)
|
|
23
|
+
try:
|
|
24
|
+
is_coroutine_function = inspect.iscoroutinefunction(func)
|
|
25
|
+
if is_coroutine_function:
|
|
26
|
+
result = await func(*args, **kwargs)
|
|
27
|
+
else:
|
|
28
|
+
result = func(*args, **kwargs)
|
|
29
|
+
tracing.update_span_status(span=span, value="OK")
|
|
30
|
+
except Exception as e:
|
|
31
|
+
result = str(e)
|
|
32
|
+
tracing.update_span_status(span=span, value="ERROR")
|
|
33
|
+
finally:
|
|
34
|
+
if not isinstance(result, dict):
|
|
35
|
+
result = {"message": result}
|
|
36
|
+
tracing.end_span(outputs=result, span=span)
|
|
37
|
+
return result
|
|
38
|
+
|
|
39
|
+
return wrapper
|
|
40
|
+
|
|
41
|
+
return decorator
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
# Stdlib Imports
|
|
2
|
-
import os
|
|
3
|
-
from threading import Lock
|
|
4
2
|
from datetime import datetime, timezone
|
|
5
3
|
from typing import Optional, Dict, Any, List, Union
|
|
6
4
|
|
|
@@ -15,38 +13,10 @@ from agenta.client.backend.types.create_span import CreateSpan, SpanKind, SpanSt
|
|
|
15
13
|
from bson.objectid import ObjectId
|
|
16
14
|
|
|
17
15
|
|
|
18
|
-
class
|
|
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
|
-
|
|
16
|
+
class Tracing(object):
|
|
17
|
+
"""Agenta llm tracing object.
|
|
45
18
|
|
|
46
|
-
|
|
47
|
-
"""The `Tracing` class is an agent for LLM tracing with specific initialization arguments.
|
|
48
|
-
|
|
49
|
-
__init__ args:
|
|
19
|
+
Args:
|
|
50
20
|
base_url (str): The URL of the backend host
|
|
51
21
|
api_key (str): The API Key of the backend host
|
|
52
22
|
tasks_manager (TaskQueue): The tasks manager dedicated to handling asynchronous tasks
|
|
@@ -54,11 +24,18 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
54
24
|
max_workers (int): The maximum number of workers to run tracing
|
|
55
25
|
"""
|
|
56
26
|
|
|
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
|
+
|
|
57
34
|
def __init__(
|
|
58
35
|
self,
|
|
59
36
|
base_url: str,
|
|
60
37
|
app_id: str,
|
|
61
|
-
variant_id:
|
|
38
|
+
variant_id: str,
|
|
62
39
|
variant_name: Optional[str] = None,
|
|
63
40
|
api_key: Optional[str] = None,
|
|
64
41
|
max_workers: Optional[int] = None,
|
|
@@ -72,8 +49,8 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
72
49
|
self.tasks_manager = TaskQueue(
|
|
73
50
|
max_workers if max_workers else 4, logger=llm_logger
|
|
74
51
|
)
|
|
75
|
-
self.active_span
|
|
76
|
-
self.active_trace
|
|
52
|
+
self.active_span = CreateSpan
|
|
53
|
+
self.active_trace = CreateSpan
|
|
77
54
|
self.recording_trace_id: Union[str, None] = None
|
|
78
55
|
self.recorded_spans: List[CreateSpan] = []
|
|
79
56
|
self.tags: List[str] = []
|
|
@@ -116,18 +93,41 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
116
93
|
def set_trace_tags(self, tags: List[str]):
|
|
117
94
|
self.tags.extend(tags)
|
|
118
95
|
|
|
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
|
+
|
|
119
122
|
def start_span(
|
|
120
123
|
self,
|
|
121
124
|
name: str,
|
|
122
125
|
spankind: str,
|
|
123
126
|
input: Dict[str, Any],
|
|
124
|
-
config:
|
|
125
|
-
**kwargs,
|
|
127
|
+
config: Dict[str, Any] = {},
|
|
126
128
|
) -> CreateSpan:
|
|
127
129
|
span_id = self._create_span_id()
|
|
128
|
-
self.llm_logger.info(
|
|
129
|
-
f"Recording {'parent' if spankind == 'workflow' else spankind} span..."
|
|
130
|
-
)
|
|
130
|
+
self.llm_logger.info(f"Recording {spankind} span...")
|
|
131
131
|
span = CreateSpan(
|
|
132
132
|
id=span_id,
|
|
133
133
|
inputs=input,
|
|
@@ -136,69 +136,47 @@ class Tracing(metaclass=SingletonMeta):
|
|
|
136
136
|
variant_id=self.variant_id,
|
|
137
137
|
variant_name=self.variant_name,
|
|
138
138
|
config=config,
|
|
139
|
-
environment=
|
|
140
|
-
|
|
141
|
-
if self.active_trace
|
|
142
|
-
else os.environ.get("AGENTA_LLM_RUN_ENVIRONMENT", "unset")
|
|
143
|
-
),
|
|
139
|
+
environment=self.active_trace.environment,
|
|
140
|
+
parent_span_id=self.parent_span_id,
|
|
144
141
|
spankind=spankind.upper(),
|
|
145
142
|
attributes={},
|
|
146
143
|
status=SpanStatusCode.UNSET.value,
|
|
147
144
|
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,
|
|
156
145
|
)
|
|
157
146
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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}")
|
|
147
|
+
self.active_span = span
|
|
148
|
+
self.span_dict[span.id] = span
|
|
149
|
+
self.parent_span_id = span.id
|
|
150
|
+
self.llm_logger.info(
|
|
151
|
+
f"Recorded active_span and setting parent_span_id: {span.id}"
|
|
152
|
+
)
|
|
172
153
|
return span
|
|
173
154
|
|
|
174
155
|
def update_span_status(self, span: CreateSpan, value: str):
|
|
175
|
-
span.status
|
|
176
|
-
self.active_span =
|
|
177
|
-
|
|
178
|
-
def end_span(self, outputs: Dict[str, Any], span: CreateSpan):
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
156
|
+
updated_span = CreateSpan(**{**span.dict(), "status": value})
|
|
157
|
+
self.active_span = updated_span
|
|
158
|
+
|
|
159
|
+
def end_span(self, outputs: Dict[str, Any], span: CreateSpan, **kwargs):
|
|
160
|
+
updated_span = CreateSpan(
|
|
161
|
+
**span.dict(),
|
|
162
|
+
end_time=datetime.now(timezone.utc),
|
|
163
|
+
outputs=[outputs["message"]],
|
|
164
|
+
cost=outputs.get("cost", None),
|
|
165
|
+
tokens=outputs.get("usage"),
|
|
166
|
+
)
|
|
183
167
|
|
|
184
168
|
# Push span to list of recorded spans
|
|
185
|
-
self.recorded_spans.append(
|
|
169
|
+
self.recorded_spans.append(updated_span)
|
|
186
170
|
self.llm_logger.info(
|
|
187
|
-
f"Pushed {
|
|
171
|
+
f"Pushed {updated_span.spankind} span {updated_span.id} to recorded spans."
|
|
188
172
|
)
|
|
189
173
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
self.end_recording(span=span)
|
|
193
|
-
|
|
194
|
-
def end_recording(self, span: CreateSpan):
|
|
174
|
+
def end_recording(self, outputs: Dict[str, Any], span: CreateSpan, **kwargs):
|
|
175
|
+
self.end_span(outputs=outputs, span=span, **kwargs)
|
|
195
176
|
if self.api_key == "":
|
|
196
177
|
return
|
|
197
178
|
|
|
198
|
-
|
|
199
|
-
raise RuntimeError("No active trace to end.")
|
|
200
|
-
|
|
201
|
-
self.llm_logger.info("Preparing to send recorded spans for processing.")
|
|
179
|
+
self.llm_logger.info(f"Preparing to send recorded spans for processing.")
|
|
202
180
|
self.llm_logger.info(f"Recorded spans => {len(self.recorded_spans)}")
|
|
203
181
|
self.tasks_manager.add_task(
|
|
204
182
|
self.active_trace.id,
|
|
@@ -106,7 +106,9 @@ 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(
|
|
109
|
+
self._logger.error(
|
|
110
|
+
f"Recording trace {task.coroutine_type} status to ERROR."
|
|
111
|
+
)
|
|
110
112
|
break
|
|
111
113
|
finally:
|
|
112
114
|
self.tasks.task_done()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
agenta/__init__.py,sha256=
|
|
1
|
+
agenta/__init__.py,sha256=rCZ-mUOGnyKQpfWQFzXIEFX7KBlGC3qFMighdIVJgDc,610
|
|
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=UvNYKUplPdK1AkFfRsOdyEI7hoTqNCtD_pKlkgtUGGo,73690
|
|
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=_3G4WUnmgXtTCkIJFpce-9PDh6KDDZ2YkvXVOE8GSx8,1793
|
|
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
|
|
@@ -119,25 +119,24 @@ agenta/client/client.py,sha256=DWOGS9A8u4wu28s9jGOR4eRhf7vo4zT7GyDvrIGu59Y,19648
|
|
|
119
119
|
agenta/client/exceptions.py,sha256=cxLjjKvZKlUgBxt4Vn9J_SsezJPPNHvrZxnoq-D6zmw,94
|
|
120
120
|
agenta/config.py,sha256=Id-Ie1yf9QRP1YPhRYaYSOruRe6RBrsCXkG9rAa-ZtA,732
|
|
121
121
|
agenta/config.toml,sha256=ptE0P49bwsu3Luyn7OLFmk2buPhj5D-MA-O_ErOGoLg,223
|
|
122
|
-
agenta/docker/docker-assets/Dockerfile.cloud.template,sha256=
|
|
123
|
-
agenta/docker/docker-assets/Dockerfile.template,sha256=
|
|
122
|
+
agenta/docker/docker-assets/Dockerfile.cloud.template,sha256=f8VU9fs0mMDISGlo3kAYzF8YyDAKgK9FJQHl4PJwykw,386
|
|
123
|
+
agenta/docker/docker-assets/Dockerfile.template,sha256=jkZM1dOPUyQiO9q4jn_RR34-A76lhv5CHJmP0OJHyoE,280
|
|
124
124
|
agenta/docker/docker-assets/README.md,sha256=XHxwh2ks_ozrtAU7SLbL3J14SB2holG6buoTxwmMiZM,102
|
|
125
125
|
agenta/docker/docker-assets/entrypoint.sh,sha256=29XK8VQjQsx4hN2j-4JDy-6kQb5y4LCqZEa7PD4eqCQ,74
|
|
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/
|
|
129
|
+
agenta/sdk/__init__.py,sha256=jmeLRuXrew02ZruODZYIu4kpw0S8vV6JhMPQWFGtj30,648
|
|
130
|
+
agenta/sdk/agenta_decorator.py,sha256=6vz0G3YCRKRzK8JrQFyy8c2RIXy2kVMwyxTS093_8vQ,17296
|
|
131
|
+
agenta/sdk/agenta_init.py,sha256=wDfStpe8_3ZXRLtikarwDKI_VpA1YW4eIz_3fXq39is,9044
|
|
131
132
|
agenta/sdk/client.py,sha256=trKyBOYFZRk0v5Eptxvh87yPf50Y9CqY6Qgv4Fy-VH4,2142
|
|
132
133
|
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=L0M5oPP6NIZihReBFzYB9JVn60QZghR8ZUTBuok9vyY,2375
|
|
136
134
|
agenta/sdk/router.py,sha256=0sbajvn5C7t18anH6yNo7-oYxldHnYfwcbmQnIXBePw,269
|
|
137
135
|
agenta/sdk/tracing/context_manager.py,sha256=HskDaiORoOhjeN375gm05wYnieQzh5UnoIsnSAHkAyc,252
|
|
138
|
-
agenta/sdk/tracing/
|
|
136
|
+
agenta/sdk/tracing/decorators.py,sha256=ujtU8gf3GDoHYuLTfEYK_2eIYZ-1oX5dpv02Mf4l_II,1191
|
|
137
|
+
agenta/sdk/tracing/llm_tracing.py,sha256=UiotJ56EFA3VPt7LREkcK2w51D9-0T1QNvBy4zNWEdY,7348
|
|
139
138
|
agenta/sdk/tracing/logger.py,sha256=4zG9c51p8xPdKA5SL8MOgBfkpCnBSuV6JfWiXO0A7oc,473
|
|
140
|
-
agenta/sdk/tracing/tasks_manager.py,sha256=
|
|
139
|
+
agenta/sdk/tracing/tasks_manager.py,sha256=XVGBEOwmHa6KcCC0PApk0_bZ0Ilk2ESuduNObB1rw2s,3792
|
|
141
140
|
agenta/sdk/types.py,sha256=Mn0yBlHh_Yr_5oQXUfsYI3V7sJAVWkJgkxEOBDOOMS0,5852
|
|
142
141
|
agenta/sdk/utils/globals.py,sha256=lpgflY8xovZJtHfJf41dbNCZGwx07YNkG9ldruv6xoI,360
|
|
143
142
|
agenta/sdk/utils/helper/openai_cost.py,sha256=1VkgvucDnNZm1pTfcVLz9icWunntp1d7zwMmnviy3Uw,5877
|
|
@@ -157,7 +156,7 @@ agenta/templates/simple_prompt/app.py,sha256=kODgF6lhzsaJPdgL5b21bUki6jkvqjWZzWR
|
|
|
157
156
|
agenta/templates/simple_prompt/env.example,sha256=g9AE5bYcGPpxawXMJ96gh8oenEPCHTabsiOnfQo3c5k,70
|
|
158
157
|
agenta/templates/simple_prompt/requirements.txt,sha256=ywRglRy7pPkw8bljmMEJJ4aOOQKrt9FGKULZ-DGkoBU,23
|
|
159
158
|
agenta/templates/simple_prompt/template.toml,sha256=DQBtRrF4GU8LBEXOZ-GGuINXMQDKGTEG5y37tnvIUIE,60
|
|
160
|
-
agenta-0.14.
|
|
161
|
-
agenta-0.14.
|
|
162
|
-
agenta-0.14.
|
|
163
|
-
agenta-0.14.
|
|
159
|
+
agenta-0.14.13.dist-info/METADATA,sha256=_saz4-uv8nCwXR7JCySOGrN5VLYf6fFsV70s-OY5L0g,26464
|
|
160
|
+
agenta-0.14.13.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
161
|
+
agenta-0.14.13.dist-info/entry_points.txt,sha256=PDiu8_8AsL7ibU9v4iNoOKR1S7F2rdxjlEprjM9QOgo,46
|
|
162
|
+
agenta-0.14.13.dist-info/RECORD,,
|