blocklog 0.2.0__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.
- blocklog-0.2.0/LICENSE +21 -0
- blocklog-0.2.0/MANIFEST.in +8 -0
- blocklog-0.2.0/PKG-INFO +272 -0
- blocklog-0.2.0/README.md +237 -0
- blocklog-0.2.0/docs/api-reference.md +206 -0
- blocklog-0.2.0/docs/async.md +54 -0
- blocklog-0.2.0/docs/changelog.md +22 -0
- blocklog-0.2.0/docs/concepts.md +31 -0
- blocklog-0.2.0/docs/configuration.md +38 -0
- blocklog-0.2.0/docs/decisions.md +66 -0
- blocklog-0.2.0/docs/decorators.md +62 -0
- blocklog-0.2.0/docs/error-handling.md +50 -0
- blocklog-0.2.0/docs/examples.md +44 -0
- blocklog-0.2.0/docs/index.md +37 -0
- blocklog-0.2.0/docs/installation.md +36 -0
- blocklog-0.2.0/docs/integrations.md +45 -0
- blocklog-0.2.0/docs/migration.md +95 -0
- blocklog-0.2.0/docs/performance.md +37 -0
- blocklog-0.2.0/docs/production.md +64 -0
- blocklog-0.2.0/docs/quickstart.md +40 -0
- blocklog-0.2.0/docs/tracing.md +26 -0
- blocklog-0.2.0/docs/troubleshooting.md +38 -0
- blocklog-0.2.0/examples/01_quickstart.py +34 -0
- blocklog-0.2.0/examples/02_stock_trading_agent.py +146 -0
- blocklog-0.2.0/examples/03_multi_agent_workflow.py +205 -0
- blocklog-0.2.0/examples/advanced/01_human_approval_workflow.py +152 -0
- blocklog-0.2.0/examples/advanced/02_incident_investigation.py +157 -0
- blocklog-0.2.0/examples/advanced/03_decision_comparison.py +162 -0
- blocklog-0.2.0/examples/advanced/langchain_alert_demo.py +34 -0
- blocklog-0.2.0/pyproject.toml +61 -0
- blocklog-0.2.0/setup.cfg +4 -0
- blocklog-0.2.0/src/blocklog/__init__.py +78 -0
- blocklog-0.2.0/src/blocklog/_global.py +20 -0
- blocklog-0.2.0/src/blocklog/_init_fn.py +95 -0
- blocklog-0.2.0/src/blocklog/api/approval.py +182 -0
- blocklog-0.2.0/src/blocklog/api/compliance.py +162 -0
- blocklog-0.2.0/src/blocklog/api/decisions.py +177 -0
- blocklog-0.2.0/src/blocklog/api/incidents.py +306 -0
- blocklog-0.2.0/src/blocklog/api/replay.py +285 -0
- blocklog-0.2.0/src/blocklog/api/traces.py +137 -0
- blocklog-0.2.0/src/blocklog/api/verify.py +100 -0
- blocklog-0.2.0/src/blocklog/approval.py +119 -0
- blocklog-0.2.0/src/blocklog/async_client.py +28 -0
- blocklog-0.2.0/src/blocklog/batching/buffer.py +22 -0
- blocklog-0.2.0/src/blocklog/client.py +194 -0
- blocklog-0.2.0/src/blocklog/compliance.py +95 -0
- blocklog-0.2.0/src/blocklog/config.py +17 -0
- blocklog-0.2.0/src/blocklog/context/managers.py +15 -0
- blocklog-0.2.0/src/blocklog/context/vars.py +13 -0
- blocklog-0.2.0/src/blocklog/decorators/__init__.py +4 -0
- blocklog-0.2.0/src/blocklog/decorators/agent.py +219 -0
- blocklog-0.2.0/src/blocklog/decorators/tool.py +206 -0
- blocklog-0.2.0/src/blocklog/incident.py +89 -0
- blocklog-0.2.0/src/blocklog/integrations/langchain.py +129 -0
- blocklog-0.2.0/src/blocklog/integrations/langgraph.py +3 -0
- blocklog-0.2.0/src/blocklog/integrations/openai_agents.py +3 -0
- blocklog-0.2.0/src/blocklog/managers/__init__.py +3 -0
- blocklog-0.2.0/src/blocklog/managers/decision.py +336 -0
- blocklog-0.2.0/src/blocklog/middleware/hooks.py +11 -0
- blocklog-0.2.0/src/blocklog/models/events.py +33 -0
- blocklog-0.2.0/src/blocklog/models/responses.py +18 -0
- blocklog-0.2.0/src/blocklog/replay.py +64 -0
- blocklog-0.2.0/src/blocklog/signing/canonical.py +5 -0
- blocklog-0.2.0/src/blocklog/signing/ed25519.py +25 -0
- blocklog-0.2.0/src/blocklog/transport/auth.py +8 -0
- blocklog-0.2.0/src/blocklog/transport/httpx_async.py +39 -0
- blocklog-0.2.0/src/blocklog/transport/httpx_sync.py +36 -0
- blocklog-0.2.0/src/blocklog/transport/retry.py +26 -0
- blocklog-0.2.0/src/blocklog/verify.py +72 -0
- blocklog-0.2.0/src/blocklog.egg-info/PKG-INFO +272 -0
- blocklog-0.2.0/src/blocklog.egg-info/SOURCES.txt +78 -0
- blocklog-0.2.0/src/blocklog.egg-info/dependency_links.txt +1 -0
- blocklog-0.2.0/src/blocklog.egg-info/requires.txt +9 -0
- blocklog-0.2.0/src/blocklog.egg-info/top_level.txt +1 -0
- blocklog-0.2.0/tests/test_client.py +177 -0
- blocklog-0.2.0/tests/test_config.py +86 -0
- blocklog-0.2.0/tests/test_context.py +12 -0
- blocklog-0.2.0/tests/test_decorators.py +185 -0
- blocklog-0.2.0/tests/test_public_api.py +210 -0
- blocklog-0.2.0/tests/test_transport.py +166 -0
blocklog-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Blocklog
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
blocklog-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: blocklog
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Infrastructure for AI Decision-Making — record, replay, verify, and govern AI agent decisions
|
|
5
|
+
Author-email: Blocklog <contact@blockloghq.com>
|
|
6
|
+
Maintainer-email: Blocklog <contact@blockloghq.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://blockloghq.com
|
|
9
|
+
Project-URL: Documentation, https://docs.blockloghq.com
|
|
10
|
+
Project-URL: Repository, https://github.com/blockloghq/blocklog-python
|
|
11
|
+
Project-URL: Issues, https://github.com/blockloghq/blocklog-python/issues
|
|
12
|
+
Keywords: ai,agents,observability,governance,security,audit,replay
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: System :: Monitoring
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: httpx<1.0,>=0.27
|
|
27
|
+
Requires-Dist: pydantic<3.0,>=2.8
|
|
28
|
+
Requires-Dist: requests>=2.32.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
32
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# Blocklog Python SDK
|
|
37
|
+
|
|
38
|
+
**Record, audit, and investigate every decision your AI agents make.**
|
|
39
|
+
|
|
40
|
+
[](https://www.python.org/downloads/)
|
|
41
|
+
[](https://github.com/blockloghq/blocklog-python)
|
|
42
|
+
[](https://opensource.org/licenses/MIT)
|
|
43
|
+
[](docs/index.md)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Why Blocklog?
|
|
48
|
+
|
|
49
|
+
When AI agents execute actions in production, the context behind their decisions is often lost. Debugging failures, reproducing state, and maintaining compliance becomes nearly impossible without a structured audit trail. Blocklog solves this by capturing exactly what the model knew, what tools it used, and what it ultimately decided—all securely anchored and optionally requiring human approval.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## What Blocklog Does
|
|
54
|
+
|
|
55
|
+
- **Trace AI agents** and their execution duration automatically.
|
|
56
|
+
- **Trace tool calls**, capturing inputs and outputs seamlessly.
|
|
57
|
+
- **Record decisions** with detailed metadata, inputs, and outputs.
|
|
58
|
+
- **Request approvals** via non-blocking human-in-the-loop workflows.
|
|
59
|
+
- **Verify records** cryptographically against a blockchain anchor.
|
|
60
|
+
- **Generate compliance evidence** (e.g., SOC2, GDPR).
|
|
61
|
+
- **Investigate failures with replay** using forensic timelines and root-cause analysis.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Architecture Overview
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
AI Agent
|
|
69
|
+
↓
|
|
70
|
+
@blocklog.agent
|
|
71
|
+
↓
|
|
72
|
+
Tools + Decisions
|
|
73
|
+
↓
|
|
74
|
+
Event Buffer
|
|
75
|
+
↓
|
|
76
|
+
Blocklog API
|
|
77
|
+
↓
|
|
78
|
+
Replay / Verification / Compliance
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
Blocklog requires Python 3.10+. Install the SDK from PyPI:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install blocklog
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For development installation or to install from source:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
git clone https://github.com/blockloghq/blocklog-python.git
|
|
95
|
+
cd blocklog-python
|
|
96
|
+
pip install -e .
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Quickstart
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import os
|
|
105
|
+
import blocklog
|
|
106
|
+
|
|
107
|
+
# 1. Initialize the SDK
|
|
108
|
+
blocklog.init(api_key=os.environ.get("BLOCKLOG_API_KEY", "blk_demo_key"))
|
|
109
|
+
|
|
110
|
+
# 2. Record tool calls
|
|
111
|
+
@blocklog.tool
|
|
112
|
+
def check_price(ticker: str) -> float:
|
|
113
|
+
return 412.50
|
|
114
|
+
|
|
115
|
+
# 3. Trace your agent
|
|
116
|
+
@blocklog.agent(name="simple-trader")
|
|
117
|
+
def run_agent():
|
|
118
|
+
price = check_price("TSLA")
|
|
119
|
+
|
|
120
|
+
# 4. Record the decision
|
|
121
|
+
with blocklog.decision(type="BUY", asset="TSLA") as d:
|
|
122
|
+
d.record_input(price=price)
|
|
123
|
+
d.record_output(order_id="ord_123")
|
|
124
|
+
|
|
125
|
+
print(f"Decision recorded: {d.id}")
|
|
126
|
+
|
|
127
|
+
if __name__ == "__main__":
|
|
128
|
+
run_agent()
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## What Happens Under The Hood?
|
|
134
|
+
|
|
135
|
+
When you apply `@blocklog.agent`, Blocklog starts an internal session context that automatically propagates a `trace_id` to any subsequent operations. When `@blocklog.tool` is invoked, it captures the inputs and outputs, linking them to the active trace. Finally, `blocklog.decision()` bundles the agent's logic into a concrete, auditable event that is asynchronously buffered and flushed to the Blocklog backend without blocking your application.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Core Concepts
|
|
140
|
+
|
|
141
|
+
- **Decision**: A structured record of an AI action, tracking the explicit inputs it considered and the outputs it generated.
|
|
142
|
+
- **Trace**: The end-to-end execution path of an agent, automatically correlating all tool calls and decisions via a shared `trace_id`.
|
|
143
|
+
- **Event**: A low-level building block representing a single state change (e.g., `TOOL_CALL`, `DECISION_INPUT`), securely buffered and dispatched.
|
|
144
|
+
- **Approval**: A human-in-the-loop (HITL) gate that flags high-stakes decisions for manual review.
|
|
145
|
+
- **Replay**: A forensic reconstruction of a trace allowing developers to understand the root cause of an agent's failure or action.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Common Use Cases
|
|
150
|
+
|
|
151
|
+
- **Trading Agents**: Capturing the exact market data (inputs) that led an agent to execute a trade (output).
|
|
152
|
+
- **AI Copilots**: Tracing user interactions and the tools invoked to fetch internal company data.
|
|
153
|
+
- **Compliance-Sensitive Workflows**: Automatically generating SOC2 or GDPR reports for AI behavior.
|
|
154
|
+
- **Customer Support Agents**: Recording decisions to escalate to human agents vs. resolving automatically.
|
|
155
|
+
- **Human-in-the-Loop Systems**: Pausing execution of high-value actions (e.g., refunds > $500) until a human reviewer approves.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Integrations
|
|
160
|
+
|
|
161
|
+
Blocklog seamlessly auto-instruments popular AI frameworks:
|
|
162
|
+
- **LangChain**: Trace chains, LLMs, and tools automatically via `client.instrument_langchain()`.
|
|
163
|
+
- **LangGraph**: Hook into graph states via `client.instrument_langgraph()`.
|
|
164
|
+
- **OpenAI Agents**: Track official SDK executions via `client.instrument_openai_agents()`.
|
|
165
|
+
|
|
166
|
+
Read more in the [Integrations Guide](docs/integrations.md).
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Documentation
|
|
171
|
+
|
|
172
|
+
| Topic | Guide |
|
|
173
|
+
|-------|-------|
|
|
174
|
+
| **Getting Started** | [Installation](docs/installation.md) • [Quickstart](docs/quickstart.md) • [Core Concepts](docs/concepts.md) |
|
|
175
|
+
| **Instrumentation** | [Tracing](docs/tracing.md) • [Decisions](docs/decisions.md) • [Decorators](docs/decorators.md) |
|
|
176
|
+
| **Frameworks** | [Integrations](docs/integrations.md) |
|
|
177
|
+
| **Operations** | [Async Usage](docs/async.md) • [Production](docs/production.md) • [Performance](docs/performance.md) |
|
|
178
|
+
| **Reference** | [API Reference](docs/api-reference.md) • [Error Handling](docs/error-handling.md) • [Troubleshooting](docs/troubleshooting.md) |
|
|
179
|
+
| **Misc** | [Examples](docs/examples.md) • [Changelog](docs/changelog.md) |
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Examples
|
|
184
|
+
|
|
185
|
+
We provide several runnable scripts in the `examples/` directory to help you understand Blocklog in practice:
|
|
186
|
+
|
|
187
|
+
- **[01_quickstart.py](examples/01_quickstart.py)**: The bare minimum needed to trace an agent, run a tool, and record a decision.
|
|
188
|
+
- **[02_stock_trading_agent.py](examples/02_stock_trading_agent.py)**: A simulated trading agent demonstrating tool tagging, human-in-the-loop approvals, and cryptographic verification.
|
|
189
|
+
- **[03_multi_agent_workflow.py](examples/03_multi_agent_workflow.py)**: A complex pipeline showing context passing across Analyst, Risk, and Executor agents, ending in a compliance report.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Production Features
|
|
194
|
+
|
|
195
|
+
- **Async Support**: Native `asyncio` compatibility utilizing `contextvars` for seamless trace propagation across `await` boundaries.
|
|
196
|
+
- **Event Buffering**: High-volume telemetry is safely batched in-memory and flushed asynchronously.
|
|
197
|
+
- **Retry Handling**: Built-in exponential backoff for transient network issues.
|
|
198
|
+
- **Signing**: Optional Ed25519 payload signing for tamper-evident, cryptographically verifiable logs.
|
|
199
|
+
- **Middleware Hooks**: Add custom logic to redact PII or inject metadata before payloads leave your server.
|
|
200
|
+
|
|
201
|
+
Read our [Production Best Practices](docs/production.md) for more details.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Contributing
|
|
206
|
+
|
|
207
|
+
We welcome contributions to the Blocklog Python SDK! Please read through our open issues or submit a Pull Request. Ensure you have installed the SDK in editable mode (`pip install -e .`) before running tests.
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Configuration
|
|
212
|
+
|
|
213
|
+
Blocklog can be configured via environment variables:
|
|
214
|
+
|
|
215
|
+
| Variable | Description | Default |
|
|
216
|
+
|----------|-------------|---------|
|
|
217
|
+
| `BLOCKLOG_API_KEY` | Your Blocklog API key | `""` |
|
|
218
|
+
| `BLOCKLOG_BASE_URL` | API base URL | `http://127.0.0.1:8000/api/v1` |
|
|
219
|
+
| `BLOCKLOG_SDK_SIGNING_KEY` | Optional seed key for hash signing | `""` |
|
|
220
|
+
| `BLOCKLOG_TIMEOUT` | Request timeout in seconds | `10` |
|
|
221
|
+
| `BLOCKLOG_MAX_RETRIES` | Number of retry attempts | `3` |
|
|
222
|
+
| `BLOCKLOG_BATCH_SIZE` | Event batch size | `100` |
|
|
223
|
+
| `BLOCKLOG_FLUSH_INTERVAL` | Batch flush interval in seconds | `2` |
|
|
224
|
+
|
|
225
|
+
## Troubleshooting
|
|
226
|
+
|
|
227
|
+
### Installation Issues
|
|
228
|
+
|
|
229
|
+
If you encounter installation errors:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Upgrade pip first
|
|
233
|
+
pip install --upgrade pip
|
|
234
|
+
|
|
235
|
+
# Install with verbose output
|
|
236
|
+
pip install blocklog -v
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Import Errors
|
|
240
|
+
|
|
241
|
+
If you get import errors after installation:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Verify installation
|
|
245
|
+
pip show blocklog
|
|
246
|
+
|
|
247
|
+
# Reinstall if needed
|
|
248
|
+
pip install --force-reinstall blocklog
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Connection Issues
|
|
252
|
+
|
|
253
|
+
If the SDK cannot connect to the Blocklog API:
|
|
254
|
+
|
|
255
|
+
1. Verify your API key is correct
|
|
256
|
+
2. Check that `BLOCKLOG_BASE_URL` points to the correct endpoint
|
|
257
|
+
3. Ensure network connectivity to the API server
|
|
258
|
+
4. Check firewall settings
|
|
259
|
+
|
|
260
|
+
## Links
|
|
261
|
+
|
|
262
|
+
- **Homepage**: https://blockloghq.com
|
|
263
|
+
- **Documentation**: https://docs.blockloghq.com
|
|
264
|
+
- **Repository**: https://github.com/blockloghq/blocklog-python
|
|
265
|
+
- **Issues**: https://github.com/blockloghq/blocklog-python/issues
|
|
266
|
+
- **PyPI**: https://pypi.org/project/blocklog/
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## License
|
|
271
|
+
|
|
272
|
+
MIT License. See the LICENSE file for details.
|
blocklog-0.2.0/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Blocklog Python SDK
|
|
2
|
+
|
|
3
|
+
**Record, audit, and investigate every decision your AI agents make.**
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](https://github.com/blockloghq/blocklog-python)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](docs/index.md)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Why Blocklog?
|
|
13
|
+
|
|
14
|
+
When AI agents execute actions in production, the context behind their decisions is often lost. Debugging failures, reproducing state, and maintaining compliance becomes nearly impossible without a structured audit trail. Blocklog solves this by capturing exactly what the model knew, what tools it used, and what it ultimately decided—all securely anchored and optionally requiring human approval.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## What Blocklog Does
|
|
19
|
+
|
|
20
|
+
- **Trace AI agents** and their execution duration automatically.
|
|
21
|
+
- **Trace tool calls**, capturing inputs and outputs seamlessly.
|
|
22
|
+
- **Record decisions** with detailed metadata, inputs, and outputs.
|
|
23
|
+
- **Request approvals** via non-blocking human-in-the-loop workflows.
|
|
24
|
+
- **Verify records** cryptographically against a blockchain anchor.
|
|
25
|
+
- **Generate compliance evidence** (e.g., SOC2, GDPR).
|
|
26
|
+
- **Investigate failures with replay** using forensic timelines and root-cause analysis.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Architecture Overview
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
AI Agent
|
|
34
|
+
↓
|
|
35
|
+
@blocklog.agent
|
|
36
|
+
↓
|
|
37
|
+
Tools + Decisions
|
|
38
|
+
↓
|
|
39
|
+
Event Buffer
|
|
40
|
+
↓
|
|
41
|
+
Blocklog API
|
|
42
|
+
↓
|
|
43
|
+
Replay / Verification / Compliance
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
Blocklog requires Python 3.10+. Install the SDK from PyPI:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install blocklog
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For development installation or to install from source:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
git clone https://github.com/blockloghq/blocklog-python.git
|
|
60
|
+
cd blocklog-python
|
|
61
|
+
pip install -e .
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Quickstart
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import os
|
|
70
|
+
import blocklog
|
|
71
|
+
|
|
72
|
+
# 1. Initialize the SDK
|
|
73
|
+
blocklog.init(api_key=os.environ.get("BLOCKLOG_API_KEY", "blk_demo_key"))
|
|
74
|
+
|
|
75
|
+
# 2. Record tool calls
|
|
76
|
+
@blocklog.tool
|
|
77
|
+
def check_price(ticker: str) -> float:
|
|
78
|
+
return 412.50
|
|
79
|
+
|
|
80
|
+
# 3. Trace your agent
|
|
81
|
+
@blocklog.agent(name="simple-trader")
|
|
82
|
+
def run_agent():
|
|
83
|
+
price = check_price("TSLA")
|
|
84
|
+
|
|
85
|
+
# 4. Record the decision
|
|
86
|
+
with blocklog.decision(type="BUY", asset="TSLA") as d:
|
|
87
|
+
d.record_input(price=price)
|
|
88
|
+
d.record_output(order_id="ord_123")
|
|
89
|
+
|
|
90
|
+
print(f"Decision recorded: {d.id}")
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
run_agent()
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## What Happens Under The Hood?
|
|
99
|
+
|
|
100
|
+
When you apply `@blocklog.agent`, Blocklog starts an internal session context that automatically propagates a `trace_id` to any subsequent operations. When `@blocklog.tool` is invoked, it captures the inputs and outputs, linking them to the active trace. Finally, `blocklog.decision()` bundles the agent's logic into a concrete, auditable event that is asynchronously buffered and flushed to the Blocklog backend without blocking your application.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Core Concepts
|
|
105
|
+
|
|
106
|
+
- **Decision**: A structured record of an AI action, tracking the explicit inputs it considered and the outputs it generated.
|
|
107
|
+
- **Trace**: The end-to-end execution path of an agent, automatically correlating all tool calls and decisions via a shared `trace_id`.
|
|
108
|
+
- **Event**: A low-level building block representing a single state change (e.g., `TOOL_CALL`, `DECISION_INPUT`), securely buffered and dispatched.
|
|
109
|
+
- **Approval**: A human-in-the-loop (HITL) gate that flags high-stakes decisions for manual review.
|
|
110
|
+
- **Replay**: A forensic reconstruction of a trace allowing developers to understand the root cause of an agent's failure or action.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Common Use Cases
|
|
115
|
+
|
|
116
|
+
- **Trading Agents**: Capturing the exact market data (inputs) that led an agent to execute a trade (output).
|
|
117
|
+
- **AI Copilots**: Tracing user interactions and the tools invoked to fetch internal company data.
|
|
118
|
+
- **Compliance-Sensitive Workflows**: Automatically generating SOC2 or GDPR reports for AI behavior.
|
|
119
|
+
- **Customer Support Agents**: Recording decisions to escalate to human agents vs. resolving automatically.
|
|
120
|
+
- **Human-in-the-Loop Systems**: Pausing execution of high-value actions (e.g., refunds > $500) until a human reviewer approves.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Integrations
|
|
125
|
+
|
|
126
|
+
Blocklog seamlessly auto-instruments popular AI frameworks:
|
|
127
|
+
- **LangChain**: Trace chains, LLMs, and tools automatically via `client.instrument_langchain()`.
|
|
128
|
+
- **LangGraph**: Hook into graph states via `client.instrument_langgraph()`.
|
|
129
|
+
- **OpenAI Agents**: Track official SDK executions via `client.instrument_openai_agents()`.
|
|
130
|
+
|
|
131
|
+
Read more in the [Integrations Guide](docs/integrations.md).
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Documentation
|
|
136
|
+
|
|
137
|
+
| Topic | Guide |
|
|
138
|
+
|-------|-------|
|
|
139
|
+
| **Getting Started** | [Installation](docs/installation.md) • [Quickstart](docs/quickstart.md) • [Core Concepts](docs/concepts.md) |
|
|
140
|
+
| **Instrumentation** | [Tracing](docs/tracing.md) • [Decisions](docs/decisions.md) • [Decorators](docs/decorators.md) |
|
|
141
|
+
| **Frameworks** | [Integrations](docs/integrations.md) |
|
|
142
|
+
| **Operations** | [Async Usage](docs/async.md) • [Production](docs/production.md) • [Performance](docs/performance.md) |
|
|
143
|
+
| **Reference** | [API Reference](docs/api-reference.md) • [Error Handling](docs/error-handling.md) • [Troubleshooting](docs/troubleshooting.md) |
|
|
144
|
+
| **Misc** | [Examples](docs/examples.md) • [Changelog](docs/changelog.md) |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Examples
|
|
149
|
+
|
|
150
|
+
We provide several runnable scripts in the `examples/` directory to help you understand Blocklog in practice:
|
|
151
|
+
|
|
152
|
+
- **[01_quickstart.py](examples/01_quickstart.py)**: The bare minimum needed to trace an agent, run a tool, and record a decision.
|
|
153
|
+
- **[02_stock_trading_agent.py](examples/02_stock_trading_agent.py)**: A simulated trading agent demonstrating tool tagging, human-in-the-loop approvals, and cryptographic verification.
|
|
154
|
+
- **[03_multi_agent_workflow.py](examples/03_multi_agent_workflow.py)**: A complex pipeline showing context passing across Analyst, Risk, and Executor agents, ending in a compliance report.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Production Features
|
|
159
|
+
|
|
160
|
+
- **Async Support**: Native `asyncio` compatibility utilizing `contextvars` for seamless trace propagation across `await` boundaries.
|
|
161
|
+
- **Event Buffering**: High-volume telemetry is safely batched in-memory and flushed asynchronously.
|
|
162
|
+
- **Retry Handling**: Built-in exponential backoff for transient network issues.
|
|
163
|
+
- **Signing**: Optional Ed25519 payload signing for tamper-evident, cryptographically verifiable logs.
|
|
164
|
+
- **Middleware Hooks**: Add custom logic to redact PII or inject metadata before payloads leave your server.
|
|
165
|
+
|
|
166
|
+
Read our [Production Best Practices](docs/production.md) for more details.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Contributing
|
|
171
|
+
|
|
172
|
+
We welcome contributions to the Blocklog Python SDK! Please read through our open issues or submit a Pull Request. Ensure you have installed the SDK in editable mode (`pip install -e .`) before running tests.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Configuration
|
|
177
|
+
|
|
178
|
+
Blocklog can be configured via environment variables:
|
|
179
|
+
|
|
180
|
+
| Variable | Description | Default |
|
|
181
|
+
|----------|-------------|---------|
|
|
182
|
+
| `BLOCKLOG_API_KEY` | Your Blocklog API key | `""` |
|
|
183
|
+
| `BLOCKLOG_BASE_URL` | API base URL | `http://127.0.0.1:8000/api/v1` |
|
|
184
|
+
| `BLOCKLOG_SDK_SIGNING_KEY` | Optional seed key for hash signing | `""` |
|
|
185
|
+
| `BLOCKLOG_TIMEOUT` | Request timeout in seconds | `10` |
|
|
186
|
+
| `BLOCKLOG_MAX_RETRIES` | Number of retry attempts | `3` |
|
|
187
|
+
| `BLOCKLOG_BATCH_SIZE` | Event batch size | `100` |
|
|
188
|
+
| `BLOCKLOG_FLUSH_INTERVAL` | Batch flush interval in seconds | `2` |
|
|
189
|
+
|
|
190
|
+
## Troubleshooting
|
|
191
|
+
|
|
192
|
+
### Installation Issues
|
|
193
|
+
|
|
194
|
+
If you encounter installation errors:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Upgrade pip first
|
|
198
|
+
pip install --upgrade pip
|
|
199
|
+
|
|
200
|
+
# Install with verbose output
|
|
201
|
+
pip install blocklog -v
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Import Errors
|
|
205
|
+
|
|
206
|
+
If you get import errors after installation:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Verify installation
|
|
210
|
+
pip show blocklog
|
|
211
|
+
|
|
212
|
+
# Reinstall if needed
|
|
213
|
+
pip install --force-reinstall blocklog
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Connection Issues
|
|
217
|
+
|
|
218
|
+
If the SDK cannot connect to the Blocklog API:
|
|
219
|
+
|
|
220
|
+
1. Verify your API key is correct
|
|
221
|
+
2. Check that `BLOCKLOG_BASE_URL` points to the correct endpoint
|
|
222
|
+
3. Ensure network connectivity to the API server
|
|
223
|
+
4. Check firewall settings
|
|
224
|
+
|
|
225
|
+
## Links
|
|
226
|
+
|
|
227
|
+
- **Homepage**: https://blockloghq.com
|
|
228
|
+
- **Documentation**: https://docs.blockloghq.com
|
|
229
|
+
- **Repository**: https://github.com/blockloghq/blocklog-python
|
|
230
|
+
- **Issues**: https://github.com/blockloghq/blocklog-python/issues
|
|
231
|
+
- **PyPI**: https://pypi.org/project/blocklog/
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
MIT License. See the LICENSE file for details.
|