langtrace-python-sdk 2.2.30__py3-none-any.whl → 2.2.31__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.
@@ -28,5 +28,5 @@ class PoetryAgents:
28
28
  goal="""Create a poem that captures the essence of a given theme or emotion""",
29
29
  allow_delegation=False,
30
30
  verbose=True,
31
- llm=self.ollama,
31
+ llm=self.open_ai,
32
32
  )
@@ -1,14 +1,11 @@
1
1
  from crewai import Crew
2
- from textwrap import dedent
3
2
  from .agents import PoetryAgents
4
3
  from .tasks import PoetryTasks
5
4
  from langtrace_python_sdk import langtrace
6
5
  from dotenv import load_dotenv
7
- import agentops
8
6
 
9
7
  load_dotenv()
10
- agentops.init()
11
- langtrace.init(write_spans_to_console=False, batch=False)
8
+ langtrace.init()
12
9
 
13
10
 
14
11
  class PoetryCrew:
@@ -29,18 +26,11 @@ class PoetryCrew:
29
26
 
30
27
 
31
28
  # This is the main function that you will use to run your custom crew.
29
+ # You can run this file using `python -m src.examples.crewai_example.simple_agent.main`
32
30
  if __name__ == "__main__":
33
31
  print("## Welcome to Poetry Crew")
34
32
  print("-------------------------------")
35
- topic = input(
36
- dedent(
37
- """
38
- What topic do you want to write a poem on?
39
- """
40
- )
41
- )
42
-
43
- poetry_crew = PoetryCrew(topic=topic)
33
+ poetry_crew = PoetryCrew(topic="cold")
44
34
  result = poetry_crew.run()
45
35
  print("\n\n########################")
46
36
  print("## Here is you poem")
@@ -18,4 +18,5 @@ class PoetryTasks:
18
18
  ),
19
19
  expected_output="A creative and expressive poem that captures the essence of the given topic.",
20
20
  agent=agent,
21
+ output_file="poem.txt",
21
22
  )
@@ -1,5 +1,4 @@
1
1
  from crewai import Crew
2
- from textwrap import dedent
3
2
  from .agents import TravelAgents
4
3
  from .tasks import TravelTasks
5
4
  from langtrace_python_sdk import langtrace
@@ -59,36 +58,8 @@ class TripCrew:
59
58
  if __name__ == "__main__":
60
59
  print("## Welcome to Trip Planner Crew")
61
60
  print("-------------------------------")
62
- origin = input(
63
- dedent(
64
- """
65
- From where will you be traveling from?
66
- """
67
- )
68
- )
69
- cities = input(
70
- dedent(
71
- """
72
- What are the cities options you are interested in visiting?
73
- """
74
- )
75
- )
76
- date_range = input(
77
- dedent(
78
- """
79
- What is the date range you are interested in traveling?
80
- """
81
- )
82
- )
83
- interests = input(
84
- dedent(
85
- """
86
- What are some of your high level interests and hobbies?
87
- """
88
- )
89
- )
90
61
 
91
- trip_crew = TripCrew(origin, cities, date_range, interests)
62
+ trip_crew = TripCrew("cairo", "marsa alam", "sep", "scuba diving")
92
63
  result = trip_crew.run()
93
64
  print("\n\n########################")
94
65
  print("## Here is you Trip Plan")
@@ -46,7 +46,7 @@ class CrewAIInstrumentation(BaseInstrumentor):
46
46
  )
47
47
  _W(
48
48
  "crewai.task",
49
- "Task.execute",
49
+ "Task.execute_sync",
50
50
  patch_crew("Task.execute", version, tracer),
51
51
  )
52
52
  except Exception as e:
@@ -2,15 +2,14 @@ import json
2
2
  from importlib_metadata import version as v
3
3
  from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME
4
4
  from langtrace_python_sdk.utils import set_span_attribute
5
- from langtrace_python_sdk.utils.llm import get_span_name
6
- from langtrace_python_sdk.utils.silently_fail import silently_fail
5
+ from langtrace_python_sdk.utils.llm import get_span_name, set_span_attributes
7
6
  from langtrace_python_sdk.constants.instrumentation.common import (
8
7
  LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY,
9
8
  SERVICE_PROVIDERS,
10
9
  )
11
10
  from opentelemetry import baggage
12
11
  from langtrace.trace_attributes import FrameworkSpanAttributes
13
- from opentelemetry.trace import SpanKind
12
+ from opentelemetry.trace import SpanKind, Span, Tracer
14
13
  from opentelemetry.trace.status import Status, StatusCode
15
14
 
16
15
 
@@ -33,8 +32,8 @@ crew_properties = {
33
32
  "share_crew": "bool",
34
33
  "step_callback": "object",
35
34
  "task_callback": "object",
36
- "prompt_file": "object",
37
- "output_log_file": "object",
35
+ "prompt_file": "str",
36
+ "output_log_file": "bool",
38
37
  }
