agenta 0.12.2__py3-none-any.whl → 0.32.0a1__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 (244) hide show
  1. agenta/__init__.py +64 -7
  2. agenta/cli/helper.py +7 -3
  3. agenta/cli/main.py +15 -50
  4. agenta/cli/variant_commands.py +50 -29
  5. agenta/client/Readme.md +72 -64
  6. agenta/client/api.py +2 -2
  7. agenta/client/backend/__init__.py +193 -22
  8. agenta/client/backend/access_control/__init__.py +1 -0
  9. agenta/client/backend/access_control/client.py +167 -0
  10. agenta/client/backend/apps/__init__.py +1 -0
  11. agenta/client/backend/apps/client.py +1691 -0
  12. agenta/client/backend/bases/__init__.py +1 -0
  13. agenta/client/backend/bases/client.py +190 -0
  14. agenta/client/backend/client.py +2508 -5712
  15. agenta/client/backend/configs/__init__.py +1 -0
  16. agenta/client/backend/configs/client.py +604 -0
  17. agenta/client/backend/containers/__init__.py +5 -0
  18. agenta/client/backend/containers/client.py +648 -0
  19. agenta/client/backend/containers/types/__init__.py +5 -0
  20. agenta/client/backend/{types → containers/types}/container_templates_response.py +1 -2
  21. agenta/client/backend/core/__init__.py +30 -0
  22. agenta/client/backend/core/client_wrapper.py +42 -9
  23. agenta/client/backend/core/file.py +70 -0
  24. agenta/client/backend/core/http_client.py +575 -0
  25. agenta/client/backend/core/jsonable_encoder.py +33 -39
  26. agenta/client/backend/core/pydantic_utilities.py +325 -0
  27. agenta/client/backend/core/query_encoder.py +60 -0
  28. agenta/client/backend/core/remove_none_from_dict.py +2 -2
  29. agenta/client/backend/core/request_options.py +35 -0
  30. agenta/client/backend/core/serialization.py +276 -0
  31. agenta/client/backend/environments/__init__.py +1 -0
  32. agenta/client/backend/environments/client.py +196 -0
  33. agenta/client/backend/evaluations/__init__.py +1 -0
  34. agenta/client/backend/evaluations/client.py +1469 -0
  35. agenta/client/backend/evaluators/__init__.py +1 -0
  36. agenta/client/backend/evaluators/client.py +1283 -0
  37. agenta/client/backend/observability/__init__.py +1 -0
  38. agenta/client/backend/observability/client.py +1286 -0
  39. agenta/client/backend/observability_v_1/__init__.py +5 -0
  40. agenta/client/backend/observability_v_1/client.py +763 -0
  41. agenta/client/backend/observability_v_1/types/__init__.py +7 -0
  42. agenta/client/backend/observability_v_1/types/format.py +5 -0
  43. agenta/client/backend/observability_v_1/types/query_analytics_response.py +7 -0
  44. agenta/client/backend/observability_v_1/types/query_traces_response.py +11 -0
  45. agenta/client/backend/scopes/__init__.py +1 -0
  46. agenta/client/backend/scopes/client.py +114 -0
  47. agenta/client/backend/testsets/__init__.py +1 -0
  48. agenta/client/backend/testsets/client.py +1284 -0
  49. agenta/client/backend/types/__init__.py +154 -26
  50. agenta/client/backend/types/agenta_node_dto.py +48 -0
  51. agenta/client/backend/types/agenta_node_dto_nodes_value.py +6 -0
  52. agenta/client/backend/types/agenta_nodes_response.py +30 -0
  53. agenta/client/backend/types/agenta_root_dto.py +30 -0
  54. agenta/client/backend/types/agenta_roots_response.py +30 -0
  55. agenta/client/backend/types/agenta_tree_dto.py +30 -0
  56. agenta/client/backend/types/agenta_trees_response.py +30 -0
  57. agenta/client/backend/types/aggregated_result.py +16 -31
  58. agenta/client/backend/types/aggregated_result_evaluator_config.py +8 -0
  59. agenta/client/backend/types/analytics_response.py +24 -0
  60. agenta/client/backend/types/app.py +17 -30
  61. agenta/client/backend/types/app_variant_response.py +36 -0
  62. agenta/client/backend/types/app_variant_revision.py +17 -32
  63. agenta/client/backend/types/base_output.py +13 -28
  64. agenta/client/backend/types/body_import_testset.py +15 -31
  65. agenta/client/backend/types/bucket_dto.py +26 -0
  66. agenta/client/backend/types/collect_status_response.py +22 -0
  67. agenta/client/backend/types/config_db.py +16 -31
  68. agenta/client/backend/types/config_dto.py +32 -0
  69. agenta/client/backend/types/config_response_model.py +32 -0
  70. agenta/client/backend/types/correct_answer.py +22 -0
  71. agenta/client/backend/types/create_app_output.py +13 -28
  72. agenta/client/backend/types/create_span.py +45 -0
  73. agenta/client/backend/types/create_trace_response.py +22 -0
  74. agenta/client/backend/types/docker_env_vars.py +13 -28
  75. agenta/client/backend/types/environment_output.py +22 -34
  76. agenta/client/backend/types/environment_output_extended.py +31 -0
  77. agenta/client/backend/types/environment_revision.py +26 -0
  78. agenta/client/backend/types/error.py +22 -0
  79. agenta/client/backend/types/evaluation.py +22 -33
  80. agenta/client/backend/types/evaluation_scenario.py +18 -33
  81. agenta/client/backend/types/evaluation_scenario_input.py +16 -31
  82. agenta/client/backend/types/evaluation_scenario_output.py +17 -30
  83. agenta/client/backend/types/evaluation_scenario_result.py +14 -29
  84. agenta/client/backend/types/evaluation_scenario_score_update.py +21 -0
  85. agenta/client/backend/types/evaluation_status_enum.py +11 -29
  86. agenta/client/backend/types/evaluation_type.py +3 -21
  87. agenta/client/backend/types/evaluator.py +20 -31
  88. agenta/client/backend/types/evaluator_config.py +21 -33
  89. agenta/client/backend/types/evaluator_mapping_output_interface.py +21 -0
  90. agenta/client/backend/types/evaluator_output_interface.py +21 -0
  91. agenta/client/backend/types/exception_dto.py +26 -0
  92. agenta/client/backend/types/get_config_response.py +23 -0
  93. agenta/client/backend/types/header_dto.py +22 -0
  94. agenta/client/backend/types/http_validation_error.py +14 -29
  95. agenta/client/backend/types/human_evaluation.py +18 -34
  96. agenta/client/backend/types/human_evaluation_scenario.py +22 -38
  97. agenta/client/backend/types/human_evaluation_scenario_input.py +13 -28
  98. agenta/client/backend/types/human_evaluation_scenario_output.py +13 -28
  99. agenta/client/backend/types/human_evaluation_scenario_update.py +30 -0
  100. agenta/client/backend/types/human_evaluation_update.py +22 -0
  101. agenta/client/backend/types/image.py +18 -32
  102. agenta/client/backend/types/invite_request.py +16 -30
  103. agenta/client/backend/types/legacy_analytics_response.py +29 -0
  104. agenta/client/backend/types/legacy_data_point.py +27 -0
  105. agenta/client/backend/types/lifecycle_dto.py +24 -0
  106. agenta/client/backend/types/link_dto.py +24 -0
  107. agenta/client/backend/types/list_api_keys_response.py +24 -0
  108. agenta/client/backend/types/llm_run_rate_limit.py +13 -28
  109. agenta/client/backend/types/llm_tokens.py +23 -0
  110. agenta/client/backend/types/metrics_dto.py +24 -0
  111. agenta/client/backend/types/new_human_evaluation.py +27 -0
  112. agenta/client/backend/types/new_testset.py +16 -31
  113. agenta/client/backend/types/node_dto.py +24 -0
  114. agenta/client/backend/types/node_type.py +19 -0
  115. agenta/client/backend/types/o_tel_context_dto.py +22 -0
  116. agenta/client/backend/types/o_tel_event_dto.py +23 -0
  117. agenta/client/backend/types/o_tel_extra_dto.py +26 -0
  118. agenta/client/backend/types/o_tel_link_dto.py +23 -0
  119. agenta/client/backend/types/o_tel_span_dto.py +37 -0
  120. agenta/client/backend/types/o_tel_span_kind.py +15 -0
  121. agenta/client/backend/types/o_tel_spans_response.py +24 -0
  122. agenta/client/backend/types/o_tel_status_code.py +8 -0
  123. agenta/client/backend/types/organization.py +22 -35
  124. agenta/client/backend/types/organization_output.py +13 -28
  125. agenta/client/backend/types/outputs.py +5 -0
  126. agenta/client/backend/types/parent_dto.py +21 -0
  127. agenta/client/backend/types/permission.py +41 -0
  128. agenta/client/backend/types/projects_response.py +28 -0
  129. agenta/client/backend/types/provider_key_dto.py +23 -0
  130. agenta/client/backend/types/provider_kind.py +21 -0
  131. agenta/client/backend/types/reference_dto.py +23 -0
  132. agenta/client/backend/types/reference_request_model.py +23 -0
  133. agenta/client/backend/types/result.py +18 -31
  134. agenta/client/backend/types/root_dto.py +21 -0
  135. agenta/client/backend/types/{human_evaluation_scenario_score.py → score.py} +1 -1
  136. agenta/client/backend/types/secret_dto.py +24 -0
  137. agenta/client/backend/types/{human_evaluation_scenario_update_score.py → secret_kind.py} +1 -1
  138. agenta/client/backend/types/secret_response_dto.py +27 -0
  139. agenta/client/backend/types/simple_evaluation_output.py +13 -28
  140. agenta/client/backend/types/span.py +39 -49
  141. agenta/client/backend/types/span_detail.py +44 -0
  142. agenta/client/backend/types/span_dto.py +54 -0
  143. agenta/client/backend/types/span_dto_nodes_value.py +9 -0
  144. agenta/client/backend/types/span_status_code.py +5 -0
  145. agenta/client/backend/types/span_variant.py +23 -0
  146. agenta/client/backend/types/status_code.py +5 -0
  147. agenta/client/backend/types/status_dto.py +23 -0
  148. agenta/client/backend/types/template.py +14 -29
  149. agenta/client/backend/types/template_image_info.py +21 -35
  150. agenta/client/backend/types/test_set_output_response.py +20 -33
  151. agenta/client/backend/types/test_set_simple_response.py +13 -28
  152. agenta/client/backend/types/time_dto.py +23 -0
  153. agenta/client/backend/types/trace_detail.py +44 -0
  154. agenta/client/backend/types/tree_dto.py +23 -0
  155. agenta/client/backend/types/tree_type.py +5 -0
  156. agenta/client/backend/types/update_app_output.py +22 -0
  157. agenta/client/backend/types/uri.py +13 -28
  158. agenta/client/backend/types/validation_error.py +13 -28
  159. agenta/client/backend/types/variant_action.py +14 -29
  160. agenta/client/backend/types/variant_action_enum.py +1 -19
  161. agenta/client/backend/types/with_pagination.py +26 -0
  162. agenta/client/backend/types/workspace_member_response.py +23 -0
  163. agenta/client/backend/types/workspace_permission.py +25 -0
  164. agenta/client/backend/types/workspace_response.py +29 -0
  165. agenta/client/backend/types/workspace_role.py +15 -0
  166. agenta/client/backend/types/workspace_role_response.py +23 -0
  167. agenta/client/backend/variants/__init__.py +5 -0
  168. agenta/client/backend/variants/client.py +2814 -0
  169. agenta/client/backend/variants/types/__init__.py +7 -0
  170. agenta/client/backend/variants/types/add_variant_from_base_and_config_response.py +8 -0
  171. agenta/client/backend/vault/__init__.py +1 -0
  172. agenta/client/backend/vault/client.py +685 -0
  173. agenta/client/client.py +1 -1
  174. agenta/config.py +0 -2
  175. agenta/config.toml +0 -1
  176. agenta/docker/docker-assets/Dockerfile.cloud.template +2 -1
  177. agenta/docker/docker-assets/Dockerfile.template +2 -1
  178. agenta/docker/docker_utils.py +11 -12
  179. agenta/sdk/__init__.py +58 -7
  180. agenta/sdk/agenta_init.py +182 -164
  181. agenta/sdk/assets.py +95 -0
  182. agenta/sdk/client.py +56 -0
  183. agenta/sdk/context/__init__.py +0 -0
  184. agenta/sdk/context/exporting.py +25 -0
  185. agenta/sdk/context/routing.py +27 -0
  186. agenta/sdk/context/tracing.py +28 -0
  187. agenta/sdk/decorators/__init__.py +0 -0
  188. agenta/sdk/decorators/routing.py +576 -0
  189. agenta/sdk/decorators/tracing.py +296 -0
  190. agenta/sdk/litellm/__init__.py +1 -0
  191. agenta/sdk/litellm/litellm.py +314 -0
  192. agenta/sdk/litellm/mockllm.py +27 -0
  193. agenta/sdk/litellm/mocks/__init__.py +26 -0
  194. agenta/sdk/managers/__init__.py +6 -0
  195. agenta/sdk/managers/config.py +208 -0
  196. agenta/sdk/managers/deployment.py +45 -0
  197. agenta/sdk/managers/secrets.py +38 -0
  198. agenta/sdk/managers/shared.py +639 -0
  199. agenta/sdk/managers/variant.py +182 -0
  200. agenta/sdk/managers/vault.py +16 -0
  201. agenta/sdk/middleware/__init__.py +0 -0
  202. agenta/sdk/middleware/auth.py +180 -0
  203. agenta/sdk/middleware/cache.py +47 -0
  204. agenta/sdk/middleware/config.py +255 -0
  205. agenta/sdk/middleware/cors.py +29 -0
  206. agenta/sdk/middleware/inline.py +38 -0
  207. agenta/sdk/middleware/mock.py +33 -0
  208. agenta/sdk/middleware/otel.py +40 -0
  209. agenta/sdk/middleware/vault.py +145 -0
  210. agenta/sdk/router.py +0 -7
  211. agenta/sdk/tracing/__init__.py +1 -0
  212. agenta/sdk/tracing/attributes.py +141 -0
  213. agenta/sdk/tracing/conventions.py +49 -0
  214. agenta/sdk/tracing/exporters.py +103 -0
  215. agenta/sdk/tracing/inline.py +1146 -0
  216. agenta/sdk/tracing/processors.py +121 -0
  217. agenta/sdk/tracing/spans.py +136 -0
  218. agenta/sdk/tracing/tracing.py +237 -0
  219. agenta/sdk/types.py +478 -74
  220. agenta/sdk/utils/__init__.py +0 -0
  221. agenta/sdk/utils/constants.py +1 -0
  222. agenta/sdk/utils/{helper/openai_cost.py → costs.py} +3 -0
  223. agenta/sdk/utils/exceptions.py +59 -0
  224. agenta/sdk/utils/globals.py +6 -10
  225. agenta/sdk/utils/helpers.py +8 -0
  226. agenta/sdk/utils/logging.py +21 -0
  227. agenta/sdk/utils/singleton.py +13 -0
  228. agenta/sdk/utils/timing.py +58 -0
  229. {agenta-0.12.2.dist-info → agenta-0.32.0a1.dist-info}/METADATA +98 -151
  230. agenta-0.32.0a1.dist-info/RECORD +263 -0
  231. {agenta-0.12.2.dist-info → agenta-0.32.0a1.dist-info}/WHEEL +1 -1
  232. agenta/client/backend/types/add_variant_from_base_and_config_response.py +0 -7
  233. agenta/client/backend/types/app_variant_output.py +0 -47
  234. agenta/client/backend/types/app_variant_output_extended.py +0 -50
  235. agenta/client/backend/types/delete_evaluation.py +0 -36
  236. agenta/client/backend/types/evaluation_webhook.py +0 -36
  237. agenta/client/backend/types/feedback.py +0 -40
  238. agenta/client/backend/types/get_config_reponse.py +0 -39
  239. agenta/client/backend/types/list_api_keys_output.py +0 -39
  240. agenta/client/backend/types/trace.py +0 -48
  241. agenta/sdk/agenta_decorator.py +0 -443
  242. agenta/sdk/context.py +0 -41
  243. agenta-0.12.2.dist-info/RECORD +0 -114
  244. {agenta-0.12.2.dist-info → agenta-0.32.0a1.dist-info}/entry_points.txt +0 -0
