ragaai-catalyst 2.1.5b25__py3-none-any.whl → 2.1.5b27__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.
@@ -510,8 +510,11 @@ class Evaluation:
510
510
  df = pd.read_csv(io.StringIO(response_text))
511
511
 
512
512
  column_list = df.columns.to_list()
513
+ # Remove unwanted columns
513
514
  column_list = [col for col in column_list if not col.startswith('_')]
514
515
  column_list = [col for col in column_list if '.' not in col]
516
+ # Remove _claims_ columns
517
+ column_list = [col for col in column_list if '_claims_' not in col]
515
518
  return df[column_list]
516
519
  else:
517
520
  return pd.DataFrame()
@@ -106,48 +106,42 @@ class AgentTracerMixin:
106
106
  if gt is not None:
107
107
  span = self.span(name)
108
108
  span.add_gt(gt)
109
- # Set agent context before initializing
110
- component_id = str(uuid.uuid4())
111
- hash_id = top_level_hash_id
112
-
113
- # Store the component ID in the instance
114
- self._agent_component_id = component_id
115
-
116
- # Get parent agent ID if exists
117
- parent_agent_id = tracer.current_agent_id.get()
118
-
119
- # Create agent component
120
- agent_component = tracer.create_agent_component(
121
- component_id=component_id,
122
- hash_id=hash_id,
123
- name=name,
124
- agent_type=agent_type,
125
- version=version,
126
- capabilities=capabilities or [],
127
- start_time=datetime.now().astimezone().isoformat(),
128
- memory_used=0,
129
- input_data=tracer._sanitize_input(args, kwargs),
130
- output_data=None,
131
- children=[],
132
- parent_id=parent_agent_id,
133
- )
134
-
135
- # Store component for later updates
136
- if not hasattr(tracer, "_agent_components"):
137
- tracer._agent_components = {}
138
- tracer._agent_components[component_id] = agent_component
139
109
 
140
- # If this is a nested agent, add it to parent's children
141
- if parent_agent_id:
142
- parent_children = tracer.agent_children.get()
143
- parent_children.append(agent_component)
144
- tracer.agent_children.set(parent_children)
145
- else:
146
- # Only add to root components if no parent
147
- tracer.add_component(agent_component)
148
-
149
- # Call original __init__ with this agent as current
150
- token = tracer.current_agent_id.set(component_id)
110
+ if not hasattr(self, '_agent_component_id'):
111
+ component_id = str(uuid.uuid4())
112
+ self._agent_component_id = component_id
113
+
114
+ # Get parent agent ID if exists
115
+ parent_agent_id = tracer.current_agent_id.get()
116
+
117
+ agent_component = tracer.create_agent_component(
118
+ component_id=component_id,
119
+ hash_id=top_level_hash_id,
120
+ name=name,
121
+ agent_type=agent_type,
122
+ version=version,
123
+ capabilities=capabilities or [],
124
+ start_time=datetime.now().astimezone().isoformat(),
125
+ memory_used=0,
126
+ input_data=tracer._sanitize_input(args, kwargs),
127
+ output_data=None,
128
+ children=[],
129
+ parent_id=parent_agent_id,
130
+ )
131
+
132
+ if not hasattr(tracer, "_agent_components"):
133
+ tracer._agent_components = {}
134
+ tracer._agent_components[component_id] = agent_component
135
+
136
+ # For class agents, only add to parent's children if parent exists
137
+ if parent_agent_id and parent_agent_id in tracer._agent_components:
138
+ parent_component = tracer._agent_components[parent_agent_id]
139
+ if not hasattr(parent_component, "children"):
140
+ parent_component["children"] = []
141
+ if component_id not in parent_component["children"]:
142
+ parent_component["children"].append(component_id)
143
+
144
+ token = tracer.current_agent_id.set(self._agent_component_id)
151
145
  try:
152
146
  original_init(self, *args, **kwargs)
153
147
  finally:
@@ -160,7 +154,6 @@ class AgentTracerMixin:
160
154
  if callable(attr_value):
161
155
 
162
156
  def wrap_method(method):
163
- @self.file_tracker.trace_decorator
164
157
  @functools.wraps(method)
165
158
  def wrapped_method(self, *args, **kwargs):