39
38
 
40
39
  task_properties = {
@@ -90,9 +89,8 @@ agent_properties = {
90
89
  }
91
90
 
92
91
 
93
- def patch_crew(operation_name, version, tracer):
92
+ def patch_crew(operation_name, version, tracer: Tracer):
94
93
  def traced_method(wrapped, instance, args, kwargs):
95
-
96
94
  service_provider = SERVICE_PROVIDERS["CREWAI"]
97
95
  extra_attributes = baggage.get_baggage(LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY)
98
96
  span_attributes = {
@@ -104,52 +102,15 @@ def patch_crew(operation_name, version, tracer):
104
102
  **(extra_attributes if extra_attributes is not None else {}),
105
103
  }
106
104
 
107
- crew_config = {}
108
- for key, value in instance.__dict__.items():
109
- if instance.__class__.__name__ == "Crew":
110
- if key in crew_properties and value is not None:
111
- if crew_properties[key] == "json":
112
- crew_config[key] = json.dumps(value)
113
- elif crew_properties[key] == "object":
114
- crew_config[key] = str(value)
115
- else:
116
- crew_config[key] = value
117
- elif instance.__class__.__name__ == "Agent":
118
- if key in agent_properties and value is not None:
119
- if agent_properties[key] == "json":
120
- crew_config[key] = json.dumps(value)
121
- elif agent_properties[key] == "object":
122
- crew_config[key] = str(value)
123
- else:
124
- crew_config[key] = value
125
- elif instance.__class__.__name__ == "Task":
126
- if key in task_properties and value is not None:
127
- if task_properties[key] == "json":
128
- crew_config[key] = json.dumps(value)
129
- elif task_properties[key] == "object":
130
- crew_config[key] = str(value)
131
- else:
132
- crew_config[key] = value
133
- if crew_config:
134
- if instance.__class__.__name__ == "Crew":
135
- if "inputs" in kwargs and kwargs["inputs"]:
136
- crew_config["inputs"] = json.dumps(kwargs["inputs"])
137
- span_attributes["crewai.crew.config"] = json.dumps(crew_config)
138
- elif instance.__class__.__name__ == "Agent":
139
- if "context" in kwargs and kwargs["context"]:
140
- crew_config["context"] = json.dumps(kwargs["context"])
141
- span_attributes["crewai.agent.config"] = json.dumps(crew_config)
142
- elif instance.__class__.__name__ == "Task":
143
- span_attributes["crewai.task.config"] = json.dumps(crew_config)
144
-
145
105
  attributes = FrameworkSpanAttributes(**span_attributes)
146
106
 
147
107
  with tracer.start_as_current_span(
148
108
  get_span_name(operation_name), kind=SpanKind.CLIENT
149
109
  ) as span:
150
- _set_input_attributes(span, kwargs, attributes)
151
110
 
152
111
  try:
112
+ set_span_attributes(span, attributes)
113
+ CrewAISpanAttributes(span=span, instance=instance)
153
114
  result = wrapped(*args, **kwargs)
154
115
  if result:
155
116
  span.set_status(Status(StatusCode.OK))
@@ -158,6 +119,7 @@ def patch_crew(operation_name, version, tracer):
158
119
  return result
159
120
 
160
121
  except Exception as err:
122
+ print("Error", err)
161
123
  # Record the exception in the span
162
124
  span.record_exception(err)
163
125
 
@@ -170,7 +132,103 @@ def patch_crew(operation_name, version, tracer):
170
132
  return traced_method
171
133
 
172
134
 
173
- @silently_fail
174
- def _set_input_attributes(span, kwargs, attributes):
175
- for field, value in attributes.model_dump(by_alias=True).items():
176
- set_span_attribute(span, field, value)
135
+ class CrewAISpanAttributes:
136
+ span: Span
137
+ crew: dict
138
+
139
+ def __init__(self, span: Span, instance) -> None:
140
+ self.span = span
141
+ self.instance = instance
142
+ self.crew = {
143
+ "tasks": [],
144
+ "agents": [],
145
+ }
146
+
147
+ self.run()
148
+
149
+ def run(self):
150
+ instance_name = self.instance.__class__.__name__
151
+ if instance_name == "Crew":
152
+ self.set_crew_attributes()
153
+ set_span_attribute(self.span, "crewai.crew.config", json.dumps(self.crew))
154
+
155
+ elif instance_name == "Agent":
156
+ agent = self.set_agent_attributes()
157
+ # for key, value in agent.items():
158
+ # set_span_attribute(self.span, key, value)
159
+ set_span_attribute(self.span, "crewai.agent.config", json.dumps(agent))
160
+ elif instance_name == "Task":
161
+ task = self.set_task_attributes()
162
+ # uncomment if you want to spread attributes for the UI instead of dumping the whole object
163
+ # for key, value in task.items():
164
+ # set_span_attribute(self.span, key, value)
165
+ set_span_attribute(self.span, "crewai.task.config", json.dumps(task))
166
+
167
+ def set_crew_attributes(self):
168
+ for key, value in self.instance.__dict__.items():
169
+ if key == "tasks":
170
+ self._parse_tasks(value)
171
+
172
+ elif key == "agents":
173
+ self._parse_agents(value)
174
+ else:
175
+ self.crew[key] = str(value)
176
+
177
+ def set_agent_attributes(self):
178
+ agent = {}
179
+ for key, value in self.instance.__dict__.items():
180
+ if value is None:
181
+ continue
182
+ agent[key] = str(value)
183
+
184
+ return agent
185
+
186
+ def set_task_attributes(self):
187
+ task = {}
188
+ for key, value in self.instance.__dict__.items():
189
+ if value is None:
190
+ continue
191
+
192
+ if key == "agent":
193
+ task[key] = value.role
194
+ else:
195
+ task[key] = str(value)
196
+ return task
197
+
198
+ def _parse_agents(self, agents):
199
+ for agent in agents:
200
+ model = None
201
+ if agent.llm is not None:
202
+ if hasattr(agent.llm, "model"):
203
+ model = agent.llm.model
204
+ elif hasattr(agent.llm, "model_name"):
205
+ model = agent.llm.model_name
206
+ self.crew["agents"].append(
207
+ {
208
+ "id": str(agent.id),
209
+ "role": agent.role,
210
+ "goal": agent.goal,
211
+ "backstory": agent.backstory,
212
+ "cache": agent.cache,
213
+ "config": agent.config,
214
+ "verbose": agent.verbose,
215
+ "allow_delegation": agent.allow_delegation,
216
+ "tools": agent.tools,
217
+ "max_iter": agent.max_iter,
218
+ "llm": str(model if model is not None else ""),
219
+ }
220
+ )
221
+
222
+ def _parse_tasks(self, tasks):
223
+ for task in tasks:
224
+ self.crew["tasks"].append(
225
+ {
226
+ "agent": task.agent.role,
227
+ "description": task.description,
228
+ "async_execution": task.async_execution,
229
+ "expected_output": task.expected_output,
230
+ "human_input": task.human_input,
231
+ "tools": task.tools,
232
+ "output_file": task.output_file,
233
+ }
234
+ )
@@ -1 +1 @@
1
- __version__ = "2.2.30"
1
+ __version__ = "2.2.31"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.2.30
3
+ Version: 2.2.31
4
4
  Summary: Python SDK for LangTrace
5
5
  Project-URL: Homepage, https://github.com/Scale3-Labs/langtrace-python-sdk
6
6
  Author-email: Scale3 Labs <engineering@scale3labs.com>
@@ -12,12 +12,12 @@ examples/cohere_example/tools.py,sha256=a5uvS058tcwU6PJbF9EDO6LPVmPj2LoW4Vn8Web3
12
12
  examples/crewai_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  examples/crewai_example/basic.py,sha256=PBu4f8yQfZO1L_22UDm_ReU9lnEcycjZcGuy5UpgDJM,1948
14
14
  examples/crewai_example/simple_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- examples/crewai_example/simple_agent/agents.py,sha256=Lq_5zeftH7TV-dsDRxfxi6sfE3t2mpQ4WulFh1FAFfs,1329
16
- examples/crewai_example/simple_agent/main.py,sha256=MJq3Xd24RIUHaSDAUpQtZb5ht5YUu5xPwgYxEY4moJk,1223
17
- examples/crewai_example/simple_agent/tasks.py,sha256=bfx_vP59akrrjNRUbVT7GDzdZlEqTQXAtGcCOCk_UFY,796
15
+ examples/crewai_example/simple_agent/agents.py,sha256=QU5kxiwja4_i508RpC8ZHHpc642ESY-NY6CW6FNgmlc,1330
16
+ examples/crewai_example/simple_agent/main.py,sha256=pL9VyZEFvu-ofBGuEQefPK07TlmCDzt9lYSigE6bZSk,1086
17
+ examples/crewai_example/simple_agent/tasks.py,sha256=JG5kPc9uBkZIDJCp0j3eporf6gnrKG3GZR5edHoeoxw,832
18
18
  examples/crewai_example/trip_planner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  examples/crewai_example/trip_planner/agents.py,sha256=bSmtD83qcB3PF21zjqdvAYe0vVvl0nhGVXX5oPeSGY8,2371
20
- examples/crewai_example/trip_planner/main.py,sha256=Ju001KRksiH1Svu6p83CfTybAPq9hruJVH9p3BmtG_c,2623
20
+ examples/crewai_example/trip_planner/main.py,sha256=dwEh60RABqaBodhkPr3lB7KS83f74WqaBjRB8YEO_jM,2056
21
21
  examples/crewai_example/trip_planner/tasks.py,sha256=ZGRaTAgkA66IN7q9EYbJqM8xWhUTxcF4ynnqTyBcSL4,5667
22
22
  examples/crewai_example/trip_planner/tools/calculator.py,sha256=bMfxJDAwbn6D26pe880S4BB3rcFeyvEyb15QR00T8kI,522
23
23
  examples/crewai_example/trip_planner/tools/search_tools.py,sha256=p8qZe_bi45OjBwiwwrH0lhTaQI_ZiLThSTEEN5dWxF0,2700
@@ -79,7 +79,7 @@ examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56sn
79
79
  examples/weaviate_example/query_text.py,sha256=wPHQTc_58kPoKTZMygVjTj-2ZcdrIuaausJfMxNQnQc,127162
80
80
  langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
81
81
  langtrace_python_sdk/langtrace.py,sha256=NOS2ws7P1Voc-zYSdO_mVb-Kea9_nD5Jq1dXY2CS97k,8208
82
- langtrace_python_sdk/version.py,sha256=3SFezL1kOpXZvo2YIaWEZ3PTHx1NRXGjgE666GlUfQE,23
82
+ langtrace_python_sdk/version.py,sha256=6OfMjX7CY3n2HJIxlcUwMMv6YFBAG7XhzkGCDFPOXkE,23
83
83
  langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
84
84
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
85
85
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -110,8 +110,8 @@ langtrace_python_sdk/instrumentation/cohere/__init__.py,sha256=sGUSLdTUyYf36Tm6L
110
110
  langtrace_python_sdk/instrumentation/cohere/instrumentation.py,sha256=YQFHZIBd7SSPD4b6Va-ZR0thf_AuBCqj5yzHLHJVWnM,2121
111
111
  langtrace_python_sdk/instrumentation/cohere/patch.py,sha256=Yb0OwxO4gG-WBfGhTFrwUUJEgpnRlyWI_FZveA4T1QU,20972
112
112
  langtrace_python_sdk/instrumentation/crewai/__init__.py,sha256=_UBKfvQv7l0g2_wnmA5F6CdSAFH0atNOVPd49zsN3aM,88
113
- langtrace_python_sdk/instrumentation/crewai/instrumentation.py,sha256=q07x6nnig9JPxDT6ZylyIShfXWjNafKBetnNcA1UdEU,1836
114
- langtrace_python_sdk/instrumentation/crewai/patch.py,sha256=4W7jEIJX4SJNViPlFTBJdSkvvPVJoI76Bb5DX673Ql8,6203
113
+ langtrace_python_sdk/instrumentation/crewai/instrumentation.py,sha256=tMzynrc1TGBM1Yq2psyOmRlJQdOKyJkl3WxFlUNF54E,1841
114
+ langtrace_python_sdk/instrumentation/crewai/patch.py,sha256=QY-RdbwQ9bRf-klacJH1f7EPmcssH_ABqK3HXI-XNHo,7503
115
115
  langtrace_python_sdk/instrumentation/dspy/__init__.py,sha256=tM1srfi_QgyCzrde4izojMrRq2Wm7Dj5QUvVQXIJzkk,84
116
116
  langtrace_python_sdk/instrumentation/dspy/instrumentation.py,sha256=o8URiDvCbZ8LL0I-4xKHkn_Ms2sETBRpn-gOliv3xzQ,2929
117
117
  langtrace_python_sdk/instrumentation/dspy/patch.py,sha256=E2P3MJBQ71or4M6BsvZOwYFtJK1UdTsYkdxVj9fSWPs,9869
@@ -209,8 +209,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
209
209
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
210
210
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
211
211
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
212
- langtrace_python_sdk-2.2.30.dist-info/METADATA,sha256=wupH7hIM1_hYrQHGpFOvcBwUnty3iiLnGKGt2ziNaDQ,14880
213
- langtrace_python_sdk-2.2.30.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
214
- langtrace_python_sdk-2.2.30.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
215
- langtrace_python_sdk-2.2.30.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
216
- langtrace_python_sdk-2.2.30.dist-info/RECORD,,
212
+ langtrace_python_sdk-2.2.31.dist-info/METADATA,sha256=TQNe1qMwc9TZw93UFcz6SL41taah8t4pemCrQFbQPLk,14880
213
+ langtrace_python_sdk-2.2.31.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
214
+ langtrace_python_sdk-2.2.31.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
215
+ langtrace_python_sdk-2.2.31.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
216
+ langtrace_python_sdk-2.2.31.dist-info/RECORD,,