agenta/config.py CHANGED
@@ -11,14 +11,12 @@ from pathlib import Path
11
11
  toml_config = toml.load(f"{Path(__file__).parent}/config.toml")
12
12
 
13
13
  # Set the environment variables from the TOML configurations
14
- os.environ["DATABASE_URL"] = toml_config["database_url"]
15
14
  os.environ["REGISTRY"] = toml_config["registry"]
16
15
  os.environ["BACKEND_URL_SUFFIX"] = toml_config["backend_url_suffix"]
17
16
  os.environ["ALLOW_ORIGINS"] = toml_config["allow_origins"]
18
17
 
19
18
 
20
19
  class Settings(BaseSettings):
21
- database_url: str
22
20
  registry: str
23
21
  backend_url_suffix: str
24
22
  allow_origins: str
agenta/config.toml CHANGED
@@ -1,5 +1,4 @@
1
1
  docker_registry_url="127.0.0.1:5001"
2
- database_url="localhost:5432"
3
2
  registry="agenta-server"
4
3
  backend_url_suffix="api"
5
4
  allow_origins="http://localhost:3000,http://localhost:3001,http://cloud.agenta.ai,https://cloud.agenta.ai"
@@ -1,6 +1,7 @@
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
+ RUN pip install --no-cache-dir --disable-pip-version-check -U agenta
4
5
  RUN pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
