# Your first workflow

A hands-on tutorial. Build a text pipeline, then an LLM app, then a cited RAG chatbot, learning the canvas, ports, runs, run targets and Chat along the way.

Source: https://glamorous-boar.cloudvent.net/first-workflow/

---

This tutorial builds three small apps by hand. Each one adds one idea. It takes about 20 minutes and assumes you finished the [Quick start](/quick-start/) and have `OPENROUTER_API_KEY` in `.env` (or in Settings → Secrets).

## Part 1: A text pipeline (no AI yet)

Goal: learn the canvas, typed ports, saving and running.

1. Click **New**, choose **Blank canvas** and name the project *Greeter*.
2. In the **Node library** on the left, search for *Manual Input* and drag it onto the canvas (or click it to add). In the **Inspector** on the right, set `key` to `name`, `value_type` to `String`, and `default` to `world`.
3. Add a **Text Template**. Set `template` to `Hello, {{ text }}!`.
4. Drag from the Manual Input's `value` port (right side) to the Text Template's `text` port (left side). Ports are coloured by type; the IDE refuses a connection the runtime would reject.
5. Add an **Output** node with `key` set to `greeting`, and connect Text Template's `text` to Output's `value`.
6. Press **Ctrl+S** (or **Save**). Every save creates a new, numbered **revision**.
7. Open **Run inputs**, type `Ada`, and click **Run**. The **Output** tab shows `{"greeting": "Hello, Ada!"}`.

What happened: the IDE saved the graph as IR, the API ran the [validation pipeline](/architecture/runtime/#validation-pipeline), compiled an execution plan, and the runtime executed the nodes in dependency order, streaming trace events to the IDE over SSE.

<Alert variant="tip" title="Read the Problems tab" text="If a node shows a red badge, open the Problems tab. Every diagnostic has a stable code (for example `PORT_MISSING_REQUIRED_INPUT`), a message and usually a hint. See [Error codes](/error-codes/)."/>

## Part 2: An LLM app

Goal: call a real model, use secrets and Chat.

1. Create another blank project, *Explainer*.
2. Add **Manual Input** with `key` = `question`.
3. Add an **LLM** node. Leave `provider` = `openrouter` and `model` = `google/gemini-3.8-flash`. In `api_key`, choose the secret name `OPENROUTER_API_KEY` (the form shows whether it is set). Set `system_prompt` to *Explain like I am twelve, in at most three sentences.*
4. Connect `question.value` → `LLM.prompt`.
5. Add **Output** with `key` = `answer`, and connect `LLM.text` → `Output.value`.
6. Save, then open the **Chat** tab and ask *Why is the sky blue?* The answer types out live (streaming), with latency, tokens and cost underneath.

Chat is simply another way to start a run: it fills the input named `question` (or the first text input) and reads the output named `answer` (or the first output).

<Alert variant="note" title="Reasoning models need room" text="Models such as Gemini 3.x think before answering, and thinking tokens come out of `max_tokens`. If you get `MODEL_EMPTY_RESPONSE` or `MODEL_OUTPUT_TRUNCATED`, raise `max_tokens` (1024 or more) or lower `reasoning_effort`."/>

## Part 3: A RAG chatbot with citations

Goal: answer from your own documents, with sources. This introduces **handles** and **run targets**.

A RAG app has two flows that share an embedding model and a vector store:

<Diagram caption="Ingestion (top) and question answering (bottom) share the Embedding Model and Vector Store handles.">

```
flowchart LR
  L[Document Loader] --> CL[Document Cleaner] --> CH[Chunker] --> IX[Index Documents] --> O1[Output: Index report]
  EM[Embedding Model] -. handle .-> IX
  VS[Vector Store] -. handle .-> IX
  Q[Manual Input: question] --> RT[Retriever] --> CB[Context Builder] --> LLM --> CI[Citation Builder] --> O2[Output: answer]
  EM -. handle .-> RT
  VS -. handle .-> RT
  Q --> CB
  CB -- sources --> CI
```

</Diagram>

The fastest way is **New → RAG answers with citations**, which wires exactly this. To understand it, inspect each node:

1. **Document Loader**: click it, then **Upload files** in the Inspector and pick `examples/data/employee-handbook.md` (or any PDF, Word, Excel, PowerPoint, HTML, CSV… file).
2. **Chunker**: splits documents into ~300-token chunks, keeping exact character offsets so citations can point to the source span.
3. **Embedding Model**: local `BAAI/bge-small-en-v1.5` via fastembed. No key needed; downloaded once.
4. **Vector Store**: embedded Qdrant on your disk. The collection is prefixed with the project ID so projects never share data.
5. **Index Documents**: embeds chunks and also builds a BM25 keyword index. Re-running skips unchanged chunks.

Now run only the ingestion flow: open the toolbar's **Run** menu and pick **Run → Index report**. That is a **run target**: only the chosen Output and everything it depends on runs. The Output tab shows how many chunks were indexed.

Then ask in **Chat**: *What is the hotel limit per night?* The question flow runs (**Retriever → Context Builder → LLM → Citation Builder**) and the answer cites its sources like `[1]`. Click a citation number to open the source chunk in the document viewer.

### What each RAG node contributed

| Node | Why it matters |
|---|---|
| Retriever | Embeds the question and finds the most similar chunks (cosine similarity). |
| Context Builder | Numbers chunks `[1]..[n]`, removes duplicates, fits a token budget and writes the prompt telling the model to cite. |
| LLM | Writes the answer from the numbered sources only. |
| Citation Builder | Maps `[n]` markers to real sources and removes citations that point nowhere. |

## What you learned

- Graphs are made of **nodes** with **typed ports**; connections are checked as you draw.
- **Save** creates an immutable **revision**; **Run** executes the saved revision.
- **Secrets** are referenced by name and resolved at run time.
- **Handles** (Embedding Model, Vector Store) let two flows share resources.
- **Run targets** run only part of a graph.
- **Chat** is a run with a question input and an answer output.

## Where to go next

- Make retrieval better: [Advanced RAG](/rag/#advanced-rag).
- Give a model tools: [Agents and tools](/agents/).
- Measure quality before and after a change: [Evaluation Lab](/evaluation/).
- Understand the theory: [Retrieval-augmented generation](/learn/rag/) in the handbook.
