ragaai-catalyst 2.1b2__py3-none-any.whl → 2.1b4__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.
@@ -225,6 +225,52 @@ class AgentTracerMixin:
225
225
  self.add_component(agent_component)
226
226
 
227
227
  return result
228
+ except Exception as e:
229
+ error_component = {
230
+ "code": 500,
231
+ "type": type(e).__name__,
232
+ "message": str(e),
233
+ "details": {}
234
+ }
235
+
236
+ # Get children even in case of error
237
+ children = self.agent_children.get()
238
+
239
+ # Set parent_id for all children
240
+ for child in children:
241
+ child["parent_id"] = component_id
242
+
243
+ # End tracking network calls for this component
244
+ self.end_component(component_id)
245
+
246
+ agent_component = self.create_agent_component(
247
+ component_id=component_id,
248
+ hash_id=hash_id,
249
+ name=name,
250
+ agent_type=agent_type,
251
+ version=version,
252
+ capabilities=capabilities or [],
253
+ start_time=start_time,
254
+ end_time=datetime.now(),
255
+ memory_used=0,
256
+ input_data=self._sanitize_input(args, kwargs),
257
+ output_data=None,
258
+ error=error_component,
259
+ children=children,
260
+ parent_id=parent_agent_id # Add parent ID if exists
261
+ )
262
+
263
+ # If this is a nested agent, add it to parent's children
264
+ if parent_agent_id:
265
+ parent_component = self._agent_components.get(parent_agent_id)
266
+ if parent_component:
267
+ if 'children' not in parent_component['data']:
268
+ parent_component['data']['children'] = []
269
+ parent_component['data']['children'].append(agent_component)
270
+ else:
271
+ # Only add to root components if no parent
272
+ self.add_component(agent_component)
273
+ raise
228
274
  finally:
229
275
  self.current_agent_id.reset(agent_token)
230
276
  self.current_agent_name.reset(agent_name_token)
@@ -112,6 +112,7 @@ class AgenticTracing(BaseTracer, LLMTracerMixin, ToolTracerMixin, AgentTracerMix
112
112
 
113
113
  # Cleanup
114
114
  self.unpatch_llm_calls()
115
+ self.user_interaction_tracer.interactions = [] # Clear interactions list
115
116
  self.is_active = False
116
117
 
117
118
 
@@ -166,16 +167,19 @@ class AgenticTracing(BaseTracer, LLMTracerMixin, ToolTracerMixin, AgentTracerMix
166
167
  def add_component(self, component_data: dict):
167
168
  """Add a component to the trace data"""
168
169
  # Convert dict to appropriate Component type
169
- filtered_data = {k: v for k, v in component_data.items() if k in ["id", "hash_id", "type", "name", "start_time", "end_time", "parent_id", "info", "data", "network_calls", "interactions"]}
170
+ filtered_data = {k: v for k, v in component_data.items() if k in ["id", "hash_id", "type", "name", "start_time", "end_time", "parent_id", "info", "data", "network_calls", "interactions", "error"]}
171
+
170
172
 
171
173
  if component_data["type"] == "llm":
172
174
  component = LLMComponent(**filtered_data)
173
- elif component_data["type"] == "agent":
175
+ elif component_data["type"] == "agent":
174
176
  component = AgentComponent(**filtered_data)
175
177
  elif component_data["type"] == "tool":
176
178
  component = ToolComponent(**filtered_data)
177
179
  else:
178
180
  component = Component(**component_data)
181
+
182
+ # import pdb; pdb.set_trace()
179
183
 
180
184
  # Check if there's an active agent context
181
185
  current_agent_id = self.current_agent_id.get()
@@ -1,27 +1,24 @@
1
1
  import json
2
2
  import os
3
3
  import platform
4
- import re
5
4
  import psutil
6
5
  import pkg_resources
7
6
  from datetime import datetime
8
7
  from pathlib import Path
9
- from typing import Optional, Dict, Any, List
8
+ from typing import List
10
9
  import uuid
11
10
  import sys
11
+ import tempfile
12
12
 
13
13
  from .data_structure import (
14
14
  Trace, Metadata, SystemInfo, OSInfo, EnvironmentInfo,
15
15
  Resources, CPUResource, MemoryResource, DiskResource, NetworkResource,
16
16
  ResourceInfo, MemoryInfo, DiskInfo, NetworkInfo,
17
- Component, LLMComponent, AgentComponent, ToolComponent,
18
- NetworkCall, Interaction, Error
17
+ Component,
19
18
  )
20
19
 
21
- from ..upload_traces import UploadTraces
22
20
  from .upload_agentic_traces import UploadAgenticTraces
23
21
  from .upload_code import upload_code
24
- from ...ragaai_catalyst import RagaAICatalyst
25
22
 
26
23
  from .file_name_tracker import TrackName
27
24
  from .zip_list_of_unique_files import zip_list_of_unique_files
@@ -182,14 +179,13 @@ class BaseTracer:
182
179
  self.trace = self._extract_cost_tokens(self.trace)
183
180
 
184
181
  # Create traces directory if it doesn't exist
185
- self.traces_dir = Path("traces")
186
- self.traces_dir.mkdir(exist_ok=True)
182
+ self.traces_dir = tempfile.gettempdir()
187
183
  filename = self.trace.id + ".json"
188
- filepath = self.traces_dir / filename
184
+ filepath = f"{self.traces_dir}/{filename}"
189
185
 
190
186
  #get unique files and zip it. Generate a unique hash ID for the contents of the files
191
187
  list_of_unique_files = self.file_tracker.get_unique_files()
192
- hash_id, zip_path = zip_list_of_unique_files(list_of_unique_files)
188
+ hash_id, zip_path = zip_list_of_unique_files(list_of_unique_files, output_dir=self.traces_dir)
193
189
 
194
190
  #replace source code with zip_path
195
191
  self.trace.metadata.system_info.source_code = hash_id
@@ -160,9 +160,8 @@ class ToolInfo:
160
160
  memory_used: int
161
161
 
162
162
  class Component:
163
- def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None, error: Optional[Error] = None):
163
+ def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None, error: Optional[Dict[str, Any]] = None):
164
164
  self.id = id
