Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

docs: add Tracer.oneshot() to CLI guide and getting-started

xf gongb54e86d9bfc7
diff --git a/website/docs/guides/tracing/cli.md b/website/docs/guides/tracing/cli.md
index 602cbaa..d1b5c0e 100644
--- a/website/docs/guides/tracing/cli.md
+++ b/website/docs/guides/tracing/cli.md
@@ -47,6 +47,15 @@ cubepi trace ls --meta conversation_id=conv_123
cubepi trace ls --meta user_id=usr_9 --meta org_id=org_1 # repeatable = AND, exact match
```
+Traces produced by [`Tracer.oneshot()`](../../api/cubepi-tracing#tracer-oneshot)
+(background LLM calls without a full agent loop) are also indexed here. Filter
+them by the `operation` name passed to `oneshot()`:
+
+```bash
+cubepi trace ls --meta oneshot_operation=consolidate_memory
+cubepi trace stats --by model --meta oneshot_operation=consolidate_memory
+```
+
Each `--meta KEY=VALUE` is matched exactly against the trace's root metadata;
repeating the flag ANDs the conditions.
diff --git a/website/docs/guides/tracing/getting-started.md b/website/docs/guides/tracing/getting-started.md
index 31445e8..738fcc6 100644
--- a/website/docs/guides/tracing/getting-started.md
+++ b/website/docs/guides/tracing/getting-started.md
@@ -225,6 +225,46 @@ contextvars are per-asyncio-task, so concurrent agents see
independent values, and nested `tracing_context` blocks merge
(tags concatenate, metadata keys union with inner winning).
+## Tracing background LLM calls (`oneshot`)
+
+`attach()` instruments a cubepi `Agent`. For background tasks that call an LLM
+directly — without a full agent loop (no tool use, no multi-turn) — use
+`Tracer.oneshot()` instead. It produces the same `invoke_agent` root span and
+`chat` child span so the `cubepi trace` CLI indexes it alongside normal agent
+runs.
+
+```python
+async with tracer.oneshot(
+ provider=provider,
+ model=model,
+ operation="consolidate_memory", # labelled in the trace
+ metadata={"conversation_id": conv_id}, # queryable via --meta
+) as session:
+ text = await session.generate(
+ system=SYSTEM_PROMPT,
+ messages=[UserMessage(content=[TextContent(text=prompt)])],
+ max_output_tokens=1500,
+ )
+```
+
+The span tree is flat (no `cubepi.turn` wrapper — there is no loop):
+
+```
+invoke_agent 820ms
+ └── chat deepseek-v3 815ms tok 3200/180
+```
+
+Filter these traces by operation name in the CLI:
+
+```bash
+cubepi trace ls --meta oneshot_operation=consolidate_memory
+cubepi trace ls --meta conversation_id=conv-123 # alongside the conversation's agent runs
+```
+
+The `operation` string is recorded as both `cubepi.oneshot.operation` (for
+dashboards) and `cubepi.metadata.oneshot_operation` (so `--meta` can reach it,
+since the CLI filter only reads `cubepi.metadata.*` attributes).
+
## Next
- [OTLP & Backends](./otlp) — Jaeger, Tempo, Honeycomb, Datadog, …