---
updatedAt: 2026-11-11T22:44:32.000Z
agentTools:
  projectIndex: https://docs.getmontecarlo.com/llms.txt
---

# Pre-Prod Agent Monitors

Pre-prod agent monitors allow you to run agent evaluations on a static golden set of prompts or conversations. These evaluations serve as repeatable tests executed against a live production or pre-production environment, enabling CI/CD pipeline gating and tracking agent performance across builds.

# Why use pre-prod monitors?

When deploying LLM-powered agents, you need confidence that code changes don't degrade agent quality. Pre-prod monitors enable:

* **Regression testing** — Run the same golden prompts against each build to detect quality regressions before deployment
* **CI/CD gating** — Automatically fail pipelines when agent evaluation scores drop below thresholds
* **Performance tracking** — Track agent quality metrics across builds over time

## How pre-prod monitors differ from standard agent monitors

| Aspect          | Standard Agent Monitors      | Pre-prod Agent Monitors                            |
| --------------- | ---------------------------- | -------------------------------------------------- |
| Metric grouping | Time-bucketed (hourly/daily) | All spans for one `ci_build_id`, per triggered run |
| Orchestration   | Scheduled by Monte Carlo     | Manually triggered via SDK                         |
| Use case        | Production monitoring        | CI/CD pipeline gating                              |

## Setup guide

### 1. Instrument your agent

First, send your agent's traces to Monte Carlo, if you don't already: with the [Monte Carlo OpenTelemetry SDK](https://pypi.org/project/montecarlo-opentelemetry/) in Python, or see [OpenTelemetry Integration](https://docs.getmontecarlo.com/docs/opentelemetry-integration) for other setups, such as [Node.js](https://docs.getmontecarlo.com/docs/nodejs-integration).

When invoking your agent during CI builds, pass `ci_build_id` and optionally `expected_output` as metadata. These metadata attributes will be available in the `attr_map` of your agent's traces. When configuring the monitor (see below), you can filter by these attributes.

**If using LangGraph Server**, pass these values in the metadata field of your request:

```json
POST /threads/{thread_id}/runs
{
  "assistant_id": "your-assistant",
  "input": {...},
  "metadata": {
    "ci_build_id": "build-127",
    "expected_output": "Expected response text"
  }
}
```

**If using a custom API layer**, use `mc.create_span_with_attributes` to propagate attributes to child spans. Each key becomes a `montecarlo.<key>` attribute. Use the keys below: Monte Carlo reads the expected output only from `montecarlo.association_properties.expected_output`.

```python
import montecarlo_opentelemetry as mc

@app.post("/analyze")
def analyze_sync() -> dict[str, Any]:
    body: dict[str, Any] = app.current_event.json_body or {}
    attributes = {
        "association_properties.ci_build_id": body["ci_build_id"],
        "association_properties.expected_output": body.get("expected_output", ""),
    }

    with mc.create_span_with_attributes("analyze_sync", attributes):
        return _analyze_handler(body)
```

**In Node.js**, pass the full attribute names to `withAttributes()` from [Node.js Integration](https://docs.getmontecarlo.com/docs/nodejs-integration), which sets them on every span started inside it:

```javascript
const { withAttributes } = require("./tracing");

withAttributes(
  {
    "montecarlo.association_properties.ci_build_id": body.ci_build_id,
    "montecarlo.association_properties.expected_output": body.expected_output ?? "",
  },
  () => analyzeHandler(body),
);
```

In Python, you can also pass attributes via the `config` argument when invoking a LangGraph:

```python
graph.ainvoke(
    input={...},
    config={"ci_build_id": "build-127", "expected_output": "..."}
)
```

### 2. Create a pre-prod agent monitor

Follow the standard [agent monitor configuration steps](https://docs.getmontecarlo.com/docs/agent-monitors-overview#configuring-agent-monitors) with these key differences:

* **Filter Spans By `ci_build_id`:** Under "Filter spans by"
  * Select `attr_map` and select the `montecarlo.association_properties.ci_build_id` attribute
  * Set the value to `{{ci_build_id}}`. The `{{ci_build_id}}` syntax creates a runtime variable that you provide when triggering the monitor via the SDK.
* **Group data:** For "Group spans by" (or "Group traces by" / "Group conversations by"), select "none" instead of "ingestion time", since pre-prod evaluations should assess all traces for a given build rather than grouping by time. Only Agent Metric and Agent Evaluation monitors offer "none", so use one of those for pre-prod.
* **Define Manual Schedule:** Under "Define schedule", set "Run monitor" to "Manually" instead of a recurring schedule, since the monitor will be triggered programmatically from your CI pipeline.

### 3. Create your CI build script

Your CI script orchestrates the pre-prod evaluation flow:

1. **Execute golden prompts** — Invoke your agent with each prompt, passing `ci_build_id` and `expected_output` in the request
2. **Wait for traces** — Poll until all traces have arrived
3. **Trigger the monitor** — Call `runMonitor` with `ci_build_id` as a runtime variable
4. **Poll for completion** — Wait until the monitor execution finishes
5. **Gate deployment** — Check the `breached` status and fail or pass the pipeline accordingly

The [Pycarlo SDK](https://docs.getmontecarlo.com/docs/using-the-sdk) provides components for building your CI script. See the [sample\_agent\_ci\_build\_script.py](https://github.com/monte-carlo-data/monte-carlo-python-sdk-examples/tree/main/monitors/sample_agent_ci_build_script.py) file for a complete reference implementation.