agenta 0.27.7a0__py3-none-any.whl → 0.27.7a2__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/client/backend/__init__.py +63 -0
- agenta/client/backend/client.py +22 -22
- agenta/client/backend/core/http_client.py +15 -7
- agenta/client/backend/observability/client.py +4 -4
- agenta/client/backend/observability_v_1/__init__.py +5 -0
- agenta/client/backend/observability_v_1/client.py +560 -0
- agenta/client/backend/observability_v_1/types/__init__.py +6 -0
- agenta/client/backend/observability_v_1/types/format.py +5 -0
- agenta/client/backend/observability_v_1/types/query_traces_response.py +11 -0
- agenta/client/backend/types/__init__.py +58 -0
- agenta/client/backend/types/agenta_node_dto.py +48 -0
- agenta/client/backend/types/agenta_node_dto_nodes_value.py +6 -0
- agenta/client/backend/types/agenta_nodes_response.py +30 -0
- agenta/client/backend/types/agenta_root_dto.py +30 -0
- agenta/client/backend/types/agenta_roots_response.py +30 -0
- agenta/client/backend/types/agenta_tree_dto.py +30 -0
- agenta/client/backend/types/agenta_trees_response.py +30 -0
- agenta/client/backend/types/collect_status_response.py +22 -0
- agenta/client/backend/types/exception_dto.py +26 -0
- agenta/client/backend/types/link_dto.py +24 -0
- agenta/client/backend/types/node_dto.py +24 -0
- agenta/client/backend/types/node_type.py +19 -0
- agenta/client/backend/types/o_tel_context_dto.py +22 -0
- agenta/client/backend/types/o_tel_event_dto.py +23 -0
- agenta/client/backend/types/o_tel_extra_dto.py +26 -0
- agenta/client/backend/types/o_tel_link_dto.py +23 -0
- agenta/client/backend/types/o_tel_span_dto.py +37 -0
- agenta/client/backend/types/o_tel_span_kind.py +15 -0
- agenta/client/backend/types/o_tel_spans_response.py +24 -0
- agenta/client/backend/types/o_tel_status_code.py +8 -0
- agenta/client/backend/types/parent_dto.py +21 -0
- agenta/client/backend/types/root_dto.py +21 -0
- agenta/client/backend/types/span_dto.py +54 -0
- agenta/client/backend/types/span_dto_nodes_value.py +9 -0
- agenta/client/backend/types/status_code.py +5 -0
- agenta/client/backend/types/status_dto.py +23 -0
- agenta/client/backend/types/time_dto.py +23 -0
- agenta/client/backend/types/tree_dto.py +23 -0
- agenta/client/backend/types/tree_type.py +5 -0
- agenta/client/backend/variants/client.py +24 -16
- agenta/sdk/__init__.py +2 -0
- agenta/sdk/decorators/routing.py +1 -1
- agenta/sdk/tracing/inline.py +29 -140
- agenta/sdk/types.py +5 -2
- {agenta-0.27.7a0.dist-info → agenta-0.27.7a2.dist-info}/METADATA +1 -1
- {agenta-0.27.7a0.dist-info → agenta-0.27.7a2.dist-info}/RECORD +48 -14
- {agenta-0.27.7a0.dist-info → agenta-0.27.7a2.dist-info}/WHEEL +0 -0
- {agenta-0.27.7a0.dist-info → agenta-0.27.7a2.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from ..core.pydantic_utilities import UniversalBaseModel
|
|
4
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2
|
|
5
|
+
import typing
|
|
6
|
+
import pydantic
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ParentDto(UniversalBaseModel):
|
|
10
|
+
id: str
|
|
11
|
+
|
|
12
|
+
if IS_PYDANTIC_V2:
|
|
13
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
14
|
+
extra="allow", frozen=True
|
|
15
|
+
) # type: ignore # Pydantic v2
|
|
16
|
+
else:
|
|
17
|
+
|
|
18
|
+
class Config:
|
|
19
|
+
frozen = True
|
|
20
|
+
smart_union = True
|
|
21
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from ..core.pydantic_utilities import UniversalBaseModel
|
|
4
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2
|
|
5
|
+
import typing
|
|
6
|
+
import pydantic
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RootDto(UniversalBaseModel):
|
|
10
|
+
id: str
|
|
11
|
+
|
|
12
|
+
if IS_PYDANTIC_V2:
|
|
13
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
14
|
+
extra="allow", frozen=True
|
|
15
|
+
) # type: ignore # Pydantic v2
|
|
16
|
+
else:
|
|
17
|
+
|
|
18
|
+
class Config:
|
|
19
|
+
frozen = True
|
|
20
|
+
smart_union = True
|
|
21
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from ..core.pydantic_utilities import UniversalBaseModel
|
|
5
|
+
import typing
|
|
6
|
+
from .lifecycle_dto import LifecycleDto
|
|
7
|
+
from .root_dto import RootDto
|
|
8
|
+
from .tree_dto import TreeDto
|
|
9
|
+
from .node_dto import NodeDto
|
|
10
|
+
from .parent_dto import ParentDto
|
|
11
|
+
from .time_dto import TimeDto
|
|
12
|
+
from .status_dto import StatusDto
|
|
13
|
+
from .exception_dto import ExceptionDto
|
|
14
|
+
from .link_dto import LinkDto
|
|
15
|
+
from .o_tel_extra_dto import OTelExtraDto
|
|
16
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2
|
|
17
|
+
import pydantic
|
|
18
|
+
from ..core.pydantic_utilities import update_forward_refs
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SpanDto(UniversalBaseModel):
|
|
22
|
+
lifecycle: typing.Optional[LifecycleDto] = None
|
|
23
|
+
root: RootDto
|
|
24
|
+
tree: TreeDto
|
|
25
|
+
node: NodeDto
|
|
26
|
+
parent: typing.Optional[ParentDto] = None
|
|
27
|
+
time: TimeDto
|
|
28
|
+
status: StatusDto
|
|
29
|
+
exception: typing.Optional[ExceptionDto] = None
|
|
30
|
+
data: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = None
|
|
31
|
+
metrics: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = None
|
|
32
|
+
meta: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = None
|
|
33
|
+
refs: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = None
|
|
34
|
+
links: typing.Optional[typing.List[LinkDto]] = None
|
|
35
|
+
otel: typing.Optional[OTelExtraDto] = None
|
|
36
|
+
nodes: typing.Optional[
|
|
37
|
+
typing.Dict[str, typing.Optional["SpanDtoNodesValue"]]
|
|
38
|
+
] = None
|
|
39
|
+
|
|
40
|
+
if IS_PYDANTIC_V2:
|
|
41
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
42
|
+
extra="allow", frozen=True
|
|
43
|
+
) # type: ignore # Pydantic v2
|
|
44
|
+
else:
|
|
45
|
+
|
|
46
|
+
class Config:
|
|
47
|
+
frozen = True
|
|
48
|
+
smart_union = True
|
|
49
|
+
extra = pydantic.Extra.allow
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
from .span_dto_nodes_value import SpanDtoNodesValue # noqa: E402
|
|
53
|
+
|
|
54
|
+
update_forward_refs(SpanDto)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import typing
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
if typing.TYPE_CHECKING:
|
|
8
|
+
from .span_dto import SpanDto
|
|
9
|
+
SpanDtoNodesValue = typing.Union["SpanDto", typing.List["SpanDto"]]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from ..core.pydantic_utilities import UniversalBaseModel
|
|
4
|
+
from .status_code import StatusCode
|
|
5
|
+
import typing
|
|
6
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2
|
|
7
|
+
import pydantic
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class StatusDto(UniversalBaseModel):
|
|
11
|
+
code: StatusCode
|
|
12
|
+
message: typing.Optional[str] = None
|
|
13
|
+
|
|
14
|
+
if IS_PYDANTIC_V2:
|
|
15
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
16
|
+
extra="allow", frozen=True
|
|
17
|
+
) # type: ignore # Pydantic v2
|
|
18
|
+
else:
|
|
19
|
+
|
|
20
|
+
class Config:
|
|
21
|
+
frozen = True
|
|
22
|
+
smart_union = True
|
|
23
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from ..core.pydantic_utilities import UniversalBaseModel
|
|
4
|
+
import datetime as dt
|
|
5
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2
|
|
6
|
+
import typing
|
|
7
|
+
import pydantic
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TimeDto(UniversalBaseModel):
|
|
11
|
+
start: dt.datetime
|
|
12
|
+
end: dt.datetime
|
|
13
|
+
|
|
14
|
+
if IS_PYDANTIC_V2:
|
|
15
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
16
|
+
extra="allow", frozen=True
|
|
17
|
+
) # type: ignore # Pydantic v2
|
|
18
|
+
else:
|
|
19
|
+
|
|
20
|
+
class Config:
|
|
21
|
+
frozen = True
|
|
22
|
+
smart_union = True
|
|
23
|
+
extra = pydantic.Extra.allow
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from ..core.pydantic_utilities import UniversalBaseModel
|
|
4
|
+
import typing
|
|
5
|
+
from .tree_type import TreeType
|
|
6
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2
|
|
7
|
+
import pydantic
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TreeDto(UniversalBaseModel):
|
|
11
|
+
id: str
|
|
12
|
+
type: typing.Optional[TreeType] = None
|
|
13
|
+
|
|
14
|
+
if IS_PYDANTIC_V2:
|
|
15
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
16
|
+
extra="allow", frozen=True
|
|
17
|
+
) # type: ignore # Pydantic v2
|
|
18
|
+
else:
|
|
19
|
+
|
|
20
|
+
class Config:
|
|
21
|
+
frozen = True
|
|
22
|
+
smart_union = True
|
|
23
|
+
extra = pydantic.Extra.allow
|
|
@@ -1104,14 +1104,14 @@ class VariantsClient:
|
|
|
1104
1104
|
def configs_delete(
|
|
1105
1105
|
self,
|
|
1106
1106
|
*,
|
|
1107
|
-
variant_ref:
|
|
1107
|
+
variant_ref: ReferenceRequestModel,
|
|
1108
1108
|
application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
|
|
1109
1109
|
request_options: typing.Optional[RequestOptions] = None,
|
|
1110
1110
|
) -> int:
|
|
1111
1111
|
"""
|
|
1112
1112
|
Parameters
|
|
1113
1113
|
----------
|
|
1114
|
-
variant_ref :
|
|
1114
|
+
variant_ref : ReferenceRequestModel
|
|
1115
1115
|
|
|
1116
1116
|
application_ref : typing.Optional[ReferenceRequestModel]
|
|
1117
1117
|
|
|
@@ -1125,13 +1125,15 @@ class VariantsClient:
|
|
|
1125
1125
|
|
|
1126
1126
|
Examples
|
|
1127
1127
|
--------
|
|
1128
|
-
from agenta import AgentaApi
|
|
1128
|
+
from agenta import AgentaApi, ReferenceRequestModel
|
|
1129
1129
|
|
|
1130
1130
|
client = AgentaApi(
|
|
1131
1131
|
api_key="YOUR_API_KEY",
|
|
1132
1132
|
base_url="https://yourhost.com/path/to/api",
|
|
1133
1133
|
)
|
|
1134
|
-
client.variants.configs_delete(
|
|
1134
|
+
client.variants.configs_delete(
|
|
1135
|
+
variant_ref=ReferenceRequestModel(),
|
|
1136
|
+
)
|
|
1135
1137
|
"""
|
|
1136
1138
|
_response = self._client_wrapper.httpx_client.request(
|
|
1137
1139
|
"variants/configs/delete",
|
|
@@ -1244,14 +1246,14 @@ class VariantsClient:
|
|
|
1244
1246
|
def configs_history(
|
|
1245
1247
|
self,
|
|
1246
1248
|
*,
|
|
1247
|
-
variant_ref:
|
|
1249
|
+
variant_ref: ReferenceRequestModel,
|
|
1248
1250
|
application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
|
|
1249
1251
|
request_options: typing.Optional[RequestOptions] = None,
|
|
1250
1252
|
) -> typing.List[ConfigResponseModel]:
|
|
1251
1253
|
"""
|
|
1252
1254
|
Parameters
|
|
1253
1255
|
----------
|
|
1254
|
-
variant_ref :
|
|
1256
|
+
variant_ref : ReferenceRequestModel
|
|
1255
1257
|
|
|
1256
1258
|
application_ref : typing.Optional[ReferenceRequestModel]
|
|
1257
1259
|
|
|
@@ -1265,13 +1267,15 @@ class VariantsClient:
|
|
|
1265
1267
|
|
|
1266
1268
|
Examples
|
|
1267
1269
|
--------
|
|
1268
|
-
from agenta import AgentaApi
|
|
1270
|
+
from agenta import AgentaApi, ReferenceRequestModel
|
|
1269
1271
|
|
|
1270
1272
|
client = AgentaApi(
|
|
1271
1273
|
api_key="YOUR_API_KEY",
|
|
1272
1274
|
base_url="https://yourhost.com/path/to/api",
|
|
1273
1275
|
)
|
|
1274
|
-
client.variants.configs_history(
|
|
1276
|
+
client.variants.configs_history(
|
|
1277
|
+
variant_ref=ReferenceRequestModel(),
|
|
1278
|
+
)
|
|
1275
1279
|
"""
|
|
1276
1280
|
_response = self._client_wrapper.httpx_client.request(
|
|
1277
1281
|
"variants/configs/history",
|
|
@@ -2504,14 +2508,14 @@ class AsyncVariantsClient:
|
|
|
2504
2508
|
async def configs_delete(
|
|
2505
2509
|
self,
|
|
2506
2510
|
*,
|
|
2507
|
-
variant_ref:
|
|
2511
|
+
variant_ref: ReferenceRequestModel,
|
|
2508
2512
|
application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
|
|
2509
2513
|
request_options: typing.Optional[RequestOptions] = None,
|
|
2510
2514
|
) -> int:
|
|
2511
2515
|
"""
|
|
2512
2516
|
Parameters
|
|
2513
2517
|
----------
|
|
2514
|
-
variant_ref :
|
|
2518
|
+
variant_ref : ReferenceRequestModel
|
|
2515
2519
|
|
|
2516
2520
|
application_ref : typing.Optional[ReferenceRequestModel]
|
|
2517
2521
|
|
|
@@ -2527,7 +2531,7 @@ class AsyncVariantsClient:
|
|
|
2527
2531
|
--------
|
|
2528
2532
|
import asyncio
|
|
2529
2533
|
|
|
2530
|
-
from agenta import AsyncAgentaApi
|
|
2534
|
+
from agenta import AsyncAgentaApi, ReferenceRequestModel
|
|
2531
2535
|
|
|
2532
2536
|
client = AsyncAgentaApi(
|
|
2533
2537
|
api_key="YOUR_API_KEY",
|
|
@@ -2536,7 +2540,9 @@ class AsyncVariantsClient:
|
|
|
2536
2540
|
|
|
2537
2541
|
|
|
2538
2542
|
async def main() -> None:
|
|
2539
|
-
await client.variants.configs_delete(
|
|
2543
|
+
await client.variants.configs_delete(
|
|
2544
|
+
variant_ref=ReferenceRequestModel(),
|
|
2545
|
+
)
|
|
2540
2546
|
|
|
2541
2547
|
|
|
2542
2548
|
asyncio.run(main())
|
|
@@ -2660,14 +2666,14 @@ class AsyncVariantsClient:
|
|
|
2660
2666
|
async def configs_history(
|
|
2661
2667
|
self,
|
|
2662
2668
|
*,
|
|
2663
|
-
variant_ref:
|
|
2669
|
+
variant_ref: ReferenceRequestModel,
|
|
2664
2670
|
application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
|
|
2665
2671
|
request_options: typing.Optional[RequestOptions] = None,
|
|
2666
2672
|
) -> typing.List[ConfigResponseModel]:
|
|
2667
2673
|
"""
|
|
2668
2674
|
Parameters
|
|
2669
2675
|
----------
|
|
2670
|
-
variant_ref :
|
|
2676
|
+
variant_ref : ReferenceRequestModel
|
|
2671
2677
|
|
|
2672
2678
|
application_ref : typing.Optional[ReferenceRequestModel]
|
|
2673
2679
|
|
|
@@ -2683,7 +2689,7 @@ class AsyncVariantsClient:
|
|
|
2683
2689
|
--------
|
|
2684
2690
|
import asyncio
|
|
2685
2691
|
|
|
2686
|
-
from agenta import AsyncAgentaApi
|
|
2692
|
+
from agenta import AsyncAgentaApi, ReferenceRequestModel
|
|
2687
2693
|
|
|
2688
2694
|
client = AsyncAgentaApi(
|
|
2689
2695
|
api_key="YOUR_API_KEY",
|
|
@@ -2692,7 +2698,9 @@ class AsyncVariantsClient:
|
|
|
2692
2698
|
|
|
2693
2699
|
|
|
2694
2700
|
async def main() -> None:
|
|
2695
|
-
await client.variants.configs_history(
|
|
2701
|
+
await client.variants.configs_history(
|
|
2702
|
+
variant_ref=ReferenceRequestModel(),
|
|
2703
|
+
)
|
|
2696
2704
|
|
|
2697
2705
|
|
|
2698
2706
|
asyncio.run(main())
|
agenta/sdk/__init__.py
CHANGED
agenta/sdk/decorators/routing.py
CHANGED
|
@@ -389,7 +389,7 @@ class entrypoint:
|
|
|
389
389
|
log.info(f"Agenta SDK - exiting with success: 200")
|
|
390
390
|
log.info(f"----------------------------------")
|
|
391
391
|
|
|
392
|
-
return BaseResponse(data=data,
|
|
392
|
+
return BaseResponse(data=data, tree=trace)
|
|
393
393
|
|
|
394
394
|
def handle_failure(self, error: Exception):
|
|
395
395
|
log.error("--------------------------------------------------")
|
agenta/sdk/tracing/inline.py
CHANGED
|
@@ -903,9 +903,9 @@ def parse_to_agenta_span_dto(
|
|
|
903
903
|
if span_dto.data:
|
|
904
904
|
span_dto.data = _unmarshal_attributes(span_dto.data)
|
|
905
905
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
906
|
+
if "outputs" in span_dto.data:
|
|
907
|
+
if "__default__" in span_dto.data["outputs"]:
|
|
908
|
+
span_dto.data["outputs"] = span_dto.data["outputs"]["__default__"]
|
|
909
909
|
|
|
910
910
|
# METRICS
|
|
911
911
|
if span_dto.metrics:
|
|
@@ -934,6 +934,17 @@ def parse_to_agenta_span_dto(
|
|
|
934
934
|
else:
|
|
935
935
|
parse_to_agenta_span_dto(v)
|
|
936
936
|
|
|
937
|
+
# MASK LINKS FOR NOW
|
|
938
|
+
span_dto.links = None
|
|
939
|
+
# ------------------
|
|
940
|
+
|
|
941
|
+
# MASK LIFECYCLE FOR NOW
|
|
942
|
+
# span_dto.lifecycle = None
|
|
943
|
+
if span_dto.lifecycle:
|
|
944
|
+
span_dto.lifecycle.updated_at = None
|
|
945
|
+
span_dto.lifecycle.updated_by_id = None
|
|
946
|
+
# ----------------------
|
|
947
|
+
|
|
937
948
|
return span_dto
|
|
938
949
|
|
|
939
950
|
|
|
@@ -945,6 +956,8 @@ def parse_to_agenta_span_dto(
|
|
|
945
956
|
from litellm import cost_calculator
|
|
946
957
|
from opentelemetry.sdk.trace import ReadableSpan
|
|
947
958
|
|
|
959
|
+
from agenta.sdk.types import AgentaNodeDto, AgentaNodesResponse
|
|
960
|
+
|
|
948
961
|
|
|
949
962
|
def parse_inline_trace(
|
|
950
963
|
spans: Dict[str, ReadableSpan],
|
|
@@ -992,51 +1005,19 @@ def parse_inline_trace(
|
|
|
992
1005
|
### services.observability.service.query() ###
|
|
993
1006
|
##############################################
|
|
994
1007
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
tokens = {
|
|
1009
|
-
"prompt_tokens": root_span.metrics.get("acc", {})
|
|
1010
|
-
.get("tokens", {})
|
|
1011
|
-
.get("prompt", 0),
|
|
1012
|
-
"completion_tokens": root_span.metrics.get("acc", {})
|
|
1013
|
-
.get("tokens", {})
|
|
1014
|
-
.get("completion", 0),
|
|
1015
|
-
"total_tokens": root_span.metrics.get("acc", {})
|
|
1016
|
-
.get("tokens", {})
|
|
1017
|
-
.get("total", 0),
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
spans = [
|
|
1021
|
-
loads(span.model_dump_json(exclude_none=True)) for span in legacy_spans
|
|
1022
|
-
]
|
|
1023
|
-
|
|
1024
|
-
inline_trace = {
|
|
1025
|
-
"trace_id": trace_id,
|
|
1026
|
-
"latency": latency,
|
|
1027
|
-
"cost": cost,
|
|
1028
|
-
"usage": tokens,
|
|
1029
|
-
"spans": spans,
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
else:
|
|
1033
|
-
spans = [
|
|
1034
|
-
loads(span_dto.model_dump_json(exclude_none=True))
|
|
1035
|
-
for span_dto in agenta_span_dtos
|
|
1036
|
-
]
|
|
1037
|
-
|
|
1038
|
-
inline_trace = spans # turn into Agenta Model ?
|
|
1039
|
-
|
|
1008
|
+
spans = [
|
|
1009
|
+
loads(
|
|
1010
|
+
span_dto.model_dump_json(
|
|
1011
|
+
exclude_none=True,
|
|
1012
|
+
exclude_defaults=True,
|
|
1013
|
+
)
|
|
1014
|
+
)
|
|
1015
|
+
for span_dto in agenta_span_dtos
|
|
1016
|
+
]
|
|
1017
|
+
inline_trace = AgentaNodesResponse(
|
|
1018
|
+
version="1.0.0",
|
|
1019
|
+
nodes=[AgentaNodeDto(**span) for span in spans],
|
|
1020
|
+
).model_dump(exclude_none=True, exclude_unset=True)
|
|
1040
1021
|
return inline_trace
|
|
1041
1022
|
|
|
1042
1023
|
|
|
@@ -1120,98 +1101,6 @@ class LlmTokens(BaseModel):
|
|
|
1120
1101
|
total_tokens: Optional[int] = 0
|
|
1121
1102
|
|
|
1122
1103
|
|
|
1123
|
-
class CreateSpan(BaseModel):
|
|
1124
|
-
id: str
|
|
1125
|
-
app_id: str
|
|
1126
|
-
variant_id: Optional[str] = None
|
|
1127
|
-
variant_name: Optional[str] = None
|
|
1128
|
-
inputs: Optional[Dict[str, Optional[Any]]] = None
|
|
1129
|
-
internals: Optional[Dict[str, Optional[Any]]] = None
|
|
1130
|
-
outputs: Optional[Union[str, Dict[str, Optional[Any]], List[Any]]] = None
|
|
1131
|
-
config: Optional[Dict[str, Optional[Any]]] = None
|
|
1132
|
-
environment: Optional[str] = None
|
|
1133
|
-
tags: Optional[List[str]] = None
|
|
1134
|
-
token_consumption: Optional[int] = None
|
|
1135
|
-
name: str
|
|
1136
|
-
parent_span_id: Optional[str] = None
|
|
1137
|
-
attributes: Optional[Dict[str, Optional[Any]]] = None
|
|
1138
|
-
spankind: str
|
|
1139
|
-
status: str
|
|
1140
|
-
user: Optional[str] = None
|
|
1141
|
-
start_time: datetime
|
|
1142
|
-
end_time: datetime
|
|
1143
|
-
tokens: Optional[LlmTokens] = None
|
|
1144
|
-
cost: Optional[float] = None
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
def _parse_to_legacy_span(span: SpanDTO) -> CreateSpan:
|
|
1148
|
-
attributes = None
|
|
1149
|
-
if span.otel:
|
|
1150
|
-
attributes = span.otel.attributes or {}
|
|
1151
|
-
|
|
1152
|
-
if span.otel.events:
|
|
1153
|
-
for event in span.otel.events:
|
|
1154
|
-
if event.name == "exception":
|
|
1155
|
-
attributes.update(**event.attributes)
|
|
1156
|
-
|
|
1157
|
-
legacy_span = CreateSpan(
|
|
1158
|
-
id=span.node.id.hex[:24],
|
|
1159
|
-
spankind=span.node.type,
|
|
1160
|
-
name=span.node.name,
|
|
1161
|
-
#
|
|
1162
|
-
status=span.status.code.name,
|
|
1163
|
-
#
|
|
1164
|
-
start_time=span.time.start,
|
|
1165
|
-
end_time=span.time.end,
|
|
1166
|
-
#
|
|
1167
|
-
parent_span_id=span.parent.id.hex[:24] if span.parent else None,
|
|
1168
|
-
#
|
|
1169
|
-
inputs=span.data.get("inputs") if span.data else {},
|
|
1170
|
-
internals=span.data.get("internals") if span.data else {},
|
|
1171
|
-
outputs=span.data.get("outputs") if span.data else {},
|
|
1172
|
-
#
|
|
1173
|
-
environment=span.meta.get("environment") if span.meta else None,
|
|
1174
|
-
config=span.meta.get("configuration") if span.meta else None,
|
|
1175
|
-
#
|
|
1176
|
-
tokens=(
|
|
1177
|
-
LlmTokens(
|
|
1178
|
-
prompt_tokens=span.metrics.get("acc", {})
|
|
1179
|
-
.get("tokens", {})
|
|
1180
|
-
.get("prompt", 0.0),
|
|
1181
|
-
completion_tokens=span.metrics.get("acc", {})
|
|
1182
|
-
.get("tokens", {})
|
|
1183
|
-
.get("completion", 0.0),
|
|
1184
|
-
total_tokens=span.metrics.get("acc", {})
|
|
1185
|
-
.get("tokens", {})
|
|
1186
|
-
.get("total", 0.0),
|
|
1187
|
-
)
|
|
1188
|
-
if span.metrics
|
|
1189
|
-
else None
|
|
1190
|
-
),
|
|
1191
|
-
cost=(
|
|
1192
|
-
span.metrics.get("acc", {}).get("costs", {}).get("total", 0.0)
|
|
1193
|
-
if span.metrics
|
|
1194
|
-
else None
|
|
1195
|
-
),
|
|
1196
|
-
#
|
|
1197
|
-
app_id=(
|
|
1198
|
-
span.refs.get("application", {}).get("id", "missing-app-id")
|
|
1199
|
-
if span.refs
|
|
1200
|
-
else "missing-app-id"
|
|
1201
|
-
),
|
|
1202
|
-
#
|
|
1203
|
-
attributes=attributes,
|
|
1204
|
-
#
|
|
1205
|
-
variant_id=None,
|
|
1206
|
-
variant_name=None,
|
|
1207
|
-
tags=None,
|
|
1208
|
-
token_consumption=None,
|
|
1209
|
-
user=None,
|
|
1210
|
-
)
|
|
1211
|
-
|
|
1212
|
-
return legacy_span
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
1104
|
TYPES_WITH_COSTS = [
|
|
1216
1105
|
"embedding",
|
|
1217
1106
|
"query",
|
agenta/sdk/types.py
CHANGED
|
@@ -4,6 +4,9 @@ from typing import Dict, List, Optional, Any, Union
|
|
|
4
4
|
|
|
5
5
|
from pydantic import ConfigDict, BaseModel, HttpUrl
|
|
6
6
|
|
|
7
|
+
from agenta.client.backend.types.agenta_node_dto import AgentaNodeDto
|
|
8
|
+
from agenta.client.backend.types.agenta_nodes_response import AgentaNodesResponse
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
@dataclass
|
|
9
12
|
class MultipleChoice:
|
|
@@ -23,9 +26,9 @@ class LLMTokenUsage(BaseModel):
|
|
|
23
26
|
|
|
24
27
|
|
|
25
28
|
class BaseResponse(BaseModel):
|
|
26
|
-
version: Optional[str] = "
|
|
29
|
+
version: Optional[str] = "3.0"
|
|
27
30
|
data: Optional[Union[str, Dict[str, Any]]] = None
|
|
28
|
-
|
|
31
|
+
tree: Optional[AgentaNodesResponse] = None
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
class DictInput(dict):
|