166
159
  gt = kwargs.get("gt") if kwargs else None
@@ -225,15 +218,60 @@ class AgentTracerMixin:
225
218
  setattr(target, attr_name, wrap_method(attr_value))
226
219
 
227
220
  # Replace __init__ with wrapped version
221
+
228
222
  target.__init__ = wrapped_init
223
+
224
+ # Wrap all methods to maintain parent-child relationship
225
+ for attr_name, attr_value in target.__dict__.items():
226
+ if callable(attr_value) and not attr_name.startswith('__'):
227
+ original_method = attr_value
228
+
229
+ def create_wrapper(method):
230
+ @self.file_tracker.trace_decorator
231
+ @functools.wraps(method)
232
+ def method_wrapper(self, *args, **kwargs):
233
+ gt = kwargs.get("gt") if kwargs else None
234
+ if gt is not None:
235
+ span = tracer.span(name)
236
+ span.add_gt(gt)
237
+ # Use the class instance's agent ID as parent
238
+ parent_id = getattr(self, '_agent_component_id', None)
239
+ if parent_id:
240
+ if asyncio.iscoroutinefunction(method):
241
+ return tracer._trace_agent_execution(
242
+ method.__get__(self, type(self)),
243
+ name,
244
+ agent_type,
245
+ version,
246
+ capabilities,
247
+ top_level_hash_id,
248
+ *args,
249
+ **kwargs,
250
+ )
251
+ else:
252
+ return tracer._trace_sync_agent_execution(
253
+ method.__get__(self, type(self)),
254
+ name,
255
+ agent_type,
256
+ version,
257
+ capabilities,
258
+ top_level_hash_id,
259
+ *args,
260
+ **kwargs,
261
+ )
262
+ else:
263
+ return method(self, *args, **kwargs)
264
+ return method_wrapper
265
+
266
+ setattr(target, attr_name, create_wrapper(original_method))
267
+
229
268
  return target
230
269
  else:
231
- # For function decorators, use existing sync/async tracing
232
- is_async = asyncio.iscoroutinefunction(target)
233
- if is_async:
234
-
235
- async def wrapper(*args, **kwargs):
236
- return await self._trace_agent_execution(
270
+ # For non-class targets (e.g., functions), use existing function wrapping logic
271
+ @functools.wraps(target)
272
+ def wrapper(*args, **kwargs):
273
+ if asyncio.iscoroutinefunction(target):
274
+ return tracer._trace_agent_execution(
237
275
  target,
238
276
  name,
239
277
  agent_type,
@@ -243,12 +281,8 @@ class AgentTracerMixin:
243
281
  *args,
244
282
  **kwargs,
245
283
  )
246
-
247
- return wrapper
248
- else:
249
-
250
- def wrapper(*args, **kwargs):
251
- return self._trace_sync_agent_execution(
284
+ else:
285
+ return tracer._trace_sync_agent_execution(
252
286
  target,
253
287
  name,
254
288
  agent_type,
@@ -258,16 +292,13 @@ class AgentTracerMixin:
258
292
  *args,
259
293
  **kwargs,
260
294
  )
261
-
262
- return wrapper
295
+ return wrapper
263
296
 
264
297
  return decorator
265
298
 
266
299
  def _trace_sync_agent_execution(
267
- self, func, name, agent_type, version, capabilities, top_level_hash_id, *args, **kwargs
300
+ self, func, name, agent_type, version, capabilities, top_level_hash_id, *args, **kwargs
268
301
  ):
269
- hash_id = top_level_hash_id
270
-
271
302
  """Synchronous version of agent tracing"""
272
303
  if not self.is_active:
273
304
  return func(*args, **kwargs)
@@ -303,7 +334,7 @@ class AgentTracerMixin:
303
334
 
304
335
  try:
305
336
  # Execute the agent
306
- result = self.file_tracker.trace_wrapper(func)(*args, **kwargs)
337
+ result = func(*args, **kwargs)
307
338
 
308
339
  # Calculate resource usage
309
340
  end_memory = psutil.Process().memory_info().rss
@@ -318,7 +349,7 @@ class AgentTracerMixin:
318
349
  # Create agent component with children and parent if exists
319
350
  agent_component = self.create_agent_component(
320
351
  component_id=component_id,
321
- hash_id=hash_id,
352
+ hash_id=top_level_hash_id,
322
353
  name=name,
323
354
  agent_type=agent_type,
324
355
  version=version,
@@ -331,12 +362,17 @@ class AgentTracerMixin:
331
362
  parent_id=parent_agent_id,
332
363
  )
333
364
 
334
- # Add this component as a child to parent's children list
335
- parent_children.append(agent_component)
336
- self.agent_children.set(parent_children)
365
+ # Store component for updates
366
+ if not hasattr(self, "_agent_components"):
367
+ self._agent_components = {}
368
+ self._agent_components[component_id] = agent_component
337
369
 
338
- # Only add to root components if no parent
339
- if not parent_agent_id:
370
+ # Only add to hierarchy if this is a root component (no parent)
371
+ # or if the parent explicitly added it as a child
372
+ if parent_agent_id:
373
+ parent_children.append(agent_component)
374
+ self.agent_children.set(parent_children)
375
+ else:
340
376
  self.add_component(agent_component)
341
377
 
342
378
  return result
@@ -351,16 +387,10 @@ class AgentTracerMixin:
351
387
  # Get children even in case of error
352
388
  children = self.agent_children.get()
353
389
 
354
- # Set parent_id for all children
355
- for child in children:
356
- child["parent_id"] = component_id
357
-
358
- # End tracking network calls for this component
359
- self.end_component(component_id)
360
-
390
+ # Create error component
361
391
  agent_component = self.create_agent_component(
362
392
  component_id=component_id,
363
- hash_id=hash_id,
393
+ hash_id=top_level_hash_id,
364
394
  name=name,
365
395
  agent_type=agent_type,
366
396
  version=version,
@@ -373,16 +403,20 @@ class AgentTracerMixin:
373
403
  children=children,
374
404
  parent_id=parent_agent_id, # Add parent ID if exists
375
405
  )
376
- # If this is a nested agent, add it to parent's children
406
+
407
+ # Store component for updates
408
+ if not hasattr(self, "_agent_components"):
409
+ self._agent_components = {}
410
+ self._agent_components[component_id] = agent_component
411
+
412
+ # Only add to hierarchy if this is a root component (no parent)
413
+ # or if the parent explicitly added it as a child
377
414
  if parent_agent_id:
378
- parent_component = self._agent_components.get(parent_agent_id)
379
- if parent_component:
380
- if "children" not in parent_component["data"]:
381
- parent_component["data"]["children"] = []
382
- parent_component["data"]["children"].append(agent_component)
415
+ parent_children.append(agent_component)
416
+ self.agent_children.set(parent_children)
383
417
  else:
384
418
  # Only add to root components if no parent
385
- self.add_component(agent_component)
419
+ self.add_component(agent_component, is_error=True)
386
420
 
387
421
  raise
388
422
  finally:
@@ -424,7 +458,7 @@ class AgentTracerMixin:
424
458
 
425
459
  try:
426
460
  # Execute the agent
427
- result = await self.file_tracker.trace_wrapper(func)(*args, **kwargs)
461
+ result = await func(*args, **kwargs)
428
462
 
429
463
  # Calculate resource usage
430
464
  end_memory = psutil.Process().memory_info().rss
@@ -451,12 +485,17 @@ class AgentTracerMixin:
451
485
  parent_id=parent_agent_id,
452
486
  )
453
487
 
454
- # Add this component as a child to parent's children list
455
- parent_children.append(agent_component)
456
- self.agent_children.set(parent_children)
488
+ # Store component for updates
489
+ if not hasattr(self, "_agent_components"):
490
+ self._agent_components = {}
491
+ self._agent_components[component_id] = agent_component
457
492
 
458
- # Only add to root components if no parent
459
- if not parent_agent_id:
493
+ # Only add to hierarchy if this is a root component (no parent)
494
+ # or if the parent explicitly added it as a child
495
+ if parent_agent_id:
496
+ parent_children.append(agent_component)
497
+ self.agent_children.set(parent_children)
498
+ else:
460
499
  self.add_component(agent_component)
461
500
 
462
501
  return result
@@ -471,13 +510,7 @@ class AgentTracerMixin:
471
510
  # Get children even in case of error
472
511
  children = self.agent_children.get()
473
512
 
474
- # Set parent_id for all children
475
- for child in children:
476
- child["parent_id"] = component_id
477
-
478
- # End tracking network calls for this component
479
- self.end_component(component_id)
480
-
513
+ # Create error component
481
514
  agent_component = self.create_agent_component(
482
515
  component_id=component_id,
483
516
  hash_id=hash_id,
@@ -494,16 +527,19 @@ class AgentTracerMixin:
494
527
  parent_id=parent_agent_id, # Add parent ID if exists
495
528
  )
496
529
 
497
- # If this is a nested agent, add it to parent's children
530
+ # Store component for updates
531
+ if not hasattr(self, "_agent_components"):
532
+ self._agent_components = {}
533
+ self._agent_components[component_id] = agent_component
534
+
535
+ # Only add to hierarchy if this is a root component (no parent)
536
+ # or if the parent explicitly added it as a child
498
537
  if parent_agent_id:
499
- parent_component = self._agent_components.get(parent_agent_id)
500
- if parent_component:
501
- if "children" not in parent_component["data"]:
502
- parent_component["data"]["children"] = []
503
- parent_component["data"]["children"].append(agent_component)
538
+ parent_children.append(agent_component)
539
+ self.agent_children.set(parent_children)
504
540
  else:
505
541
  # Only add to root components if no parent
506
- self.add_component(agent_component)
542
+ self.add_component(agent_component, is_error=True)
507
543
 
508
544
  raise
509
545
  finally:
@@ -137,6 +137,7 @@ class BaseTracer:
137
137
  """Initialize a new trace"""
138
138
  self.tracking = True
139
139
  self.trace_id = str(uuid.uuid4())
140
+ self.file_tracker.trace_main_file()
140
141
  self.system_monitor = SystemMonitor(self.trace_id)
141
142
  threading.Thread(target=self._track_memory_usage).start()
142
143
  threading.Thread(target=self._track_cpu_usage).start()
@@ -41,7 +41,6 @@ class CustomTracerMixin:
41
41
  # Check if the function is async
42
42
  is_async = asyncio.iscoroutinefunction(func)
43
43
 
44
- @self.file_tracker.trace_decorator
45
44
  @functools.wraps(func)
46
45
  async def async_wrapper(*args, **kwargs):
47
46
  async_wrapper.metadata = metadata
@@ -53,7 +52,6 @@ class CustomTracerMixin:
53
52
  func, name or func.__name__, custom_type, version, trace_variables, *args, **kwargs
54
53
  )