5
6
  RUN pip install --no-cache-dir --disable-pip-version-check mangum
6
7
  COPY . ${LAMBDA_TASK_ROOT}
@@ -4,9 +4,10 @@ WORKDIR /app
4
4
 
5
5
  COPY . .
6
6
 
7
+ RUN pip install --no-cache-dir --disable-pip-version-check -U agenta
7
8
  RUN pip install --no-cache-dir --disable-pip-version-check -r requirements.txt
8
9
 
9
10
  EXPOSE 80
10
11
 
12
+ RUN ["chmod", "+x", "./entrypoint.sh"]
11
13
  CMD ["./entrypoint.sh"]
12
- # uvicorn agenta_backend.main:app --reload --host 0.0.0.0 --port 8881
@@ -3,19 +3,16 @@ import shutil
3
3
  import tarfile
4
4
  import tempfile
5
5
  from pathlib import Path
6
- from tempfile import TemporaryDirectory
6
+ import os
7
7
 
8
- import docker
9
- from agenta.config import settings
10
- from docker.models.images import Image
11
8
 
12
9
  logger = logging.getLogger(__name__)
13
10
  logger.setLevel(logging.DEBUG)
14
11
 
15
- DEBUG = False
12
+ DEBUG = os.environ.get("AGENTA_CLI_DEBUG", False)
16
13
 
