Skip to main content
This tutorial explains how to use agent configs as code to do the following:
  • Synchronize LaunchDarkly prompt variations and tools with a Git repository using ldcli sync.
  • Enforce code ownership in the LaunchDarkly UI.
  • Gate every prompt change in GitHub Actions with offline evaluations before the change reaches LaunchDarkly.

Full walkthrough: Manage agent configs as code and gate prompt changes in CI.

In the companion tutorial, Run AgentControl offline evaluations in CI, a pull request workflow runs your application’s handler and tools against a versioned dataset and blocks regressions before merge. That workflow catches changes inside the repository, such as a modified policy document or retriever, on every pull request. However, when someone edits a variation’s prompt directly in LaunchDarkly, the change takes effect immediately without opening a pull request or running your pull request check. By managing your agent configs as code in Git with ldcli sync, you close that gap. After you finish this tutorial, your repository and LaunchDarkly share a single ownership contract:
  • Git owns the prompt content. Synced variations are marked “Defined in code” and locked against accidental edits in the LaunchDarkly UI, while teammates can still click Duplicate variation to run experiments in the UI.
  • Pull requests preview and test every prompt change. Your CI workflow runs ldcli sync all --dry-run --diff alongside your offline evaluation suite, blocking any prompt edit that degrades answer accuracy before ldcli sync applies it.
  • LaunchDarkly still owns traffic. Merging a prompt change to main publishes the new variation version to LaunchDarkly while leaving targeting rules, segments, and guarded rollouts untouched.

Prerequisites

To complete this tutorial, you need:
  • A LaunchDarkly access token with write access to your project. You use this token to authenticate the CLI and to set LD_API_TOKEN in your .env file.
  • A local checkout of the offline-evals-ci repository. Clone the repository, copy .env.example to .env, and set these environment variables:
    • LD_SDK_KEY
    • LD_API_TOKEN
    • LD_PROJECT_KEY
    • OPENAI_API_KEY
  • A LaunchDarkly project with the resources from Run AgentControl offline evaluations in CI. Run python -m bootstrap.bootstrap from your checkout to create these resources in your project:
    • policy-agent config with its grounded and concise variations.
    • search_member_policy tool.
    • policy-accuracy and policy-tool-use judges.
  • The LaunchDarkly CLI with sync support, authenticated with your access token.

Concepts

Before you run ldcli sync, review the three mechanisms that govern how agent configs as code keeps Git and LaunchDarkly in agreement:
MechanismHow it worksHow to use it
Two-owner modelEvery variation, tool, and skill has a single owner. Resources created in the LaunchDarkly UI start owned by LaunchDarkly. When you sync a resource from your repository with ldcli sync, LaunchDarkly marks it “Defined in code” and makes its content read-only in the UI.To experiment in the UI without changing the governed variation, click Duplicate variation on the variation card to create a LaunchDarkly-owned copy.
Three-way fingerprint baselineEach working copy stores the SHA-256 fingerprint of its last synchronized state in .launchdarkly/sync.lock.Commit sync.lock to Git alongside your prompt files so ldcli sync can compare your local working copy, the committed baseline, and LaunchDarkly.
Governance and traffic separationldcli sync manages what a variation says, including its messages, model parameters, and attached tools or skills.Use LaunchDarkly targeting rules and guarded rollouts to control which variation serves production traffic.

Step 1: Bootstrap existing variations into your repository

Start by pulling the policy-agent variations and their attached search_member_policy tool from LaunchDarkly into .launchdarkly/ so your repository has a tracked baseline.
  1. Preview the files that ldcli sync prompts add creates without writing to disk by running the following command from the root of your offline-evals-ci checkout:
  1. Review the preview output. The CLI lists the tool file and the two variation files it generates, as in the following example:
  1. Run the command with --yes --no-input to write the files and record their initial SHA-256 fingerprints in .launchdarkly/sync.lock. Here is the command:
Terminal output showing ldcli sync prompts add creating search_member_policy.json, grounded.prompt.md, and concise.prompt.md and recording SHA-256 fingerprints in sync.lock.

Running ldcli sync prompts add to pull the grounded and concise variations and their search_member_policy tool into .launchdarkly/.

  1. Open .launchdarkly/<your-project-key>/configs/policy-agent/concise.prompt.md to inspect the generated format. The YAML frontmatter stores the variation key, mode, model configuration, and tool references, and the body holds the role blocks:
Editor view of .launchdarkly/offline-evals-ci/configs/policy-agent/concise.prompt.md showing YAML frontmatter and the system prompt block.

The generated concise.prompt.md file storing YAML frontmatter for the model and tool bindings alongside the system prompt role block.

If your team already stores prompts in Python, TypeScript, JavaScript, or Markdown files, you do not have to move them into .launchdarkly/ markdown files. Use ldcli sync prompts link to bind a variation directly to the existing constant or agent definition in your code.
  1. Remove the generated grounded.prompt.md file so you can link the grounded variation directly to SYSTEM_PROMPT in bootstrap/bootstrap.py. Use these commands:
  1. Confirm that ldcli writes a .ref.yaml descriptor and records the variation as synchronized. The output is below:
Terminal output of ldcli sync prompts link writing grounded.ref.yaml and recording policy-agent/grounded as synchronized.

Linking SYSTEM_PROMPT in bootstrap/bootstrap.py directly to the grounded variation with ldcli sync prompts link.

