# Build (workflow)

Stage 2. Now that you've picked a model in [Select](/6.-build-wire-your-code/workflow.md), wire your code to emit **traces** — the data Stratix needs to grade what your AI did. The Build stage is where you instrument your application AND iterate on the AI feature with evaluation feedback in the loop.

## The question this stage answers

*"Can Stratix see what my AI is doing, and am I building toward something I can evaluate?"*

## What to do

1. **Pick an instrumentation strategy.**

* **SDK trace ingest** — call `client.traces.create(...)` after each AI call (or batch)
* **Framework integration** — if your framework has a Stratix integration, wire it in (see [Integrations](/6.-build-wire-your-code/migration.md))
* **OTel-style** — emit OpenTelemetry-like spans and post them as a trace

2. **Capture the whole chain.** A trace with only the top-level call is grading-friendly but useless for root-cause. Capture every span — every tool call, every retrieval, every nested LLM call.
3. **Annotate with tags.** `production`, `ab-test-v2`, `customer-tier-X` — make filtering tractable later.
4. **Test the ingest.** Send a single trace; confirm it appears in Premium → Traces.
5. **Iterate with evaluation in the loop.** As you build, run small evaluation passes against representative data so quality feedback lands while the code is still in flight, not at the end.

## What you'll have at the end

* Traces flowing into Stratix from your application
* A trace set you can grade with scorers and judges
* An evaluation feedback loop running alongside development

## Sample code

```python
from layerlens import Stratix
client = Stratix()

client.traces.create(
 id="trace-1",
 name="answer-question",
 inputs={"prompt": prompt_text},
 outputs={"response": response_text},
 spans=[
 {"name": "retrieval", "kind": "tool", "inputs": {...}, "outputs": {...}},
 {"name": "llm", "kind": "llm", "model": "claude-opus-4-7", "inputs": {...}, "outputs": {...}}
 ],
 tags={"environment": "production", "feature": "support-bot"}
)
```

## Where to next

* [Observe →](/6.-build-wire-your-code/workflow.md)
* [Concept: Traces and spans](/6.-build-wire-your-code/traces-and-spans.md)
* [Stratix Premium — Traces](/7.-observe-see-whats-happening/traces.md)
* [Integrations](/6.-build-wire-your-code/migration.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.layerlens.ai/6.-build-wire-your-code/workflow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