17
14
 
18
- def create_dockerfile(out_folder: Path):
15
+ def create_dockerfile(out_folder: Path) -> Path:
19
16
  """Creates a dockerfile based on the template in the out_folder.
20
17
 
21
18
  Arguments:
@@ -55,12 +52,14 @@ def build_tar_docker_container(folder: Path, file_name: Path) -> Path:
55
52
  shutil.copy(Path(__file__).parent / "docker-assets" / "lambda_function.py", folder)
56
53
  shutil.copy(Path(__file__).parent / "docker-assets" / "entrypoint.sh", folder)
57
54
 
55
+ # Initialize agentaignore_content with an empty string
56
+ agentaignore_content = ""
57
+
58
58
  # Read the contents of .gitignore file
59
- gitignore_content = ""
60
- gitignore_file_path = folder / ".gitignore"
61
- if gitignore_file_path.exists():
62
- with open(gitignore_file_path, "r") as gitignore_file:
63
- gitignore_content = gitignore_file.read()
59
+ agentaignore_file_path = folder / ".agentaignore"
60
+ if agentaignore_file_path.exists():
61
+ with open(agentaignore_file_path, "r") as agentaignore_file:
62
+ agentaignore_content = agentaignore_file.read()
64
63
 
65
64
  # Create a temporary directory
66
65
  with tempfile.TemporaryDirectory() as temp_dir:
@@ -68,7 +67,7 @@ def build_tar_docker_container(folder: Path, file_name: Path) -> Path:
68
67
 
69
68
  # Clean - remove '/' from every files and folders in the gitignore contents
70
69
  sanitized_patterns = [
71
- pattern.replace("/", "") for pattern in gitignore_content.splitlines()
70
+ pattern.replace("/", "") for pattern in agentaignore_content.splitlines()
72
71
  ]
73
72
 
74
73
  # Function to ignore files based on the patterns
agenta/sdk/__init__.py CHANGED
@@ -1,20 +1,71 @@
1
+ from typing import Optional, Callable, Any
2
+
1
3
  from .utils.preinit import PreInitObject # always the first import!
2
- from . import agenta_decorator, context, types, utils # noqa: F401
3
- from .agenta_decorator import app, entrypoint
4
- from .context import get_contexts, save_context
4
+
5
+ import agenta.client.backend.types as client_types # pylint: disable=wrong-import-order
6
+
5
7
  from .types import (
6
- Context,
7
8
  DictInput,
9
+ MultipleChoice,
8
10
  FloatParam,
9
- InFile,
10
11
  IntParam,
11
12
  MultipleChoiceParam,
13
+ GroupedMultipleChoiceParam,
12
14
  TextParam,
13
15
  MessagesInput,
14
16
  FileInputURL,
15
17
  BinaryParam,
18
+ Prompt,
19
+ AgentaNodeDto,
20
+ AgentaNodesResponse,
16
21
  )
17
- from .agenta_init import Config, init
18
- from .utils.helper.openai_cost import calculate_token_usage
22
+
23
+ from .tracing import Tracing, get_tracer
24
+ from .decorators.tracing import instrument
25
+ from .tracing.conventions import Reference
26
+ from .decorators.routing import entrypoint, app, route
27
+ from .agenta_init import Config, AgentaSingleton, init as _init
28
+ from .utils.costs import calculate_token_usage
29
+ from .managers.vault import VaultManager
30
+ from .managers.secrets import SecretsManager
31
+ from .managers.config import ConfigManager
32
+ from .managers.variant import VariantManager
33
+ from .managers.deployment import DeploymentManager
19
34
 
20
35
  config = PreInitObject("agenta.config", Config)
36
+ DEFAULT_AGENTA_SINGLETON_INSTANCE = AgentaSingleton()
37
+
38
+ types = client_types
39
+
40
+ api = None
41
+ async_api = None
42
+
43
+ tracing = DEFAULT_AGENTA_SINGLETON_INSTANCE.tracing # type: ignore
44
+ tracer = get_tracer(tracing)
45
+
46
+
47
+ def init(
48
+ host: Optional[str] = None,
49
+ api_key: Optional[str] = None,
50
+ config_fname: Optional[str] = None,
51
+ redact: Optional[Callable[..., Any]] = None,
52
+ redact_on_error: Optional[bool] = True,
53
+ # DEPRECATING
54
+ app_id: Optional[str] = None,
55
+ ):
56
+ global api, async_api, tracing, tracer # pylint: disable=global-statement
57
+
58
+ _init(
59
+ host=host,
60
+ api_key=api_key,
61
+ config_fname=config_fname,
62
+ redact=redact,
63
+ redact_on_error=redact_on_error,
64
+ app_id=app_id,
65
+ )
66
+
67
+ api = DEFAULT_AGENTA_SINGLETON_INSTANCE.api # type: ignore
68
+ async_api = DEFAULT_AGENTA_SINGLETON_INSTANCE.async_api # type: ignore
69
+
70
+ tracing = DEFAULT_AGENTA_SINGLETON_INSTANCE.tracing # type: ignore
71
+ tracer = get_tracer(tracing)
agenta/sdk/agenta_init.py CHANGED
@@ -1,33 +1,25 @@
1
- from agenta.client.exceptions import APIRequestError
2
- from agenta.client.backend.client import AgentaApi
3
- import os
4
- import logging
5
- from typing import Any, Optional
1
+ import toml
2
+ from os import getenv
3
+ from typing import Optional, Callable, Any
4
+ from importlib.metadata import version
6
5
 
7
- from .utils.globals import set_global
6
+ from agenta.sdk.utils.logging import log
7
+ from agenta.sdk.utils.globals import set_global
8
+ from agenta.client.backend.client import AgentaApi, AsyncAgentaApi
8
9
 
9
- logger = logging.getLogger(__name__)
10
- logger.setLevel(logging.DEBUG)
11
-
12
-
13
- BACKEND_URL_SUFFIX = os.environ.get("BACKEND_URL_SUFFIX", "api")
14
- CLIENT_API_KEY = os.environ.get("AGENTA_API_KEY")
15
- CLIENT_HOST = os.environ.get("AGENTA_HOST", "http://localhost")
16
-
17
- # initialize the client with the backend url and api key
18
- backend_url = f"{CLIENT_HOST}/{BACKEND_URL_SUFFIX}"
19
- client = AgentaApi(
20
- base_url=backend_url,
21
- api_key=CLIENT_API_KEY if CLIENT_API_KEY else "",
22
- )
10
+ from agenta.sdk.tracing import Tracing
11
+ from agenta.sdk.context.routing import routing_context
23
12
 
24
13
 
25
14
  class AgentaSingleton:
26
15
  """Singleton class to save all the "global variables" for the sdk."""
27
16
 
28
17
  _instance = None
29
- setup = None
30
18
  config = None
19
+ tracing = None
20
+
21
+ api = None
22
+ async_api = None
31
23
 
32
24
  def __new__(cls):
33
25
  if not cls._instance:
@@ -36,78 +28,140 @@ class AgentaSingleton:
36
28
 
37
29
  def init(
38
30
  self,
39
- app_name: Optional[str] = None,
40
- base_name: Optional[str] = None,
41
- api_key: Optional[str] = None,
42
- base_id: Optional[str] = None,
31
+ *,
43
32
  host: Optional[str] = None,
44
- **kwargs: Any,
33
+ api_key: Optional[str] = None,
34
+ config_fname: Optional[str] = None,
35
+ redact: Optional[Callable[..., Any]] = None,
36
+ redact_on_error: Optional[bool] = True,
37
+ # DEPRECATING
38
+ app_id: Optional[str] = None,
45
39
  ) -> None:
46
- """Main function to initialize the singleton.
40
+ """
41
+ Main function to initialize the singleton.
42
+
43
+ Initializes the singleton with the given `app_id`, `host`, and `api_key`. The order of precedence for these variables is:
44
+ 1. Explicit argument provided in the function call.
45
+ 2. Value from the configuration file specified by `config_fname`.
46
+ 3. Environment variables.
47
47
 
48
- Initializes the singleton with the given `app_name`, `base_name`, and `host`. If any of these arguments are not provided,
49
- the function will look for them in environment variables.
48
+ Examples:
49
+ ag.init(app_id="xxxx", api_key="xxx")
50
+ ag.init(config_fname="config.toml")
51
+ ag.init() #assuming env vars are set
50
52
 
51
53
  Args:
52
- app_name (Optional[str]): Name of the Agenta application. Defaults to None. If not provided, will look for "AGENTA_APP_NAME" in environment variables.
53
- 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.
54
- host (Optional[str]): Host name of the backend server. Defaults to None. If not provided, will look for "AGENTA_HOST" in environment variables.
55
- kwargs (Any): Additional keyword arguments.
54
+ app_id (Optional[str]): ID of the Agenta application. Defaults to None. If not provided, will look for "app_id" in the config file, then "AGENTA_APP_ID" in environment variables.
55
+ host (Optional[str]): Host name of the backend server. Defaults to None. If not provided, will look for "backend_host" in the config file, then "AGENTA_HOST" in environment variables.
56
+ api_key (Optional[str]): API Key to use with the host of the backend server. Defaults to None. If not provided, will look for "api_key" in the config file, then "AGENTA_API_KEY" in environment variables.
57
+ config_fname (Optional[str]): Path to the configuration file (relative or absolute). Defaults to None.
56
58
 
57
59
  Raises:
58
- ValueError: If `app_name`, `base_name`, or `host` are not specified either as arguments or in the environment variables.
60
+ ValueError: If `app_id` is not specified either as an argument, in the config file, or in the environment variables.
59
61
  """