165
- self.error = error
166
165
  self.hash_id = hash_id
167
166
  self.type = type
168
167
  self.name = name
@@ -171,8 +170,10 @@ class Component:
171
170
  self.parent_id = parent_id
172
171
  self.info = info
173
172
  self.data = data
173
+ self.error = error
174
174
  self.network_calls = network_calls or []
175
175
  self.interactions = []
176
+ self.error = error
176
177
  if interactions:
177
178
  for interaction in interactions:
178
179
  if isinstance(interaction, dict):
@@ -197,22 +198,24 @@ class Component:
197
198
  "end_time": self.end_time,
198
199
  "parent_id": self.parent_id,
199
200
  "info": self.info,
201
+ "error": self.error,
200
202
  "data": self.data,
203
+ "error": self.error,
201
204
  "network_calls": [call.to_dict() if hasattr(call, 'to_dict') else call for call in self.network_calls],
202
205
  "interactions": self.interactions
203
206
  }
204
207
 
205
208
  class LLMComponent(Component):
206
- def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None):
207
- super().__init__(id, hash_id, type, name, start_time, end_time, parent_id, info, data, network_calls, interactions)
209
+ def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None, error: Optional[Dict[str, Any]] = None):
210
+ super().__init__(id, hash_id, type, name, start_time, end_time, parent_id, info, data, network_calls, interactions, error)
208
211
 
209
212
  class AgentComponent(Component):
210
- def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None):
211
- super().__init__(id, hash_id, type, name, start_time, end_time, parent_id, info, data, network_calls, interactions)
213
+ def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None, error: Optional[Dict[str, Any]] = None):
214
+ super().__init__(id, hash_id, type, name, start_time, end_time, parent_id, info, data, network_calls, interactions, error)
212
215
 
213
216
  class ToolComponent(Component):
214
- def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None):
215
- super().__init__(id, hash_id, type, name, start_time, end_time, parent_id, info, data, network_calls, interactions)
217
+ def __init__(self, id: str, hash_id: str, type: str, name: str, start_time: str, end_time: str, parent_id: int, info: Dict[str, Any], data: Dict[str, Any], network_calls: Optional[List[NetworkCall]] = None, interactions: Optional[List[Union[Interaction, Dict]]] = None, error: Optional[Dict[str, Any]] = None):
218
+ super().__init__(id, hash_id, type, name, start_time, end_time, parent_id, info, data, network_calls, interactions, error)
216
219
 
217
220
  @dataclass
218
221
  class ComponentInfo:
