traceAI-agentscope 0.1.0__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.
- traceai_agentscope/__init__.py +7 -0
- traceai_agentscope/_lifecycle.py +320 -0
- traceai_agentscope/_middleware.py +63 -0
- traceai_agentscope/_projection.py +229 -0
- traceai_agentscope/py.typed +0 -0
- traceai_agentscope-0.1.0.dist-info/METADATA +94 -0
- traceai_agentscope-0.1.0.dist-info/RECORD +9 -0
- traceai_agentscope-0.1.0.dist-info/WHEEL +4 -0
- traceai_agentscope-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Export AgentScope's native OpenTelemetry spans to Future AGI."""
|
|
2
|
+
|
|
3
|
+
from ._lifecycle import Handle, configure
|
|
4
|
+
from ._middleware import TracingMiddleware
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0" # x-release-please-version
|
|
7
|
+
__all__ = ["configure", "Handle", "TracingMiddleware", "__version__"]
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"""One reusable processor per global provider, with bounded cleanup waits."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from collections import OrderedDict
|
|
7
|
+
from collections.abc import Mapping
|
|
8
|
+
from threading import Event, RLock, Thread
|
|
9
|
+
from weakref import WeakKeyDictionary
|
|
10
|
+
|
|
11
|
+
from opentelemetry import trace
|
|
12
|
+
from opentelemetry.sdk.trace import SpanProcessor, TracerProvider
|
|
13
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExporter
|
|
14
|
+
from opentelemetry.trace import ProxyTracerProvider
|
|
15
|
+
|
|
16
|
+
from ._projection import is_native, project
|
|
17
|
+
|
|
18
|
+
_logger = logging.getLogger(__name__)
|
|
19
|
+
_lock = RLock()
|
|
20
|
+
_slots: WeakKeyDictionary[TracerProvider, _Slot] = WeakKeyDictionary()
|
|
21
|
+
_configuring = False
|
|
22
|
+
_MAX_OPEN = 65536
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _timeout(value):
|
|
26
|
+
if type(value) is not int or value < 0 or value > 300000:
|
|
27
|
+
raise ValueError("timeout_millis must be an integer between 0 and 300000")
|
|
28
|
+
return value / 1000
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _key(span):
|
|
32
|
+
context = span.context
|
|
33
|
+
return context.trace_id, context.span_id, span.start_time
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class _Pipeline:
|
|
37
|
+
def __init__(self, exporter, signature, project_name, capture_content):
|
|
38
|
+
self.signature = signature
|
|
39
|
+
self.project_name, self.capture_content = project_name, capture_content
|
|
40
|
+
# Only projected copies enter this queue. SDK defaults overridden to bound memory.
|
|
41
|
+
self.processor = BatchSpanProcessor(
|
|
42
|
+
exporter,
|
|
43
|
+
max_queue_size=2048,
|
|
44
|
+
max_export_batch_size=512,
|
|
45
|
+
schedule_delay_millis=5000,
|
|
46
|
+
export_timeout_millis=10000,
|
|
47
|
+
)
|
|
48
|
+
self.lock = RLock()
|
|
49
|
+
self.closed = False
|
|
50
|
+
self.done = Event()
|
|
51
|
+
self.close_ok = False
|
|
52
|
+
self.flush_done = Event()
|
|
53
|
+
self.flush_done.set()
|
|
54
|
+
self.flush_ok = True
|
|
55
|
+
|
|
56
|
+
def force_flush(self, timeout_millis):
|
|
57
|
+
seconds = _timeout(timeout_millis)
|
|
58
|
+
with self.lock:
|
|
59
|
+
if self.closed:
|
|
60
|
+
return self.done.is_set() and self.close_ok
|
|
61
|
+
if self.flush_done.is_set():
|
|
62
|
+
self.flush_ok = False
|
|
63
|
+
self.flush_done.clear()
|
|
64
|
+
# Some SDK versions/exporters ignore flush deadlines. One worker at a
|
|
65
|
+
# time limits callers' wait without accumulating blocked flush threads.
|
|
66
|
+
Thread(
|
|
67
|
+
target=self._flush,
|
|
68
|
+
args=(timeout_millis,),
|
|
69
|
+
daemon=True,
|
|
70
|
+
name="traceai-agentscope-flush",
|
|
71
|
+
).start()
|
|
72
|
+
return self.flush_done.wait(seconds) and self.flush_ok
|
|
73
|
+
|
|
74
|
+
def _flush(self, timeout_millis):
|
|
75
|
+
try:
|
|
76
|
+
self.flush_ok = bool(self.processor.force_flush(timeout_millis))
|
|
77
|
+
except Exception:
|
|
78
|
+
# Exception values/stacks may contain application data or credentials.
|
|
79
|
+
_logger.warning("AgentScope exporter flush failed; details withheld")
|
|
80
|
+
self.flush_ok = False
|
|
81
|
+
finally:
|
|
82
|
+
self.flush_done.set()
|
|
83
|
+
|
|
84
|
+
def shutdown(self, timeout_millis):
|
|
85
|
+
seconds = _timeout(timeout_millis)
|
|
86
|
+
with self.lock:
|
|
87
|
+
if not self.closed:
|
|
88
|
+
self.closed = True
|
|
89
|
+
Thread(
|
|
90
|
+
target=self._close, daemon=True, name="traceai-agentscope-close"
|
|
91
|
+
).start()
|
|
92
|
+
return self.done.wait(seconds) and self.close_ok
|
|
93
|
+
|
|
94
|
+
def _close(self):
|
|
95
|
+
try:
|
|
96
|
+
# Avoid concurrent exporter teardown and an outstanding explicit flush.
|
|
97
|
+
self.flush_done.wait()
|
|
98
|
+
self.processor.shutdown()
|
|
99
|
+
self.close_ok = True
|
|
100
|
+
except Exception:
|
|
101
|
+
_logger.warning("AgentScope exporter shutdown failed; details withheld")
|
|
102
|
+
self.close_ok = False
|
|
103
|
+
finally:
|
|
104
|
+
self.done.set()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class _Slot(SpanProcessor):
|
|
108
|
+
def __init__(self, owns_provider):
|
|
109
|
+
self.lock = RLock()
|
|
110
|
+
self.pipeline = None
|
|
111
|
+
self.closing = None
|
|
112
|
+
self.stopped = False
|
|
113
|
+
self.owns_provider = owns_provider
|
|
114
|
+
self.open = OrderedDict()
|
|
115
|
+
|
|
116
|
+
def on_start(self, span, parent_context=None):
|
|
117
|
+
if not is_native(span):
|
|
118
|
+
return
|
|
119
|
+
with self.lock:
|
|
120
|
+
if self.pipeline is not None:
|
|
121
|
+
key = _key(span)
|
|
122
|
+
# A collision cannot safely be attributed to either operation.
|
|
123
|
+
if key in self.open:
|
|
124
|
+
self.open[key] = None
|
|
125
|
+
else:
|
|
126
|
+
if len(self.open) >= _MAX_OPEN:
|
|
127
|
+
self.open.popitem(last=False)
|
|
128
|
+
self.open[key] = self.pipeline
|
|
129
|
+
|
|
130
|
+
def on_end(self, span):
|
|
131
|
+
with self.lock:
|
|
132
|
+
pipeline = self.open.pop(_key(span), None)
|
|
133
|
+
if pipeline is None:
|
|
134
|
+
return
|
|
135
|
+
try:
|
|
136
|
+
projected = project(span, pipeline.project_name, pipeline.capture_content)
|
|
137
|
+
except Exception:
|
|
138
|
+
# Fail closed. No native content or exception values in diagnostics.
|
|
139
|
+
_logger.warning(
|
|
140
|
+
"AgentScope span projection failed; span dropped, details withheld"
|
|
141
|
+
)
|
|
142
|
+
return
|
|
143
|
+
if projected is not None:
|
|
144
|
+
with self.lock:
|
|
145
|
+
if self.pipeline is pipeline:
|
|
146
|
+
# The SDK on_end only enqueues; no exporter/user code under this lock.
|
|
147
|
+
pipeline.processor.on_end(projected)
|
|
148
|
+
|
|
149
|
+
def detach(self, pipeline, timeout_millis):
|
|
150
|
+
_timeout(timeout_millis)
|
|
151
|
+
with self.lock:
|
|
152
|
+
if self.pipeline is pipeline:
|
|
153
|
+
self.pipeline = None
|
|
154
|
+
self.closing = pipeline
|
|
155
|
+
self.open.clear()
|
|
156
|
+
elif self.pipeline is None and self.closing is None:
|
|
157
|
+
# A failed attachment may have registered an inactive slot.
|
|
158
|
+
self.closing = pipeline
|
|
159
|
+
return pipeline.shutdown(timeout_millis)
|
|
160
|
+
|
|
161
|
+
def force_flush(self, timeout_millis=30000):
|
|
162
|
+
with self.lock:
|
|
163
|
+
pipeline = self.pipeline
|
|
164
|
+
return True if pipeline is None else pipeline.force_flush(timeout_millis)
|
|
165
|
+
|
|
166
|
+
def shutdown(self):
|
|
167
|
+
with self.lock:
|
|
168
|
+
self.stopped = True
|
|
169
|
+
pipeline = self.pipeline or self.closing
|
|
170
|
+
if pipeline is not None:
|
|
171
|
+
self.detach(pipeline, 5000)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class Handle:
|
|
175
|
+
"""Own this destination, not the application's global provider.
|
|
176
|
+
|
|
177
|
+
Both lifecycle methods return False on a deadline or cleanup failure. A flush
|
|
178
|
+
reports queue drainage, not remote delivery. End spans before shutdown.
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
provider: TracerProvider
|
|
182
|
+
owns_provider: bool
|
|
183
|
+
|
|
184
|
+
def __init__(
|
|
185
|
+
self, provider: TracerProvider, slot: _Slot, pipeline: _Pipeline
|
|
186
|
+
) -> None:
|
|
187
|
+
self.provider = provider
|
|
188
|
+
self.owns_provider = slot.owns_provider
|
|
189
|
+
self._slot, self._pipeline = slot, pipeline
|
|
190
|
+
|
|
191
|
+
def force_flush(self, timeout_millis: int = 5000) -> bool:
|
|
192
|
+
return self._pipeline.force_flush(timeout_millis)
|
|
193
|
+
|
|
194
|
+
def shutdown(self, timeout_millis: int = 5000) -> bool:
|
|
195
|
+
return self._slot.detach(self._pipeline, timeout_millis)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def configure(
|
|
199
|
+
*,
|
|
200
|
+
project_name: str,
|
|
201
|
+
capture_content: bool = False,
|
|
202
|
+
provider: TracerProvider | None = None,
|
|
203
|
+
endpoint: str | None = None,
|
|
204
|
+
headers: Mapping[str, str] | None = None,
|
|
205
|
+
exporter: SpanExporter | None = None,
|
|
206
|
+
) -> Handle:
|
|
207
|
+
"""Reuse the global SDK provider or install one if none has been registered.
|
|
208
|
+
|
|
209
|
+
A supplied provider must already be global, or is installed if OTel still uses
|
|
210
|
+
its default proxy. Never replaces a live provider. A supplied exporter becomes
|
|
211
|
+
this handle's responsibility only after validation; other processors are untouched.
|
|
212
|
+
"""
|
|
213
|
+
if not isinstance(project_name, str) or not project_name.strip():
|
|
214
|
+
raise ValueError("project_name must be a nonempty string")
|
|
215
|
+
if type(capture_content) is not bool:
|
|
216
|
+
raise TypeError("capture_content must be a bool")
|
|
217
|
+
if endpoint is not None and (not isinstance(endpoint, str) or not endpoint):
|
|
218
|
+
raise ValueError("endpoint must be a nonempty string")
|
|
219
|
+
if headers is not None and (
|
|
220
|
+
not isinstance(headers, Mapping)
|
|
221
|
+
or not all(
|
|
222
|
+
isinstance(k, str) and isinstance(v, str) for k, v in headers.items()
|
|
223
|
+
)
|
|
224
|
+
):
|
|
225
|
+
raise TypeError("headers must map strings to strings")
|
|
226
|
+
if exporter is not None:
|
|
227
|
+
if endpoint is not None or headers is not None:
|
|
228
|
+
raise ValueError("use exporter or endpoint/headers, not both")
|
|
229
|
+
if not all(
|
|
230
|
+
callable(getattr(exporter, m, None))
|
|
231
|
+
for m in ("export", "force_flush", "shutdown")
|
|
232
|
+
):
|
|
233
|
+
raise TypeError(
|
|
234
|
+
"exporter must implement the OpenTelemetry exporter interface"
|
|
235
|
+
)
|
|
236
|
+
signature = (
|
|
237
|
+
project_name,
|
|
238
|
+
capture_content,
|
|
239
|
+
endpoint,
|
|
240
|
+
tuple(sorted((headers or {}).items())),
|
|
241
|
+
id(exporter) if exporter is not None else None,
|
|
242
|
+
)
|
|
243
|
+
global _configuring
|
|
244
|
+
with _lock:
|
|
245
|
+
if _configuring:
|
|
246
|
+
raise RuntimeError("another AgentScope configure is in progress")
|
|
247
|
+
_configuring = True
|
|
248
|
+
pipeline = None
|
|
249
|
+
try:
|
|
250
|
+
current = trace.get_tracer_provider()
|
|
251
|
+
owns_provider = provider is None and isinstance(current, ProxyTracerProvider)
|
|
252
|
+
if provider is None:
|
|
253
|
+
if owns_provider:
|
|
254
|
+
provider = TracerProvider()
|
|
255
|
+
elif isinstance(current, TracerProvider):
|
|
256
|
+
provider = current
|
|
257
|
+
if not isinstance(provider, TracerProvider):
|
|
258
|
+
raise TypeError("AgentScope requires an OpenTelemetry SDK TracerProvider")
|
|
259
|
+
if not isinstance(current, ProxyTracerProvider) and current is not provider:
|
|
260
|
+
raise ValueError("provider must be the global provider used by AgentScope")
|
|
261
|
+
if getattr(provider, "_default_processor", False):
|
|
262
|
+
raise ValueError(
|
|
263
|
+
"provider must not replace existing processors when one is added"
|
|
264
|
+
)
|
|
265
|
+
if getattr(provider, "_disabled", False):
|
|
266
|
+
raise ValueError("the OpenTelemetry SDK is disabled")
|
|
267
|
+
with _lock:
|
|
268
|
+
slot = _slots.get(provider)
|
|
269
|
+
if slot is not None:
|
|
270
|
+
with slot.lock:
|
|
271
|
+
if slot.stopped:
|
|
272
|
+
raise RuntimeError("provider has been shut down")
|
|
273
|
+
if slot.pipeline is not None:
|
|
274
|
+
if slot.pipeline.signature != signature:
|
|
275
|
+
raise ValueError(
|
|
276
|
+
"already configured with different options; shut down first"
|
|
277
|
+
)
|
|
278
|
+
return Handle(provider, slot, slot.pipeline)
|
|
279
|
+
if slot.closing is not None and not slot.closing.done.is_set():
|
|
280
|
+
raise RuntimeError("previous exporter is still closing")
|
|
281
|
+
if exporter is None:
|
|
282
|
+
from fi_instrumentation.otel import HTTPSpanExporter
|
|
283
|
+
|
|
284
|
+
exporter = HTTPSpanExporter(endpoint=endpoint, headers=headers, timeout=10)
|
|
285
|
+
pipeline = _Pipeline(exporter, signature, project_name, capture_content)
|
|
286
|
+
if slot is None:
|
|
287
|
+
slot = _Slot(owns_provider)
|
|
288
|
+
try:
|
|
289
|
+
provider.add_span_processor(slot)
|
|
290
|
+
except BaseException:
|
|
291
|
+
# SDK subclasses can attach and then raise. Reuse an attached inactive
|
|
292
|
+
# slot on retry instead of silently accumulating duplicate processors.
|
|
293
|
+
active = getattr(provider, "_active_span_processor", None)
|
|
294
|
+
if slot in getattr(active, "_span_processors", ()):
|
|
295
|
+
with _lock:
|
|
296
|
+
_slots[provider] = slot
|
|
297
|
+
raise
|
|
298
|
+
with _lock:
|
|
299
|
+
_slots[provider] = slot
|
|
300
|
+
with slot.lock:
|
|
301
|
+
if slot.stopped:
|
|
302
|
+
raise RuntimeError("provider has been shut down")
|
|
303
|
+
slot.pipeline = pipeline
|
|
304
|
+
if isinstance(current, ProxyTracerProvider):
|
|
305
|
+
trace.set_tracer_provider(provider)
|
|
306
|
+
if trace.get_tracer_provider() is not provider:
|
|
307
|
+
raise RuntimeError(
|
|
308
|
+
"another provider won global registration; configure again"
|
|
309
|
+
)
|
|
310
|
+
handle = Handle(provider, slot, pipeline)
|
|
311
|
+
pipeline = None
|
|
312
|
+
return handle
|
|
313
|
+
finally:
|
|
314
|
+
if pipeline is not None:
|
|
315
|
+
if slot is not None:
|
|
316
|
+
slot.detach(pipeline, 0)
|
|
317
|
+
else:
|
|
318
|
+
pipeline.shutdown(0)
|
|
319
|
+
with _lock:
|
|
320
|
+
_configuring = False
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Use native spans, adding only the missing metadata signal for tool errors."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import AsyncGenerator, Callable
|
|
4
|
+
from typing import TYPE_CHECKING, Any
|
|
5
|
+
|
|
6
|
+
from agentscope.message import ToolCallBlock, ToolResultBlock, ToolResultState
|
|
7
|
+
from agentscope.middleware import TracingMiddleware as NativeTracingMiddleware
|
|
8
|
+
from agentscope.tool import ToolChunk, ToolResponse
|
|
9
|
+
from opentelemetry import trace
|
|
10
|
+
|
|
11
|
+
from ._projection import TOOL_ERROR
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from agentscope.agent import Agent
|
|
15
|
+
|
|
16
|
+
_ToolResult = ToolResultBlock | ToolChunk | ToolResponse
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TracingMiddleware(NativeTracingMiddleware):
|
|
20
|
+
"""Native AgentScope middleware with returned tool errors marked on its span.
|
|
21
|
+
|
|
22
|
+
No new spans and no model SDK instrumentation. Use one instance in place of
|
|
23
|
+
(not alongside) AgentScope's TracingMiddleware.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
async def on_acting(
|
|
27
|
+
self,
|
|
28
|
+
agent: "Agent",
|
|
29
|
+
input_kwargs: dict[str, Any],
|
|
30
|
+
next_handler: Callable[..., AsyncGenerator[_ToolResult, None]],
|
|
31
|
+
) -> AsyncGenerator[_ToolResult, None]:
|
|
32
|
+
async def observe_result(**kwargs):
|
|
33
|
+
gen = next_handler(**kwargs)
|
|
34
|
+
try:
|
|
35
|
+
async for item in gen:
|
|
36
|
+
if (
|
|
37
|
+
isinstance(input_kwargs.get("tool_call"), ToolCallBlock)
|
|
38
|
+
and isinstance(item, (ToolResultBlock, ToolChunk, ToolResponse))
|
|
39
|
+
and item.state == ToolResultState.ERROR
|
|
40
|
+
):
|
|
41
|
+
# Native middleware advances this iterator with its tool span current.
|
|
42
|
+
# Do not mark an unrelated parent when native tracing short-circuits.
|
|
43
|
+
span = trace.get_current_span()
|
|
44
|
+
scope = getattr(span, "instrumentation_scope", None)
|
|
45
|
+
if (
|
|
46
|
+
scope is not None
|
|
47
|
+
and scope.name == "agentscope"
|
|
48
|
+
and (getattr(span, "attributes", None) or {}).get(
|
|
49
|
+
"gen_ai.operation.name"
|
|
50
|
+
)
|
|
51
|
+
== "execute_tool"
|
|
52
|
+
):
|
|
53
|
+
span.set_attribute(TOOL_ERROR, True)
|
|
54
|
+
yield item
|
|
55
|
+
finally:
|
|
56
|
+
await gen.aclose()
|
|
57
|
+
|
|
58
|
+
gen = super().on_acting(agent, input_kwargs, observe_result)
|
|
59
|
+
try:
|
|
60
|
+
async for item in gen:
|
|
61
|
+
yield item
|
|
62
|
+
finally:
|
|
63
|
+
await gen.aclose()
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"""Destination-local projection; never mutate the native span or its provider."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import math
|
|
5
|
+
import re
|
|
6
|
+
from typing import TypeGuard
|
|
7
|
+
|
|
8
|
+
from opentelemetry.sdk.resources import Resource
|
|
9
|
+
from opentelemetry.sdk.trace import Event, ReadableSpan
|
|
10
|
+
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
|
|
11
|
+
from opentelemetry.trace import Link, SpanContext, Status, StatusCode
|
|
12
|
+
|
|
13
|
+
KINDS = {"invoke_agent": "AGENT", "chat": "LLM", "execute_tool": "TOOL"}
|
|
14
|
+
TOOL_ERROR = "traceai.agentscope.tool.error"
|
|
15
|
+
MAX_CONTENT = 65536
|
|
16
|
+
_IDENTIFIERS = frozenset(
|
|
17
|
+
{
|
|
18
|
+
"gen_ai.conversation.id",
|
|
19
|
+
"gen_ai.provider.name",
|
|
20
|
+
"gen_ai.request.model",
|
|
21
|
+
"gen_ai.agent.name",
|
|
22
|
+
"gen_ai.tool.name",
|
|
23
|
+
"gen_ai.tool.call.id",
|
|
24
|
+
"gen_ai.response.id",
|
|
25
|
+
"agentscope.agent.reply_id",
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
_NUMBERS = frozenset(
|
|
29
|
+
{
|
|
30
|
+
"gen_ai.request.temperature",
|
|
31
|
+
"gen_ai.request.top_p",
|
|
32
|
+
"gen_ai.request.top_k",
|
|
33
|
+
"gen_ai.request.max_tokens",
|
|
34
|
+
"gen_ai.request.presence_penalty",
|
|
35
|
+
"gen_ai.request.frequency_penalty",
|
|
36
|
+
"gen_ai.request.seed",
|
|
37
|
+
"gen_ai.usage.input_tokens",
|
|
38
|
+
"gen_ai.usage.output_tokens",
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
_CONTENT = frozenset(
|
|
42
|
+
{
|
|
43
|
+
"gen_ai.input.messages",
|
|
44
|
+
"gen_ai.output.messages",
|
|
45
|
+
"gen_ai.tool.call.arguments",
|
|
46
|
+
"gen_ai.tool.call.result",
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
# Field-name redaction, not free-text secret detection. Token-count keys are not credentials.
|
|
50
|
+
_PRIVATE_KEY = re.compile(
|
|
51
|
+
r"(?:apikey|authorization|password|passwd|credential|clientsecret|secretkey|"
|
|
52
|
+
r"privatekey|accesstoken|refreshtoken|authtoken|bearertoken|idtoken|sessiontoken|"
|
|
53
|
+
r"securitytoken|accesskeyid|secretaccesskey|stacktrace|traceback)"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _identifier(value: object) -> TypeGuard[str]:
|
|
58
|
+
return (
|
|
59
|
+
isinstance(value, str)
|
|
60
|
+
and 0 < len(value) <= 256
|
|
61
|
+
and all(c.isascii() and (c.isalnum() or c in "._-/:@") for c in value)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _number(value):
|
|
66
|
+
return (type(value) is int and -(2**63) <= value < 2**63) or (
|
|
67
|
+
type(value) is float and math.isfinite(value)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _redact(value, depth=0):
|
|
72
|
+
if depth > 16:
|
|
73
|
+
raise ValueError("content nesting limit")
|
|
74
|
+
if isinstance(value, dict):
|
|
75
|
+
return {
|
|
76
|
+
key: (
|
|
77
|
+
"[REDACTED]"
|
|
78
|
+
if _PRIVATE_KEY.search(re.sub(r"[^a-z0-9]", "", key.lower()))
|
|
79
|
+
or key.lower() in {"token", "secret"}
|
|
80
|
+
else _redact(item, depth + 1)
|
|
81
|
+
)
|
|
82
|
+
for key, item in value.items()
|
|
83
|
+
}
|
|
84
|
+
if isinstance(value, list):
|
|
85
|
+
return [_redact(item, depth + 1) for item in value]
|
|
86
|
+
if isinstance(value, str) and value.lstrip().startswith(("{", "[")):
|
|
87
|
+
# Tool arguments can be JSON serialized inside a message's JSON document.
|
|
88
|
+
try:
|
|
89
|
+
nested = json.loads(value)
|
|
90
|
+
except (ValueError, RecursionError):
|
|
91
|
+
# Do not leak a truncated structured payload that might contain credentials.
|
|
92
|
+
return "[OMITTED]"
|
|
93
|
+
return json.dumps(
|
|
94
|
+
_redact(nested, depth + 1), ensure_ascii=False, allow_nan=False
|
|
95
|
+
)
|
|
96
|
+
return value
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _content(value):
|
|
100
|
+
if not isinstance(value, str) or len(value) > MAX_CONTENT:
|
|
101
|
+
return None
|
|
102
|
+
try:
|
|
103
|
+
decoded = json.loads(value)
|
|
104
|
+
if not isinstance(decoded, (dict, list)):
|
|
105
|
+
# AgentScope 2.0.10 serializes tool objects as opaque repr strings.
|
|
106
|
+
# These cannot be field-redacted safely; never parse/eval a repr.
|
|
107
|
+
return None
|
|
108
|
+
return json.dumps(_redact(decoded), ensure_ascii=False, allow_nan=False)
|
|
109
|
+
except (ValueError, TypeError, RecursionError):
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _context(context):
|
|
114
|
+
if context is None:
|
|
115
|
+
return None
|
|
116
|
+
# Tracestate can carry arbitrary vendor content. IDs and sampling are enough here.
|
|
117
|
+
return SpanContext(
|
|
118
|
+
context.trace_id, context.span_id, context.is_remote, context.trace_flags
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def is_native(span: ReadableSpan) -> bool:
|
|
123
|
+
scope = span.instrumentation_scope
|
|
124
|
+
attrs = span.attributes or {}
|
|
125
|
+
operation = attrs.get("gen_ai.operation.name")
|
|
126
|
+
return (
|
|
127
|
+
scope is not None
|
|
128
|
+
and scope.name == "agentscope"
|
|
129
|
+
and isinstance(operation, str)
|
|
130
|
+
and operation in KINDS
|
|
131
|
+
and not attrs.get("agentscope.agent.is_external_execution", False)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def project(
|
|
136
|
+
span: ReadableSpan, project_name: str, capture_content: bool
|
|
137
|
+
) -> ReadableSpan | None:
|
|
138
|
+
"""Return an allowlisted copy of one real native operation, or None.
|
|
139
|
+
|
|
140
|
+
Native external-execution receipt spans are synthetic (no execution timing).
|
|
141
|
+
They and unrelated instrumentation never go to this destination.
|
|
142
|
+
"""
|
|
143
|
+
if not is_native(span):
|
|
144
|
+
return None
|
|
145
|
+
attrs = span.attributes or {}
|
|
146
|
+
operation = attrs["gen_ai.operation.name"]
|
|
147
|
+
assert isinstance(operation, str) # validated by is_native
|
|
148
|
+
out = {
|
|
149
|
+
key: value
|
|
150
|
+
for key, value in attrs.items()
|
|
151
|
+
if (key in _IDENTIFIERS and _identifier(value))
|
|
152
|
+
or (key in _NUMBERS and _number(value))
|
|
153
|
+
}
|
|
154
|
+
out["gen_ai.operation.name"] = operation
|
|
155
|
+
out["fi.span.kind"] = KINDS[operation]
|
|
156
|
+
if "gen_ai.conversation.id" in out:
|
|
157
|
+
out["session.id"] = out["gen_ai.conversation.id"]
|
|
158
|
+
if operation != "chat":
|
|
159
|
+
# Usage belongs only to the native model call, never aggregate it onto parents.
|
|
160
|
+
out.pop("gen_ai.usage.input_tokens", None)
|
|
161
|
+
out.pop("gen_ai.usage.output_tokens", None)
|
|
162
|
+
|
|
163
|
+
code = span.status.status_code
|
|
164
|
+
if operation == "execute_tool" and attrs.get(TOOL_ERROR) is True:
|
|
165
|
+
code = StatusCode.ERROR
|
|
166
|
+
out[TOOL_ERROR] = True
|
|
167
|
+
|
|
168
|
+
if capture_content:
|
|
169
|
+
for key in _CONTENT:
|
|
170
|
+
value = _content(attrs.get(key))
|
|
171
|
+
if value is not None:
|
|
172
|
+
out[key] = value
|
|
173
|
+
for direction, source in (
|
|
174
|
+
(
|
|
175
|
+
"input",
|
|
176
|
+
"gen_ai.tool.call.arguments"
|
|
177
|
+
if operation == "execute_tool"
|
|
178
|
+
else "gen_ai.input.messages",
|
|
179
|
+
),
|
|
180
|
+
(
|
|
181
|
+
"output",
|
|
182
|
+
"gen_ai.tool.call.result"
|
|
183
|
+
if operation == "execute_tool"
|
|
184
|
+
else "gen_ai.output.messages",
|
|
185
|
+
),
|
|
186
|
+
):
|
|
187
|
+
if source in out:
|
|
188
|
+
out[direction + ".value"] = out[source]
|
|
189
|
+
out[direction + ".mime_type"] = "application/json"
|
|
190
|
+
|
|
191
|
+
# Names, resources, scope attributes, status descriptions, events and links are all
|
|
192
|
+
# potential content channels. Reconstruct them instead of proxying the original.
|
|
193
|
+
name_key = {
|
|
194
|
+
"invoke_agent": "gen_ai.agent.name",
|
|
195
|
+
"chat": "gen_ai.request.model",
|
|
196
|
+
"execute_tool": "gen_ai.tool.name",
|
|
197
|
+
}[operation]
|
|
198
|
+
identifier = out.get(name_key)
|
|
199
|
+
name = operation + (" " + identifier if isinstance(identifier, str) else "")
|
|
200
|
+
events = []
|
|
201
|
+
for event in span.events:
|
|
202
|
+
if event.name == "exception":
|
|
203
|
+
exception_type = (event.attributes or {}).get("exception.type")
|
|
204
|
+
safe = (
|
|
205
|
+
{"exception.type": exception_type}
|
|
206
|
+
if _identifier(exception_type)
|
|
207
|
+
else {}
|
|
208
|
+
)
|
|
209
|
+
events.append(Event("exception", safe, event.timestamp))
|
|
210
|
+
return ReadableSpan(
|
|
211
|
+
name=name,
|
|
212
|
+
context=_context(span.context),
|
|
213
|
+
parent=_context(span.parent),
|
|
214
|
+
resource=Resource(
|
|
215
|
+
{
|
|
216
|
+
"project_name": project_name,
|
|
217
|
+
"project_type": "observe",
|
|
218
|
+
"service.name": "agentscope",
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
attributes=out,
|
|
222
|
+
events=events,
|
|
223
|
+
links=[Link(_context(link.context), {}) for link in span.links],
|
|
224
|
+
kind=span.kind,
|
|
225
|
+
status=Status(code),
|
|
226
|
+
start_time=span.start_time,
|
|
227
|
+
end_time=span.end_time,
|
|
228
|
+
instrumentation_scope=InstrumentationScope("agentscope"),
|
|
229
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: traceAI-agentscope
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Future AGI adapter for AgentScope native OpenTelemetry tracing
|
|
5
|
+
Project-URL: Repository, https://github.com/future-agi/traceAI
|
|
6
|
+
Project-URL: Documentation, https://docs.futureagi.com/docs/integrations/frameworks/agentscope
|
|
7
|
+
Author-email: Future AGI <no-reply@futureagi.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: <3.14,>=3.11
|
|
11
|
+
Requires-Dist: agentscope<2.1,>=2.0.10
|
|
12
|
+
Requires-Dist: fi-instrumentation-otel<2,>=1.2.2
|
|
13
|
+
Requires-Dist: opentelemetry-sdk<2,>=1.39
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: build<2,>=1.2; extra == 'dev'
|
|
16
|
+
Requires-Dist: hatchling<2,>=1.27; extra == 'dev'
|
|
17
|
+
Requires-Dist: mypy<2,>=1.15; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest<9,>=8; extra == 'dev'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# traceAI-agentscope
|
|
22
|
+
|
|
23
|
+
Send AgentScope's native reply, model-call and tool-execution spans to Future AGI. This adapter uses AgentScope's `TracingMiddleware`; it does not wrap model SDKs or create a second set of spans.
|
|
24
|
+
|
|
25
|
+
Requires Python 3.11–3.13 and AgentScope 2.0.10–2.0.x.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install traceAI-agentscope
|
|
29
|
+
export FI_API_KEY="YOUR_FI_API_KEY"
|
|
30
|
+
export FI_SECRET_KEY="YOUR_FI_SECRET_KEY"
|
|
31
|
+
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import asyncio
|
|
36
|
+
import os
|
|
37
|
+
|
|
38
|
+
from agentscope.agent import Agent
|
|
39
|
+
from agentscope.credential import OpenAICredential
|
|
40
|
+
from agentscope.message import UserMsg
|
|
41
|
+
from agentscope.model import OpenAIChatModel
|
|
42
|
+
from agentscope.state import AgentState
|
|
43
|
+
from traceai_agentscope import configure, TracingMiddleware
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def main():
|
|
47
|
+
tracing = configure(project_name="support-agent")
|
|
48
|
+
try:
|
|
49
|
+
agent = Agent(
|
|
50
|
+
name="support",
|
|
51
|
+
system_prompt="Explain technical concepts in one short paragraph.",
|
|
52
|
+
model=OpenAIChatModel(
|
|
53
|
+
credential=OpenAICredential(api_key=os.environ["OPENAI_API_KEY"]),
|
|
54
|
+
model="gpt-4o-mini",
|
|
55
|
+
),
|
|
56
|
+
state=AgentState(session_id="support-session-001"),
|
|
57
|
+
middlewares=[TracingMiddleware()],
|
|
58
|
+
)
|
|
59
|
+
answer = await agent.reply(UserMsg(name="user", content="What is a trace?"))
|
|
60
|
+
print(answer)
|
|
61
|
+
finally:
|
|
62
|
+
# Lifecycle methods are synchronous; keep blocking work off your async loop.
|
|
63
|
+
await asyncio.to_thread(tracing.shutdown, 5000)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
asyncio.run(main())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Open **Observe** and select `support-agent`. Replies are `AGENT` spans, model calls are `LLM` spans, and tool executions are `TOOL` spans. Native trace IDs, parentage and timing are preserved. Model token counts stay on model spans. The native conversation ID is also exported as `session.id`; use an opaque session identifier, not an email address or prompt.
|
|
70
|
+
|
|
71
|
+
Use the adapter middleware **instead of**, not alongside, the native `TracingMiddleware`. Configuration alone does not correct the native middleware's returned-tool-error status. Do not also instrument the model SDK for the same calls. Returned tool results with `state=ERROR` (`ToolResultBlock`, `ToolChunk`, or `ToolResponse`) are marked as errors at this destination, including intermediate streamed results. Exception messages and stacks remain excluded. Native synthetic spans for receipts of externally executed tools are not exported: they do not measure execution of those tools.
|
|
72
|
+
|
|
73
|
+
## Content controls
|
|
74
|
+
|
|
75
|
+
Metadata-only is the default. Recognized operational identifiers and numeric settings are retained; arbitrary attributes, resource fields, link attributes, scope attributes, status descriptions and event payloads are not forwarded. Span names are rebuilt from the operation and an allowlisted identifier. Names, model identifiers and session IDs are metadata, not automatically anonymized; keep sensitive data out of them.
|
|
76
|
+
|
|
77
|
+
Set `capture_content=True` in `configure` to include native messages and tool arguments/results, with `input.value` and `output.value` aliases. Known credential and stacktrace fields in structured content are redacted, including nested JSON strings. This is **not** a free-text secret detector: messages and tool output can contain personal data or credentials in prose. Enable content capture only for approved application data. Malformed, overly nested or oversized structured values (over 65,536 characters) are omitted. AgentScope 2.0.10 emits tool results as opaque object representations, which are also omitted; upgrade to 2.0.11 to capture structured tool output.
|
|
78
|
+
|
|
79
|
+
Filtering applies only to this adapter's destination, before its export queue. AgentScope records content in memory unconditionally. Other processors on the global provider still receive the original native spans and need their own privacy controls.
|
|
80
|
+
|
|
81
|
+
## Provider and lifecycle
|
|
82
|
+
|
|
83
|
+
`configure` reuses the global OpenTelemetry SDK provider, or installs one when no provider is registered. An explicit `provider=` must be that global provider or be installed before any other provider. An incompatible or disabled provider is rejected rather than silently exporting nothing. Sampling and span limits belong to the provider; the adapter does not change them.
|
|
84
|
+
|
|
85
|
+
The returned handle exposes `provider` and `owns_provider` (whether the adapter created it). It owns only its export pipeline: shutdown never stops the provider or other destinations, including when the adapter created the provider. A global provider cannot be replaced, so the installed provider stays reusable.
|
|
86
|
+
|
|
87
|
+
- `force_flush(timeout_millis=5000)` drains ended spans without detaching.
|
|
88
|
+
- `shutdown(timeout_millis=5000)` detaches immediately, drains queued spans and closes the exporter. Call it after finishing your agent operations.
|
|
89
|
+
- Both return `False` on a deadline or cleanup failure; a successful flush means queue drainage, not confirmed delivery to Future AGI. Cleanup may finish in the background after a deadline.
|
|
90
|
+
- Repeated configuration with the same explicit options shares one pipeline. Different options require shutdown first. Do not change credentials through environment variables while a pipeline is active; shut it down and configure again.
|
|
91
|
+
- Spans already open when you configure, or still open when you shut down, are not exported. Reconfiguration does not adopt old spans. At most 65,536 open spans and 2,048 queued ended spans are retained; overload drops spans.
|
|
92
|
+
- Reconfiguration waits for previous cleanup to complete by rejecting attempts while it is still closing. Overlapping configuration calls fail fast. A provider shut down through OpenTelemetry cannot be reused.
|
|
93
|
+
|
|
94
|
+
`FI_BASE_URL` selects your Future AGI origin. Alternatively pass a full OTLP HTTP `endpoint` and `headers`, or a custom OpenTelemetry `exporter` (not both). The default exporter uses OTLP HTTP/protobuf with a 10-second request timeout. A custom exporter transfers to this pipeline and must implement `export`, `force_flush` and `shutdown`. Lifecycle deadlines bound callers' waits even for a stuck custom exporter; daemon cleanup cannot guarantee delivery on process termination.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
traceai_agentscope/__init__.py,sha256=YULYofaBdrCygkkoBy29l8Oh1x1OZ2fAwXlG1v3UXwg,275
|
|
2
|
+
traceai_agentscope/_lifecycle.py,sha256=RS9xxenFPwFR_l3KuPzHD7lgz34cgD61UkpZ2yBT8l4,12353
|
|
3
|
+
traceai_agentscope/_middleware.py,sha256=Sxl_gEgDSq8z73z6CDSAfhXR7qoCkkx1uRKkx8aW_Tk,2524
|
|
4
|
+
traceai_agentscope/_projection.py,sha256=-IHZB4Kvq4lwP56x6I5pc2EmrZHgWNzzmVJRsx0s_SM,7844
|
|
5
|
+
traceai_agentscope/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
traceai_agentscope-0.1.0.dist-info/METADATA,sha256=uEk7nTYvdifqvT-iYVLtqE63DC9eQNTyUbROsd1gpmg,6946
|
|
7
|
+
traceai_agentscope-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
8
|
+
traceai_agentscope-0.1.0.dist-info/licenses/LICENSE,sha256=MdFVOqVey1yWrQ7QcNxBkeYHdrsTUICh6lhmP3LxOEc,11308
|
|
9
|
+
traceai_agentscope-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for acceptance of support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However, in
|
|
169
|
+
accepting such obligations, You may act only on Your own behalf and on
|
|
170
|
+
Your sole responsibility, not on behalf of any other Contributor, and
|
|
171
|
+
only if You agree to indemnify, defend, and hold each Contributor
|
|
172
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
173
|
+
such Contributor by reason of your accepting any such warranty or
|
|
174
|
+
additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024-2026 Future AGI, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|