Editor view of grounded.ref.yaml alongside bootstrap/bootstrap.py showing the linked SYSTEM_PROMPT constant.

The grounded.ref.yaml reference descriptor pointing to constants[id="SYSTEM_PROMPT"] in bootstrap/bootstrap.py.

  1. Inspect .launchdarkly/sync.lock to verify that all three resources are tracked. Here is the lockfile:
Editor view of .launchdarkly/sync.lock showing SHA-256 fingerprints for search_member_policy, policy-agent/concise, and policy-agent/grounded.

The .launchdarkly/sync.lock file storing SHA-256 baseline fingerprints for each synced tool and variation.

Step 3: Verify the read-only lock and Duplicate variation flow in LaunchDarkly

After ldcli sync registers your repository in the project’s sync manifest, LaunchDarkly locks the synced variations against direct UI edits so no one can silently overwrite what your repository governs. To verify the lock in LaunchDarkly:
  1. In LaunchDarkly, click Agent management > Agents. The Agents list appears.
  2. Click Policy agent and open the Variations tab.
  3. Locate the grounded variation card. The card displays a “Defined in code” alert naming bootstrap/bootstrap.py. The prompt and model fields are read-only.
LaunchDarkly UI showing the policy-agent grounded variation card with the Defined in code banner and locked prompt fields.

The grounded variation in LaunchDarkly marked Defined in code with read-only prompt and model fields.

  1. Click Duplicate variation inside the “Defined in code” alert when you want to test a candidate prompt or model in the Playground or an experiment. LaunchDarkly creates a new variation named grounded-copy owned by LaunchDarkly while keeping grounded locked to Git.
LaunchDarkly Duplicate variation card creating a LaunchDarkly-owned grounded-copy variation while keeping grounded locked to Git.

Clicking Duplicate variation on a Defined in code variation creates an editable LaunchDarkly-owned copy for experimentation.

Step 4: Preview drift and block a bad prompt edit in pull request CI

When an engineer edits a synced prompt in a pull request, your CI workflow previews the exact LaunchDarkly diff and runs your offline evaluation dataset before any write reaches LaunchDarkly.
  1. Simulate a faulty prompt edit in bootstrap/bootstrap.py by changing Rule 2 of SYSTEM_PROMPT so the assistant rounds copay amounts instead of quoting them. Here is the updated constant:
  1. Run ldcli sync all --dry-run --diff locally to preview how ldcli compares the edited Python constant against LaunchDarkly without applying it. Here is the command:
  1. Review the diff output. The CLI reports 1 prompt push for policy-agent/grounded and prints the exact line change:
Terminal output of ldcli sync all --dry-run --diff showing the +1 -1 unified diff on policy-agent/grounded.

Running ldcli sync all --dry-run --diff to preview the exact prompt projection change before applying.

  1. Update .github/workflows/evals-pr.yml so pull requests run ldcli sync all --dry-run --diff alongside evals/run_evals.py, and merges to main run ldcli sync all --yes --no-input only after the checks pass:
When a pull request contains the rounded-copay prompt edit, the policy-accuracy judge fails row 1 because the assistant quotes $30 instead of the expected $25 Gold plan primary care copay. As a result, evals-gate fails and GitHub blocks the merge before sync-apply can run.
GitHub Pull Request showing sync-preview diff summary, failed policy-accuracy evaluation for member M-1001, and Merging is blocked.

GitHub Pull Request #4 blocked by evals-gate after policy-accuracy flags the $30 rounded copay against the $25 reference dataset.

Step 5: Reconcile approved changes on merge

After you restore Rule 2 in bootstrap/bootstrap.py to Quote dollar amounts exactly. and merge the pull request to main, ldcli sync all --yes --no-input publishes the approved variation to LaunchDarkly.
GitHub Pull Request showing passing offline, sync-preview, evals, and evals-gate checks ready for merge.

After restoring the exact-dollar rule in bootstrap/bootstrap.py, all pull request evaluation checks pass and the pull request merges to main.

  1. Run ldcli sync all --yes --no-input to apply the approved local state and update the remote manifest and .launchdarkly/sync.lock. Here is the command:
  1. Confirm that the CLI verifies state before writing, publishes the updated variation, and leaves all three resources in sync. Here is the output:
Terminal output of ldcli sync all --yes --no-input publishing policy-agent/grounded to LaunchDarkly while keeping targeting rules untouched.

Running ldcli sync all --yes --no-input on merge to main to publish the approved variation version and update the sync manifest.

Troubleshooting

Use the table below to diagnose common ldcli sync messages:
Message or codeCauseFix
variation_managed_in_codeA user or script attempted to edit a code-owned variation through the LaunchDarkly UI or REST API without ldcli sync, returning HTTP 403.Edit the prompt in your Git repository and run ldcli sync, or click Duplicate variation in the UI to experiment on a copy.
Note: <key> is managed in LaunchDarkly; pulled, not pushedSomeone switched the variation’s source of truth to LaunchDarkly in the UI.Open the variation menu in LaunchDarkly and enable Code sync to return ownership to your repository.
Another working copy synced <key> after your sync.lockA teammate or CI job pushed a newer change to LaunchDarkly from another clone of the repository.Run git pull to update your local .launchdarkly/ files and sync.lock, then run ldcli sync again.