agenta 0.26.0a0__py3-none-any.whl → 0.27.0__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 +29 -10
- agenta/cli/helper.py +5 -1
- agenta/client/backend/__init__.py +14 -0
- agenta/client/backend/apps/client.py +28 -20
- agenta/client/backend/client.py +47 -16
- agenta/client/backend/containers/client.py +5 -1
- agenta/client/backend/core/__init__.py +2 -1
- agenta/client/backend/core/client_wrapper.py +6 -6
- agenta/client/backend/core/file.py +33 -11
- agenta/client/backend/core/http_client.py +45 -31
- agenta/client/backend/core/pydantic_utilities.py +144 -29
- agenta/client/backend/core/request_options.py +3 -0
- agenta/client/backend/core/serialization.py +139 -42
- agenta/client/backend/evaluations/client.py +7 -2
- agenta/client/backend/evaluators/client.py +349 -1
- agenta/client/backend/observability/client.py +11 -2
- agenta/client/backend/testsets/client.py +10 -10
- agenta/client/backend/types/__init__.py +14 -0
- agenta/client/backend/types/app.py +1 -0
- agenta/client/backend/types/app_variant_response.py +3 -1
- agenta/client/backend/types/config_dto.py +32 -0
- agenta/client/backend/types/config_response_model.py +32 -0
- agenta/client/backend/types/create_span.py +3 -2
- agenta/client/backend/types/environment_output.py +1 -0
- agenta/client/backend/types/environment_output_extended.py +1 -0
- agenta/client/backend/types/evaluation.py +1 -2
- agenta/client/backend/types/evaluator.py +2 -0
- agenta/client/backend/types/evaluator_config.py +1 -0
- agenta/client/backend/types/evaluator_mapping_output_interface.py +21 -0
- agenta/client/backend/types/evaluator_output_interface.py +21 -0
- agenta/client/backend/types/human_evaluation.py +1 -2
- agenta/client/backend/types/lifecycle_dto.py +24 -0
- agenta/client/backend/types/llm_tokens.py +2 -2
- agenta/client/backend/types/reference_dto.py +23 -0
- agenta/client/backend/types/reference_request_model.py +23 -0
- agenta/client/backend/types/span.py +1 -0
- agenta/client/backend/types/span_detail.py +7 -1
- agenta/client/backend/types/test_set_output_response.py +5 -2
- agenta/client/backend/types/trace_detail.py +7 -1
- agenta/client/backend/types/with_pagination.py +4 -2
- agenta/client/backend/variants/client.py +1565 -272
- agenta/docker/docker-assets/Dockerfile.cloud.template +1 -1
- agenta/sdk/__init__.py +44 -7
- agenta/sdk/agenta_init.py +85 -33
- agenta/sdk/context/__init__.py +0 -0
- agenta/sdk/context/routing.py +26 -0
- agenta/sdk/context/tracing.py +3 -0
- agenta/sdk/decorators/__init__.py +0 -0
- agenta/sdk/decorators/{llm_entrypoint.py → routing.py} +216 -191
- agenta/sdk/decorators/tracing.py +218 -99
- agenta/sdk/litellm/__init__.py +1 -0
- agenta/sdk/litellm/litellm.py +288 -0
- agenta/sdk/managers/__init__.py +6 -0
- agenta/sdk/managers/config.py +318 -0
- agenta/sdk/managers/deployment.py +45 -0
- agenta/sdk/managers/shared.py +639 -0
- agenta/sdk/managers/variant.py +182 -0
- agenta/sdk/router.py +0 -7
- agenta/sdk/tracing/__init__.py +1 -0
- agenta/sdk/tracing/attributes.py +141 -0
- agenta/sdk/tracing/context.py +24 -0
- agenta/sdk/tracing/conventions.py +49 -0
- agenta/sdk/tracing/exporters.py +65 -0
- agenta/sdk/tracing/inline.py +1252 -0
- agenta/sdk/tracing/processors.py +117 -0
- agenta/sdk/tracing/spans.py +136 -0
- agenta/sdk/tracing/tracing.py +233 -0
- agenta/sdk/types.py +49 -2
- agenta/sdk/utils/{helper/openai_cost.py → costs.py} +3 -0
- agenta/sdk/utils/debug.py +5 -5
- agenta/sdk/utils/exceptions.py +52 -0
- agenta/sdk/utils/globals.py +3 -5
- agenta/sdk/{tracing/logger.py → utils/logging.py} +3 -5
- agenta/sdk/utils/singleton.py +13 -0
- {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/METADATA +5 -1
- {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/RECORD +78 -57
- agenta/sdk/config_manager.py +0 -205
- agenta/sdk/context.py +0 -41
- agenta/sdk/decorators/base.py +0 -10
- agenta/sdk/tracing/callbacks.py +0 -187
- agenta/sdk/tracing/llm_tracing.py +0 -617
- agenta/sdk/tracing/tasks_manager.py +0 -129
- agenta/sdk/tracing/tracing_context.py +0 -27
- {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/WHEEL +0 -0
- {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/entry_points.txt +0 -0
agenta/sdk/__init__.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
1
3
|
from .utils.preinit import PreInitObject # always the first import!
|
|
2
|
-
|
|
4
|
+
|
|
5
|
+
import agenta.client.backend.types as client_types # pylint: disable=wrong-import-order
|
|
6
|
+
|
|
3
7
|
from .types import (
|
|
4
|
-
Context,
|
|
5
8
|
DictInput,
|
|
6
9
|
MultipleChoice,
|
|
7
10
|
FloatParam,
|
|
@@ -13,15 +16,49 @@ from .types import (
|
|
|
13
16
|
MessagesInput,
|
|
14
17
|
FileInputURL,
|
|
15
18
|
BinaryParam,
|
|
19
|
+
Prompt,
|
|
16
20
|
)
|
|
17
21
|
|
|
18
|
-
from .tracing
|
|
22
|
+
from .tracing import Tracing, get_tracer
|
|
19
23
|
from .decorators.tracing import instrument
|
|
20
|
-
from .
|
|
21
|
-
from .
|
|
22
|
-
from .
|
|
23
|
-
from .
|
|
24
|
+
from .tracing.conventions import Reference
|
|
25
|
+
from .decorators.routing import entrypoint, app, route
|
|
26
|
+
from .agenta_init import Config, AgentaSingleton, init as _init
|
|
27
|
+
from .utils.costs import calculate_token_usage
|
|
28
|
+
from .managers.config import ConfigManager
|
|
29
|
+
from .managers.variant import VariantManager
|
|
30
|
+
from .managers.deployment import DeploymentManager
|
|
24
31
|
|
|
25
32
|
config = PreInitObject("agenta.config", Config)
|
|
26
33
|
DEFAULT_AGENTA_SINGLETON_INSTANCE = AgentaSingleton()
|
|
34
|
+
|
|
35
|
+
types = client_types
|
|
36
|
+
|
|
37
|
+
api = None
|
|
38
|
+
async_api = None
|
|
39
|
+
|
|
27
40
|
tracing = DEFAULT_AGENTA_SINGLETON_INSTANCE.tracing # type: ignore
|
|
41
|
+
tracer = get_tracer(tracing)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def init(
|
|
45
|
+
host: Optional[str] = None,
|
|
46
|
+
app_id: Optional[str] = None,
|
|
47
|
+
api_key: Optional[str] = None,
|
|
48
|
+
config_fname: Optional[str] = None,
|
|
49
|
+
):
|
|
50
|
+
global api, async_api, tracing, tracer
|
|
51
|
+
|
|
52
|
+
_init(
|
|
53
|
+
host=host,
|
|
54
|
+
api_key=api_key,
|
|
55
|
+
config_fname=config_fname,
|
|
56
|
+
# DEPRECATING
|
|
57
|
+
app_id=app_id,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
api = DEFAULT_AGENTA_SINGLETON_INSTANCE.api # type: ignore
|
|
61
|
+
async_api = DEFAULT_AGENTA_SINGLETON_INSTANCE.async_api # type: ignore
|
|
62
|
+
|
|
63
|
+
tracing = DEFAULT_AGENTA_SINGLETON_INSTANCE.tracing # type: ignore
|
|
64
|
+
tracer = get_tracer(tracing)
|
agenta/sdk/agenta_init.py
CHANGED
|
@@ -2,10 +2,12 @@ import os
|
|
|
2
2
|
import logging
|
|
3
3
|
import toml
|
|
4
4
|
from typing import Optional
|
|
5
|
+
from importlib.metadata import version
|
|
5
6
|
|
|
7
|
+
from agenta.sdk.utils.logging import log
|
|
6
8
|
from agenta.sdk.utils.globals import set_global
|
|
7
|
-
from agenta.client.backend.client import AgentaApi
|
|
8
|
-
from agenta.sdk.tracing
|
|
9
|
+
from agenta.client.backend.client import AgentaApi, AsyncAgentaApi
|
|
10
|
+
from agenta.sdk.tracing import Tracing
|
|
9
11
|
from agenta.client.exceptions import APIRequestError
|
|
10
12
|
|
|
11
13
|
|
|
@@ -17,9 +19,11 @@ class AgentaSingleton:
|
|
|
17
19
|
"""Singleton class to save all the "global variables" for the sdk."""
|
|
18
20
|
|
|
19
21
|
_instance = None
|
|
20
|
-
setup = None
|
|
21
22
|
config = None
|
|
22
|
-
tracing
|
|
23
|
+
tracing = None
|
|
24
|
+
|
|
25
|
+
api = None
|
|
26
|
+
async_api = None
|
|
23
27
|
|
|
24
28
|
def __new__(cls):
|
|
25
29
|
if not cls._instance:
|
|
@@ -28,12 +32,15 @@ class AgentaSingleton:
|
|
|
28
32
|
|
|
29
33
|
def init(
|
|
30
34
|
self,
|
|
31
|
-
|
|
35
|
+
*,
|
|
32
36
|
host: Optional[str] = None,
|
|
33
37
|
api_key: Optional[str] = None,
|
|
34
38
|
config_fname: Optional[str] = None,
|
|
39
|
+
# DEPRECATING
|
|
40
|
+
app_id: Optional[str] = None,
|
|
35
41
|
) -> None:
|
|
36
|
-
"""
|
|
42
|
+
"""
|
|
43
|
+
Main function to initialize the singleton.
|
|
37
44
|
|
|
38
45
|
Initializes the singleton with the given `app_id`, `host`, and `api_key`. The order of precedence for these variables is:
|
|
39
46
|
1. Explicit argument provided in the function call.
|
|
@@ -54,47 +61,89 @@ class AgentaSingleton:
|
|
|
54
61
|
Raises:
|
|
55
62
|
ValueError: If `app_id` is not specified either as an argument, in the config file, or in the environment variables.
|
|
56
63
|
"""
|
|
64
|
+
|
|
65
|
+
log.info("---------------------------")
|
|
66
|
+
log.info("Agenta SDK - using version: %s", version("agenta"))
|
|
67
|
+
log.info("---------------------------")
|
|
68
|
+
|
|
57
69
|
config = {}
|
|
58
70
|
if config_fname:
|
|
59
71
|
config = toml.load(config_fname)
|
|
60
72
|
|
|
61
|
-
self.app_id = app_id or config.get("app_id") or os.environ.get("AGENTA_APP_ID")
|
|
62
73
|
self.host = (
|
|
63
74
|
host
|
|
75
|
+
or os.environ.get("AGENTA_HOST")
|
|
64
76
|
or config.get("backend_host")
|
|
65
|
-
or
|
|
77
|
+
or config.get("host")
|
|
78
|
+
or "https://cloud.agenta.ai"
|
|
66
79
|
)
|
|
80
|
+
|
|
81
|
+
self.app_id = app_id or config.get("app_id") or os.environ.get("AGENTA_APP_ID")
|
|
82
|
+
# if not self.app_id:
|
|
83
|
+
# raise ValueError(
|
|
84
|
+
# "App ID must be specified. You can provide it in one of the following ways:\n"
|
|
85
|
+
# "1. As an argument when calling ag.init(app_id='your_app_id').\n"
|
|
86
|
+
# "2. In the configuration file specified by config_fname.\n"
|
|
87
|
+
# "3. As an environment variable 'AGENTA_APP_ID'."
|
|
88
|
+
# )
|
|
89
|
+
|
|
67
90
|
self.api_key = (
|
|
68
|
-
api_key or
|
|
91
|
+
api_key or os.environ.get("AGENTA_API_KEY") or config.get("api_key")
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
self.tracing = Tracing(
|
|
95
|
+
url=f"{self.host}/api/observability/v1/otlp/traces", # type: ignore
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
self.tracing.configure(
|
|
99
|
+
api_key=self.api_key,
|
|
100
|
+
# DEPRECATING
|
|
101
|
+
app_id=self.app_id,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
self.api = AgentaApi(
|
|
105
|
+
base_url=self.host + "/api",
|
|
106
|
+
api_key=api_key if api_key else "",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
self.async_api = AsyncAgentaApi(
|
|
110
|
+
base_url=self.host + "/api",
|
|
111
|
+
api_key=api_key if api_key else "",
|
|
69
112
|
)
|
|
70
113
|
|
|
71
|
-
if not self.app_id:
|
|
72
|
-
raise ValueError(
|
|
73
|
-
"App ID must be specified. You can provide it in one of the following ways:\n"
|
|
74
|
-
"1. As an argument when calling ag.init(app_id='your_app_id').\n"
|
|
75
|
-
"2. In the configuration file specified by config_fname.\n"
|
|
76
|
-
"3. As an environment variable 'AGENTA_APP_ID'."
|
|
77
|
-
)
|
|
78
114
|
self.base_id = os.environ.get("AGENTA_BASE_ID")
|
|
79
|
-
if self.base_id is None:
|
|
80
|
-
print(
|
|
81
|
-
"Warning: Your configuration will not be saved permanently since base_id is not provided."
|
|
82
|
-
)
|
|
83
115
|
|
|
84
|
-
self.config = Config(
|
|
116
|
+
self.config = Config(
|
|
117
|
+
host=self.host,
|
|
118
|
+
base_id=self.base_id,
|
|
119
|
+
api_key=self.api_key,
|
|
120
|
+
)
|
|
85
121
|
|
|
86
122
|
|
|
87
123
|
class Config:
|
|
88
|
-
def __init__(
|
|
89
|
-
self
|
|
124
|
+
def __init__(
|
|
125
|
+
self,
|
|
126
|
+
host: str,
|
|
127
|
+
base_id: Optional[str] = None,
|
|
128
|
+
api_key: Optional[str] = "",
|
|
129
|
+
):
|
|
90
130
|
self.host = host
|
|
91
131
|
|
|
132
|
+
self.base_id = base_id
|
|
133
|
+
|
|
134
|
+
if self.base_id is None:
|
|
135
|
+
# print(
|
|
136
|
+
# "Warning: Your configuration will not be saved permanently since base_id is not provided.\n"
|
|
137
|
+
# )
|
|
138
|
+
pass
|
|
139
|
+
|
|
92
140
|
if base_id is None or host is None:
|
|
93
141
|
self.persist = False
|
|
94
142
|
else:
|
|
95
143
|
self.persist = True
|
|
96
144
|
self.client = AgentaApi(
|
|
97
|
-
base_url=self.host + "/api",
|
|
145
|
+
base_url=self.host + "/api",
|
|
146
|
+
api_key=api_key if api_key else "",
|
|
98
147
|
)
|
|
99
148
|
|
|
100
149
|
def register_default(self, overwrite=False, **kwargs):
|
|
@@ -208,11 +257,11 @@ class Config:
|
|
|
208
257
|
|
|
209
258
|
|
|
210
259
|
def init(
|
|
211
|
-
app_id: Optional[str] = None,
|
|
212
260
|
host: Optional[str] = None,
|
|
213
261
|
api_key: Optional[str] = None,
|
|
214
262
|
config_fname: Optional[str] = None,
|
|
215
|
-
|
|
263
|
+
# DEPRECATED
|
|
264
|
+
app_id: Optional[str] = None,
|
|
216
265
|
):
|
|
217
266
|
"""Main function to initialize the agenta sdk.
|
|
218
267
|
|
|
@@ -238,12 +287,15 @@ def init(
|
|
|
238
287
|
|
|
239
288
|
singleton = AgentaSingleton()
|
|
240
289
|
|
|
241
|
-
singleton.init(
|
|
290
|
+
singleton.init(
|
|
291
|
+
host=host,
|
|
292
|
+
api_key=api_key,
|
|
293
|
+
config_fname=config_fname,
|
|
294
|
+
# DEPRECATED
|
|
295
|
+
app_id=app_id,
|
|
296
|
+
)
|
|
242
297
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
api_key=singleton.api_key,
|
|
247
|
-
max_workers=max_workers,
|
|
298
|
+
set_global(
|
|
299
|
+
config=singleton.config,
|
|
300
|
+
tracing=singleton.tracing,
|
|
248
301
|
)
|
|
249
|
-
set_global(setup=singleton.setup, config=singleton.config, tracing=tracing)
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
from contextvars import ContextVar
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
|
|
5
|
+
routing_context = ContextVar("routing_context", default={})
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@contextmanager
|
|
9
|
+
def routing_context_manager(
|
|
10
|
+
*,
|
|
11
|
+
config: Optional[Dict[str, Any]] = None,
|
|
12
|
+
application: Optional[Dict[str, Any]] = None,
|
|
13
|
+
variant: Optional[Dict[str, Any]] = None,
|
|
14
|
+
environment: Optional[Dict[str, Any]] = None,
|
|
15
|
+
):
|
|
16
|
+
context = {
|
|
17
|
+
"config": config,
|
|
18
|
+
"application": application,
|
|
19
|
+
"variant": variant,
|
|
20
|
+
"environment": environment,
|
|
21
|
+
}
|
|
22
|
+
token = routing_context.set(context)
|
|
23
|
+
try:
|
|
24
|
+
yield
|
|
25
|
+
finally:
|
|
26
|
+
routing_context.reset(token)
|
|
File without changes
|