60
- if app_name is None:
61
- app_name = os.environ.get("AGENTA_APP_NAME")
62
- if base_name is None:
63
- base_name = os.environ.get("AGENTA_BASE_NAME")
64
- if api_key is None:
65
- api_key = os.environ.get("AGENTA_API_KEY")
66
- if base_id is None:
67
- base_id = os.environ.get("AGENTA_BASE_ID")
68
- if host is None:
69
- host = os.environ.get("AGENTA_HOST", "http://localhost")
70
-
71
- if base_id is None:
72
- if app_name is None or base_name is None:
73
- print(
74
- f"Warning: Your configuration will not be saved permanently since app_name and base_name are not provided."
75
- )
76
- else:
77
- try:
78
- apps = client.list_apps(app_name=app_name)
79
- if len(apps) == 0:
80
- raise APIRequestError(f"App with name {app_name} not found")
81
-
82
- app_id = apps[0].app_id
83
- if not app_id:
84
- raise APIRequestError(
85
- f"App with name {app_name} does not exist on the server."
86
- )
87
-
88
- bases = client.list_bases(app_id=app_id, base_name=base_name)
89
- if len(bases) == 0:
90
- raise APIRequestError(f"No base was found for the app {app_id}")
91
-
92
- base_id = bases[0].base_id
93
- except Exception as ex:
94
- raise APIRequestError(
95
- f"Failed to get base id and/or app_id from the server with error: {ex}"
96
- )
97
- self.base_id = base_id
98
- self.host = host
99
- self.api_key = api_key
100
- self.config = Config(base_id=base_id, host=host)
62
+
63
+ log.info("Agenta - SDK version: %s", version("agenta"))
64
+
65
+ config = {}
66
+ if config_fname:
67
+ config = toml.load(config_fname)
68
+
69
+ self.host = (
70
+ host
71
+ or getenv("AGENTA_HOST")
72
+ or config.get("backend_host")
73
+ or config.get("host")
74
+ or "https://cloud.agenta.ai"
75
+ )
76
+
77
+ self.app_id = app_id or config.get("app_id") or getenv("AGENTA_APP_ID")
78
+ # if not self.app_id:
79
+ # raise ValueError(
80
+ # "App ID must be specified. You can provide it in one of the following ways:\n"
81
+ # "1. As an argument when calling ag.init(app_id='your_app_id').\n"
82
+ # "2. In the configuration file specified by config_fname.\n"
83
+ # "3. As an environment variable 'AGENTA_APP_ID'."
84
+ # )
85
+
86
+ self.api_key = api_key or getenv("AGENTA_API_KEY") or config.get("api_key")
87
+
88
+ self.base_id = getenv("AGENTA_BASE_ID")
89
+
90
+ self.service_id = getenv("AGENTA_SERVICE_ID") or self.base_id
91
+
92
+ log.info("Agenta - Service ID: %s", self.service_id)
93
+ log.info("Agenta - Application ID: %s", self.app_id)
94
+
95
+ self.tracing = Tracing(
96
+ url=f"{self.host}/api/observability/v1/otlp/traces", # type: ignore
97
+ redact=redact,
98
+ redact_on_error=redact_on_error,
99
+ )
100
+
101
+ self.tracing.configure(
102
+ api_key=self.api_key,
103
+ service_id=self.service_id,
104
+ # DEPRECATING
105
+ app_id=self.app_id,
106
+ )
107
+
108
+ self.api = AgentaApi(
109
+ base_url=self.host + "/api",
110
+ api_key=self.api_key if self.api_key else "",
111
+ )
112
+
113
+ self.async_api = AsyncAgentaApi(
114
+ base_url=self.host + "/api",
115
+ api_key=self.api_key if self.api_key else "",
116
+ )
117
+
118
+ self.config = Config(
119
+ host=self.host,
120
+ base_id=self.base_id,
121
+ api_key=self.api_key,
122
+ )
101
123
 
