|
| 1 | +--- |
| 2 | +id: mlflow |
| 3 | +title: MLflow Integration |
| 4 | +sidebar_label: MLflow |
| 5 | +--- |
| 6 | + |
| 7 | +VoltAgent ships with an OpenTelemetry-based observability layer. You can export spans directly to [MLflow](https://mlflow.org) using standard OpenTelemetry packages — no additional wrapper needed. MLflow's OTLP endpoint ingests VoltAgent traces and renders them with rich span-type icons, chat UI, and token usage summaries. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- An MLflow server running and accessible. You can [set one up locally](https://mlflow.org/docs/latest/genai/getting-started/connect-environment.html) (via pip, Docker Compose, etc.) or use a managed service like [Databricks](https://www.databricks.com/), [AWS SageMaker](https://aws.amazon.com/sagemaker/ai/experiments/), and more. |
| 12 | +- A basic VoltAgent application setup. |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +Install the OpenTelemetry SDK and OTLP protobuf exporter: |
| 17 | + |
| 18 | +```bash npm2yarn |
| 19 | +npm install @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-proto |
| 20 | +``` |
| 21 | + |
| 22 | +## Setup |
| 23 | + |
| 24 | +### Configure VoltAgent |
| 25 | + |
| 26 | +In your application (e.g., `src/index.ts`) import the observability class and the OpenTelemetry packages: |
| 27 | + |
| 28 | +```typescript |
| 29 | +import { Agent, VoltAgent, VoltAgentObservability } from "@voltagent/core"; |
| 30 | +import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base"; |
| 31 | +import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto"; |
| 32 | +``` |
| 33 | + |
| 34 | +Create a `VoltAgentObservability` instance and attach the MLflow exporter: |
| 35 | + |
| 36 | +```typescript |
| 37 | +const mlflowExporter = new OTLPTraceExporter({ |
| 38 | + url: `${process.env.MLFLOW_TRACKING_URI}/v1/traces`, |
| 39 | + headers: { |
| 40 | + "x-mlflow-experiment-id": process.env.MLFLOW_EXPERIMENT_ID ?? "0", |
| 41 | + }, |
| 42 | +}); |
| 43 | + |
| 44 | +const observability = new VoltAgentObservability({ |
| 45 | + spanProcessors: [new BatchSpanProcessor(mlflowExporter)], |
| 46 | +}); |
| 47 | + |
| 48 | +const agent = new Agent({ |
| 49 | + name: "my-voltagent-app", |
| 50 | + instructions: "A helpful assistant", |
| 51 | + model: "openai/gpt-4o-mini", |
| 52 | +}); |
| 53 | + |
| 54 | +new VoltAgent({ |
| 55 | + agents: { agent }, |
| 56 | + observability, |
| 57 | +}); |
| 58 | +``` |
| 59 | + |
| 60 | +Add the required environment variables to your `.env` file: |
| 61 | + |
| 62 | +```bash |
| 63 | +OPENAI_API_KEY=your-api-key |
| 64 | +MLFLOW_TRACKING_URI=http://localhost:5000 |
| 65 | +MLFLOW_EXPERIMENT_ID=0 |
| 66 | +``` |
| 67 | + |
| 68 | +### Run and View Traces |
| 69 | + |
| 70 | +Start the VoltAgent development server: |
| 71 | + |
| 72 | +```bash |
| 73 | +npm run dev |
| 74 | +``` |
| 75 | + |
| 76 | +Interact with your agent via the [VoltAgent Console](https://console.voltagent.dev), then open the MLflow UI at `http://localhost:5000` to see your traces. |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +## How it Works |
| 81 | + |
| 82 | +- VoltAgent initializes a global OpenTelemetry tracer provider. |
| 83 | +- The standard `OTLPTraceExporter` sends spans to MLflow's `/v1/traces` endpoint via OTLP/HTTP (protobuf). |
| 84 | +- MLflow automatically translates VoltAgent's semantic conventions for optimal visualization — mapping agent, LLM, tool, and memory spans to dedicated span types, extracting token usage metrics, and rendering chat messages in a rich UI. |
| 85 | +- All agent and workflow spans flow through the observability pipeline, giving you end-to-end visibility into your agent's execution. |
| 86 | + |
| 87 | +## Learn More |
| 88 | + |
| 89 | +- [MLflow Tracing](https://mlflow.org/docs/latest/genai/tracing/index.html) — Full tracing guide including evaluation, prompt management, and more. |
| 90 | +- [MLflow OpenTelemetry Integration](https://mlflow.org/docs/latest/genai/tracing/opentelemetry.html) — Details on MLflow's OpenTelemetry support. |
| 91 | +- [MLflow VoltAgent Guide](https://mlflow.org/docs/latest/genai/tracing/integrations/listing/voltagent.html) — Step-by-step setup tutorial with screenshots. |
0 commit comments