aigie 0.1.2__tar.gz
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.
- aigie-0.1.2/PKG-INFO +316 -0
- aigie-0.1.2/README.md +241 -0
- aigie-0.1.2/aigie/__init__.py +1416 -0
- aigie-0.1.2/aigie/alerting.py +915 -0
- aigie-0.1.2/aigie/annotations.py +616 -0
- aigie-0.1.2/aigie/auto_instrument/__init__.py +132 -0
- aigie-0.1.2/aigie/auto_instrument/dspy.py +212 -0
- aigie-0.1.2/aigie/auto_instrument/haystack.py +543 -0
- aigie-0.1.2/aigie/auto_instrument/langchain.py +541 -0
- aigie-0.1.2/aigie/auto_instrument/langgraph.py +227 -0
- aigie-0.1.2/aigie/auto_instrument/llm.py +930 -0
- aigie-0.1.2/aigie/auto_instrument/tools.py +113 -0
- aigie-0.1.2/aigie/auto_instrument/trace.py +129 -0
- aigie-0.1.2/aigie/batch_evaluation.py +480 -0
- aigie-0.1.2/aigie/buffer.py +303 -0
- aigie-0.1.2/aigie/callback.py +2345 -0
- aigie-0.1.2/aigie/client.py +1626 -0
- aigie-0.1.2/aigie/compression.py +338 -0
- aigie-0.1.2/aigie/config.py +322 -0
- aigie-0.1.2/aigie/context.py +183 -0
- aigie-0.1.2/aigie/context_manager.py +368 -0
- aigie-0.1.2/aigie/cost_tracking.py +492 -0
- aigie-0.1.2/aigie/datasets.py +524 -0
- aigie-0.1.2/aigie/decorators.py +136 -0
- aigie-0.1.2/aigie/decorators_v2.py +477 -0
- aigie-0.1.2/aigie/decorators_v3.py +1189 -0
- aigie-0.1.2/aigie/drift/__init__.py +16 -0
- aigie-0.1.2/aigie/drift/monitor.py +786 -0
- aigie-0.1.2/aigie/evaluation.py +618 -0
- aigie-0.1.2/aigie/experiments.py +500 -0
- aigie-0.1.2/aigie/graph_view.py +868 -0
- aigie-0.1.2/aigie/interceptor/__init__.py +44 -0
- aigie-0.1.2/aigie/interceptor/chain.py +528 -0
- aigie-0.1.2/aigie/interceptor/context_tracker.py +349 -0
- aigie-0.1.2/aigie/interceptor/protocols.py +626 -0
- aigie-0.1.2/aigie/judge/__init__.py +47 -0
- aigie-0.1.2/aigie/judge/context_aggregator.py +627 -0
- aigie-0.1.2/aigie/judge/criteria.py +339 -0
- aigie-0.1.2/aigie/judge/evaluator.py +800 -0
- aigie-0.1.2/aigie/langgraph.py +870 -0
- aigie-0.1.2/aigie/leaderboards.py +830 -0
- aigie-0.1.2/aigie/licensing.py +470 -0
- aigie-0.1.2/aigie/metrics/__init__.py +36 -0
- aigie-0.1.2/aigie/metrics/base.py +162 -0
- aigie-0.1.2/aigie/metrics/checkpoint.py +336 -0
- aigie-0.1.2/aigie/metrics/drift.py +465 -0
- aigie-0.1.2/aigie/metrics/nested.py +299 -0
- aigie-0.1.2/aigie/metrics/recovery.py +464 -0
- aigie-0.1.2/aigie/metrics/reliability.py +223 -0
- aigie-0.1.2/aigie/metrics/types.py +71 -0
- aigie-0.1.2/aigie/observe.py +331 -0
- aigie-0.1.2/aigie/opentelemetry.py +293 -0
- aigie-0.1.2/aigie/playground.py +618 -0
- aigie-0.1.2/aigie/prompts.py +616 -0
- aigie-0.1.2/aigie/pytest_plugin.py +225 -0
- aigie-0.1.2/aigie/query_api.py +632 -0
- aigie-0.1.2/aigie/realtime/__init__.py +18 -0
- aigie-0.1.2/aigie/realtime/auto_fix.py +565 -0
- aigie-0.1.2/aigie/realtime/connector.py +590 -0
- aigie-0.1.2/aigie/rules/__init__.py +29 -0
- aigie-0.1.2/aigie/rules/builtin.py +424 -0
- aigie-0.1.2/aigie/rules/engine.py +430 -0
- aigie-0.1.2/aigie/runtime/__init__.py +36 -0
- aigie-0.1.2/aigie/runtime/remediation_loop.py +915 -0
- aigie-0.1.2/aigie/runtime/span_interceptor.py +644 -0
- aigie-0.1.2/aigie/safety_metrics.py +471 -0
- aigie-0.1.2/aigie/sampling.py +66 -0
- aigie-0.1.2/aigie/sessions.py +359 -0
- aigie-0.1.2/aigie/span.py +387 -0
- aigie-0.1.2/aigie/span_replay.py +783 -0
- aigie-0.1.2/aigie/streaming.py +166 -0
- aigie-0.1.2/aigie/summary_evaluators.py +551 -0
- aigie-0.1.2/aigie/sync_client.py +220 -0
- aigie-0.1.2/aigie/trace.py +643 -0
- aigie-0.1.2/aigie/types.py +100 -0
- aigie-0.1.2/aigie/uuid7.py +226 -0
- aigie-0.1.2/aigie/wrappers.py +784 -0
- aigie-0.1.2/aigie/wrappers_bedrock.py +370 -0
- aigie-0.1.2/aigie/wrappers_cohere.py +488 -0
- aigie-0.1.2/aigie.egg-info/PKG-INFO +316 -0
- aigie-0.1.2/aigie.egg-info/SOURCES.txt +87 -0
- aigie-0.1.2/aigie.egg-info/dependency_links.txt +1 -0
- aigie-0.1.2/aigie.egg-info/entry_points.txt +2 -0
- aigie-0.1.2/aigie.egg-info/not-zip-safe +1 -0
- aigie-0.1.2/aigie.egg-info/requires.txt +47 -0
- aigie-0.1.2/aigie.egg-info/top_level.txt +1 -0
- aigie-0.1.2/pyproject.toml +87 -0
- aigie-0.1.2/setup.cfg +4 -0
- aigie-0.1.2/setup.py +155 -0
aigie-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aigie
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Enterprise-grade AI agent reliability monitoring and autonomous remediation
|
|
5
|
+
Home-page: https://github.com/aigie/aigie-sdk
|
|
6
|
+
Author: Aigie Team
|
|
7
|
+
Author-email: support@aigie.io
|
|
8
|
+
Project-URL: Documentation, https://docs.aigie.io
|
|
9
|
+
Project-URL: Source, https://github.com/aigie/aigie-sdk
|
|
10
|
+
Project-URL: Tracker, https://github.com/aigie/aigie-sdk/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/aigie/aigie-sdk/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: ai agent monitoring observability llm reliability remediation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: httpx>=0.25.0
|
|
26
|
+
Provides-Extra: compression
|
|
27
|
+
Requires-Dist: zstandard>=0.22.0; extra == "compression"
|
|
28
|
+
Provides-Extra: openai
|
|
29
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
30
|
+
Provides-Extra: anthropic
|
|
31
|
+
Requires-Dist: anthropic>=0.18.0; extra == "anthropic"
|
|
32
|
+
Provides-Extra: gemini
|
|
33
|
+
Requires-Dist: google-generativeai>=0.3.0; extra == "gemini"
|
|
34
|
+
Provides-Extra: langchain
|
|
35
|
+
Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
|
|
36
|
+
Provides-Extra: opentelemetry
|
|
37
|
+
Requires-Dist: opentelemetry-api>=1.20.0; extra == "opentelemetry"
|
|
38
|
+
Requires-Dist: opentelemetry-sdk>=1.20.0; extra == "opentelemetry"
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest-httpx>=0.30.0; extra == "dev"
|
|
44
|
+
Requires-Dist: pytest-benchmark>=4.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
|
|
46
|
+
Requires-Dist: respx>=0.20.0; extra == "dev"
|
|
47
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
48
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
49
|
+
Requires-Dist: mypy>=1.5.0; extra == "dev"
|
|
50
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
51
|
+
Provides-Extra: docs
|
|
52
|
+
Requires-Dist: sphinx>=7.0.0; extra == "docs"
|
|
53
|
+
Requires-Dist: sphinx-rtd-theme>=1.3.0; extra == "docs"
|
|
54
|
+
Requires-Dist: sphinx-autodoc-typehints>=1.24.0; extra == "docs"
|
|
55
|
+
Provides-Extra: all
|
|
56
|
+
Requires-Dist: zstandard>=0.22.0; extra == "all"
|
|
57
|
+
Requires-Dist: openai>=1.0.0; extra == "all"
|
|
58
|
+
Requires-Dist: anthropic>=0.18.0; extra == "all"
|
|
59
|
+
Requires-Dist: google-generativeai>=0.3.0; extra == "all"
|
|
60
|
+
Requires-Dist: langchain-core>=0.1.0; extra == "all"
|
|
61
|
+
Requires-Dist: opentelemetry-api>=1.20.0; extra == "all"
|
|
62
|
+
Requires-Dist: opentelemetry-sdk>=1.20.0; extra == "all"
|
|
63
|
+
Dynamic: author
|
|
64
|
+
Dynamic: author-email
|
|
65
|
+
Dynamic: classifier
|
|
66
|
+
Dynamic: description
|
|
67
|
+
Dynamic: description-content-type
|
|
68
|
+
Dynamic: home-page
|
|
69
|
+
Dynamic: keywords
|
|
70
|
+
Dynamic: project-url
|
|
71
|
+
Dynamic: provides-extra
|
|
72
|
+
Dynamic: requires-dist
|
|
73
|
+
Dynamic: requires-python
|
|
74
|
+
Dynamic: summary
|
|
75
|
+
|
|
76
|
+
# Aigie SDK
|
|
77
|
+
|
|
78
|
+
Production-grade Python SDK for integrating Aigie monitoring into your AI agent workflows.
|
|
79
|
+
|
|
80
|
+
## ✨ Features
|
|
81
|
+
|
|
82
|
+
- 🚀 **Event Buffering**: 10-100x performance improvement with batch uploads
|
|
83
|
+
- 🎯 **Decorator Support**: 50%+ less boilerplate code
|
|
84
|
+
- ⚙️ **Flexible Configuration**: Config class with sensible defaults
|
|
85
|
+
- 🔄 **Automatic Retries**: Exponential backoff with configurable policies
|
|
86
|
+
- 🔗 **LangChain Integration**: Seamless callback handler
|
|
87
|
+
- 📊 **Production Ready**: Handles network failures, race conditions, and more
|
|
88
|
+
|
|
89
|
+
## Quick Start
|
|
90
|
+
|
|
91
|
+
### Installation
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install aigie
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Basic Usage
|
|
98
|
+
|
|
99
|
+
#### Option 1: Context Manager (Traditional)
|
|
100
|
+
```python
|
|
101
|
+
from aigie import Aigie
|
|
102
|
+
|
|
103
|
+
aigie = Aigie()
|
|
104
|
+
await aigie.initialize()
|
|
105
|
+
|
|
106
|
+
async with aigie.trace("My Workflow") as trace:
|
|
107
|
+
async with trace.span("operation", type="llm") as span:
|
|
108
|
+
result = await do_work()
|
|
109
|
+
span.set_output({"result": result})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Option 2: Decorator (Recommended - 50% less code!)
|
|
113
|
+
```python
|
|
114
|
+
from aigie import Aigie
|
|
115
|
+
|
|
116
|
+
aigie = Aigie()
|
|
117
|
+
await aigie.initialize()
|
|
118
|
+
|
|
119
|
+
@aigie.trace(name="my_workflow")
|
|
120
|
+
async def my_workflow():
|
|
121
|
+
@aigie.span(name="operation", type="llm")
|
|
122
|
+
async def operation():
|
|
123
|
+
return await do_work()
|
|
124
|
+
return await operation()
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Option 3: With Configuration
|
|
128
|
+
```python
|
|
129
|
+
from aigie import Aigie, Config
|
|
130
|
+
|
|
131
|
+
config = Config(
|
|
132
|
+
api_url="https://api.aigie.com",
|
|
133
|
+
api_key="your-key",
|
|
134
|
+
batch_size=100, # Buffer 100 events before sending
|
|
135
|
+
flush_interval=5.0 # Or flush every 5 seconds
|
|
136
|
+
)
|
|
137
|
+
aigie = Aigie(config=config)
|
|
138
|
+
await aigie.initialize()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Configuration
|
|
142
|
+
|
|
143
|
+
### Environment Variables
|
|
144
|
+
```bash
|
|
145
|
+
export AIGIE_API_URL=http://your-aigie-instance:8000/api
|
|
146
|
+
export AIGIE_API_KEY=your-api-key-here
|
|
147
|
+
export AIGIE_BATCH_SIZE=100
|
|
148
|
+
export AIGIE_FLUSH_INTERVAL=5.0
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Config Object
|
|
152
|
+
```python
|
|
153
|
+
from aigie import Config
|
|
154
|
+
|
|
155
|
+
config = Config(
|
|
156
|
+
api_url="https://api.aigie.com",
|
|
157
|
+
api_key="your-key",
|
|
158
|
+
batch_size=100,
|
|
159
|
+
flush_interval=5.0,
|
|
160
|
+
enable_buffering=True, # Default: True
|
|
161
|
+
max_retries=3
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Performance
|
|
166
|
+
|
|
167
|
+
### Before (No Buffering)
|
|
168
|
+
- 1000 spans = 1000+ API calls
|
|
169
|
+
- ~30 seconds total time
|
|
170
|
+
- High network overhead
|
|
171
|
+
|
|
172
|
+
### After (With Buffering)
|
|
173
|
+
- 1000 spans = 2-10 API calls
|
|
174
|
+
- ~0.5 seconds total time
|
|
175
|
+
- **99%+ reduction in API calls**
|
|
176
|
+
|
|
177
|
+
## Advanced Features
|
|
178
|
+
|
|
179
|
+
### OpenTelemetry Integration
|
|
180
|
+
|
|
181
|
+
Works with any OpenTelemetry-compatible tool (Datadog, New Relic, Jaeger, etc.):
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from aigie import Aigie
|
|
185
|
+
from aigie.opentelemetry import setup_opentelemetry
|
|
186
|
+
|
|
187
|
+
aigie = Aigie()
|
|
188
|
+
await aigie.initialize()
|
|
189
|
+
|
|
190
|
+
# One-line setup
|
|
191
|
+
setup_opentelemetry(aigie, service_name="my-service")
|
|
192
|
+
|
|
193
|
+
# Now all OTel spans automatically go to Aigie!
|
|
194
|
+
from opentelemetry import trace
|
|
195
|
+
tracer = trace.get_tracer(__name__)
|
|
196
|
+
|
|
197
|
+
with tracer.start_as_current_span("operation"):
|
|
198
|
+
# Automatically traced
|
|
199
|
+
pass
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Synchronous API
|
|
203
|
+
|
|
204
|
+
For non-async codebases:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from aigie import AigieSync
|
|
208
|
+
|
|
209
|
+
aigie = AigieSync()
|
|
210
|
+
aigie.initialize() # Blocking
|
|
211
|
+
|
|
212
|
+
with aigie.trace("workflow") as trace:
|
|
213
|
+
with trace.span("operation") as span:
|
|
214
|
+
result = do_work() # Sync code
|
|
215
|
+
span.set_output({"result": result})
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Installation
|
|
219
|
+
|
|
220
|
+
### Basic
|
|
221
|
+
```bash
|
|
222
|
+
pip install aigie
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### With OpenTelemetry
|
|
226
|
+
```bash
|
|
227
|
+
pip install aigie[opentelemetry]
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### With LangChain
|
|
231
|
+
```bash
|
|
232
|
+
pip install aigie[langchain]
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### All Features
|
|
236
|
+
```bash
|
|
237
|
+
pip install aigie[all]
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Advanced Features (Phase 3)
|
|
241
|
+
|
|
242
|
+
### W3C Trace Context Propagation
|
|
243
|
+
|
|
244
|
+
Distributed tracing across microservices:
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
# Extract from incoming request
|
|
248
|
+
context = aigie.extract_trace_context(request.headers)
|
|
249
|
+
|
|
250
|
+
async with aigie.trace("workflow") as trace:
|
|
251
|
+
trace.set_trace_context(context)
|
|
252
|
+
|
|
253
|
+
# Propagate to downstream service
|
|
254
|
+
headers = trace.get_trace_headers()
|
|
255
|
+
response = await httpx.get("https://api.example.com", headers=headers)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Prompt Management
|
|
259
|
+
|
|
260
|
+
Create, version, and track prompts:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
# Create prompt
|
|
264
|
+
prompt = await aigie.prompts.create(
|
|
265
|
+
name="customer_support",
|
|
266
|
+
template="You are a helpful assistant. Customer: {customer_name}",
|
|
267
|
+
version="1.0"
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
# Use in trace
|
|
271
|
+
async with aigie.trace("support") as trace:
|
|
272
|
+
trace.set_prompt(prompt)
|
|
273
|
+
rendered = prompt.render(customer_name="John")
|
|
274
|
+
response = await llm.ainvoke(rendered)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Evaluation Hooks
|
|
278
|
+
|
|
279
|
+
Automatic quality monitoring:
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
from aigie import EvaluationHook, ScoreType
|
|
283
|
+
|
|
284
|
+
hook = EvaluationHook(
|
|
285
|
+
name="accuracy",
|
|
286
|
+
evaluator=accuracy_evaluator,
|
|
287
|
+
score_type=ScoreType.ACCURACY
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
async with aigie.trace("workflow") as trace:
|
|
291
|
+
trace.add_evaluation_hook(hook)
|
|
292
|
+
result = await do_work()
|
|
293
|
+
await trace.run_evaluations(expected, result)
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Streaming Support
|
|
297
|
+
|
|
298
|
+
Real-time span updates:
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
async with aigie.trace("workflow") as trace:
|
|
302
|
+
async with trace.span("llm_call", stream=True) as span:
|
|
303
|
+
async for chunk in llm.astream("Hello"):
|
|
304
|
+
span.append_output(chunk) # Update in real-time
|
|
305
|
+
yield chunk
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Documentation
|
|
309
|
+
|
|
310
|
+
- [SDK Improvement Analysis](./SDK_IMPROVEMENT_ANALYSIS.md) - Comprehensive analysis
|
|
311
|
+
- [Examples](./EXAMPLES_IMPROVED.md) - Before/after code examples
|
|
312
|
+
- [Comparison Table](./COMPARISON_TABLE.md) - Feature comparison with market leaders
|
|
313
|
+
- [Phase 2 Features](./PHASE2_FEATURES.md) - OpenTelemetry, Sync API, Type Hints
|
|
314
|
+
- [Phase 3 Features](./PHASE3_FEATURES.md) - W3C Context, Prompts, Evaluations, Streaming
|
|
315
|
+
|
|
316
|
+
|
aigie-0.1.2/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Aigie SDK
|
|
2
|
+
|
|
3
|
+
Production-grade Python SDK for integrating Aigie monitoring into your AI agent workflows.
|
|
4
|
+
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Event Buffering**: 10-100x performance improvement with batch uploads
|
|
8
|
+
- 🎯 **Decorator Support**: 50%+ less boilerplate code
|
|
9
|
+
- ⚙️ **Flexible Configuration**: Config class with sensible defaults
|
|
10
|
+
- 🔄 **Automatic Retries**: Exponential backoff with configurable policies
|
|
11
|
+
- 🔗 **LangChain Integration**: Seamless callback handler
|
|
12
|
+
- 📊 **Production Ready**: Handles network failures, race conditions, and more
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
### Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install aigie
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Basic Usage
|
|
23
|
+
|
|
24
|
+
#### Option 1: Context Manager (Traditional)
|
|
25
|
+
```python
|
|
26
|
+
from aigie import Aigie
|
|
27
|
+
|
|
28
|
+
aigie = Aigie()
|
|
29
|
+
await aigie.initialize()
|
|
30
|
+
|
|
31
|
+
async with aigie.trace("My Workflow") as trace:
|
|
32
|
+
async with trace.span("operation", type="llm") as span:
|
|
33
|
+
result = await do_work()
|
|
34
|
+
span.set_output({"result": result})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### Option 2: Decorator (Recommended - 50% less code!)
|
|
38
|
+
```python
|
|
39
|
+
from aigie import Aigie
|
|
40
|
+
|
|
41
|
+
aigie = Aigie()
|
|
42
|
+
await aigie.initialize()
|
|
43
|
+
|
|
44
|
+
@aigie.trace(name="my_workflow")
|
|
45
|
+
async def my_workflow():
|
|
46
|
+
@aigie.span(name="operation", type="llm")
|
|
47
|
+
async def operation():
|
|
48
|
+
return await do_work()
|
|
49
|
+
return await operation()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Option 3: With Configuration
|
|
53
|
+
```python
|
|
54
|
+
from aigie import Aigie, Config
|
|
55
|
+
|
|
56
|
+
config = Config(
|
|
57
|
+
api_url="https://api.aigie.com",
|
|
58
|
+
api_key="your-key",
|
|
59
|
+
batch_size=100, # Buffer 100 events before sending
|
|
60
|
+
flush_interval=5.0 # Or flush every 5 seconds
|
|
61
|
+
)
|
|
62
|
+
aigie = Aigie(config=config)
|
|
63
|
+
await aigie.initialize()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
### Environment Variables
|
|
69
|
+
```bash
|
|
70
|
+
export AIGIE_API_URL=http://your-aigie-instance:8000/api
|
|
71
|
+
export AIGIE_API_KEY=your-api-key-here
|
|
72
|
+
export AIGIE_BATCH_SIZE=100
|
|
73
|
+
export AIGIE_FLUSH_INTERVAL=5.0
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Config Object
|
|
77
|
+
```python
|
|
78
|
+
from aigie import Config
|
|
79
|
+
|
|
80
|
+
config = Config(
|
|
81
|
+
api_url="https://api.aigie.com",
|
|
82
|
+
api_key="your-key",
|
|
83
|
+
batch_size=100,
|
|
84
|
+
flush_interval=5.0,
|
|
85
|
+
enable_buffering=True, # Default: True
|
|
86
|
+
max_retries=3
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Performance
|
|
91
|
+
|
|
92
|
+
### Before (No Buffering)
|
|
93
|
+
- 1000 spans = 1000+ API calls
|
|
94
|
+
- ~30 seconds total time
|
|
95
|
+
- High network overhead
|
|
96
|
+
|
|
97
|
+
### After (With Buffering)
|
|
98
|
+
- 1000 spans = 2-10 API calls
|
|
99
|
+
- ~0.5 seconds total time
|
|
100
|
+
- **99%+ reduction in API calls**
|
|
101
|
+
|
|
102
|
+
## Advanced Features
|
|
103
|
+
|
|
104
|
+
### OpenTelemetry Integration
|
|
105
|
+
|
|
106
|
+
Works with any OpenTelemetry-compatible tool (Datadog, New Relic, Jaeger, etc.):
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from aigie import Aigie
|
|
110
|
+
from aigie.opentelemetry import setup_opentelemetry
|
|
111
|
+
|
|
112
|
+
aigie = Aigie()
|
|
113
|
+
await aigie.initialize()
|
|
114
|
+
|
|
115
|
+
# One-line setup
|
|
116
|
+
setup_opentelemetry(aigie, service_name="my-service")
|
|
117
|
+
|
|
118
|
+
# Now all OTel spans automatically go to Aigie!
|
|
119
|
+
from opentelemetry import trace
|
|
120
|
+
tracer = trace.get_tracer(__name__)
|
|
121
|
+
|
|
122
|
+
with tracer.start_as_current_span("operation"):
|
|
123
|
+
# Automatically traced
|
|
124
|
+
pass
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Synchronous API
|
|
128
|
+
|
|
129
|
+
For non-async codebases:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from aigie import AigieSync
|
|
133
|
+
|
|
134
|
+
aigie = AigieSync()
|
|
135
|
+
aigie.initialize() # Blocking
|
|
136
|
+
|
|
137
|
+
with aigie.trace("workflow") as trace:
|
|
138
|
+
with trace.span("operation") as span:
|
|
139
|
+
result = do_work() # Sync code
|
|
140
|
+
span.set_output({"result": result})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Installation
|
|
144
|
+
|
|
145
|
+
### Basic
|
|
146
|
+
```bash
|
|
147
|
+
pip install aigie
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### With OpenTelemetry
|
|
151
|
+
```bash
|
|
152
|
+
pip install aigie[opentelemetry]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### With LangChain
|
|
156
|
+
```bash
|
|
157
|
+
pip install aigie[langchain]
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### All Features
|
|
161
|
+
```bash
|
|
162
|
+
pip install aigie[all]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Advanced Features (Phase 3)
|
|
166
|
+
|
|
167
|
+
### W3C Trace Context Propagation
|
|
168
|
+
|
|
169
|
+
Distributed tracing across microservices:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
# Extract from incoming request
|
|
173
|
+
context = aigie.extract_trace_context(request.headers)
|
|
174
|
+
|
|
175
|
+
async with aigie.trace("workflow") as trace:
|
|
176
|
+
trace.set_trace_context(context)
|
|
177
|
+
|
|
178
|
+
# Propagate to downstream service
|
|
179
|
+
headers = trace.get_trace_headers()
|
|
180
|
+
response = await httpx.get("https://api.example.com", headers=headers)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Prompt Management
|
|
184
|
+
|
|
185
|
+
Create, version, and track prompts:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# Create prompt
|
|
189
|
+
prompt = await aigie.prompts.create(
|
|
190
|
+
name="customer_support",
|
|
191
|
+
template="You are a helpful assistant. Customer: {customer_name}",
|
|
192
|
+
version="1.0"
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# Use in trace
|
|
196
|
+
async with aigie.trace("support") as trace:
|
|
197
|
+
trace.set_prompt(prompt)
|
|
198
|
+
rendered = prompt.render(customer_name="John")
|
|
199
|
+
response = await llm.ainvoke(rendered)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Evaluation Hooks
|
|
203
|
+
|
|
204
|
+
Automatic quality monitoring:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from aigie import EvaluationHook, ScoreType
|
|
208
|
+
|
|
209
|
+
hook = EvaluationHook(
|
|
210
|
+
name="accuracy",
|
|
211
|
+
evaluator=accuracy_evaluator,
|
|
212
|
+
score_type=ScoreType.ACCURACY
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
async with aigie.trace("workflow") as trace:
|
|
216
|
+
trace.add_evaluation_hook(hook)
|
|
217
|
+
result = await do_work()
|
|
218
|
+
await trace.run_evaluations(expected, result)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Streaming Support
|
|
222
|
+
|
|
223
|
+
Real-time span updates:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
async with aigie.trace("workflow") as trace:
|
|
227
|
+
async with trace.span("llm_call", stream=True) as span:
|
|
228
|
+
async for chunk in llm.astream("Hello"):
|
|
229
|
+
span.append_output(chunk) # Update in real-time
|
|
230
|
+
yield chunk
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Documentation
|
|
234
|
+
|
|
235
|
+
- [SDK Improvement Analysis](./SDK_IMPROVEMENT_ANALYSIS.md) - Comprehensive analysis
|
|
236
|
+
- [Examples](./EXAMPLES_IMPROVED.md) - Before/after code examples
|
|
237
|
+
- [Comparison Table](./COMPARISON_TABLE.md) - Feature comparison with market leaders
|
|
238
|
+
- [Phase 2 Features](./PHASE2_FEATURES.md) - OpenTelemetry, Sync API, Type Hints
|
|
239
|
+
- [Phase 3 Features](./PHASE3_FEATURES.md) - W3C Context, Prompts, Evaluations, Streaming
|
|
240
|
+
|
|
241
|
+
|