@@ -501,6 +501,12 @@ class LLMTracerMixin:
501
501
  name = self.current_llm_call_name.get()
502
502
  if name is None:
503
503
  name = original_func.__name__
504
+
505
+ end_memory = psutil.Process().memory_info().rss
506
+ memory_used = max(0, end_memory - start_memory)
507
+
508
+ # Get parent agent ID if exists
509
+ parent_agent_id = self.current_agent_id.get() if hasattr(self, 'current_agent_id') else None
504
510
 
505
511
  llm_component = self.create_llm_component(
506
512
  component_id=component_id,
@@ -508,15 +514,24 @@ class LLMTracerMixin:
508
514
  name=name,
509
515
  llm_type="unknown",
510
516
  version="1.0.0",
511
- memory_used=0,
517
+ memory_used=memory_used,
512
518
  start_time=start_time,
513
519
  end_time=end_time,
514
520
  input_data=self._extract_input_data(args, kwargs, None),
515
521
  output_data=None,
516
- error=error_component
522
+ error=error_component,
523
+ parent_id=parent_agent_id
517
524
  )
518
525
 
519
- self.add_component(llm_component)
526
+ # If this is part of an agent trace, add it to agent's children
527
+ if parent_agent_id and hasattr(self, 'agent_children'):
528
+ parent_children = self.agent_children.get()
529
+ parent_children.append(llm_component)
530
+ self.agent_children.set(parent_children)
531
+ else:
532
+ # Only add to root components if no parent
533
+ self.add_component(llm_component)
534
+
520
535
  raise
521
536
 
522
537
  def trace_llm_call_sync(self, original_func, *args, **kwargs):
@@ -603,6 +618,9 @@ class LLMTracerMixin:
603
618
  end_memory = psutil.Process().memory_info().rss
604
619
  memory_used = max(0, end_memory - start_memory)
605
620
 
621
+ # Get parent agent ID if exists
622
+ parent_agent_id = self.current_agent_id.get() if hasattr(self, 'current_agent_id') else None
623
+
606
624
  llm_component = self.create_llm_component(
607
625
  component_id=component_id,
608
626
  hash_id=hash_id,
@@ -614,10 +632,19 @@ class LLMTracerMixin:
614
632
  end_time=end_time,
615
633
  input_data=self._extract_input_data(args, kwargs, None),
616
634
  output_data=None,
617
- error=error_component
635
+ error=error_component,
636
+ parent_id=parent_agent_id
618
637
  )
619
638
 
620
- self.add_component(llm_component)
639
+ # If this is part of an agent trace, add it to agent's children
640
+ if parent_agent_id and hasattr(self, 'agent_children'):
641
+ parent_children = self.agent_children.get()
642
+ parent_children.append(llm_component)
643
+ self.agent_children.set(parent_children)
644
+ else:
645
+ # Only add to root components if no parent
646
+ self.add_component(llm_component)
647
+
621
648
  raise
622
649
 
623
650
  def trace_llm(self, name: str = None):
@@ -654,6 +681,10 @@ class LLMTracerMixin:
654
681
  finally:
655
682
 
656
683
  llm_component = self.llm_data
684
+ llm_component['name'] = name
685
+
686
+ if self.gt:
687
+ llm_component["data"]["gt"] = self.gt
657
688
 
658
689
  if error_info:
659
690
  llm_component["error"] = error_info["error"]
@@ -7,6 +7,8 @@ import importlib.util
7
7
  import json
8
8
  import astor
9
9
  from pathlib import Path
10
+ import logging
11
+ logger = logging.getLogger(__name__)
10
12
 
11
13
  # Define the PackageUsageRemover class
12
14
  class PackageUsageRemover(ast.NodeTransformer):
@@ -165,15 +167,15 @@ class TraceDependencyTracker:
165
167
  try:
166
168
  relative_path = os.path.relpath(filepath, base_path)
167
169
  zipf.write(filepath, relative_path)
168
- print(f"Added to zip: {relative_path}")
170
+ # logger.info(f"Added to zip: {relative_path}")
169
171
  except Exception as e:
170
172
  print(f"Warning: Could not add {filepath} to zip: {str(e)}")
171
173
 
172
174
  return hash_id, zip_filename
173
175
 
174
176
  # Main function for creating a zip of unique files