55
54
 
56
- @self.file_tracker.trace_decorator
57
55
  @functools.wraps(func)
58
56
  def sync_wrapper(*args, **kwargs):
59
57
  sync_wrapper.metadata = metadata
@@ -104,7 +102,7 @@ class CustomTracerMixin:
104
102
 
105
103
  try:
106
104
  # Execute the function
107
- result = self.file_tracker.trace_wrapper(func)(*args, **kwargs)
105
+ result = func(*args, **kwargs)
108
106
 
109
107
  # Calculate resource usage
110
108
  end_time = datetime.now().astimezone().isoformat()
@@ -160,7 +158,7 @@ class CustomTracerMixin:
160
158
  error=error_component
161
159
  )
162
160
 
163
- self.add_component(custom_component)
161
+ self.add_component(custom_component, is_error=True)
164
162
  raise
165
163
 
166
164
  async def _trace_custom_execution(self, func, name, custom_type, version, trace_variables, *args, **kwargs):
@@ -192,7 +190,7 @@ class CustomTracerMixin:
192
190
 
193
191
  try:
194
192
  # Execute the function
195
- result = await self.file_tracker.trace_wrapper(func)(*args, **kwargs)
193
+ result = await func(*args, **kwargs)
196
194
 
197
195
  # Calculate resource usage
198
196
  end_time = datetime.now().astimezone().isoformat()
@@ -240,7 +238,7 @@ class CustomTracerMixin:
240
238
  output_data=None,
241
239
  error=error_component
242
240
  )
243
- self.add_component(custom_component)
241
+ self.add_component(custom_component, is_error=True)
244
242
  raise
245
243
 
246
244
  def create_custom_component(self, **kwargs):