agenta 0.27.0a9__py3-none-any.whl → 0.27.0a12__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.

Files changed (61) hide show
  1. agenta/__init__.py +21 -3
  2. agenta/client/backend/__init__.py +14 -0
  3. agenta/client/backend/apps/client.py +28 -20
  4. agenta/client/backend/client.py +25 -2
  5. agenta/client/backend/containers/client.py +5 -1
  6. agenta/client/backend/core/__init__.py +2 -1
  7. agenta/client/backend/core/client_wrapper.py +6 -6
  8. agenta/client/backend/core/file.py +33 -11
  9. agenta/client/backend/core/http_client.py +24 -18
  10. agenta/client/backend/core/pydantic_utilities.py +144 -29
  11. agenta/client/backend/core/request_options.py +3 -0
  12. agenta/client/backend/core/serialization.py +139 -42
  13. agenta/client/backend/evaluations/client.py +7 -2
  14. agenta/client/backend/evaluators/client.py +349 -1
  15. agenta/client/backend/observability/client.py +11 -2
  16. agenta/client/backend/testsets/client.py +10 -10
  17. agenta/client/backend/types/__init__.py +14 -0
  18. agenta/client/backend/types/app.py +1 -0
  19. agenta/client/backend/types/app_variant_response.py +3 -1
  20. agenta/client/backend/types/config_dto.py +32 -0
  21. agenta/client/backend/types/config_response_model.py +32 -0
  22. agenta/client/backend/types/create_span.py +3 -2
  23. agenta/client/backend/types/environment_output.py +1 -0
  24. agenta/client/backend/types/environment_output_extended.py +1 -0
  25. agenta/client/backend/types/evaluation.py +1 -2
  26. agenta/client/backend/types/evaluator.py +2 -0
  27. agenta/client/backend/types/evaluator_config.py +1 -0
  28. agenta/client/backend/types/evaluator_mapping_output_interface.py +21 -0
  29. agenta/client/backend/types/evaluator_output_interface.py +21 -0
  30. agenta/client/backend/types/human_evaluation.py +1 -2
  31. agenta/client/backend/types/lifecycle_dto.py +24 -0
  32. agenta/client/backend/types/llm_tokens.py +2 -2
  33. agenta/client/backend/types/reference_dto.py +23 -0
  34. agenta/client/backend/types/reference_request_model.py +23 -0
  35. agenta/client/backend/types/span.py +1 -0
  36. agenta/client/backend/types/span_detail.py +7 -1
  37. agenta/client/backend/types/test_set_output_response.py +5 -2
  38. agenta/client/backend/types/trace_detail.py +7 -1
  39. agenta/client/backend/types/with_pagination.py +4 -2
  40. agenta/client/backend/variants/client.py +1565 -272
  41. agenta/sdk/__init__.py +19 -5
  42. agenta/sdk/agenta_init.py +21 -7
  43. agenta/sdk/context/routing.py +6 -5
  44. agenta/sdk/decorators/routing.py +16 -5
  45. agenta/sdk/decorators/tracing.py +16 -9
  46. agenta/sdk/litellm/litellm.py +47 -36
  47. agenta/sdk/managers/__init__.py +6 -0
  48. agenta/sdk/managers/config.py +318 -0
  49. agenta/sdk/managers/deployment.py +45 -0
  50. agenta/sdk/managers/shared.py +639 -0
  51. agenta/sdk/managers/variant.py +182 -0
  52. agenta/sdk/tracing/exporters.py +0 -1
  53. agenta/sdk/tracing/inline.py +45 -0
  54. agenta/sdk/tracing/processors.py +0 -1
  55. agenta/sdk/types.py +47 -2
  56. agenta/sdk/utils/exceptions.py +31 -1
  57. {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/METADATA +1 -1
  58. {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/RECORD +60 -49
  59. agenta/sdk/config_manager.py +0 -205
  60. {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/WHEEL +0 -0
  61. {agenta-0.27.0a9.dist-info → agenta-0.27.0a12.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,318 @@
1
+ import json
2
+ import logging
3
+ from pathlib import Path
4
+ from typing import Optional, Type, TypeVar, Dict, Any, Union
5
+
6
+ import yaml
7
+ from pydantic import BaseModel
8
+
9
+ from agenta.sdk.managers.shared import SharedManager
10
+ from agenta.sdk.decorators.routing import routing_context
11
+
12
+ T = TypeVar("T", bound=BaseModel)
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+ AVAILABLE_ENVIRONMENTS = ["development", "production", "staging"]
17
+
18
+
19
+ class ConfigManager:
20
+ @staticmethod
21
+ def get_from_route(
22
+ schema: Optional[Type[T]] = None,
23
+ ) -> Union[Dict[str, Any], T]:
24
+ """
25
+ Retrieves the configuration from the route context and returns a config object.
26
+
27
+ This method checks the route context for configuration information and returns
28
+ an instance of the specified schema based on the available context data.
29
+
30
+ Args:
31
+ schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
32
+
33
+ Returns:
34
+ T: An instance of the specified schema populated with the configuration data.
35
+
36
+ Raises:
37
+ ValueError: If conflicting configuration sources are provided or if no valid
38
+ configuration source is found in the context.
39
+
40
+ Note:
41
+ The method prioritizes the inputs in the following way:
42
+ 1. 'config' (i.e. when called explicitly from the playground)
43
+ 2. 'environment'
44
+ 3. 'variant'
45
+ Only one of these should be provided.
46
+ """
47
+
48
+ context = routing_context.get()
49
+
50
+ parameters = None
51
+
52
+ if "config" in context and context["config"]:
53
+ parameters = context["config"]
54
+
55
+ else:
56
+ app_id: Optional[str] = None
57
+ app_slug: Optional[str] = None
58
+ variant_id: Optional[str] = None
59
+ variant_slug: Optional[str] = None
60
+ variant_version: Optional[int] = None
61
+ environment_id: Optional[str] = None
62
+ environment_slug: Optional[str] = None
63
+ environment_version: Optional[int] = None
64
+
65
+ if "application" in context:
66
+ app_id = context["application"].get("id")
67
+ app_slug = context["application"].get("slug")
68
+
69
+ if "variant" in context:
70
+ variant_id = context["variant"].get("id")
71
+ variant_slug = context["variant"].get("slug")
72
+ variant_version = context["variant"].get("version")
73
+
74
+ if "environment" in context:
75
+ environment_id = context["environment"].get("id")
76
+ environment_slug = context["environment"].get("slug")
77
+ environment_version = context["environment"].get("version")
78
+
79
+ parameters = ConfigManager.get_from_registry(
80
+ app_id=app_id,
81
+ app_slug=app_slug,
82
+ variant_id=variant_id,
83
+ variant_slug=variant_slug,
84
+ variant_version=variant_version,
85
+ environment_id=environment_id,
86
+ environment_slug=environment_slug,
87
+ environment_version=environment_version,
88
+ )
89
+
90
+ if schema:
91
+ return schema(**parameters)
92
+
93
+ return parameters
94
+
95
+ @staticmethod
96
+ async def async_get_from_route(
97
+ schema: Optional[Type[T]] = None,
98
+ ) -> Union[Dict[str, Any], T]:
99
+ """
100
+ Asynchronously retrieves the configuration from the route context and returns a config object.
101
+
102
+ This method checks the route context for configuration information and returns
103
+ an instance of the specified schema based on the available context data.
104
+
105
+ Args:
106
+ schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
107
+
108
+ Returns:
109
+ T: An instance of the specified schema populated with the configuration data.
110
+
111
+ Raises:
112
+ ValueError: If conflicting configuration sources are provided or if no valid
113
+ configuration source is found in the context.
114
+
115
+ Note:
116
+ The method prioritizes the inputs in the following way:
117
+ 1. 'config' (i.e. when called explicitly from the playground)
118
+ 2. 'environment'
119
+ 3. 'variant'
120
+ Only one of these should be provided.
121
+ """
122
+
123
+ context = routing_context.get()
124
+
125
+ parameters = None
126
+
127
+ if "config" in context and context["config"]:
128
+ parameters = context["config"]
129
+
130
+ else:
131
+ app_id: Optional[str] = None
132
+ app_slug: Optional[str] = None
133
+ variant_id: Optional[str] = None
134
+ variant_slug: Optional[str] = None
135
+ variant_version: Optional[int] = None
136
+ environment_id: Optional[str] = None
137
+ environment_slug: Optional[str] = None
138
+ environment_version: Optional[int] = None
139
+
140
+ if "application" in context:
141
+ app_id = context["application"].get("id")
142
+ app_slug = context["application"].get("slug")
143
+
144
+ if "variant" in context:
145
+ variant_id = context["variant"].get("id")
146
+ variant_slug = context["variant"].get("slug")
147
+ variant_version = context["variant"].get("version")
148
+
149
+ if "environment" in context:
150
+ environment_id = context["environment"].get("id")
151
+ environment_slug = context["environment"].get("slug")
152
+ environment_version = context["environment"].get("version")
153
+
154
+ parameters = await ConfigManager.async_get_from_registry(
155
+ app_id=app_id,
156
+ app_slug=app_slug,
157
+ variant_id=variant_id,
158
+ variant_slug=variant_slug,
159
+ variant_version=variant_version,
160
+ environment_id=environment_id,
161
+ environment_slug=environment_slug,
162
+ environment_version=environment_version,
163
+ )
164
+
165
+ if schema:
166
+ return schema(**parameters)
167
+
168
+ return parameters
169
+
170
+ @staticmethod
171
+ def get_from_registry(
172
+ schema: Optional[Type[T]] = None,
173
+ #
174
+ app_id: Optional[str] = None,
175
+ app_slug: Optional[str] = None,
176
+ variant_id: Optional[str] = None,
177
+ variant_slug: Optional[str] = None,
178
+ variant_version: Optional[int] = None,
179
+ environment_id: Optional[str] = None,
180
+ environment_slug: Optional[str] = None,
181
+ environment_version: Optional[int] = None,
182
+ ) -> Union[Dict[str, Any], T]:
183
+ """
184
+ Pulls the parameters for the app variant from the server and returns a config object.
185
+
186
+ This method retrieves the configuration from the backend server based on the provided
187
+ environment or variant. It then validates and returns the configuration as an instance
188
+ of the specified schema.
189
+
190
+ Args:
191
+ app_slug (str): The unique identifier for the application whose configuration is to be fetched.
192
+ variant_slug (Optional[str]): The variant name to fetch the configuration for. Defaults to None.
193
+ variant_version (Optional[int]): The version number of the variant to fetch. Defaults to None.
194
+ environment_slug (Optional[str]): The environment name to fetch the configuration for.
195
+ Must be one of "development", "production", or "staging". Defaults to None.
196
+
197
+ Raises:
198
+ Exception: For any other errors during the process (e.g., API communication issues).
199
+ """
200
+ config = SharedManager.fetch(
201
+ app_id=app_id,
202
+ app_slug=app_slug,
203
+ variant_id=variant_id,
204
+ variant_slug=variant_slug,
205
+ variant_version=variant_version,
206
+ environment_id=environment_id,
207
+ environment_slug=environment_slug,
208
+ environment_version=environment_version,
209
+ )
210
+
211
+ if schema:
212
+ return schema(**config.params)
213
+
214
+ return config.params
215
+
216
+ @staticmethod
217
+ async def async_get_from_registry(
218
+ schema: Optional[Type[T]] = None,
219
+ #
220
+ app_id: Optional[str] = None,
221
+ app_slug: Optional[str] = None,
222
+ variant_id: Optional[str] = None,
223
+ variant_slug: Optional[str] = None,
224
+ variant_version: Optional[int] = None,
225
+ environment_id: Optional[str] = None,
226
+ environment_slug: Optional[str] = None,
227
+ environment_version: Optional[int] = None,
228
+ ) -> Union[Dict[str, Any], T]:
229
+ """
230
+ Pulls the parameters for the app variant from the server and returns a config object.
231
+
232
+ This method retrieves the configuration from the backend server based on the provided
233
+ environment or variant. It then validates and returns the configuration as an instance
234
+ of the specified schema.
235
+
236
+ Args:
237
+ app_slug (str): The unique identifier for the application whose configuration is to be fetched.
238
+ variant_slug (Optional[str]): The variant name to fetch the configuration for. Defaults to None.
239
+ variant_version (Optional[int]): The version number of the variant to fetch. Defaults to None.
240
+ environment_slug (Optional[str]): The environment name to fetch the configuration for.
241
+ Must be one of "development", "production", or "staging". Defaults to None.
242
+
243
+ Raises:
244
+ Exception: For any other errors during the process (e.g., API communication issues).
245
+ """
246
+ config = await SharedManager.afetch(
247
+ app_id=app_id,
248
+ app_slug=app_slug,
249
+ variant_id=variant_id,
250
+ variant_slug=variant_slug,
251
+ variant_version=variant_version,
252
+ environment_id=environment_id,
253
+ environment_slug=environment_slug,
254
+ environment_version=environment_version,
255
+ )
256
+
257
+ if schema:
258
+ return schema(**config.params)
259
+
260
+ return config.params
261
+
262
+ @staticmethod
263
+ def get_from_yaml(
264
+ filename: str,
265
+ schema: Optional[Type[T]] = None,
266
+ ) -> T:
267
+ """
268
+ Loads configuration from a YAML file and returns a config object.
269
+
270
+ Args:
271
+ filename (str): The name of the YAML file to load.
272
+ schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
273
+
274
+ Returns:
275
+ T: An instance of the specified schema populated with the configuration data.
276
+
277
+ Raises:
278
+ FileNotFoundError: If the specified file doesn't exist.
279
+ ValidationError: If the loaded configuration data doesn't match the schema.
280
+ """
281
+ file_path = Path(filename)
282
+
283
+ with open(file_path, "r", encoding="utf-8") as file:
284
+ parameters = yaml.safe_load(file)
285
+
286
+ if schema:
287
+ return schema(**parameters)
288
+
289
+ return parameters
290
+
291
+ @staticmethod
292
+ def get_from_json(
293
+ filename: str,
294
+ schema: Optional[Type[T]] = None,
295
+ ) -> T:
296
+ """
297
+ Loads configuration from a JSON file and returns a config object.
298
+
299
+ Args:
300
+ filename (str): The name of the JSON file to load.
301
+ schema (Type[T]): A Pydantic model class that defines the structure of the configuration.
302
+
303
+ Returns:
304
+ T: An instance of the specified schema populated with the configuration data.
305
+
306
+ Raises:
307
+ FileNotFoundError: If the specified file doesn't exist.
308
+ ValidationError: If the loaded configuration data doesn't match the schema.
309
+ """
310
+ file_path = Path(filename)
311
+
312
+ with open(file_path, "r", encoding="utf-8") as file:
313
+ parameters = json.load(file)
314
+
315
+ if schema:
316
+ return schema(**parameters)
317
+
318
+ return parameters
@@ -0,0 +1,45 @@
1
+ from typing import Optional
2
+
3
+ from agenta.sdk.managers.shared import SharedManager
4
+
5
+
6
+ class DeploymentManager:
7
+ @classmethod
8
+ def deploy(
9
+ cls,
10
+ *,
11
+ variant_slug: str,
12
+ environment_slug: str,
13
+ #
14
+ app_id: Optional[str] = None,
15
+ app_slug: Optional[str] = None,
16
+ variant_version: Optional[int] = None,
17
+ ):
18
+ deployment = SharedManager.deploy(
19
+ app_id=app_id,
20
+ app_slug=app_slug,
21
+ variant_slug=variant_slug,
22
+ variant_version=variant_version,
23
+ environment_slug=environment_slug,
24
+ )
25
+ return deployment
26
+
27
+ @classmethod
28
+ async def adeploy(
29
+ cls,
30
+ *,
31
+ variant_slug: str,
32
+ environment_slug: str,
33
+ #
34
+ app_id: Optional[str] = None,
35
+ app_slug: Optional[str] = None,
36
+ variant_version: Optional[int] = None,
37
+ ):
38
+ deployment = await SharedManager.adeploy(
39
+ app_id=app_id,
40
+ app_slug=app_slug,
41
+ variant_slug=variant_slug,
42
+ variant_version=variant_version,
43
+ environment_slug=environment_slug,
44
+ )
45
+ return deployment