175
- def zip_list_of_unique_files(filepaths):
176
- tracker = TraceDependencyTracker()
177
+ def zip_list_of_unique_files(filepaths, output_dir):
178
+ tracker = TraceDependencyTracker(output_dir)
177
179
  return tracker.create_zip(filepaths)
178
180
 
179
181
  # Example usage
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ragaai_catalyst
3
- Version: 2.1b2
3
+ Version: 2.1b4
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
- Requires-Python: >=3.9
6
+ Requires-Python: >=3.11
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: aiohttp>=3.10.2
9
9
  Requires-Dist: opentelemetry-api==1.25.0
@@ -27,13 +27,13 @@ Requires-Dist: Markdown>=3.7
27
27
  Requires-Dist: litellm==1.51.1
28
28
  Requires-Dist: tenacity==8.3.0
29
29
  Requires-Dist: tqdm>=4.66.5
30
- Requires-Dist: llama-index==0.10.0
31
- Requires-Dist: pyopenssl==24.2.1
30
+ Requires-Dist: llama-index>=0.10.0
31
+ Requires-Dist: pyopenssl>=24.2.1
32
32
  Requires-Dist: psutil~=6.0.0
33
33
  Requires-Dist: py-cpuinfo~=9.0.0
34
34
  Requires-Dist: requests~=2.32.3
35
35
  Requires-Dist: GPUtil~=1.4.0
36
- Requires-Dist: astor==0.8.1
36
+ Requires-Dist: astor>=0.8.1
37
37
  Provides-Extra: dev
38
38
  Requires-Dist: pytest; extra == "dev"
39
39
  Requires-Dist: pytest-cov; extra == "dev"
@@ -16,12 +16,12 @@ ragaai_catalyst/tracers/llamaindex_callback.py,sha256=vPE7MieKjfwLrLUnnPs20Df0xN
16
16
  ragaai_catalyst/tracers/tracer.py,sha256=dGYQfo0RXms6w-sAJf04gqTo1zOXTqreGXaJlnvK48A,12463
17
17
  ragaai_catalyst/tracers/upload_traces.py,sha256=hs0PEmit3n3_uUqrdbwcBdyK5Nbkik3JQVwJMEwYTd4,4796
18
18
  ragaai_catalyst/tracers/agentic_tracing/__init__.py,sha256=6QyQI8P7aNFHTantNJOP1ZdSNrDKBLhlg_gGNj7tm1c,73
19
- ragaai_catalyst/tracers/agentic_tracing/agent_tracer.py,sha256=Ff9KbTjKkuZkGAECyvKRe8LjjAjwQ-seTwsX2ycGnIg,18995
20
- ragaai_catalyst/tracers/agentic_tracing/agentic_tracing.py,sha256=vlh1nvIx9qAHI1m4YKe1R9HkjWiA6sKnP_6GRUed00g,8366
21
- ragaai_catalyst/tracers/agentic_tracing/base.py,sha256=xnd9jE_aEh56iSharHuMlHxBvPcSQD8KtihPLjKn5Mc,14199
22
- ragaai_catalyst/tracers/agentic_tracing/data_structure.py,sha256=qyfCI1oGQ461WbS6BYBiAEUmgpw9xFsccpjsi_mVX3c,7152
19
+ ragaai_catalyst/tracers/agentic_tracing/agent_tracer.py,sha256=M5RBNzcuSCEKv-rYwmzBMN-BxvthM3y6d_279UYERZQ,20832
20
+ ragaai_catalyst/tracers/agentic_tracing/agentic_tracing.py,sha256=WsddEXn2afdPx8PfignQoLIwZfn9350XsqtkqtZdMxw,8502
21
+ ragaai_catalyst/tracers/agentic_tracing/base.py,sha256=jRf_-5EIfCzGbaSQtkqgiDQAH4ymoKUrg9A8YqB08jk,14008
22
+ ragaai_catalyst/tracers/agentic_tracing/data_structure.py,sha256=wkZctMTUQUViqKrHhdZiMERSBVfwURAJ-lFlQUou638,7395
23
23
  ragaai_catalyst/tracers/agentic_tracing/file_name_tracker.py,sha256=515NNDQJTyy3O-2rdlUYUoWL9qSwLIfvV3sMB9BtHp8,1366
