ragaai-catalyst 2.2.5b1__py3-none-any.whl → 2.2.5b2__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/tracers/main_tracer.py +4 -263
- {ragaai_catalyst-2.2.5b1.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/METADATA +1 -1
- {ragaai_catalyst-2.2.5b1.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/RECORD +6 -6
- {ragaai_catalyst-2.2.5b1.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/WHEEL +0 -0
- {ragaai_catalyst-2.2.5b1.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/licenses/LICENSE +0 -0
- {ragaai_catalyst-2.2.5b1.dist-info → ragaai_catalyst-2.2.5b2.dist-info}/top_level.txt +0 -0
@@ -7,7 +7,7 @@ import os
|
|
7
7
|
import builtins
|
8
8
|
from pathlib import Path
|
9
9
|
import logging
|
10
|
-
|
10
|
+
logger = logging.getLogger(__name__)
|
11
11
|
|
12
12
|
from ..data.data_structure import (
|
13
13
|
Trace,
|
@@ -99,272 +99,13 @@ class AgenticTracing():
|
|
99
99
|
self.component_user_interaction = {}
|
100
100
|
|
101
101
|
|
102
|
-
def start_component(self, component_id: str):
|
103
|
-
"""Start tracking network calls for a component"""
|
104
|
-
self.component_network_calls[component_id] = []
|
105
|
-
self.network_tracer.network_calls = [] # Reset network calls
|
106
|
-
self.current_component_id.set(component_id)
|
107
|
-
self.user_interaction_tracer.component_id.set(component_id)
|
108
|
-
|
109
|
-
def end_component(self, component_id: str):
|
110
|
-
"""End tracking network calls for a component"""
|
111
|
-
self.component_network_calls[component_id] = (
|
112
|
-
self.network_tracer.network_calls.copy()
|
113
|
-
)
|
114
|
-
self.network_tracer.network_calls = [] # Reset for next component
|
115
|
-
|
116
|
-
# Store user interactions for the component
|
117
|
-
for interaction in self.user_interaction_tracer.interactions:
|
118
|
-
interaction_component_id = interaction.get("component_id")
|
119
|
-
if interaction_component_id not in self.component_user_interaction:
|
120
|
-
self.component_user_interaction[interaction_component_id] = []
|
121
|
-
if interaction not in self.component_user_interaction[interaction_component_id]:
|
122
|
-
self.component_user_interaction[interaction_component_id].append(interaction)
|
123
|
-
|
124
|
-
# Only reset component_id if it matches the current one
|
125
|
-
# This ensures we don't reset a parent's component_id when a child component ends
|
126
|
-
if self.current_component_id.get() == component_id:
|
127
|
-
# Get the parent agent's component_id if it exists
|
128
|
-
parent_agent_id = self.current_agent_id.get()
|
129
|
-
# If there's a parent agent, set the component_id back to the parent's
|
130
|
-
if parent_agent_id:
|
131
|
-
self.current_component_id.set(parent_agent_id)
|
132
|
-
self.user_interaction_tracer.component_id.set(parent_agent_id)
|
133
|
-
else:
|
134
|
-
# Only reset to None if there's no parent
|
135
|
-
self.current_component_id.set(None)
|
136
|
-
self.user_interaction_tracer.component_id.set(None)
|
137
|
-
|
138
102
|
def register_post_processor(self, post_processor_func):
|
139
103
|
"""
|
140
104
|
Pass through the post-processor registration to the BaseTracer
|
141
105
|
"""
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
"""Start tracing"""
|
146
|
-
self.is_active = True
|
147
|
-
|
148
|
-
# Setup user interaction tracing
|
149
|
-
self.user_interaction_tracer.project_id.set(self.project_id)
|
150
|
-
self.user_interaction_tracer.trace_id.set(self.trace_id)
|
151
|
-
self.user_interaction_tracer.tracer = self
|
152
|
-
self.user_interaction_tracer.component_id.set(self.current_component_id.get())
|
153
|
-
|
154
|
-
# Start base tracer (includes system info and resource monitoring)
|
155
|
-
super().start()
|
156
|
-
|
157
|
-
# Activate network tracing
|
158
|
-
self.network_tracer.activate_patches()
|
159
|
-
|
160
|
-
# take care of the auto instrumentation
|
161
|
-
if self.auto_instrument_user_interaction:
|
162
|
-
ToolTracerMixin.instrument_user_interaction_calls(self)
|
163
|
-
LLMTracerMixin.instrument_user_interaction_calls(self)
|
164
|
-
AgentTracerMixin.instrument_user_interaction_calls(self)
|
165
|
-
CustomTracerMixin.instrument_user_interaction_calls(self)
|
166
|
-
builtins.print = self.user_interaction_tracer.traced_print
|
167
|
-
builtins.input = self.user_interaction_tracer.traced_input
|
168
|
-
|
169
|
-
if self.auto_instrument_network:
|
170
|
-
ToolTracerMixin.instrument_network_calls(self)
|
171
|
-
LLMTracerMixin.instrument_network_calls(self)
|
172
|
-
AgentTracerMixin.instrument_network_calls(self)
|
173
|
-
CustomTracerMixin.instrument_network_calls(self)
|
174
|
-
|
175
|
-
if self.auto_instrument_file_io:
|
176
|
-
ToolTracerMixin.instrument_file_io_calls(self)
|
177
|
-
LLMTracerMixin.instrument_file_io_calls(self)
|
178
|
-
AgentTracerMixin.instrument_file_io_calls(self)
|
179
|
-
CustomTracerMixin.instrument_file_io_calls(self)
|
180
|
-
builtins.open = self.user_interaction_tracer.traced_open
|
181
|
-
|
182
|
-
if self.auto_instrument_llm:
|
183
|
-
self.instrument_llm_calls()
|
184
|
-
|
185
|
-
if self.auto_instrument_tool:
|
186
|
-
self.instrument_tool_calls()
|
187
|
-
|
188
|
-
if self.auto_instrument_agent:
|
189
|
-
self.instrument_agent_calls()
|
190
|
-
|
191
|
-
if self.auto_instrument_custom:
|
192
|
-
self.instrument_custom_calls()
|
193
|
-
|
194
|
-
def stop(self):
|
195
|
-
"""Stop tracing and save results"""
|
196
|
-
if self.is_active:
|
197
|
-
# Restore original print and input functions
|
198
|
-
builtins.print = self.user_interaction_tracer.original_print
|
199
|
-
builtins.input = self.user_interaction_tracer.original_input
|
200
|
-
builtins.open = self.user_interaction_tracer.original_open
|
201
|
-
|
202
|
-
# Calculate final metrics before stopping
|
203
|
-
self._calculate_final_metrics()
|
204
|
-
|
205
|
-
# Deactivate network tracing
|
206
|
-
self.network_tracer.deactivate_patches()
|
207
|
-
|
208
|
-
# Clear visited metrics when stopping trace
|
209
|
-
self.visited_metrics.clear()
|
210
|
-
|
211
|
-
# Stop base tracer (includes saving to file)
|
212
|
-
super().stop()
|
213
|
-
|
214
|
-
# Cleanup
|
215
|
-
self.unpatch_llm_calls()
|
216
|
-
self.user_interaction_tracer.interactions = [] # Clear interactions list
|
217
|
-
self.is_active = False
|
218
|
-
|
219
|
-
def _calculate_final_metrics(self):
|
220
|
-
"""Calculate total cost and tokens from all components"""
|
221
|
-
total_cost = 0.0
|
222
|
-
total_tokens = 0
|
223
|
-
|
224
|
-
processed_components = set()
|
225
|
-
|
226
|
-
def process_component(component):
|
227
|
-
nonlocal total_cost, total_tokens
|
228
|
-
# Convert component to dict if it's an object
|
229
|
-
comp_dict = (
|
230
|
-
component.__dict__ if hasattr(component, "__dict__") else component
|
231
|
-
)
|
232
|
-
|
233
|
-
comp_id = comp_dict.get("id") or comp_dict.get("component_id")
|
234
|
-
if comp_id in processed_components:
|
235
|
-
return # Skip if already processed
|
236
|
-
processed_components.add(comp_id)
|
237
|
-
|
238
|
-
if comp_dict.get("type") == "llm":
|
239
|
-
info = comp_dict.get("info", {})
|
240
|
-
if isinstance(info, dict):
|
241
|
-
# Extract cost
|
242
|
-
cost_info = info.get("cost", {})
|
243
|
-
if isinstance(cost_info, dict):
|
244
|
-
total_cost += cost_info.get("total_cost", 0)
|
245
|
-
|
246
|
-
# Extract tokens
|
247
|
-
token_info = info.get("tokens", {})
|
248
|
-
if isinstance(token_info, dict):
|
249
|
-
total_tokens += token_info.get("total_tokens", 0)
|
250
|
-
else:
|
251
|
-
token_info = info.get("token_usage", {})
|
252
|
-
if isinstance(token_info, dict):
|
253
|
-
total_tokens += token_info.get("total_tokens", 0)
|
254
|
-
|
255
|
-
# Process children if they exist
|
256
|
-
data = comp_dict.get("data", {})
|
257
|
-
if isinstance(data, dict):
|
258
|
-
children = data.get("children", [])
|
259
|
-
if children:
|
260
|
-
for child in children:
|
261
|
-
process_component(child)
|
262
|
-
|
263
|
-
# Process all root components
|
264
|
-
for component in self.components:
|
265
|
-
process_component(component)
|
266
|
-
|
267
|
-
# Update metadata in trace
|
268
|
-
if hasattr(self, "trace"):
|
269
|
-
if isinstance(self.trace.metadata, dict):
|
270
|
-
self.trace.metadata["total_cost"] = total_cost
|
271
|
-
self.trace.metadata["total_tokens"] = total_tokens
|
272
|
-
else:
|
273
|
-
self.trace.metadata.total_cost = total_cost
|
274
|
-
self.trace.metadata.total_tokens = total_tokens
|
275
|
-
|
276
|
-
def add_component(self, component_data: dict, is_error: bool = False):
|
277
|
-
"""Add a component to the trace data"""
|
278
|
-
# Convert dict to appropriate Component type
|
279
|
-
filtered_data = {
|
280
|
-
k: v
|
281
|
-
for k, v in component_data.items()
|
282
|
-
if k
|
283
|
-
in [
|
284
|
-
"id",
|
285
|
-
"hash_id",
|
286
|
-
"source_hash_id",
|
287
|
-
"type",
|
288
|
-
"name",
|
289
|
-
"start_time",
|
290
|
-
"end_time",
|
291
|
-
"parent_id",
|
292
|
-
"info",
|
293
|
-
"extra_info",
|
294
|
-
"data",
|
295
|
-
"metadata",
|
296
|
-
"metrics",
|
297
|
-
"feedback",
|
298
|
-
"network_calls",
|
299
|
-
"interactions",
|
300
|
-
"error",
|
301
|
-
]
|
302
|
-
}
|
303
|
-
|
304
|
-
if component_data == None or component_data == {} or component_data.get("type", None) == None:
|
305
|
-
# Only show warning if it hasn't been shown before
|
306
|
-
if not self._warning_shown:
|
307
|
-
import toml
|
308
|
-
import os
|
309
|
-
from pathlib import Path
|
310
|
-
|
311
|
-
# Load supported LLM calls from TOML file
|
312
|
-
current_dir = Path(__file__).parent
|
313
|
-
toml_path = current_dir / "../utils/supported_llm_provider.toml"
|
314
|
-
try:
|
315
|
-
with open(toml_path, "r") as f:
|
316
|
-
config = toml.load(f)
|
317
|
-
supported_calls = ", ".join(config["supported_llm_calls"])
|
318
|
-
except Exception as e:
|
319
|
-
supported_calls = "Error loading supported LLM calls"
|
320
|
-
|
321
|
-
# ANSI escape codes for colors and formatting
|
322
|
-
RED = "\033[91m"
|
323
|
-
BOLD = "\033[1m"
|
324
|
-
RESET = "\033[0m"
|
325
|
-
BIG = "\033[1;2m" # Makes text slightly larger in supported terminals
|
326
|
-
|
327
|
-
warning_msg = f"""{RED}{BOLD}{BIG}
|
328
|
-
╔════════════════════════ COMPONENT DATA INCOMPLETE ════════════════════════╗
|
329
|
-
║ ║
|
330
|
-
║ Please ensure these requirements: ║
|
331
|
-
║ ✗ trace_llm decorator must have a stand alone llm call ║
|
332
|
-
║ ✗ trace_tool decorator must be a stand alone tool/function call ║
|
333
|
-
║ ✗ trace_agent decorator can have multiple/nested llm/tool/agent calls ║
|
334
|
-
║ ║
|
335
|
-
║ Supported LLM calls: ║
|
336
|
-
║ {supported_calls} ║
|
337
|
-
║ ║
|
338
|
-
╚══════════════════════════════════════════════════════════════════════════╝
|
339
|
-
{RESET}"""
|
340
|
-
# Use logger.warning for the message
|
341
|
-
logging.warning(warning_msg)
|
342
|
-
self._warning_shown = True
|
343
|
-
return
|
344
|
-
|
345
|
-
if component_data["type"] == "llm":
|
346
|
-
component = LLMComponent(**filtered_data)
|
347
|
-
elif component_data["type"] == "agent":
|
348
|
-
component = AgentComponent(**filtered_data)
|
349
|
-
elif component_data["type"] == "tool":
|
350
|
-
component = ToolComponent(**filtered_data)
|
351
|
-
else:
|
352
|
-
component = Component(**component_data)
|
353
|
-
|
354
|
-
# Check if there's an active agent context
|
355
|
-
current_agent_id = self.current_agent_id.get()
|
356
|
-
if current_agent_id and component_data["type"] in ["llm", "tool", "custom"]:
|
357
|
-
# Add this component as a child of the current agent
|
358
|
-
current_children = self.agent_children.get()
|
359
|
-
current_children.append(component_data)
|
360
|
-
self.agent_children.set(current_children)
|
361
|
-
else:
|
362
|
-
# Add component to the main trace
|
363
|
-
super().add_component(component)
|
364
|
-
|
365
|
-
# Handle error case
|
366
|
-
if is_error and not self.current_agent_id.get():
|
367
|
-
self.stop()
|
106
|
+
if not callable(post_processor_func):
|
107
|
+
logger.error("post_processor_func must be a callable")
|
108
|
+
self.post_processor = post_processor_func
|
368
109
|
|
369
110
|
def __enter__(self):
|
370
111
|
"""Context manager entry"""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ragaai_catalyst
|
3
|
-
Version: 2.2.
|
3
|
+
Version: 2.2.5b2
|
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>, Tushar Kumar <tushar.kumar@raga.ai>, Rishabh Pandey <rishabh.pandey@raga.ai>, Jyotsana C G <jyotsana@raga.ai>
|
6
6
|
Requires-Python: <=3.13.2,>=3.10
|
@@ -33,7 +33,7 @@ ragaai_catalyst/tracers/agentic_tracing/__init__.py,sha256=yf6SKvOPSpH-9LiKaoLKX
|
|
33
33
|
ragaai_catalyst/tracers/agentic_tracing/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
34
34
|
ragaai_catalyst/tracers/agentic_tracing/data/data_structure.py,sha256=icAtNzKN_I0YtfuJ3RF8BdZJK3ohqxkVZIdvM5_YugY,9327
|
35
35
|
ragaai_catalyst/tracers/agentic_tracing/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
36
|
-
ragaai_catalyst/tracers/agentic_tracing/tracers/main_tracer.py,sha256=
|
36
|
+
ragaai_catalyst/tracers/agentic_tracing/tracers/main_tracer.py,sha256=Wq4LFclPlLy47LyXvbaLeYiSMQABj7VYS3J87xyea_E,4159
|
37
37
|
ragaai_catalyst/tracers/agentic_tracing/upload/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
38
|
ragaai_catalyst/tracers/agentic_tracing/upload/trace_uploader.py,sha256=iMUMFR9XVipCBunpv8_No8bCoP3lqG47M5dg-ugibWo,21006
|
39
39
|
ragaai_catalyst/tracers/agentic_tracing/upload/upload_agentic_traces.py,sha256=t3spo5w7TyfR0Zeqm1h5Z-bJ-BlZ3EPGTvRdK5lpFpE,11705
|
@@ -57,8 +57,8 @@ ragaai_catalyst/tracers/utils/model_prices_and_context_window_backup.json,sha256
|
|
57
57
|
ragaai_catalyst/tracers/utils/rag_extraction_logic_final.py,sha256=3ygkRT__lLDRflRttjzPu28tIA8cTCiGQVMQjqMItqQ,11309
|
58
58
|
ragaai_catalyst/tracers/utils/trace_json_converter.py,sha256=-HZVmijeUFLO7e9OAvi1RJdWVTxPRUHPd1MkKQlCD54,11785
|
59
59
|
ragaai_catalyst/tracers/utils/utils.py,sha256=o-p9n2ZuophdrV0wrixu-BqRHCkovup_klc3mS8mU8g,2374
|
60
|
-
ragaai_catalyst-2.2.
|
61
|
-
ragaai_catalyst-2.2.
|
62
|
-
ragaai_catalyst-2.2.
|
63
|
-
ragaai_catalyst-2.2.
|
64
|
-
ragaai_catalyst-2.2.
|
60
|
+
ragaai_catalyst-2.2.5b2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
61
|
+
ragaai_catalyst-2.2.5b2.dist-info/METADATA,sha256=vFJ9Lsi-FZtVdCvgW3LEs7PQcoN4oAzDCjyXm5iXIKM,17679
|
62
|
+
ragaai_catalyst-2.2.5b2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
63
|
+
ragaai_catalyst-2.2.5b2.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
|
64
|
+
ragaai_catalyst-2.2.5b2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|