102
124
 
103
125
  class Config:
104
- def __init__(self, base_id, host):
105
- self.base_id = base_id
106
- self.host = host
107
- if base_id is None or host is None:
108
- self.persist = False
109
- else:
110
- self.persist = True
126
+ def __init__(
127
+ self,
128
+ # LEGACY
129
+ host: Optional[str] = None,
130
+ base_id: Optional[str] = None,
131
+ api_key: Optional[str] = None,
132
+ # LEGACY
133
+ **kwargs,
134
+ ):
135
+ self.default_parameters = {**kwargs}
136
+
137
+ def set_default(self, **kwargs):
138
+ self.default_parameters.update(kwargs)
139
+
140
+ def get_default(self):
141
+ return self.default_parameters
142
+
143
+ def __getattr__(self, key):
144
+ context = routing_context.get()
145
+
146
+ parameters = context.parameters
147
+
148
+ if not parameters:
149
+ return None
150
+
151
+ if key in parameters:
152
+ value = parameters[key]
153
+
154
+ if isinstance(value, dict):
155
+ nested_config = Config()
156
+ nested_config.set_default(**value)
157
+
158
+ return nested_config
159
+
160
+ return value
161
+
162
+ return None
163
+
164
+ ### --- LEGACY --- ###
111
165
 
