Your First AI Pipeline

Build your first AI pipeline and service with ZenML in minutes.

Build and evaluate a real AI service powered by a ZenML pipeline. This quickstart works out of the box with a deterministic fallback and upgrades seamlessly to LLMs when you add a provider API key.

Why pipelines?

  • Reproducible & portable: Run the same code locally or on the cloud by switching stacks.

  • One approach for models and agents: Steps, pipelines, and artifacts work for sklearn and LLMs alike.

  • Evaluate & observe by default: Quality reports, lineage, and step metadata (tokens, latency) out of the box.

Modeling agents as pipelines makes non-deterministic workflows debuggable and shippable: prompts, tools, and routing become explicit steps; runs produce versioned artifacts (including traces and metrics) you can compare and evaluate. This is the same pattern you use for classical ML, so agents and models share the lifecycle and tooling.

What you'll build

  • Document analysis service: A FastAPI app that triggers a ZenML pipeline

  • LLM-first with fallback: Uses LiteLLM if an API key is set, otherwise runs a deterministic analysis that doesn't require making an API request to an LLM service

  • Tracked artifacts: Summary, keywords, sentiment, readability, and rich metadata

  • Quality evaluation: A separate pipeline that annotates runs and generates an HTML report

Architecture (at a glance)

Prerequisites

pip install "zenml[server]"
zenml init

Optional (for LLM mode via LiteLLM, OpenAI shown):

export OPENAI_API_KEY="your-key"

Get the example

git clone --depth 1 https://github.com/zenml-io/zenml.git
cd zenml/examples/minimal_agent_production
pip install -r requirements.txt

Already have the repo? Just cd examples/minimal_agent_production and continue.

Run the service

uvicorn app.main:app --reload --port 8010

Open http://localhost:8010 to use the UI, or call it programmatically:

curl -X POST http://localhost:8010/analyze \
  -H 'Content-Type: application/json' \
  -d '{
        "filename": "sample-report.txt",
        "content": "This is a sample document for analysis...",
        "document_type": "report",
        "analysis_type": "full"
      }'

The endpoint triggers a ZenML pipeline run that stores detailed results and metadata you can inspect in the dashboard.

FastAPI document analysis UI
The web UI served by uvicorn at http://localhost:8010.

Inspect your pipeline runs

zenml login --local

In the dashboard, open the latest run to explore:

  • Steps like ingest_document_step, analyze_document_step, render_report_step

  • Artifacts like DocumentAnalysis with summary, keywords, sentiment, readability score

  • Metadata such as latency, token usage, and model name (when in LLM mode)

Document analysis pipeline DAG in ZenML dashboard
Document analysis pipeline DAG with step-level artifacts and metadata.

Evaluate quality

Generate a quality report across recent analyses:

python run_evaluation.py

Open the run in the dashboard and locate the HTML report artifact with per-item annotations (summary quality, keyword relevance, sentiment accuracy, completeness) and aggregated scores.

Evaluation pipeline DAG in ZenML dashboard
Evaluation pipeline producing an HTML report artifact with aggregated metrics.

How it works (at a glance)

  • The FastAPI app forwards requests to the document_analysis_pipeline in pipelines/production.py

  • The analyze step uses LiteLLM if an API key is configured, otherwise a deterministic analyzer

  • Artifacts are versioned and traceable; evaluation runs read past analyses and render a report

Key files to explore:

  • examples/minimal_agent_production/pipelines/production.py

  • examples/minimal_agent_production/steps/analyze.py

  • examples/minimal_agent_production/run_evaluation.py

Production next steps

  • Run remotely: Configure a remote stack/orchestrator and run the same pipeline on managed compute. See Deploy

  • Automate triggering: Create a run template (ZenML Pro) and trigger via API/webhooks from your app

  • Operationalize: Add caching, retries, schedules, and CI/CD using concepts in the docs

Extend it

  • Swap LLMs/providers through LiteLLM without code changes

  • Add guardrails/structured outputs via Pydantic models

  • Add retrieval or additional steps for more advanced analysis

Looking for the code? Browse the complete example at examples/minimal_agent_production.

Last updated

Was this helpful?