CI/CD Integration

This guide shows how to run Sagewai agents in CI pipelines — PR summaries, evaluation quality gates, fleet worker deployment, and webhook-triggered agent runs.

Sagewai offers three reusable GitHub Actions plus a trigger system for event-driven execution. Agents run headlessly in CI, can post results as PR comments, and can fail a build when agent performance drops below a threshold.

Reusable GitHub Actions

Note: These actions are in development and will be published to the GitHub Marketplace as sagewai/actions/*. Until then, use the CLI commands in CLI for CI below — they work with any CI system today.

run-agent

Execute any Sagewai agent in your pipeline:

- uses: sagewai/actions/run-agent@v1
  with:
    agent: summarizer
    input: "Summarize this PR: ${{ github.event.pull_request.title }}"
    fleet-gateway: ${{ secrets.SAGEWAI_GATEWAY_URL }}
    api-key: ${{ secrets.SAGEWAI_API_KEY }}
    model: gpt-4o              # optional model override
    post-as-comment: 'true'    # post result as PR comment

Common uses: PR summaries, code review agents, release note generation, documentation freshness checks.

run-evals

Fail CI when agent quality drops below a threshold:

- uses: sagewai/actions/run-evals@v1
  with:
    eval-suite: evals/core-suite.yaml
    threshold: '0.8'           # fail if score < 80%
    api-key: ${{ secrets.SAGEWAI_API_KEY }}

Common uses: regression testing for agent quality, continuous evaluation on push to main, benchmark tracking across releases, A/B testing configurations.

deploy-worker

Build, register, and deploy fleet workers from CI:

- uses: sagewai/actions/deploy-worker@v1
  with:
    fleet-gateway: ${{ secrets.SAGEWAI_GATEWAY_URL }}
    enrollment-key: ${{ secrets.ENROLLMENT_KEY }}
    worker-pool: gpu-inference
    labels: 'gpu,llama3'
    models: 'ollama/llama3.1:70b'

Common uses: auto-deploy workers on version tags, register GPU runners, scale worker pools, blue-green worker deployments.

Workflow Templates

PR Summary Bot

Post a summary comment on every pull request:

name: PR Summary
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  summarize:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: sagewai/actions/run-agent@v1
        with:
          agent: summarizer
          input: |
            Summarize the changes in this PR:
            Title: ${{ github.event.pull_request.title }}
            Body: ${{ github.event.pull_request.body }}
            Files changed: ${{ github.event.pull_request.changed_files }}
          fleet-gateway: ${{ secrets.SAGEWAI_GATEWAY_URL }}
          api-key: ${{ secrets.SAGEWAI_API_KEY }}
          post-as-comment: 'true'

Eval Quality Gate

Block merges when agent quality regresses:

name: Agent Quality Gate
on:
  push:
    branches: [main]
    paths:
      - 'agents/**'
      - 'evals/**'

jobs:
  evaluate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: sagewai/actions/run-evals@v1
        with:
          eval-suite: evals/core-suite.yaml
          threshold: '0.8'
          api-key: ${{ secrets.SAGEWAI_API_KEY }}

      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: eval-results
          path: eval-results/

Worker Deployment on Tag

Deploy workers when a version tag is pushed:

name: Deploy Workers
on:
  push:
    tags: ['v*']

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: sagewai/actions/deploy-worker@v1
        with:
          fleet-gateway: ${{ secrets.SAGEWAI_GATEWAY_URL }}
          enrollment-key: ${{ secrets.ENROLLMENT_KEY }}
          worker-pool: production
          models: 'gpt-4o,claude-sonnet-4'

Trigger System

The gateway's trigger system maps external events to agent actions.

How It Works

from sagewai.gateway.triggers import TriggerSpec, EventFilter, Strategy

trigger = TriggerSpec(
    source="github",
    strategy=Strategy.WEBHOOK,
    filter=EventFilter(
        event_types=["pull_request"],
        keywords=["review"],
    ),
    target="code-reviewer",
    action="chat",
    context={"repo": "sagewai/platform"},
)

Strategies

StrategyHow It WorksUse Case
WEBHOOKReceives HTTP POST eventsGitHub webhooks, Slack events
LISTENERReal-time event streamLive monitoring, chat integrations
POLLERPolls at configurable intervalsStatus checks, queue monitoring

Actions

ActionWhat It Does
chatSends event data as a message to an agent
run_workflowSubmits a workflow run with event context
execute_toolCalls a specific tool with event arguments

Event Filters

EventFilter(
    channels=["#deployments"],        # source channel
    event_types=["push", "release"],  # event type
    senders=["ci-bot"],               # who sent it
    keywords=["production"],          # content matching
    recipients=["ops-team"],          # target audience
)

CLI for CI

Run agents headlessly from any CI system:

# Run an agent with direct input
sagewai run --agent reviewer --input "Review this diff" --model gpt-4o

# Run from a YAML config
sagewai run --config agent.yaml

# Run an evaluation suite
sagewai eval run -d evals.jsonl --agent-name QAAgent

# Register a worker from CI
sagewai fleet register \
  --name ci-worker \
  --gateway $SAGEWAI_GATEWAY_URL \
  --enrollment-key $ENROLLMENT_KEY \
  --pool ci \
  --models gpt-4o

Harness as CI Proxy

Route CI agent calls through the harness to control costs:

env:
  ANTHROPIC_BASE_URL: ${{ secrets.HARNESS_URL }}/v1
  ANTHROPIC_API_KEY: ${{ secrets.HARNESS_KEY }}

With the harness in the path you can set per-workflow budgets (e.g., $5 max per PR review), route to cheaper models for CI tasks (Haiku for summaries, Sonnet for reviews), capture a full audit trail of CI LLM spend, and let the complexity classifier choose the model automatically.

Secrets Reference

SecretPurposeRequired For
SAGEWAI_GATEWAY_URLFleet gateway endpointrun-agent, deploy-worker
SAGEWAI_API_KEYAPI authenticationrun-agent, run-evals
ENROLLMENT_KEYWorker registrationdeploy-worker
OPENAI_API_KEYDirect LLM accessIf not using harness
ANTHROPIC_API_KEYDirect Anthropic accessIf not using harness

Self-Hosted Runners with Local Inference

Run fleet workers on self-hosted GitHub Actions runners with Ollama for $0/token CI agent execution:

  1. Set up a self-hosted runner with GPU access.
  2. Install Ollama: curl -fsSL https://ollama.ai/install.sh | sh
  3. Pull your model: ollama pull llama3.1:8b
  4. Register as a fleet worker:
sagewai fleet register \
  --gateway https://sagewai.internal:8000 \
  --enrollment-key $KEY \
  --pool ci-local \
  --models ollama/llama3.1:8b

Jobs targeting the ci-local pool run on your own hardware without LLM API costs.

Other CI Systems

The CLI works with any CI system. Use pip install sagewai && sagewai run ... in the relevant step:

CI SystemHow to Use
GitHub ActionsUse sagewai/actions/* (recommended)
GitLab CIpip install sagewai && sagewai run ...
Jenkinssh 'sagewai run --agent ...' in pipeline
CircleCIAdd sagewai to executor, run CLI commands
Azure DevOpsScript task with sagewai run ...