112
166
  def register_default(self, overwrite=False, **kwargs):
113
167
  """alias for default"""
@@ -119,94 +173,58 @@ class Config:
119
173
  overwrite: Whether to overwrite the existing configuration or not
120
174
  **kwargs: A dict containing the parameters
121
175
  """
122
- self.set(
123
- **kwargs
124
- ) # In case there is no connectivity, we still can use the default values
125
- try:
126
- self.push(config_name="default", overwrite=overwrite, **kwargs)
127
- except Exception as ex:
128
- logger.warning(
129
- "Unable to push the default configuration to the server." + str(ex)
130
- )
131
-
132
- def push(self, config_name: str, overwrite=True, **kwargs):
133
- """Pushes the parameters for the app variant to the server
134
- Args:
135
- config_name: Name of the configuration to push to
136
- overwrite: Whether to overwrite the existing configuration or not
137
- **kwargs: A dict containing the parameters
138
- """
139
- if not self.persist:
140
- return
141
- try:
142
- client.save_config(
143
- base_id=self.base_id,
144
- config_name=config_name,
145
- parameters=kwargs,
146
- overwrite=overwrite,
147
- )
148
- except Exception as ex:
149
- logger.warning(
150
- "Failed to push the configuration to the server with error: " + str(ex)
151
- )
152
-
153
- def pull(self, config_name: str = "default", environment_name: str = None):
154
- """Pulls the parameters for the app variant from the server and sets them to the config"""
155
- if not self.persist and (
156
- config_name != "default" or environment_name is not None
157
- ):
158
- raise Exception(
159
- "Cannot pull the configuration from the server since the app_name and base_name are not provided."
160
- )
161
- if self.persist:
162
- try:
163
- if environment_name:
164
- config = client.get_config(
165
- base_id=self.base_id, environment_name=environment_name
166
- )
167
-
168
- else:
169
- config = client.get_config(
170
- base_id=self.base_id,
171
- config_name=config_name,
172
- )
173
- except Exception as ex:
174
- logger.warning(
175
- "Failed to pull the configuration from the server with error: "
176
- + str(ex)
177
- )
178
- try:
179
- self.set(**config.parameters)
180
- except Exception as ex:
181
- logger.warning("Failed to set the configuration with error: " + str(ex))
176
+ self.set(**kwargs)
182
177
 
183
- def all(self):
184
- """Returns all the parameters for the app variant"""
185
- return {
186
- k: v
187
- for k, v in self.__dict__.items()
188
- if k
189
- not in ["app_name", "base_name", "host", "base_id", "api_key", "persist"]
190
- }
191
-
192
- # function to set the parameters for the app variant
193
178
  def set(self, **kwargs):
194
- """Sets the parameters for the app variant
179
+ self.set_default(**kwargs)
195
180
 
196
- Args:
197
- **kwargs: A dict containing the parameters
198
- """
199
- for key, value in kwargs.items():
200
- setattr(self, key, value)
181
+ def all(self):
182
+ return self.default_parameters
201
183
 
202
184
 
203
- def init(app_name=None, base_name=None, **kwargs):
204
- """Main function to be called by the user to initialize the sdk.
185
+ def init(
186
+ host: Optional[str] = None,
187
+ api_key: Optional[str] = None,
188
+ config_fname: Optional[str] = None,
189
+ redact: Optional[Callable[..., Any]] = None,
190
+ redact_on_error: Optional[bool] = True,
191
+ # DEPRECATING
192
+ app_id: Optional[str] = None,
193
+ ):
194
+ """Main function to initialize the agenta sdk.
195
+
196
+ Initializes agenta with the given `app_id`, `host`, and `api_key`. The order of precedence for these variables is:
197
+ 1. Explicit argument provided in the function call.
198
+ 2. Value from the configuration file specified by `config_fname`.
199
+ 3. Environment variables.
200
+
201
+ - `app_id` is a required parameter (to be specified in one of the above ways)
202
+ - `host` is optional and defaults to "https://cloud.agenta.ai"
203
+ - `api_key` is optional and defaults to "". It is required only when using cloud or enterprise version of agenta.
204
+
205
205
 
206
206
  Args:
207
- app_name: _description_. Defaults to None.
208
- base_name: _description_. Defaults to None.
207
+ app_id (Optional[str]): ID of the Agenta application. Defaults to None. If not provided, will look for "app_id" in the config file, then "AGENTA_APP_ID" in environment variables.
208
+ host (Optional[str]): Host name of the backend server. Defaults to None. If not provided, will look for "backend_host" in the config file, then "AGENTA_HOST" in environment variables.
209
+ api_key (Optional[str]): API Key to use with the host of the backend server. Defaults to None. If not provided, will look for "api_key" in the config file, then "AGENTA_API_KEY" in environment variables.
210
+ config_fname (Optional[str]): Path to the configuration file. Defaults to None.
211
+
212
+ Raises:
213
+ ValueError: If `app_id` is not specified either as an argument, in the config file, or in the environment variables.
209
214
  """