24
- ragaai_catalyst/tracers/agentic_tracing/llm_tracer.py,sha256=PTOnyj4AVEyUqyQK1fY-Beckt0v_-BvJfGwIEoIxca4,32561
24
+ ragaai_catalyst/tracers/agentic_tracing/llm_tracer.py,sha256=oxziex6mT4RcZY1zWTVgsPXVewiTWt16CQAfWi9_YD0,34072
25
25
  ragaai_catalyst/tracers/agentic_tracing/network_tracer.py,sha256=6FTA15xMnum9omM_0Jd9cMIuWdKu1gR5Tc8fOXAkP8E,10068
26
26
  ragaai_catalyst/tracers/agentic_tracing/sample.py,sha256=S4rCcKzU_5SB62BYEbNn_1VbbTdG4396N8rdZ3ZNGcE,5654
27
27
  ragaai_catalyst/tracers/agentic_tracing/tool_tracer.py,sha256=Yc4x82rk0hCANwXUt4M66Qv_4OdpsXsjlq6OIOef1io,8763
@@ -30,7 +30,7 @@ ragaai_catalyst/tracers/agentic_tracing/unique_decorator_test.py,sha256=Xk1cLzs-
30
30
  ragaai_catalyst/tracers/agentic_tracing/upload_agentic_traces.py,sha256=ydaWAbrSS5B6ijabzTnUVxlW8m6eX5dsEJnzl06ZDFU,7539
31
31
  ragaai_catalyst/tracers/agentic_tracing/upload_code.py,sha256=u9bRWcM5oDezJupEQoHUXrKz7YvZJK9IZf10ejBWoa4,4254
32
32
  ragaai_catalyst/tracers/agentic_tracing/user_interaction_tracer.py,sha256=wsCwTK7tM_L3mdNrcg5Mq3D1k07XCHZkhOB26kz_rLY,1472
33
- ragaai_catalyst/tracers/agentic_tracing/zip_list_of_unique_files.py,sha256=qlK-7HtybA7Z0xvK0iiVE7lC0gsDgwvdO0MJ9a37f2w,7486
33
+ ragaai_catalyst/tracers/agentic_tracing/zip_list_of_unique_files.py,sha256=faFat_OAUnVJGnauMVo6yeHhTv-_njgyXGOtUwYJ8kE,7568
34
34
  ragaai_catalyst/tracers/agentic_tracing/examples/FinancialAnalysisSystem.ipynb,sha256=0qZxjWqYCTAVvdo3Tsp544D8Am48wfeMQ9RKpKgAL8g,34291
35
35
  ragaai_catalyst/tracers/agentic_tracing/examples/GameActivityEventPlanner.ipynb,sha256=QCMFJYbGX0fd9eMW4PqyQLZjyWuTXo7n1nqO_hMLf0s,4225
36
36
  ragaai_catalyst/tracers/agentic_tracing/examples/TravelPlanner.ipynb,sha256=fU3inXoemJbdTkGAQl_N1UwVEZ10LrKv4gCEpbQ4ISg,43481
@@ -50,7 +50,7 @@ ragaai_catalyst/tracers/instrumentators/llamaindex.py,sha256=SMrRlR4xM7k9HK43hak
50
50
  ragaai_catalyst/tracers/instrumentators/openai.py,sha256=14R4KW9wQCR1xysLfsP_nxS7cqXrTPoD8En4MBAaZUU,379
51
51
  ragaai_catalyst/tracers/utils/__init__.py,sha256=KeMaZtYaTojilpLv65qH08QmpYclfpacDA0U3wg6Ybw,64
52
52
  ragaai_catalyst/tracers/utils/utils.py,sha256=ViygfJ7vZ7U0CTSA1lbxVloHp4NSlmfDzBRNCJuMhis,2374
53
- ragaai_catalyst-2.1b2.dist-info/METADATA,sha256=Epkb-INU3JO8UmJXpehYK4lT3iqr62xjmf3nU1YbUI4,1795
54
- ragaai_catalyst-2.1b2.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
55
- ragaai_catalyst-2.1b2.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
56
- ragaai_catalyst-2.1b2.dist-info/RECORD,,
53
+ ragaai_catalyst-2.1b4.dist-info/METADATA,sha256=A9MMHw5G0oZq-8lh5mwo57hNwgYsOhM80wOXe418FDQ,1796
54
+ ragaai_catalyst-2.1b4.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
55
+ ragaai_catalyst-2.1b4.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
56
+ ragaai_catalyst-2.1b4.dist-info/RECORD,,