ragaai-catalyst 2.1.4.1b0__py3-none-any.whl → 2.1.4.1b1__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.
- ragaai_catalyst/tracers/agentic_tracing/data/data_structure.py +4 -2
- ragaai_catalyst/tracers/agentic_tracing/tracers/base.py +97 -7
- ragaai_catalyst/tracers/agentic_tracing/upload/upload_trace_metric.py +7 -0
- {ragaai_catalyst-2.1.4.1b0.dist-info → ragaai_catalyst-2.1.4.1b1.dist-info}/METADATA +1 -1
- {ragaai_catalyst-2.1.4.1b0.dist-info → ragaai_catalyst-2.1.4.1b1.dist-info}/RECORD +8 -8
- {ragaai_catalyst-2.1.4.1b0.dist-info → ragaai_catalyst-2.1.4.1b1.dist-info}/LICENSE +0 -0
- {ragaai_catalyst-2.1.4.1b0.dist-info → ragaai_catalyst-2.1.4.1b1.dist-info}/WHEEL +0 -0
- {ragaai_catalyst-2.1.4.1b0.dist-info → ragaai_catalyst-2.1.4.1b1.dist-info}/top_level.txt +0 -0
@@ -271,7 +271,7 @@ class ComponentInfo:
|
|
271
271
|
cost: Optional[Dict[str, float]] = None
|
272
272
|
|
273
273
|
class Trace:
|
274
|
-
def __init__(self, id: str, trace_name: str, project_name: str, start_time: str, end_time: str, metadata: Optional[Metadata] = None, data: Optional[List[Dict[str, Any]]] = None, replays: Optional[Dict[str, Any]] = None):
|
274
|
+
def __init__(self, id: str, trace_name: str, project_name: str, start_time: str, end_time: str, metadata: Optional[Metadata] = None, data: Optional[List[Dict[str, Any]]] = None, replays: Optional[Dict[str, Any]] = None, metrics: Optional[List[Dict[str, Any]]] = None):
|
275
275
|
self.id = id
|
276
276
|
self.trace_name = trace_name
|
277
277
|
self.project_name = project_name
|
@@ -280,6 +280,7 @@ class Trace:
|
|
280
280
|
self.metadata = metadata or Metadata()
|
281
281
|
self.data = data or []
|
282
282
|
self.replays = replays
|
283
|
+
self.metrics = metrics or []
|
283
284
|
|
284
285
|
def to_dict(self):
|
285
286
|
return {
|
@@ -288,7 +289,8 @@ class Trace:
|
|
288
289
|
"project_name": self.project_name,
|
289
290
|
"start_time": self.start_time,
|
290
291
|
"end_time": self.end_time,
|
291
|
-
"metadata": self.metadata
|
292
|
+
"metadata": self.metadata,
|
292
293
|
"data": self.data,
|
293
294
|
"replays": self.replays,
|
295
|
+
"metrics": self.metrics
|
294
296
|
}
|
@@ -5,7 +5,7 @@ import psutil
|
|
5
5
|
import pkg_resources
|
6
6
|
from datetime import datetime
|
7
7
|
from pathlib import Path
|
8
|
-
from typing import List, Any
|
8
|
+
from typing import List, Any, Dict
|
9
9
|
import uuid
|
10
10
|
import sys
|
11
11
|
import tempfile
|
@@ -81,6 +81,7 @@ class BaseTracer:
|
|
81
81
|
self.project_id = self.user_details["project_id"] # Access the project_id
|
82
82
|
self.trace_name = self.user_details["trace_name"] # Access the trace_name
|
83
83
|
self.visited_metrics = []
|
84
|
+
self.trace_metrics = [] # Store metrics here
|
84
85
|
|
85
86
|
# Initialize trace data
|
86
87
|
self.trace_id = None
|
@@ -211,6 +212,10 @@ class BaseTracer:
|
|
211
212
|
threading.Thread(target=self._track_disk_usage).start()
|
212
213
|
threading.Thread(target=self._track_network_usage).start()
|
213
214
|
|
215
|
+
# Reset metrics
|
216
|
+
self.visited_metrics = []
|
217
|
+
self.trace_metrics = []
|
218
|
+
|
214
219
|
metadata = Metadata(
|
215
220
|
cost={},
|
216
221
|
tokens={},
|
@@ -241,6 +246,7 @@ class BaseTracer:
|
|
241
246
|
metadata=metadata,
|
242
247
|
data=self.data_key,
|
243
248
|
replays={"source": None},
|
249
|
+
metrics=[] # Initialize empty metrics list
|
244
250
|
)
|
245
251
|
|
246
252
|
def stop(self):
|
@@ -300,8 +306,12 @@ class BaseTracer:
|
|
300
306
|
# replace source code with zip_path
|
301
307
|
self.trace.metadata.system_info.source_code = hash_id
|
302
308
|
|
309
|
+
# Add metrics to trace before saving
|
310
|
+
trace_data = self.trace.to_dict()
|
311
|
+
|
312
|
+
trace_data["metrics"] = self.trace_metrics
|
313
|
+
|
303
314
|
# Clean up trace_data before saving
|
304
|
-
trace_data = self.trace.__dict__
|
305
315
|
cleaned_trace_data = self._clean_trace(trace_data)
|
306
316
|
|
307
317
|
# Format interactions and add to trace
|
@@ -609,9 +619,7 @@ class BaseTracer:
|
|
609
619
|
"span_id": child.get("id"),
|
610
620
|
"interaction_type": "llm_call_end",
|
611
621
|
"name": child.get("name"),
|
612
|
-
"content": {
|
613
|
-
"response": child.get("data", {}).get("output")
|
614
|
-
},
|
622
|
+
"content": {"response": child.get("data", {}).get("output")},
|
615
623
|
"timestamp": child.get("end_time"),
|
616
624
|
"error": child.get("error"),
|
617
625
|
}
|
@@ -882,8 +890,90 @@ class BaseTracer:
|
|
882
890
|
|
883
891
|
return {"workflow": sorted_interactions}
|
884
892
|
|
893
|
+
def add_metrics(
|
894
|
+
self,
|
895
|
+
name: str | List[Dict[str, Any]] | Dict[str, Any] = None,
|
896
|
+
score: float | int = None,
|
897
|
+
reasoning: str = "",
|
898
|
+
cost: float = None,
|
899
|
+
latency: float = None,
|
900
|
+
metadata: Dict[str, Any] = None,
|
901
|
+
config: Dict[str, Any] = None,
|
902
|
+
):
|
903
|
+
"""Add metrics at the trace level.
|
904
|
+
|
905
|
+
Can be called in two ways:
|
906
|
+
1. With individual parameters:
|
907
|
+
tracer.add_metrics(name="metric_name", score=0.9, reasoning="Good performance")
|
908
|
+
|
909
|
+
2. With a dictionary or list of dictionaries:
|
910
|
+
tracer.add_metrics({"name": "metric_name", "score": 0.9})
|
911
|
+
tracer.add_metrics([{"name": "metric1", "score": 0.9}, {"name": "metric2", "score": 0.8}])
|
912
|
+
|
913
|
+
Args:
|
914
|
+
name: Either the metric name (str) or a metric dictionary/list of dictionaries
|
915
|
+
score: Score value (float or int) when using individual parameters
|
916
|
+
reasoning: Optional explanation for the score
|
917
|
+
cost: Optional cost associated with the metric
|
918
|
+
latency: Optional latency measurement
|
919
|
+
metadata: Optional additional metadata as key-value pairs
|
920
|
+
config: Optional configuration parameters
|
921
|
+
"""
|
922
|
+
if not hasattr(self, 'trace'):
|
923
|
+
logger.warning("Cannot add metrics before trace is initialized. Call start() first.")
|
924
|
+
return
|
925
|
+
|
926
|
+
# Convert individual parameters to metric dict if needed
|
927
|
+
if isinstance(name, str):
|
928
|
+
metrics = [{
|
929
|
+
"name": name,
|
930
|
+
"score": score,
|
931
|
+
"reasoning": reasoning,
|
932
|
+
"cost": cost,
|
933
|
+
"latency": latency,
|
934
|
+
"metadata": metadata or {},
|
935
|
+
"config": config or {}
|
936
|
+
}]
|
937
|
+
else:
|
938
|
+
# Handle dict or list input
|
939
|
+
metrics = name if isinstance(name, list) else [name] if isinstance(name, dict) else []
|
940
|
+
|
941
|
+
try:
|
942
|
+
for metric in metrics:
|
943
|
+
if not isinstance(metric, dict):
|
944
|
+
raise ValueError(f"Expected dict, got {type(metric)}")
|
945
|
+
|
946
|
+
if "name" not in metric or "score" not in metric:
|
947
|
+
raise ValueError("Metric must contain 'name' and 'score' fields")
|
948
|
+
|
949
|
+
# Handle duplicate metric names
|
950
|
+
metric_name = metric["name"]
|
951
|
+
if metric_name in self.visited_metrics:
|
952
|
+
count = sum(1 for m in self.visited_metrics if m.startswith(metric_name))
|
953
|
+
metric_name = f"{metric_name}_{count + 1}"
|
954
|
+
self.visited_metrics.append(metric_name)
|
955
|
+
|
956
|
+
formatted_metric = {
|
957
|
+
"name": metric_name, # Use potentially modified name
|
958
|
+
"score": metric["score"],
|
959
|
+
"reason": metric.get("reasoning", ""),
|
960
|
+
"source": "user",
|
961
|
+
"cost": metric.get("cost"),
|
962
|
+
"latency": metric.get("latency"),
|
963
|
+
"metadata": metric.get("metadata", {}),
|
964
|
+
"mappings": [],
|
965
|
+
"config": metric.get("config", {})
|
966
|
+
}
|
967
|
+
|
968
|
+
self.trace_metrics.append(formatted_metric)
|
969
|
+
logger.debug(f"Added trace-level metric: {formatted_metric}")
|
970
|
+
|
971
|
+
except ValueError as e:
|
972
|
+
logger.error(f"Validation Error: {e}")
|
973
|
+
except Exception as e:
|
974
|
+
logger.error(f"Error adding metric: {e}")
|
975
|
+
|
885
976
|
def span(self, span_name):
|
886
977
|
if span_name not in self.span_attributes_dict:
|
887
978
|
self.span_attributes_dict[span_name] = SpanAttributes(span_name)
|
888
|
-
return self.span_attributes_dict[span_name]
|
889
|
-
|
979
|
+
return self.span_attributes_dict[span_name]
|
@@ -59,6 +59,13 @@ def _get_children_metrics_of_agent(children_traces):
|
|
59
59
|
|
60
60
|
def get_trace_metrics_from_trace(traces):
|
61
61
|
metrics = []
|
62
|
+
|
63
|
+
# get trace level metrics
|
64
|
+
if "metrics" in traces.keys():
|
65
|
+
if len(traces["metrics"]) > 0:
|
66
|
+
metrics.extend(traces["metrics"])
|
67
|
+
|
68
|
+
# get span level metrics
|
62
69
|
for span in traces["data"][0]["spans"]:
|
63
70
|
if span["type"] == "agent":
|
64
71
|
children_metric = _get_children_metrics_of_agent(span["data"]["children"])
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: ragaai_catalyst
|
3
|
-
Version: 2.1.4.
|
3
|
+
Version: 2.1.4.1b1
|
4
4
|
Summary: RAGA AI CATALYST
|
5
5
|
Author-email: Kiran Scaria <kiran.scaria@raga.ai>, Kedar Gaikwad <kedar.gaikwad@raga.ai>, Dushyant Mahajan <dushyant.mahajan@raga.ai>, Siddhartha Kosti <siddhartha.kosti@raga.ai>, Ritika Goel <ritika.goel@raga.ai>, Vijay Chaurasia <vijay.chaurasia@raga.ai>
|
6
6
|
Requires-Python: <3.13,>=3.9
|
@@ -18,7 +18,7 @@ ragaai_catalyst/tracers/upload_traces.py,sha256=mT5rverNUL5Rcal9VR5_c75wHBAUrm2p
|
|
18
18
|
ragaai_catalyst/tracers/agentic_tracing/README.md,sha256=X4QwLb7-Jg7GQMIXj-SerZIgDETfw-7VgYlczOR8ZeQ,4508
|
19
19
|
ragaai_catalyst/tracers/agentic_tracing/__init__.py,sha256=yf6SKvOPSpH-9LiKaoLKXwqj5sez8F_5wkOb91yp0oE,260
|
20
20
|
ragaai_catalyst/tracers/agentic_tracing/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
|
-
ragaai_catalyst/tracers/agentic_tracing/data/data_structure.py,sha256=
|
21
|
+
ragaai_catalyst/tracers/agentic_tracing/data/data_structure.py,sha256=icAtNzKN_I0YtfuJ3RF8BdZJK3ohqxkVZIdvM5_YugY,9327
|
22
22
|
ragaai_catalyst/tracers/agentic_tracing/tests/FinancialAnalysisSystem.ipynb,sha256=0qZxjWqYCTAVvdo3Tsp544D8Am48wfeMQ9RKpKgAL8g,34291
|
23
23
|
ragaai_catalyst/tracers/agentic_tracing/tests/GameActivityEventPlanner.ipynb,sha256=QCMFJYbGX0fd9eMW4PqyQLZjyWuTXo7n1nqO_hMLf0s,4225
|
24
24
|
ragaai_catalyst/tracers/agentic_tracing/tests/TravelPlanner.ipynb,sha256=fU3inXoemJbdTkGAQl_N1UwVEZ10LrKv4gCEpbQ4ISg,43481
|
@@ -27,7 +27,7 @@ ragaai_catalyst/tracers/agentic_tracing/tests/ai_travel_agent.py,sha256=S4rCcKzU
|
|
27
27
|
ragaai_catalyst/tracers/agentic_tracing/tests/unique_decorator_test.py,sha256=Xk1cLzs-2A3dgyBwRRnCWs7Eubki40FVonwd433hPN8,4805
|
28
28
|
ragaai_catalyst/tracers/agentic_tracing/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
29
|
ragaai_catalyst/tracers/agentic_tracing/tracers/agent_tracer.py,sha256=aLiq5nPie5TT61QYtvAtvErsxjPFYiUxjayn5aCX1_k,25543
|
30
|
-
ragaai_catalyst/tracers/agentic_tracing/tracers/base.py,sha256=
|
30
|
+
ragaai_catalyst/tracers/agentic_tracing/tracers/base.py,sha256=13AkXbO6NE1a2rlimsROW3527vUnmin8_bRMNZfXarg,38783
|
31
31
|
ragaai_catalyst/tracers/agentic_tracing/tracers/custom_tracer.py,sha256=uay8lU7T-CKsVu8KvWX31qfMqufK9S3Ive7XKo2Ksmk,12252
|
32
32
|
ragaai_catalyst/tracers/agentic_tracing/tracers/langgraph_tracer.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
33
|
ragaai_catalyst/tracers/agentic_tracing/tracers/llm_tracer.py,sha256=fn5qxb365GmQkJy_yZAY5TiiWRMFKPNJdYk8KFr8uWA,29343
|
@@ -38,7 +38,7 @@ ragaai_catalyst/tracers/agentic_tracing/tracers/user_interaction_tracer.py,sha25
|
|
38
38
|
ragaai_catalyst/tracers/agentic_tracing/upload/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
39
39
|
ragaai_catalyst/tracers/agentic_tracing/upload/upload_agentic_traces.py,sha256=1MDKXAAPzOEdxFKWWQrRgrmM3kz--DGXSywGXQmR3lQ,6041
|
40
40
|
ragaai_catalyst/tracers/agentic_tracing/upload/upload_code.py,sha256=HgpMgI-JTWZrizcM7GGUIaAgaZF4aRT3D0dJXVEkblY,4271
|
41
|
-
ragaai_catalyst/tracers/agentic_tracing/upload/upload_trace_metric.py,sha256=
|
41
|
+
ragaai_catalyst/tracers/agentic_tracing/upload/upload_trace_metric.py,sha256=id66gfx-XYj_zsAmicBKojBOqJQ__FJLSoZ0db56aes,3493
|
42
42
|
ragaai_catalyst/tracers/agentic_tracing/utils/__init__.py,sha256=XdB3X_ufe4RVvGorxSqAiB9dYv4UD7Hvvuw3bsDUppY,60
|
43
43
|
ragaai_catalyst/tracers/agentic_tracing/utils/api_utils.py,sha256=JyNCbfpW-w4O9CjtemTqmor2Rh1WGpQwhRaDSRmBxw8,689
|
44
44
|
ragaai_catalyst/tracers/agentic_tracing/utils/create_dataset_schema.py,sha256=lgvJL0cakJrX8WGsnU05YGvotequSj6HgSohyR4OJNE,804
|
@@ -60,8 +60,8 @@ ragaai_catalyst/tracers/instrumentators/llamaindex.py,sha256=SMrRlR4xM7k9HK43hak
|
|
60
60
|
ragaai_catalyst/tracers/instrumentators/openai.py,sha256=14R4KW9wQCR1xysLfsP_nxS7cqXrTPoD8En4MBAaZUU,379
|
61
61
|
ragaai_catalyst/tracers/utils/__init__.py,sha256=KeMaZtYaTojilpLv65qH08QmpYclfpacDA0U3wg6Ybw,64
|
62
62
|
ragaai_catalyst/tracers/utils/utils.py,sha256=ViygfJ7vZ7U0CTSA1lbxVloHp4NSlmfDzBRNCJuMhis,2374
|
63
|
-
ragaai_catalyst-2.1.4.
|
64
|
-
ragaai_catalyst-2.1.4.
|
65
|
-
ragaai_catalyst-2.1.4.
|
66
|
-
ragaai_catalyst-2.1.4.
|
67
|
-
ragaai_catalyst-2.1.4.
|
63
|
+
ragaai_catalyst-2.1.4.1b1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
64
|
+
ragaai_catalyst-2.1.4.1b1.dist-info/METADATA,sha256=w1o5CYUrQ3M0x_vn1GBYsOGXSTPYUxToxp4RIRjI1jI,12794
|
65
|
+
ragaai_catalyst-2.1.4.1b1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
66
|
+
ragaai_catalyst-2.1.4.1b1.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
|
67
|
+
ragaai_catalyst-2.1.4.1b1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|