agenta 0.26.0__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.0.dist-info → agenta-0.27.0.dist-info}/METADATA +5 -1
  76. {agenta-0.26.0.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.0.dist-info → agenta-0.27.0.dist-info}/WHEEL +0 -0
  85. {agenta-0.26.0.dist-info → agenta-0.27.0.dist-info}/entry_points.txt +0 -0
@@ -1,129 +0,0 @@
1
- # Stdlib Imports
2
- import queue
3
- import asyncio
4
- from logging import Logger
5
- from typing import Coroutine, Optional, Union
6
- from concurrent.futures import ThreadPoolExecutor
7
-
8
- # Own Imports
9
- from agenta.client.backend.types.error import Error
10
- from agenta.client.backend.client import AsyncObservabilityClient
11
-
12
-
13
- class AsyncTask(object):
14
- """Wraps a coroutine (an asynchronous function defined with async def).
15
-
16
- Args:
17
- coroutine (Coroutine): asynchronous function
18
- """
19
-
20
- def __init__(
21
- self,
22
- coroutine_id: str,
23
- coroutine_type: str,
24
- coroutine: Coroutine,
25
- client: AsyncObservabilityClient,
26
- ):
27
- self.coroutine_id = coroutine_id
28
- self.coroutine_type = coroutine_type
29
- self.coroutine = coroutine
30
- self.task: Optional[asyncio.Task] = None
31
- self.client = client
32
-
33
- async def run(self) -> Union[asyncio.Task, Error]:
34
- """Creates an asyncio Task from the coroutine and starts it
35
-
36
- Returns:
37
- Task: asyncio task
38
- """
39
-
40
- try:
41
- self.task = asyncio.create_task(self.coroutine)
42
- except Exception as exc:
43
- return Error(message="error running task", stacktrace=str(exc))
44
- return await self.task
45
-
46
- def cancel(self):
47
- """
48
- Cancels running asyncio Task.
49
- """
50
-
51
- if self.task:
52
- self.task.cancel()
53
-
54
-
55
- class TaskQueue(object):
56
- """Stores a list of AsyncTask instances.
57
-
58
- Args:
59
- tasks (List[AsyncTasks]): list of async task instances
60
-
61
- Example Usage:
62
- ```python
63
- queue = TaskQueue()
64
- queue.add_task(long_running_task(1))
65
- queue.add_task(long_running_task(2))
66
- ```
67
- """
68
-
69
- def __init__(self, num_workers: int, logger: Logger):
70
- self.tasks = queue.Queue() # type: ignore
71
- self._logger = logger
72
- self._thread_pool = ThreadPoolExecutor(max_workers=num_workers)
73
-
74
- def add_task(
75
- self,
76
- coroutine_id: str,
77
- coroutine_type: str,
78
- coroutine: Coroutine,
79
- obs_client: AsyncObservabilityClient,
80
- ) -> AsyncTask:
81
- """Adds a new task to be executed.
82
-
83
- Args:
84
- coroutine_id (str): The Id of the coroutine
85
- coroutine_type (str): The type of coroutine
86
- coroutine (Coroutine): async task
87
- obs_client (AsyncObservabilityClient): The async observability client
88
-
89
- Returns:
90
- AsyncTask: task to be executed
91
- """
92
-
93
- task = AsyncTask(coroutine_id, coroutine_type, coroutine, obs_client)
94
- self.tasks.put(task)
95
- return self._worker()
96
-
97
- def _worker(self):
98
- """
99
- Runs task gotten from the queue in a thread pool.
100
- """
101
-
102
- while True:
103
- task: AsyncTask = self.tasks.get() # type: ignore
104
- try:
105
- future = self._thread_pool.submit(asyncio.run, task.run())
106
- future.result()
107
- except Exception as exc:
108
- self._logger.error(
109
- f"Task '{task.coroutine_type}' failed with error: {str(exc)}"
110
- )
111
- break
112
- finally:
113
- self.tasks.task_done()
114
- break
115
-
116
- def _get_size(self) -> int:
117
- """Returns the approximate number of items in the queue."""
118
-
119
- return self.tasks.qsize()
120
-
121
- def flush(self) -> None:
122
- """Clears all items from the queue."""
123
-
124
- q_size = self._get_size()
125
- self._logger.info("Flushing queue...")
126
- with self.tasks.mutex: # acts as a lock to ensure that only one thread can access the queue
127
- self.tasks.join()
128
- self._logger.info(f"Queue with {q_size} items flushed successfully")
129
- return
@@ -1,27 +0,0 @@
1
- from contextvars import ContextVar
2
-
3
- from typing import Optional, Dict, List
4
-
5
- from agenta.client.backend.types.create_span import CreateSpan
6
-
7
- CURRENT_TRACING_CONTEXT_KEY = "current_tracing_context"
8
-
9
-
10
- class TracingContext:
11
- def __init__(self):
12
- ### --- TRACE --- ###
13
- self.trace_id: Optional[str] = None
14
- self.trace_tags: List[str] = []
15
-
16
- ### --- SPANS --- ###
17
- self.active_span: Optional[CreateSpan] = None
18
- self.spans: Dict[str, CreateSpan] = {}
19
-
20
- def __repr__(self) -> str:
21
- return f"TracingContext(trace='{self.trace_id}', spans={[f'{span.id} {span.spankind}' for span in self.spans.values()]})"
22
-
23
- def __str__(self) -> str:
24
- return self.__repr__()
25
-
26
-
27
- tracing_context = ContextVar(CURRENT_TRACING_CONTEXT_KEY, default=None)