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

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Packages and server binaries are not published yet: build from source, as the quick start shows. Check the status note on the introduction page before you suggest `cargo add`, `npm install` or `pip install`.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.

# Rust library

> The magpiedb crate: an embedded store for AI-agent traces that runs inside your process, like SQLite.

`magpiedb` is the engine of Magpie: an embedded store for AI-agent traces. One engine does three jobs:

1. Full-text search over the input and output of spans (prompts and replies).
2. Whole-trace queries: "runs where a tool failed AND the agent was asked about refunds".
3. Sums: tokens, cost and counts per model, user or day.

It runs inside your process, like SQLite. A store is one folder of files that do not change after they are written. One process writes a store; other processes can open it read-only.

The same engine is in the [Node package](https://docs.magpiedb.com/libraries/node.md) (`npm install magpiedb`), the [Python package](https://docs.magpiedb.com/libraries/python.md) (`pip install magpiedb`) and in `magpie-server`, which takes OpenTelemetry traces over OTLP and serves a JSON query API: [github.com/intojhanurag/magpie](https://github.com/intojhanurag/magpie).

> [!WARNING]
>
> Magpie is not on crates.io yet, and release 0.1.0 is not out. Until it is, you build it from the repo (see the [quickstart](https://docs.magpiedb.com/quickstart.md)). You need Rust (stable).

## Example

```rust theme={null}
use magpiedb::{Filter, Options, Span, Store, Text, TraceQuery};

fn main() -> Result<(), magpiedb::Error> {
    let store = Store::open("traces", Options::default())?;

    let mut span = Span::new("trace-1", "span-1", "tool_call", 1_700_000_000_000);
    span.input = "look up the refund policy".into();
    store.upsert(vec![span])?;          // write again when the span ends: it replaces this version
    store.commit()?;                     // or wait: the store commits on a timer

    let hits = store.count(&Filter { text: Some(Text::phrase("refund policy")), ..Default::default() })?;
    let failed = store.find_traces(&TraceQuery {
        any_span: vec![Filter { kind: Some("tool_call".into()), has_error: Some(true), ..Default::default() }],
        limit: 50,
        ..Default::default()
    })?;
    println!("{hits} spans with the phrase, {} traces with a failed tool call", failed.count);
    Ok(())
}
```

## Add it to your app

From the quickstart: make an app and add the crate by path. `REPO` is the folder of the repo. This app was run on 2026-12-04 (see the [quickstart](https://docs.magpiedb.com/quickstart.md)).

```sh theme={null}
cargo new --quiet my-rust-app && cd my-rust-app
cargo add --quiet magpiedb --path "$REPO/crates/core"
cat > src/main.rs <<'EOF'
use magpiedb::{Filter, Options, Span, Store, Text, TraceQuery};

fn main() -> Result<(), magpiedb::Error> {
    let store = Store::open("traces", Options::default())?;

    let mut span = Span::new("trace-1", "span-1", "tool_call", 1_700_000_000_000);
    span.input = "look up the refund policy".into();
    span.error = Some("timeout".into());
    store.upsert(vec![span])?; // write it again when the span ends: it replaces this version
    store.commit()?;           // or wait: the store commits on a timer (0.5 s)

    let hits = store.count(&Filter { text: Some(Text::phrase("refund policy")), ..Default::default() })?;
    let failed = store.find_traces(&TraceQuery {
        any_span: vec![Filter { kind: Some("tool_call".into()), has_error: Some(true), ..Default::default() }],
        limit: 50,
        ..Default::default()
    })?;
    println!("{hits} span with the phrase; failed tool calls in {} trace: {}", failed.count, failed.traces[0].trace_id);
    store.close()
}
EOF
cargo run --quiet --release
cd ..
```

```text theme={null}
1 span with the phrase; failed tool calls in 1 trace: trace-1
```

The first build of the app compiles the engine (some minutes). The docs of the Rust API: `cargo doc -p magpiedb --open` in the repo.

## Status

Version 0.1: the first release. The file format of a store has a compatibility number; a build refuses a store of another number before it changes a byte. Limits and measurements: [`docs/FINDINGS.md`](https://github.com/intojhanurag/magpie/blob/main/docs/FINDINGS.md) in the repository. More limits: [limits](https://docs.magpiedb.com/limits.md).

## License

Apache-2.0.


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