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.

Files changed (85) hide show
  1. agenta/__init__.py +29 -10
  2. agenta/cli/helper.py +5 -1
  3. agenta/client/backend/__init__.py +14 -0
  4. agenta/client/backend/apps/client.py +28 -20
  5. agenta/client/backend/client.py +47 -16
  6. agenta/client/backend/containers/client.py +5 -1
  7. agenta/client/backend/core/__init__.py +2 -1
  8. agenta/client/backend/core/client_wrapper.py +6 -6
  9. agenta/client/backend/core/file.py +33 -11
  10. agenta/client/backend/core/http_client.py +45 -31
  11. agenta/client/backend/core/pydantic_utilities.py +144 -29
  12. agenta/client/backend/core/request_options.py +3 -0
  13. agenta/client/backend/core/serialization.py +139 -42
  14. agenta/client/backend/evaluations/client.py +7 -2
  15. agenta/client/backend/evaluators/client.py +349 -1
  16. agenta/client/backend/observability/client.py +11 -2
  17. agenta/client/backend/testsets/client.py +10 -10
  18. agenta/client/backend/types/__init__.py +14 -0
  19. agenta/client/backend/types/app.py +1 -0
  20. agenta/client/backend/types/app_variant_response.py +3 -1
  21. agenta/client/backend/types/config_dto.py +32 -0
  22. agenta/client/backend/types/config_response_model.py +32 -0
  23. agenta/client/backend/types/create_span.py +3 -2
  24. agenta/client/backend/types/environment_output.py +1 -0
  25. agenta/client/backend/types/environment_output_extended.py +1 -0
  26. agenta/client/backend/types/evaluation.py +1 -2
  27. agenta/client/backend/types/evaluator.py +2 -0
  28. agenta/client/backend/types/evaluator_config.py +1 -0
  29. agenta/client/backend/types/evaluator_mapping_output_interface.py +21 -0
  30. agenta/client/backend/types/evaluator_output_interface.py +21 -0
  31. agenta/client/backend/types/human_evaluation.py +1 -2
  32. agenta/client/backend/types/lifecycle_dto.py +24 -0
  33. agenta/client/backend/types/llm_tokens.py +2 -2
  34. agenta/client/backend/types/reference_dto.py +23 -0
  35. agenta/client/backend/types/reference_request_model.py +23 -0
  36. agenta/client/backend/types/span.py +1 -0
  37. agenta/client/backend/types/span_detail.py +7 -1
  38. agenta/client/backend/types/test_set_output_response.py +5 -2
  39. agenta/client/backend/types/trace_detail.py +7 -1
  40. agenta/client/backend/types/with_pagination.py +4 -2
  41. agenta/client/backend/variants/client.py +1565 -272
  42. agenta/docker/docker-assets/Dockerfile.cloud.template +1 -1
  43. agenta/sdk/__init__.py +44 -7
  44. agenta/sdk/agenta_init.py +85 -33
  45. agenta/sdk/context/__init__.py +0 -0
  46. agenta/sdk/context/routing.py +26 -0
  47. agenta/sdk/context/tracing.py +3 -0
  48. agenta/sdk/decorators/__init__.py +0 -0
  49. agenta/sdk/decorators/{llm_entrypoint.py → routing.py} +216 -191
  50. agenta/sdk/decorators/tracing.py +218 -99
  51. agenta/sdk/litellm/__init__.py +1 -0
  52. agenta/sdk/litellm/litellm.py +288 -0
  53. agenta/sdk/managers/__init__.py +6 -0
  54. agenta/sdk/managers/config.py +318 -0
  55. agenta/sdk/managers/deployment.py +45 -0
  56. agenta/sdk/managers/shared.py +639 -0
  57. agenta/sdk/managers/variant.py +182 -0
  58. agenta/sdk/router.py +0 -7
  59. agenta/sdk/tracing/__init__.py +1 -0
  60. agenta/sdk/tracing/attributes.py +141 -0
  61. agenta/sdk/tracing/context.py +24 -0
  62. agenta/sdk/tracing/conventions.py +49 -0
  63. agenta/sdk/tracing/exporters.py +65 -0
  64. agenta/sdk/tracing/inline.py +1252 -0
  65. agenta/sdk/tracing/processors.py +117 -0
  66. agenta/sdk/tracing/spans.py +136 -0
  67. agenta/sdk/tracing/tracing.py +233 -0
  68. agenta/sdk/types.py +49 -2
  69. agenta/sdk/utils/{helper/openai_cost.py → costs.py} +3 -0
  70. agenta/sdk/utils/debug.py +5 -5
  71. agenta/sdk/utils/exceptions.py +52 -0
  72. agenta/sdk/utils/globals.py +3 -5
  73. agenta/sdk/{tracing/logger.py → utils/logging.py} +3 -5
  74. agenta/sdk/utils/singleton.py +13 -0
  75. {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/METADATA +5 -1
  76. {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/RECORD +78 -57
  77. agenta/sdk/config_manager.py +0 -205
  78. agenta/sdk/context.py +0 -41
  79. agenta/sdk/decorators/base.py +0 -10
  80. agenta/sdk/tracing/callbacks.py +0 -187
  81. agenta/sdk/tracing/llm_tracing.py +0 -617
  82. agenta/sdk/tracing/tasks_manager.py +0 -129
  83. agenta/sdk/tracing/tracing_context.py +0 -27
  84. {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/WHEEL +0 -0
  85. {agenta-0.26.0a0.dist-info → agenta-0.27.0.dist-info}/entry_points.txt +0 -0
@@ -1,4 +1,4 @@
1
- FROM public.ecr.aws/s2t9a1r1/agentaai/lambda_templates_public:main
1
+ FROM public.ecr.aws/h3w6n5z0/agentaai/lambda_templates_public:main
2
2
 
3
3
  COPY requirements.txt ${LAMBDA_TASK_ROOT}
4
4
  RUN pip install --no-cache-dir --disable-pip-version-check -U agenta
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
- from .context import get_contexts, save_context
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.llm_tracing import Tracing
22
+ from .tracing import Tracing, get_tracer
19
23
  from .decorators.tracing import instrument
20
- from .decorators.llm_entrypoint import entrypoint, app, route
21
- from .agenta_init import Config, AgentaSingleton, init
22
- from .utils.helper.openai_cost import calculate_token_usage
23
- from .config_manager import ConfigManager
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.llm_tracing import 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: Optional[Tracing] = None
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
- app_id: Optional[str] = None,
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
- """Main function to initialize the singleton.
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 os.environ.get("AGENTA_HOST", "https://cloud.agenta.ai")
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 config.get("api_key") or os.environ.get("AGENTA_API_KEY")
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(base_id=self.base_id, host=self.host, api_key=self.api_key) # type: ignore
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__(self, base_id: str, host: str, api_key: Optional[str] = ""):
89
- self.base_id = base_id
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", api_key=api_key if api_key else ""
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
- max_workers: Optional[int] = None,
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(app_id=app_id, host=host, api_key=api_key, config_fname=config_fname)
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
- tracing = Tracing(
244
- host=singleton.host, # type: ignore
245
- app_id=singleton.app_id, # type: ignore
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)
@@ -0,0 +1,3 @@
1
+ from contextvars import ContextVar
2
+
3
+ tracing_context = ContextVar("tracing_context", default={})
File without changes