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

# Examples

> 47 curated, runnable demos. Each one solves a real situation a developer would recognize, with captured Ollama output in the file header.

Every example lives under [`examples/`](https://github.com/0xvasanth/cognis/tree/main/examples) in the repo. They're real, runnable programs — not snippets — and each one is shaped around a recognizable scenario, not an API tour.

## How each example is shaped

Open any file and you'll see this header at the top:

```rust theme={null}
//! What you'll learn:    <one-sentence takeaway>
//! Why this matters:     <when you'd reach for this in your code>
//! Scenario:             <the situation the body enacts>
//! Run with:             <exact cargo command>
//! Sample output:        <captured against Ollama / llama3.1>
```

So you can decide whether the example is what you want without running it.

## How to run

```bash theme={null}
git clone https://github.com/0xvasanth/cognis.git
cd cognis
cargo run -p cognis-examples --example <NAME>
```

For LLM-backed examples, set `COGNIS_PROVIDER` plus the matching key. The simplest path is local Ollama — no key needed:

```bash theme={null}
ollama pull llama3.1
COGNIS_PROVIDER=ollama COGNIS_OLLAMA_MODEL=llama3.1 \
  cargo run -p cognis-examples --example agents_react_agent
```

See [Environment variables](/reference/env-vars) for the full provider env-var table, and [Quickstart](/get-started/quickstart) for the smallest working agent.

## Categories

<CardGroup cols={2}>
  <Card title="Quickstart V2" icon="bolt" href="/examples/quickstart">
    8 numbered demos that walk the V2 surface end-to-end. The fastest way to learn the shape of every layer.
  </Card>

  <Card title="Chains" icon="link" href="/examples/chains">
    4 examples on composition — `pipe`, structured extraction, typed runnables, dirty-JSON repair.
  </Card>

  <Card title="Agents" icon="robot" href="/examples/agents">
    5 examples on the agent loop — ReAct, conversational memory, multi-agent, planning, streaming events.
  </Card>

  <Card title="Memory" icon="brain" href="/examples/memory">
    3 examples covering the memory variants — Buffer/Window/TokenBuffer trade-offs, summary compaction, knowledge-graph triples.
  </Card>

  <Card title="Models" icon="plug" href="/examples/models">
    4 examples on LLM clients — streaming, embeddings + similarity search, length-based model routing, multimodal.
  </Card>

  <Card title="Tools" icon="screwdriver-wrench" href="/examples/tools">
    4 examples on tool definition and dispatch — typed schemas, multi-tool agent, orchestrator DAG, stateful HTTP.
  </Card>

  <Card title="Retrieval" icon="magnifying-glass" href="/examples/retrieval">
    5 examples on RAG — splitters, end-to-end pipeline, incremental indexing, cross-encoder reranking, caching.
  </Card>

  <Card title="Graphs" icon="diagram-project" href="/examples/graphs">
    5 examples on `Graph<S>` — polling state machines, checkpointing, HITL interrupts, semantic routing, topic channels.
  </Card>

  <Card title="Observability" icon="chart-line" href="/examples/observability">
    3 examples on observers, evaluation harness, and pre-flight health checks.
  </Card>

  <Card title="Resilience" icon="shield" href="/examples/resilience">
    4 examples on error handling, retry/backoff, cost-based rate limiters, SSRF guards.
  </Card>

  <Card title="Parsers" icon="brackets-curly" href="/examples/parsers">
    2 examples on output-fixing and retry parsers — making structured output robust against bad model JSON.
  </Card>
</CardGroup>

## Looking for something larger?

Standalone examples show one feature at a time. For full applications that combine several layers (research assistants, code Q\&A over a repo, multi-agent debate, streaming UIs, more), see [Patterns](/patterns/research-assistant).
