raindrop-deep-agents 0.0.1__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.
- raindrop_deep_agents-0.0.1/.gitignore +90 -0
- raindrop_deep_agents-0.0.1/LICENSE +21 -0
- raindrop_deep_agents-0.0.1/PKG-INFO +194 -0
- raindrop_deep_agents-0.0.1/README.md +175 -0
- raindrop_deep_agents-0.0.1/examples/deep-agents-python-basic/e2e_verify.py +310 -0
- raindrop_deep_agents-0.0.1/examples/deep-agents-python-basic/main.py +37 -0
- raindrop_deep_agents-0.0.1/pyproject.toml +53 -0
- raindrop_deep_agents-0.0.1/raindrop_deep_agents/__init__.py +23 -0
- raindrop_deep_agents-0.0.1/raindrop_deep_agents/_wrapt_compat.py +112 -0
- raindrop_deep_agents-0.0.1/raindrop_deep_agents/handler.py +1419 -0
- raindrop_deep_agents-0.0.1/raindrop_deep_agents/py.typed +0 -0
- raindrop_deep_agents-0.0.1/tests/conftest.py +48 -0
- raindrop_deep_agents-0.0.1/tests/test_e2e.py +1168 -0
- raindrop_deep_agents-0.0.1/tests/test_handler.py +2216 -0
- raindrop_deep_agents-0.0.1/tests/test_wrapt_compat.py +125 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
.zodprompt-eval.sqlite
|
|
2
|
+
.topicmatch-eval.sqlite
|
|
3
|
+
# Logs
|
|
4
|
+
logs
|
|
5
|
+
*.log
|
|
6
|
+
npm-debug.log*
|
|
7
|
+
yarn-debug.log*
|
|
8
|
+
yarn-error.log*
|
|
9
|
+
pnpm-debug.log*
|
|
10
|
+
lerna-debug.log*
|
|
11
|
+
env/
|
|
12
|
+
temp
|
|
13
|
+
.env*
|
|
14
|
+
node_modules
|
|
15
|
+
dist
|
|
16
|
+
dist-ssr
|
|
17
|
+
*.local
|
|
18
|
+
.env
|
|
19
|
+
.yarn
|
|
20
|
+
.yarnrc.yml
|
|
21
|
+
.pnpm-store
|
|
22
|
+
package-lock.json
|
|
23
|
+
.turbo
|
|
24
|
+
*.tsbuildinfo
|
|
25
|
+
apps/**/secrets/**
|
|
26
|
+
*/*/eval-results
|
|
27
|
+
apps/dashboard/eval-results/metadata/
|
|
28
|
+
# Editor directories and files
|
|
29
|
+
.vscode/*
|
|
30
|
+
!.vscode/extensions.json
|
|
31
|
+
!.vscode/settings.json
|
|
32
|
+
!.vscode/tasks.json
|
|
33
|
+
!.vscode/launch.json
|
|
34
|
+
.idea
|
|
35
|
+
.DS_Store
|
|
36
|
+
*.suo
|
|
37
|
+
*.ntvs*
|
|
38
|
+
*.njsproj
|
|
39
|
+
*.sln
|
|
40
|
+
*.sw?
|
|
41
|
+
*bite-sight-prompts.txt
|
|
42
|
+
|
|
43
|
+
# Python files
|
|
44
|
+
*.pyc
|
|
45
|
+
__pycache__/
|
|
46
|
+
.venv/
|
|
47
|
+
|
|
48
|
+
myenv/
|
|
49
|
+
|
|
50
|
+
build/
|
|
51
|
+
dawnai.egg-info/
|
|
52
|
+
|
|
53
|
+
.next/
|
|
54
|
+
|
|
55
|
+
.vercel
|
|
56
|
+
|
|
57
|
+
.extra
|
|
58
|
+
|
|
59
|
+
packages/scripts/local-configs
|
|
60
|
+
|
|
61
|
+
gcp-auth.json
|
|
62
|
+
|
|
63
|
+
.crush/
|
|
64
|
+
mcp.json
|
|
65
|
+
|
|
66
|
+
# Don't commit local dev setup SST state
|
|
67
|
+
infra/.sst
|
|
68
|
+
plans/
|
|
69
|
+
.evals/
|
|
70
|
+
apps/dawn/app/api/internal/evals/
|
|
71
|
+
.sst/
|
|
72
|
+
sample-*.json
|
|
73
|
+
results.txt
|
|
74
|
+
|
|
75
|
+
# Dev logs
|
|
76
|
+
.logs/
|
|
77
|
+
tmp/
|
|
78
|
+
|
|
79
|
+
# Supabase local
|
|
80
|
+
**/supabase/.branches
|
|
81
|
+
**/supabase/.temp
|
|
82
|
+
**/supabase/seeds/
|
|
83
|
+
|
|
84
|
+
# Coding Agents
|
|
85
|
+
.claude/
|
|
86
|
+
**/opencode/
|
|
87
|
+
**/opencode/**
|
|
88
|
+
|
|
89
|
+
.zed/
|
|
90
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Raindrop AI
|
|
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.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: raindrop-deep-agents
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Raindrop integration for Deep Agents
|
|
5
|
+
Project-URL: Homepage, https://raindrop.ai
|
|
6
|
+
Project-URL: Documentation, https://docs.raindrop.ai
|
|
7
|
+
Project-URL: Repository, https://github.com/invisible-tools/dawn/tree/main/packages/deep-agents-python
|
|
8
|
+
Author-email: Raindrop AI <sdk@raindrop.ai>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Typing :: Typed
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
14
|
+
Requires-Dist: raindrop-ai>=0.0.42
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: requests>=2.28; extra == 'dev'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# raindrop-deep-agents
|
|
21
|
+
|
|
22
|
+
Raindrop integration for [Deep Agents](https://docs.langchain.com/oss/python/deepagents/overview) (Python). Pass a single LangChain callback handler and Raindrop captures every LLM call, tool invocation, chain step, and agent action — with full OpenTelemetry trace nesting linked to the resulting dashboard event.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install raindrop-deep-agents deepagents langchain-core langchain-openai
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> Works with both `wrapt < 2.0` and `wrapt >= 2.0`. The upstream `opentelemetry-instrumentation-langchain` package (latest 0.59.2) still calls `wrapt.wrap_function_wrapper(module="...", ...)` with the legacy `module=` keyword argument that wrapt 2.0 [renamed to `target=`](https://wrapt.readthedocs.io/en/latest/changes.html). Without a workaround the instrumentor crashes on activation and Traceloop silently swallows the error — traces never reach the dashboard while events keep working (tracked upstream at [traceloop/openllmetry#4009](https://github.com/traceloop/openllmetry/issues/4009) and [Arize-ai/openinference#2996](https://github.com/Arize-ai/openinference/issues/2996)). On import, this package installs a small backwards-compat shim (`raindrop_deep_agents/_wrapt_compat.py`) that translates `module=` → `target=` for any caller using wrapt 2.x; on wrapt 1.x the shim is a no-op. We can drop the shim once the upstream instrumentors migrate.
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from raindrop_deep_agents import RaindropDeepAgents
|
|
36
|
+
from deepagents import create_deep_agent
|
|
37
|
+
from langchain_openai import ChatOpenAI
|
|
38
|
+
from langchain_core.messages import HumanMessage
|
|
39
|
+
|
|
40
|
+
raindrop = RaindropDeepAgents(
|
|
41
|
+
api_key="rk_...",
|
|
42
|
+
user_id="user-123",
|
|
43
|
+
convo_id="session-abc",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
llm = ChatOpenAI(model="gpt-4o-mini")
|
|
47
|
+
agent = create_deep_agent(model=llm, system_prompt="Be concise.")
|
|
48
|
+
|
|
49
|
+
result = agent.invoke(
|
|
50
|
+
{"messages": [HumanMessage(content="Hello!")]},
|
|
51
|
+
config={"callbacks": [raindrop.handler]},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
raindrop.shutdown()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Factory Function (alternative)
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from raindrop_deep_agents import create_raindrop_deep_agents
|
|
61
|
+
|
|
62
|
+
raindrop = create_raindrop_deep_agents(api_key="rk_...", user_id="user-123")
|
|
63
|
+
agent = create_deep_agent(model=llm)
|
|
64
|
+
agent.invoke(
|
|
65
|
+
{"messages": [HumanMessage(content="Hello")]},
|
|
66
|
+
config={"callbacks": [raindrop.handler]},
|
|
67
|
+
)
|
|
68
|
+
raindrop.shutdown()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## What Gets Captured
|
|
72
|
+
|
|
73
|
+
- **LLM calls** — model name, input, output, prompt + completion tokens, finish reason
|
|
74
|
+
- **Tool calls** — tool name, input arguments, output, duration as nested `TOOL_CALL` spans linked to the parent event (via `interaction.track_tool()`)
|
|
75
|
+
- **Chains** — root chain input/output captured as the canonical event (the user's question → final assistant reply)
|
|
76
|
+
- **Agent actions** — tool selection events captured during the agent loop
|
|
77
|
+
- **Errors** — exception type and message captured for both LLM and tool failures
|
|
78
|
+
- **Extended token categories** — cached tokens (`ai.usage.cached_tokens`) and reasoning tokens (`ai.usage.thoughts_tokens`) when available from the provider (e.g. OpenAI, Anthropic)
|
|
79
|
+
- **Finish reason** — captured as `ai.finish_reason` in event properties (`"stop"`, `"length"`, `"tool_calls"`, etc.)
|
|
80
|
+
- **Tags & metadata** — anything passed via LangChain `config={"tags": [...], "metadata": {...}}` is forwarded to event properties
|
|
81
|
+
|
|
82
|
+
## Debug Mode
|
|
83
|
+
|
|
84
|
+
Enable verbose logging with `debug=True`:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
raindrop = RaindropDeepAgents(
|
|
88
|
+
api_key="rk_...",
|
|
89
|
+
debug=True,
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Identify Users
|
|
94
|
+
|
|
95
|
+
Associate events with a user after initialization:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
raindrop.identify("user-123", {"name": "Alice", "plan": "pro"})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Track Signals
|
|
102
|
+
|
|
103
|
+
Send feedback, edits, or custom signals attached to a specific event:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
# After an agent.invoke(...), attach a feedback signal to the event
|
|
107
|
+
# that just shipped. ``raindrop.last_event_id`` is the canonical
|
|
108
|
+
# event_id the handler emitted for the root chain — using it (rather
|
|
109
|
+
# than a freshly generated UUID) ensures the signal links to the real
|
|
110
|
+
# dashboard row instead of creating an orphan signal.
|
|
111
|
+
if raindrop.last_event_id:
|
|
112
|
+
raindrop.track_signal(
|
|
113
|
+
event_id=raindrop.last_event_id,
|
|
114
|
+
name="thumbs_up",
|
|
115
|
+
signal_type="feedback",
|
|
116
|
+
sentiment="POSITIVE",
|
|
117
|
+
comment="user liked the answer",
|
|
118
|
+
)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Flushing and Shutdown
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
raindrop.flush() # flush pending events
|
|
125
|
+
raindrop.shutdown() # flush + release resources (always call before process exit)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API Reference
|
|
129
|
+
|
|
130
|
+
### `RaindropDeepAgents`
|
|
131
|
+
|
|
132
|
+
| Parameter | Type | Default | Description |
|
|
133
|
+
|-----------|------|---------|-------------|
|
|
134
|
+
| `api_key` | `Optional[str]` | `None` | Raindrop API key. If `None`, telemetry shipping is disabled (a `UserWarning` is issued). |
|
|
135
|
+
| `user_id` | `Optional[str]` | `None` | Stamped on every event. Falls back to `"unknown"` if not set. |
|
|
136
|
+
| `convo_id` | `Optional[str]` | `None` | Conversation/session ID — events sharing this value are grouped on the dashboard. |
|
|
137
|
+
| `tracing_enabled` | `bool` | `True` | Enable distributed tracing (activates the LangChain OTel instrumentor). |
|
|
138
|
+
| `bypass_otel_for_tools` | `bool` | `True` | Bypass OTEL for tool spans — emits OTLP directly to `/v1/traces`. |
|
|
139
|
+
| `debug` | `bool` | `False` | Enable DEBUG-level logging. |
|
|
140
|
+
|
|
141
|
+
#### Methods
|
|
142
|
+
|
|
143
|
+
| Method | Description |
|
|
144
|
+
|--------|-------------|
|
|
145
|
+
| `handler` | Property — the LangChain callback handler. Pass into `config={"callbacks": [...]}` on `agent.invoke(...)`. |
|
|
146
|
+
| `last_event_id` | Property — `event_id` of the most recently shipped root event (or `None` if none has landed yet). Use this to attach a `track_signal` to the agent invocation you just ran without having to poll the dashboard API. |
|
|
147
|
+
| `identify(user_id, traits)` | Identify a user with optional traits. |
|
|
148
|
+
| `track_signal(event_id, name, signal_type, ...)` | Track a feedback / edit / default signal against an event. |
|
|
149
|
+
| `flush()` | Flush all pending events to the Raindrop API. |
|
|
150
|
+
| `shutdown()` | Flush remaining events and release resources. |
|
|
151
|
+
|
|
152
|
+
## Async Support
|
|
153
|
+
|
|
154
|
+
The handler inherits from LangChain's `BaseCallbackHandler` and works with both synchronous and asynchronous Deep Agents invocations:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
result = await agent.ainvoke(
|
|
158
|
+
{"messages": [HumanMessage(content="Hello")]},
|
|
159
|
+
config={"callbacks": [raindrop.handler]},
|
|
160
|
+
)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## LangGraph Internals
|
|
164
|
+
|
|
165
|
+
Deep Agents is built on LangGraph. The handler keeps the outer `LangGraph` chain as the canonical root (so OTel association context is set before any span exists), and filters internal LangGraph nodes (`__start__`, `__end__`, `ChannelWrite`, `ChannelRead`, `Branch:*`, dunder names) so they don't pollute the dashboard.
|
|
166
|
+
|
|
167
|
+
## Known Limitations
|
|
168
|
+
|
|
169
|
+
- **Beta status** — API surface may change in minor releases.
|
|
170
|
+
- **Streaming** — Token-by-token streaming events are not captured individually; only the final aggregated response per LLM call is tracked.
|
|
171
|
+
- **Subagent isolation** — Each subagent invoked via the `task` tool fires its own callback chain. Events are correctly grouped by `convo_id`, but the parent–child trace relationship across subagents is best-effort.
|
|
172
|
+
- **OTel context propagation** — The LangChain instrumentor sometimes does not propagate `traceloop.association.properties.user_id` baggage to every span produced inside a LangGraph callback context. The dashboard still shows the trace under the correct event because the SDK records `trace_id` on the root event's properties — but filtering the global Traces page by `user_id` may not surface every relevant span. Tracked upstream at [traceloop/openllmetry#2271](https://github.com/traceloop/openllmetry/issues/2271).
|
|
173
|
+
- **Concurrent invocations on a shared handler** — A single `RaindropDeepAgents` instance keeps one in-flight OTel association context (`_interaction`) at a time. Running multiple `agent.invoke(...)` / `agent.ainvoke(...)` calls **concurrently with the same handler** (e.g. `await asyncio.gather(...)` inside one process) will let later invocations share or overwrite the earlier one's interaction, scrambling the linkage between events and traces. **Workaround**: instantiate one `RaindropDeepAgents` per concurrent request (cheap — it's just a wrapper around module-level SDK state). Sequential invocations on a single instance are fine and exercised by the e2e test suite.
|
|
174
|
+
- **Long chain inputs/outputs are truncated** — Chain-level input and output captured on the root event are truncated to ~8 KB to stay within the SDK's payload limits. The full message history is still visible on the per-LLM child events; only the canonical-row summary is shortened.
|
|
175
|
+
- **Python SDK feature surface** — The Raindrop Python SDK uses module-level functions and does not expose the TypeScript-only `EventShipper` / `TraceShipper` low-level APIs. Equivalent capability is exposed as top-level methods (`identify()`, `track_signal()`) on this class.
|
|
176
|
+
|
|
177
|
+
## Testing
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
cd packages/deep-agents-python
|
|
181
|
+
pip install -e ".[dev]"
|
|
182
|
+
python -m pytest tests/test_handler.py -v # unit tests (no external services)
|
|
183
|
+
|
|
184
|
+
# E2E suite — exercises real Deep Agents + LLM and verifies dashboard ingestion.
|
|
185
|
+
# Tests skip in environments without keys (CI), so set them locally:
|
|
186
|
+
RAINDROP_WRITE_KEY=... \
|
|
187
|
+
OPENAI_API_KEY=... \
|
|
188
|
+
RAINDROP_DASHBOARD_TOKEN=... \
|
|
189
|
+
python -m pytest tests/test_e2e.py -v
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The dashboard token comes from `app.raindrop.ai` → DevTools → Network → any `backend.raindrop.ai` request → `Authorization: Bearer ...` (expires every ~30 minutes).
|
|
193
|
+
|
|
194
|
+
See [`examples/deep-agents-python-basic/`](../../examples/deep-agents-python-basic) for a runnable end-to-end example with a tool call, `identify()`, and `track_signal()`.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# raindrop-deep-agents
|
|
2
|
+
|
|
3
|
+
Raindrop integration for [Deep Agents](https://docs.langchain.com/oss/python/deepagents/overview) (Python). Pass a single LangChain callback handler and Raindrop captures every LLM call, tool invocation, chain step, and agent action — with full OpenTelemetry trace nesting linked to the resulting dashboard event.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install raindrop-deep-agents deepagents langchain-core langchain-openai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> Works with both `wrapt < 2.0` and `wrapt >= 2.0`. The upstream `opentelemetry-instrumentation-langchain` package (latest 0.59.2) still calls `wrapt.wrap_function_wrapper(module="...", ...)` with the legacy `module=` keyword argument that wrapt 2.0 [renamed to `target=`](https://wrapt.readthedocs.io/en/latest/changes.html). Without a workaround the instrumentor crashes on activation and Traceloop silently swallows the error — traces never reach the dashboard while events keep working (tracked upstream at [traceloop/openllmetry#4009](https://github.com/traceloop/openllmetry/issues/4009) and [Arize-ai/openinference#2996](https://github.com/Arize-ai/openinference/issues/2996)). On import, this package installs a small backwards-compat shim (`raindrop_deep_agents/_wrapt_compat.py`) that translates `module=` → `target=` for any caller using wrapt 2.x; on wrapt 1.x the shim is a no-op. We can drop the shim once the upstream instrumentors migrate.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from raindrop_deep_agents import RaindropDeepAgents
|
|
17
|
+
from deepagents import create_deep_agent
|
|
18
|
+
from langchain_openai import ChatOpenAI
|
|
19
|
+
from langchain_core.messages import HumanMessage
|
|
20
|
+
|
|
21
|
+
raindrop = RaindropDeepAgents(
|
|
22
|
+
api_key="rk_...",
|
|
23
|
+
user_id="user-123",
|
|
24
|
+
convo_id="session-abc",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
llm = ChatOpenAI(model="gpt-4o-mini")
|
|
28
|
+
agent = create_deep_agent(model=llm, system_prompt="Be concise.")
|
|
29
|
+
|
|
30
|
+
result = agent.invoke(
|
|
31
|
+
{"messages": [HumanMessage(content="Hello!")]},
|
|
32
|
+
config={"callbacks": [raindrop.handler]},
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
raindrop.shutdown()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Factory Function (alternative)
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from raindrop_deep_agents import create_raindrop_deep_agents
|
|
42
|
+
|
|
43
|
+
raindrop = create_raindrop_deep_agents(api_key="rk_...", user_id="user-123")
|
|
44
|
+
agent = create_deep_agent(model=llm)
|
|
45
|
+
agent.invoke(
|
|
46
|
+
{"messages": [HumanMessage(content="Hello")]},
|
|
47
|
+
config={"callbacks": [raindrop.handler]},
|
|
48
|
+
)
|
|
49
|
+
raindrop.shutdown()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## What Gets Captured
|
|
53
|
+
|
|
54
|
+
- **LLM calls** — model name, input, output, prompt + completion tokens, finish reason
|
|
55
|
+
- **Tool calls** — tool name, input arguments, output, duration as nested `TOOL_CALL` spans linked to the parent event (via `interaction.track_tool()`)
|
|
56
|
+
- **Chains** — root chain input/output captured as the canonical event (the user's question → final assistant reply)
|
|
57
|
+
- **Agent actions** — tool selection events captured during the agent loop
|
|
58
|
+
- **Errors** — exception type and message captured for both LLM and tool failures
|
|
59
|
+
- **Extended token categories** — cached tokens (`ai.usage.cached_tokens`) and reasoning tokens (`ai.usage.thoughts_tokens`) when available from the provider (e.g. OpenAI, Anthropic)
|
|
60
|
+
- **Finish reason** — captured as `ai.finish_reason` in event properties (`"stop"`, `"length"`, `"tool_calls"`, etc.)
|
|
61
|
+
- **Tags & metadata** — anything passed via LangChain `config={"tags": [...], "metadata": {...}}` is forwarded to event properties
|
|
62
|
+
|
|
63
|
+
## Debug Mode
|
|
64
|
+
|
|
65
|
+
Enable verbose logging with `debug=True`:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
raindrop = RaindropDeepAgents(
|
|
69
|
+
api_key="rk_...",
|
|
70
|
+
debug=True,
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Identify Users
|
|
75
|
+
|
|
76
|
+
Associate events with a user after initialization:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
raindrop.identify("user-123", {"name": "Alice", "plan": "pro"})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Track Signals
|
|
83
|
+
|
|
84
|
+
Send feedback, edits, or custom signals attached to a specific event:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
# After an agent.invoke(...), attach a feedback signal to the event
|
|
88
|
+
# that just shipped. ``raindrop.last_event_id`` is the canonical
|
|
89
|
+
# event_id the handler emitted for the root chain — using it (rather
|
|
90
|
+
# than a freshly generated UUID) ensures the signal links to the real
|
|
91
|
+
# dashboard row instead of creating an orphan signal.
|
|
92
|
+
if raindrop.last_event_id:
|
|
93
|
+
raindrop.track_signal(
|
|
94
|
+
event_id=raindrop.last_event_id,
|
|
95
|
+
name="thumbs_up",
|
|
96
|
+
signal_type="feedback",
|
|
97
|
+
sentiment="POSITIVE",
|
|
98
|
+
comment="user liked the answer",
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Flushing and Shutdown
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
raindrop.flush() # flush pending events
|
|
106
|
+
raindrop.shutdown() # flush + release resources (always call before process exit)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API Reference
|
|
110
|
+
|
|
111
|
+
### `RaindropDeepAgents`
|
|
112
|
+
|
|
113
|
+
| Parameter | Type | Default | Description |
|
|
114
|
+
|-----------|------|---------|-------------|
|
|
115
|
+
| `api_key` | `Optional[str]` | `None` | Raindrop API key. If `None`, telemetry shipping is disabled (a `UserWarning` is issued). |
|
|
116
|
+
| `user_id` | `Optional[str]` | `None` | Stamped on every event. Falls back to `"unknown"` if not set. |
|
|
117
|
+
| `convo_id` | `Optional[str]` | `None` | Conversation/session ID — events sharing this value are grouped on the dashboard. |
|
|
118
|
+
| `tracing_enabled` | `bool` | `True` | Enable distributed tracing (activates the LangChain OTel instrumentor). |
|
|
119
|
+
| `bypass_otel_for_tools` | `bool` | `True` | Bypass OTEL for tool spans — emits OTLP directly to `/v1/traces`. |
|
|
120
|
+
| `debug` | `bool` | `False` | Enable DEBUG-level logging. |
|
|
121
|
+
|
|
122
|
+
#### Methods
|
|
123
|
+
|
|
124
|
+
| Method | Description |
|
|
125
|
+
|--------|-------------|
|
|
126
|
+
| `handler` | Property — the LangChain callback handler. Pass into `config={"callbacks": [...]}` on `agent.invoke(...)`. |
|
|
127
|
+
| `last_event_id` | Property — `event_id` of the most recently shipped root event (or `None` if none has landed yet). Use this to attach a `track_signal` to the agent invocation you just ran without having to poll the dashboard API. |
|
|
128
|
+
| `identify(user_id, traits)` | Identify a user with optional traits. |
|
|
129
|
+
| `track_signal(event_id, name, signal_type, ...)` | Track a feedback / edit / default signal against an event. |
|
|
130
|
+
| `flush()` | Flush all pending events to the Raindrop API. |
|
|
131
|
+
| `shutdown()` | Flush remaining events and release resources. |
|
|
132
|
+
|
|
133
|
+
## Async Support
|
|
134
|
+
|
|
135
|
+
The handler inherits from LangChain's `BaseCallbackHandler` and works with both synchronous and asynchronous Deep Agents invocations:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
result = await agent.ainvoke(
|
|
139
|
+
{"messages": [HumanMessage(content="Hello")]},
|
|
140
|
+
config={"callbacks": [raindrop.handler]},
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## LangGraph Internals
|
|
145
|
+
|
|
146
|
+
Deep Agents is built on LangGraph. The handler keeps the outer `LangGraph` chain as the canonical root (so OTel association context is set before any span exists), and filters internal LangGraph nodes (`__start__`, `__end__`, `ChannelWrite`, `ChannelRead`, `Branch:*`, dunder names) so they don't pollute the dashboard.
|
|
147
|
+
|
|
148
|
+
## Known Limitations
|
|
149
|
+
|
|
150
|
+
- **Beta status** — API surface may change in minor releases.
|
|
151
|
+
- **Streaming** — Token-by-token streaming events are not captured individually; only the final aggregated response per LLM call is tracked.
|
|
152
|
+
- **Subagent isolation** — Each subagent invoked via the `task` tool fires its own callback chain. Events are correctly grouped by `convo_id`, but the parent–child trace relationship across subagents is best-effort.
|
|
153
|
+
- **OTel context propagation** — The LangChain instrumentor sometimes does not propagate `traceloop.association.properties.user_id` baggage to every span produced inside a LangGraph callback context. The dashboard still shows the trace under the correct event because the SDK records `trace_id` on the root event's properties — but filtering the global Traces page by `user_id` may not surface every relevant span. Tracked upstream at [traceloop/openllmetry#2271](https://github.com/traceloop/openllmetry/issues/2271).
|
|
154
|
+
- **Concurrent invocations on a shared handler** — A single `RaindropDeepAgents` instance keeps one in-flight OTel association context (`_interaction`) at a time. Running multiple `agent.invoke(...)` / `agent.ainvoke(...)` calls **concurrently with the same handler** (e.g. `await asyncio.gather(...)` inside one process) will let later invocations share or overwrite the earlier one's interaction, scrambling the linkage between events and traces. **Workaround**: instantiate one `RaindropDeepAgents` per concurrent request (cheap — it's just a wrapper around module-level SDK state). Sequential invocations on a single instance are fine and exercised by the e2e test suite.
|
|
155
|
+
- **Long chain inputs/outputs are truncated** — Chain-level input and output captured on the root event are truncated to ~8 KB to stay within the SDK's payload limits. The full message history is still visible on the per-LLM child events; only the canonical-row summary is shortened.
|
|
156
|
+
- **Python SDK feature surface** — The Raindrop Python SDK uses module-level functions and does not expose the TypeScript-only `EventShipper` / `TraceShipper` low-level APIs. Equivalent capability is exposed as top-level methods (`identify()`, `track_signal()`) on this class.
|
|
157
|
+
|
|
158
|
+
## Testing
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
cd packages/deep-agents-python
|
|
162
|
+
pip install -e ".[dev]"
|
|
163
|
+
python -m pytest tests/test_handler.py -v # unit tests (no external services)
|
|
164
|
+
|
|
165
|
+
# E2E suite — exercises real Deep Agents + LLM and verifies dashboard ingestion.
|
|
166
|
+
# Tests skip in environments without keys (CI), so set them locally:
|
|
167
|
+
RAINDROP_WRITE_KEY=... \
|
|
168
|
+
OPENAI_API_KEY=... \
|
|
169
|
+
RAINDROP_DASHBOARD_TOKEN=... \
|
|
170
|
+
python -m pytest tests/test_e2e.py -v
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The dashboard token comes from `app.raindrop.ai` → DevTools → Network → any `backend.raindrop.ai` request → `Authorization: Bearer ...` (expires every ~30 minutes).
|
|
174
|
+
|
|
175
|
+
See [`examples/deep-agents-python-basic/`](../../examples/deep-agents-python-basic) for a runnable end-to-end example with a tool call, `identify()`, and `track_signal()`.
|