For the complete documentation index, see llms.txt. This page is also available as Markdown.

Use Worker Agents in pipelines

Add Worker Agent steps to Harness pipelines, reference agent outputs, and gate deployments based on agent decisions.

Worker Agents execute as pipeline steps inside Harness CI and CD stages. Reference an agent by name and version in your pipeline YAML, and Harness runs the agent container at execution time with access to your codebase, trigger context, and platform data via MCP connectors. Agent steps publish output variables that downstream steps read to gate deployments, route approvals, or trigger notifications based on the agent decisions. This integration embeds AI-powered reviews, compliance checks, and risk assessments directly into your delivery workflows.


What you will learn in this topic

By the end of this topic, you will be able to:


Before you begin

Before you add a Worker Agent to a pipeline, ensure you have the following:

  • Worker Agent created: A Worker Agent must exist in your account. Go to Worker Agents overview to create one.

  • Model Connector configured: At least one Anthropic or OpenAI connector. Go to Model Connectors for setup instructions.

  • Pipeline access: Permission to create and edit pipelines in your Harness project.


Use a Worker Agent in a pipeline

Worker Agents are referenced in pipeline YAML using the Agent step type. Add an Agent step to your pipeline, specify the agent by name and version, and Harness automatically inherits all inputs and environment variables from the agent definition at runtime.

PIPELINE YAML VS. AGENT DEFINITION

The pipeline YAML only contains a reference to the agent (agentName: name@version). It does not contain the agent's instructions, inputs, outputs, environment variables, or container image. That configuration lives in the Worker Agent Catalog. To view or edit the full agent definition, go to AI > Worker Agents, select the agent, and switch to the YAML tab.


Add an Agent step

Add a Worker Agent step to your pipeline to execute AI-powered tasks during pipeline execution. The Agent step integrates directly with your CI or CD stages and runs the agent container with full access to pipeline context.

  1. Open your pipeline in the Pipeline Studio.

  2. Click Add Step in the stage execution panel.

  3. In the step library, select Agents in the right sidebar, then select Agent.

Select the Agent step from the Agents category in the step library

  1. In the Step Parameters panel, enter a Name for the step.

  2. Select the Agent from the dropdown. This lists all Worker Agents available in your project scope.

  3. Select the Version to pin the step to a specific agent version, or choose Always use stable to use the latest stable version automatically.

  4. (Optional) Fill in any override fields such as LLM Connector or Model Name. These fields override the values configured in the agent definition for this specific pipeline step. If you leave them empty, the agent uses the connector and model from its own definition.

  5. Click Apply Changes.

LLM CONNECTOR IN THE AGENT DEFINITION VS. THE PIPELINE STEP

Configure the Model Connector in the agent definition (AI > Worker Agents > select the agent). The agent definition is the source of truth for which LLM provider and model the agent uses. The LLM Connector field on the pipeline Agent step is an optional override. Leave it empty to use the connector already configured on the agent. Use the override only when you need a specific pipeline to use a different connector or model than the agent default.

Agent step configuration with version selection and input fields


Step reference syntax

The Agent step YAML syntax follows a simple structure. The agentName field references the agent by identifier and version, and Harness resolves the full agent definition at execution time.

The following table describes each field in the Agent step:

Field
Description

type: Agent

Identifies this as a Worker Agent step.

agentName

The agent identifier and version in name@version format (such as pr_review_agent@1.0.6).

agentSettings

Reserved for future per-step agent overrides. Leave as empty string.


Agent step expands to a step group at runtime

Understanding how Harness expands Agent steps is critical for referencing output variables. At execution time, Harness converts the Agent step into a step group, which changes the expression path you use to access agent outputs.

At execution time, Harness expands the Agent step into a step group containing the agent's internal run step. This affects how you reference output variables. The expression path includes the outer step identifier (the Agent step) and the inner step name (derived from the agent name and version):

For example, if the Agent step identifier is assess_plan_safety and the agent is iacm_plan_safety_agent@1.0.8, the inner step name is iacm_plan_safety_agent_1 and the expression is:

When you add a Run step after the Agent step and configure its command field to read output variables, the pipeline UI displays an input field. Paste or type the full expression into that input field.

FIND THE INNER STEP NAME

Run the pipeline once. In the execution view, expand the Agent step group to see the inner step name. Use that name in your output variable expressions.


Example: PR pipeline with Agent step in a CI stage

This example demonstrates a PR review pipeline that triggers on pull request events, clones the source code, and runs a Worker Agent to review the changes.

This pipeline runs on every pull request, clones the codebase from the go-example repository, and executes the pr_review_agent Worker Agent inside the CI stage.


How it works end-to-end

The PR pipeline executes the following sequence when triggered by a pull request event.

  1. A PR is opened or updated on the go-example repository.

  2. The pipeline trigger fires and populates <+trigger.prNumber>, <+trigger.repoName>, <+trigger.sourceBranch>, <+trigger.targetBranch>, <+trigger.commitSha>, and <+trigger.baseCommitSha>.

  3. The CI stage clones the source branch at the head commit.

  4. The Agent step launches the pr_review_agent Worker Agent container.

  5. The agent uses Harness MCP to fetch the exact PR diff and produces a structured review with findings and an approval decision.


Example: IaC plan safety gate with agent outputs

This example demonstrates an infrastructure deployment pipeline that uses a Worker Agent to assess Terraform plan safety and gate deployment based on the agent risk assessment.

This pipeline prepares a Terraform plan, runs a safety assessment agent, and gates deployment based on the agent's output variables. It demonstrates a three-step pattern: prepare data, run the agent, and validate outputs in a downstream step.

This pipeline follows three steps:

  1. Prepare Terraform Plan: Copies a Terraform JSON plan file to the shared agent output directory at /harness/.agent/output/tfplan.json.

  2. Assess Plan Safety: The iacm_plan_safety_agent Worker Agent reads the plan, evaluates risk across destructive actions, public exposure, encryption removal, and IAM expansion, then publishes output variables (RECOMMENDATION, RISK_LEVEL, MAX_RISK_SCORE, VALIDATION_STATUS, RISK_ASSESSMENT_PATH).

  3. Gate On Agent Outputs: A downstream Run step reads the agent's output variables using Harness expressions and fails the pipeline if VALIDATION_STATUS is FAIL, blocking unsafe infrastructure changes from proceeding.


Next steps

Last updated

Was this helpful?