> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracepress.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Live pipelines

> Run the same pipelines on traces as they arrive, and keep them running on a server.

A live pipeline is an ordinary pipeline over a live source: it emits results while runs are
still going instead of after they finish.

## Is my agent stuck right now?

`tp.watch.otlp()` receives traces from any OTLP exporter. This monitor keeps a running note per
trace with `lm_fold` and flags agents that loop or make no headway:

```python theme={null}
import asyncio
import tracepress as tp

tp.configure(lm="openrouter:openai/gpt-6-luna")
live = tp.watch.otlp(port=4318)          # point your exporter at http://localhost:4318/v1/traces

monitor = live.steps.group_by("trace").lm_fold(
    "progress, source, message, reasoning, tool_calls: list[dict], observation -> progress, stuck: bool, concern",
    instructions="You are monitoring a coding agent live. `previous_progress` is your running note "
                 "on what it has done so far. Update it with the newest step. Set `stuck` if the agent "
                 "seems to be looping or making no headway, and give a short `concern` (or 'none').",
    emit="update")

async def watch():
    async for event in monitor.events():
        if isinstance(event, tp.Closed):
            continue
        if event.row.stuck:
            print(event.row.trace, event.row.concern)

asyncio.run(watch())
```

* Steps stream in as their spans complete.
* `emit="update"` emits the fold's state after every step, not only when the trace ends. Rows
  have `final=False` until then, and a `version` that goes up with each update.
* `.events()` yields every row as it's produced, plus a `tp.Closed` event when a group ends.

`emit="update"` works on `lm_reduce` too, and `emit=tp.every(n)` updates after every n rows. In
batch it changes nothing, and a reduce's final row always comes from a full reduce at close.

## Try it on stored runs

`tp.replay` plays a stored source back as a stream, so you can build a live pipeline without a
live system. Harbor steps are keyed by `trial` rather than `trace`:

```python theme={null}
live = tp.replay(tp.read.harbor("jobs/my-job"), speed=30)   # 30x real time; omit for as fast as possible
monitor = live.steps.group_by("trial").lm_fold(...)
```

[examples/live\_monitor.py](https://github.com/Ziems/tracepress/blob/main/examples/live_monitor.py)
is this monitor as a script:

```bash theme={null}
uv run python examples/live_monitor.py example_harbor_jobs/trials --tasks wal-recovery-ordering --limit 2 --speed 30
```

## Keep pipelines running on a server

`tracepress serve` holds one live stream of traces and runs registered pipelines on it
continuously. Any client can stream traces in, register a pipeline, or listen:

```bash theme={null}
tracepress serve --port 7700 --lm openrouter:openai/gpt-6-luna
```

```python theme={null}
client = tp.connect("localhost:7700")
client.stream(tp.watch.otlp())                      # or client.push(rows, table="steps")

live = client.source                                # the server's stream, to build pipelines on
frustration = live.steps.lm_map("source, message -> frustrated: bool, why")
client.register(name="frustration", pipeline=frustration)

# in another process, e.g. a Slack bot
async for e in tp.connect("localhost:7700").listen("frustration"):
    if e.kind != "closed" and e.row.frustrated:
        slack.post(e.row.why)
```

A pipeline registered later catches up on the stream so far, and registering a name again
replaces it.

> [!WARNING]
>
> Registering ships the pipeline's code (pickled), so the server runs what clients send. It
> listens on localhost by default; any other `--host` needs `--token`.

## Next steps

> [card] [CLI](https://docs.tracepress.ai/reference/cli.md)
>
> Every `tracepress serve` option.

> [card] [Load traces](https://docs.tracepress.ai/cookbooks/sources.md)
>
> Which OpenTelemetry conventions become steps.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.