215
+
210
216
  singleton = AgentaSingleton()
211
- singleton.init(app_name=app_name, base_name=base_name, **kwargs)
212
- set_global(setup=singleton.setup, config=singleton.config)
217
+
218
+ singleton.init(
219
+ host=host,
220
+ api_key=api_key,
221
+ config_fname=config_fname,
222
+ redact=redact,
223
+ redact_on_error=redact_on_error,
224
+ app_id=app_id,
225
+ )
226
+
227
+ set_global(
228
+ config=singleton.config,
229
+ tracing=singleton.tracing,
230
+ )
agenta/sdk/assets.py ADDED
@@ -0,0 +1,95 @@
1
+ supported_llm_models = {
2
+ "Aleph Alpha": [
3
+ "luminous-base",
4
+ "luminous-base-control",
5
+ "luminous-extended-control",
6
+ "luminous-supreme",
7
+ ],
8
+ "Anthropic": [
9
+ "anthropic/claude-3-5-sonnet-20240620",
10
+ "anthropic/claude-3-opus-20240229",
11
+ "anthropic/claude-3-sonnet-20240229",
12
+ "anthropic/claude-3-haiku-20240307",
13
+ "anthropic/claude-2.1",
14
+ "anthropic/claude-2",
15
+ "anthropic/claude-instant-1.2",
16
+ "anthropic/claude-instant-1",
17
+ ],
18
+ "Anyscale": [
19
+ "anyscale/meta-llama/Llama-2-13b-chat-hf",
20
+ "anyscale/meta-llama/Llama-2-70b-chat-hf",
21
+ ],
22
+ "Cohere": [
23
+ "cohere/command-light",
24
+ "cohere/command-r-plus",
25
+ "cohere/command-nightly",
26
+ ],
27
+ "DeepInfra": [
28
+ "deepinfra/meta-llama/Llama-2-70b-chat-hf",
29
+ "deepinfra/meta-llama/Llama-2-13b-chat-hf",
30
+ "deepinfra/codellama/CodeLlama-34b-Instruct-hf",
31
+ "deepinfra/mistralai/Mistral-7B-Instruct-v0.1",
32
+ "deepinfra/jondurbin/airoboros-l2-70b-gpt4-1.4.1",
33
+ ],
34
+ "Gemini": [
35
+ "gemini/gemini-1.5-pro-latest",
36
+ "gemini/gemini-1.5-flash",
37
+ ],
38
+ "Groq": [
39
+ "groq/llama3-8b-8192",
40
+ "groq/llama3-70b-8192",
41
+ "groq/llama2-70b-4096",
42
+ "groq/mixtral-8x7b-32768",
43
+ "groq/gemma-7b-it",
44
+ ],
45
+ "Mistral": [
46
+ "mistral/mistral-tiny",
47
+ "mistral/mistral-small",
48
+ "mistral/mistral-medium",
49
+ "mistral/mistral-large-latest",
50
+ ],
51
+ "Open AI": [
52
+ "gpt-3.5-turbo-1106",
53
+ "gpt-3.5-turbo",
54
+ "gpt-4",
55
+ "gpt-4o",
56
+ "gpt-4o-mini",
57
+ "gpt-4-1106-preview",
58
+ ],
59
+ "OpenRouter": [
60
+ "openrouter/openai/gpt-3.5-turbo",
61
+ "openrouter/openai/gpt-3.5-turbo-16k",
62
+ "openrouter/anthropic/claude-instant-v1",
63
+ "openrouter/google/palm-2-chat-bison",
64
+ "openrouter/google/palm-2-codechat-bison",
65
+ "openrouter/meta-llama/llama-2-13b-chat",
66
+ "openrouter/meta-llama/llama-2-70b-chat",
67
+ ],
68
+ "Perplexity AI": [
69
+ "perplexity/pplx-7b-chat",
70
+ "perplexity/pplx-70b-chat",
71
+ "perplexity/pplx-7b-online",
72
+ "perplexity/pplx-70b-online",
73
+ ],
74
+ "Together AI": [
75
+ "together_ai/togethercomputer/llama-2-70b-chat",
76
+ "together_ai/togethercomputer/llama-2-70b",
77
+ "together_ai/togethercomputer/LLaMA-2-7B-32K",
78
+ "together_ai/togethercomputer/Llama-2-7B-32K-Instruct",
79
+ "together_ai/togethercomputer/llama-2-7b",
80
+ "together_ai/togethercomputer/alpaca-7b",
81
+ "together_ai/togethercomputer/CodeLlama-34b-Instruct",
82
+ "together_ai/togethercomputer/CodeLlama-34b-Python",
83
+ "together_ai/WizardLM/WizardCoder-Python-34B-V1.0",
84
+ "together_ai/NousResearch/Nous-Hermes-Llama2-13b",
85
+ "together_ai/Austism/chronos-hermes-13b",
86
+ ],
87
+ }
88
+
89
+ providers_list = list(supported_llm_models.keys())
90
+
91
+ model_to_provider_mapping = {
92
+ model: provider
93
+ for provider, models in supported_llm_models.items()
94
+ for model in models
95
+ }