Skip to main content

agentrix-run

agentrix-run submits an Agentrix CI run from a command line or CI job. Use it when you want a pipeline to ask an Agentrix agent to review a pull request, summarize a change, produce structured output, or start an asynchronous task that you can inspect in the Agentrix app.

It is separate from the main agentrix daemon CLI. agentrix-run talks to the Agentrix API, creates a CI run, and either streams events until the task finishes or returns after creating the run.

Requirements​

  • Node.js 20 or newer in the CI job.
  • An Agentrix API key with access to the target organization and repository.
  • A reachable Agentrix API endpoint. The public cloud endpoint defaults to https://agentrix.xmz.ai.
  • A repository registered in Agentrix. In GitHub Actions and GitLab CI, agentrix-run can detect the current repository from CI environment variables.
  • A runner ID, unless your Agentrix deployment has a default cloud runner configured or the selected companion agent is already bound to a machine.
  • For --resume, an existing task ID. Resume mode does not need repository context or a runner ID.

Set the API key as an environment variable:

export AGENTRIX_API_KEY=<your-api-key>

You can pass the key as --api-key. Use --base-url or AGENTRIX_BASE_URL only when you need to override the default public cloud API URL.

Security Mode​

agentrix-run creates CI runs through the Agentrix API. When you pass a machine-* runner ID, the task executes on that local machine, but the CI run is still a plaintext CI mode task: the prompt and CI context are sent to the API as regular request data and stored as regular task events.

This is different from local tasks started from the Agentrix app, where the app has the user's local encryption material and can submit encryptedMessage, dataEncryptionKey, and ownerEncryptedDataKey. Do not put secrets in --prompt; keep secrets in CI secret stores or machine-local configuration.

Run from a shell​

Pin the npm package version in CI. The repository currently publishes @agentrix/agentrix-run.

npx --yes @agentrix/[email protected] \
--agent codex \
--prompt "Review this change and return one short summary sentence." \
--response-mode stream \
--runner-id cloud-default

If you are running outside GitHub Actions or GitLab CI, pass the repository context yourself:

npx --yes @agentrix/[email protected] \
--agent codex \
--prompt "Review this branch." \
--repo '{"gitServerId":"github","owner":"xmz-ai","name":"agentrix"}' \
--base-ref develop \
--head-ref feature/demo \
--pr-number 123 \
--runner-id cloud-default

You can also append a message to an existing task. agentrix-run reuses that task's execution context; if the worker is online, the message is delivered to the agent, and if the worker has exited, the backend resumes the task:

npx --yes @agentrix/[email protected] \
--resume task-abc123 \
--prompt "Continue checking the failing tests and return the final conclusion." \
--response-mode stream

Response modes​

ModeBehaviorExit code
streamCreates the run, streams task events, waits for a terminal status, and exits when the run finishes. This is the default.0 only when the final status is completed; non-zero for failed, canceled, or timeout.
asyncCreates the run and prints the run metadata without waiting for completion.0 if the run was created.

With --resume, response modes have the same meaning: stream keeps observing the task after the message is accepted, and async only confirms that the backend accepted the message.

In stream mode, stdout contains JSON lines for streamed events:

{"type":"run.created","data":{"runId":"run-..."}}
{"type":"task.event","data":{}}
{"type":"run.completed","data":{"runId":"run-...","status":"completed","result":"...","detailUrl":"..."}}

In async mode, stdout prints standard fields:

run_id=run-abc123
status=queued
detail_url=https://agentrix.xmz.ai/tasks/task-abc123

Use --result-file when another CI step needs to read the result:

npx --yes @agentrix/[email protected] \
--agent codex \
--prompt "Summarize this PR." \
--result-file agentrix-result.json

The result file is JSON:

{
"runId": "run-abc123",
"status": "completed",
"result": "Short summary text.",
"structuredOutput": null,
"detailUrl": "https://agentrix.xmz.ai/tasks/task-abc123"
}

Structured output​

Pass a JSON Schema string with --output-schema. agentrix-run normalizes object schemas for strict structured output: object nodes get additionalProperties: false, and every declared property is added to required.

npx --yes @agentrix/[email protected] \
--agent codex \
--prompt "Summarize this change." \
--output-schema '{"type":"object","properties":{"summary":{"type":"string"},"risk":{"type":"string"}}}' \
--result-file agentrix-result.json

The normalized structured output is written under structuredOutput in the result file and exposed as structured-output-json by the GitHub Action.

GitHub Actions​

Use the public action wrapper for GitHub Actions:

name: Agentrix

on:
pull_request:

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

- id: agentrix
uses: xmz-ai/agentrix-run-action@v1
with:
api-key: ${{ secrets.AGENTRIX_API_KEY }}
agent: codex
prompt: >-
Review this PR and return one short summary sentence.
runner-id: cloud-default

- name: Print result
run: |
echo "run id: ${{ steps.agentrix.outputs.run-id }}"
echo "status: ${{ steps.agentrix.outputs.status }}"
echo "detail url: ${{ steps.agentrix.outputs.detail-url }}"
echo "result: ${{ steps.agentrix.outputs.result }}"

The action automatically detects repository owner, repository name, ref, commit SHA, pull request base/head refs, pull request number, event name, and workflow run URL from GitHub Actions environment variables.

GitHub Action inputs​

InputRequiredDescription
agentYesAgent ID or name, for example codex.
promptYesPrompt text sent to Agentrix.
base-urlNoAgentrix API base URL override. Defaults to https://agentrix.xmz.ai.
api-keyYesAgentrix API key. Store it in GitHub Actions secrets.
titleNoCustom task title in Agentrix.
output-schemaNoJSON Schema string for structured output.
repoNoJSON repository override. Use this when auto-detection is not enough.
git-server-idNoGit server ID used for the auto-detected repository. Defaults to github.
response-modeNostream or async. Defaults to stream.
issue-numberNoIssue number override. Pull request numbers are detected from the event payload.
branch-nameNoExplicit task checkout branch. When set, it overrides the auto-detected PR/MR head branch for workspace checkout.
timeoutNoHTTP read timeout; in stream mode it is also the total wait timeout, in seconds. Defaults to 30 seconds for async and 1800 seconds for stream.
capability-profileNoCapability profile passed to execution.
runner-idUsually yesRunner ID, such as a cloud-* or machine-* ID. You can omit it only when your deployment has a default cloud runner or the selected companion agent is machine-bound.

GitHub Action outputs​

OutputDescription
run-idAgentrix run ID.
statusFinal run status in stream mode, or creation status in async mode.
detail-urlAgentrix task URL.
resultFinal result text. Empty in async mode.
structured-output-jsonFinal structured output as a JSON string. null when no structured output exists.

GitLab CI​

For GitLab CI, add a hidden .agentrix-run job to your .gitlab-ci.yml or to a shared CI template that your projects can include:

.agentrix-run:
image: node:20-alpine
variables:
AGENTRIX_RESPONSE_MODE: stream
script:
- |
set -eu
set -- \
--agent "$AGENTRIX_AGENT" \
--prompt "$AGENTRIX_PROMPT" \
--response-mode "${AGENTRIX_RESPONSE_MODE:-stream}" \
--runner-id "$AGENTRIX_RUNNER_ID"

if [ -n "${AGENTRIX_TITLE:-}" ]; then
set -- "$@" --title "$AGENTRIX_TITLE"
fi
if [ -n "${AGENTRIX_OUTPUT_SCHEMA:-}" ]; then
set -- "$@" --output-schema "$AGENTRIX_OUTPUT_SCHEMA"
fi
if [ -n "${AGENTRIX_REPO:-}" ]; then
set -- "$@" --repo "$AGENTRIX_REPO"
fi
if [ -n "${AGENTRIX_BRANCH_NAME:-}" ]; then
set -- "$@" --branch-name "$AGENTRIX_BRANCH_NAME"
fi
if [ -n "${AGENTRIX_TIMEOUT:-}" ]; then
set -- "$@" --timeout "$AGENTRIX_TIMEOUT"
fi
if [ -n "${AGENTRIX_CAPABILITY_PROFILE:-}" ]; then
set -- "$@" --capability-profile "$AGENTRIX_CAPABILITY_PROFILE"
fi
if [ -n "${AGENTRIX_RESULT_FILE:-}" ]; then
set -- "$@" --result-file "$AGENTRIX_RESULT_FILE"
fi
if [ -n "${AGENTRIX_BASE_URL:-}" ]; then
set -- "$@" --base-url "$AGENTRIX_BASE_URL"
fi

npx --yes @agentrix/agentrix-run "$@"

Then extend the hidden job from a visible pipeline job:

agentrix_review:
extends: .agentrix-run
variables:
AGENTRIX_AGENT: codex
AGENTRIX_PROMPT: Review this merge request and return one short summary sentence.
AGENTRIX_RESPONSE_MODE: stream
AGENTRIX_RUNNER_ID: cloud-default

Store AGENTRIX_API_KEY as a masked CI variable. GitLab CI detection reads project path, commit ref, commit SHA, merge request source/target branches, merge request IID, job URL, and pipeline URL from the standard GitLab environment.

Pipelines Triggered by the Daemon Webhook​

When a GitLab pipeline is triggered by the Agentrix daemon webhook bridge, the daemon normalizes the GitLab webhook into GITLAB_BRIDGE_EVENT_NAME and GITLAB_BRIDGE_EVENT_ACTION, then sets issue, MR, pipeline, and comment variables with the same GITLAB_BRIDGE_* prefix. Standard GitLab variables are still available, so agentrix-run can auto-detect the repository and commit from CI_PROJECT_PATH, CI_COMMIT_REF_NAME, and CI_COMMIT_SHA.

Use one job per webhook class and gate each job with rules on the normalized event variables:

agentrix_issue_triage:
extends: .agentrix-run
rules:
- if: '$GITLAB_BRIDGE_EVENT_NAME == "issues"'
when: on_success
- when: never
variables:
AGENTRIX_AGENT: codex
AGENTRIX_RESPONSE_MODE: stream
AGENTRIX_RUNNER_ID: cloud-default
AGENTRIX_TITLE: "Issue #$GITLAB_BRIDGE_ISSUE_NUMBER: $GITLAB_BRIDGE_EVENT_ACTION"
AGENTRIX_PROMPT: >-
Review GitLab issue #$GITLAB_BRIDGE_ISSUE_NUMBER in this repository.
Event action: $GITLAB_BRIDGE_EVENT_ACTION.
Issue title: $GITLAB_BRIDGE_ISSUE_TITLE.
Decide whether this needs agent work, and return a short triage summary.

MR review job:

agentrix_mr_review:
extends: .agentrix-run
rules:
- if: '$GITLAB_BRIDGE_EVENT_NAME == "pull_request" && ($GITLAB_BRIDGE_EVENT_ACTION == "opened" || $GITLAB_BRIDGE_EVENT_ACTION == "reopened" || $GITLAB_BRIDGE_EVENT_ACTION == "synchronize")'
when: on_success
- when: never
variables:
AGENTRIX_AGENT: codex
AGENTRIX_RESPONSE_MODE: stream
AGENTRIX_RUNNER_ID: cloud-default
AGENTRIX_TITLE: "MR !$GITLAB_BRIDGE_PR_NUMBER review"
AGENTRIX_PROMPT: >-
Review GitLab merge request !$GITLAB_BRIDGE_PR_NUMBER.
Source branch: $GITLAB_BRIDGE_HEAD_REF.
Target branch: $GITLAB_BRIDGE_BASE_REF.
Return concise findings and suggested fixes.

Comment job. The daemon forwards supported non-system comments by default:

agentrix_comment_command:
extends: .agentrix-run
rules:
- if: '$GITLAB_BRIDGE_EVENT_NAME == "issue_comment"'
when: on_success
- when: never
variables:
AGENTRIX_AGENT: codex
AGENTRIX_RESPONSE_MODE: stream
AGENTRIX_RUNNER_ID: cloud-default
AGENTRIX_TITLE: "Agentrix comment command"
AGENTRIX_PROMPT: >-
Handle this GitLab comment.
Issue: $GITLAB_BRIDGE_ISSUE_NUMBER.
Merge request: $GITLAB_BRIDGE_PR_NUMBER.
Comment: $GITLAB_BRIDGE_COMMENT_BODY

Pipeline-failure diagnosis job. Pipeline webhooks are forwarded as workflow_run events, including pipelines created by trigger tokens:

agentrix_pipeline_failed:
extends: .agentrix-run
rules:
- if: '$GITLAB_BRIDGE_EVENT_NAME == "workflow_run" && $GITLAB_BRIDGE_EVENT_ACTION == "completed" && $GITLAB_BRIDGE_WORKFLOW_RUN_CONCLUSION == "failure"'
when: on_success
- when: never
variables:
AGENTRIX_AGENT: codex
AGENTRIX_RESPONSE_MODE: stream
AGENTRIX_RUNNER_ID: cloud-default
AGENTRIX_TITLE: "Pipeline $GITLAB_BRIDGE_WORKFLOW_RUN_ID failed"
AGENTRIX_PROMPT: >-
Diagnose failed GitLab pipeline $GITLAB_BRIDGE_WORKFLOW_RUN_ID.
Ref: $GITLAB_BRIDGE_WORKFLOW_RUN_REF.
SHA: $GITLAB_BRIDGE_WORKFLOW_RUN_SHA.
Pipeline URL: $GITLAB_BRIDGE_WORKFLOW_RUN_URL.
Explain the likely cause and propose the smallest fix.

For other action-specific handling, split jobs with stricter rules:

agentrix_issue_closed:
extends: .agentrix-run
rules:
- if: '$GITLAB_BRIDGE_EVENT_NAME == "issues" && $GITLAB_BRIDGE_EVENT_ACTION == "closed"'
when: on_success
- when: never
variables:
AGENTRIX_AGENT: codex
AGENTRIX_PROMPT: "Summarize the closing state of GitLab issue #$GITLAB_BRIDGE_ISSUE_NUMBER."
AGENTRIX_RESPONSE_MODE: async
AGENTRIX_RUNNER_ID: cloud-default

Do not rely on CI_PIPELINE_SOURCE alone to separate sources. Daemon-triggered pipelines are usually trigger pipelines in GitLab, so prefer GITLAB_BRIDGE_EVENT_NAME and GITLAB_BRIDGE_EVENT_ACTION for routing.

CLI options​

OptionRequiredDescription
--agent <agent>Required for new runsAgent ID or name.
--resume <task-id>NoAppend the --prompt message to an existing task. When set, agentrix-run does not create a new CI run and does not require --agent.
--prompt <prompt>YesPrompt text sent to Agentrix.
--title <text>NoCustom task title in Agentrix.
--client-task-id <id>NoStable business key for idempotent creation. Retries with the same API user and key return the same run; the first request wins.
--repo <json>Usually auto-detectedJSON repository object. It must include gitServerId and either serverRepoId or owner plus name.
--output-schema <json>NoJSON Schema string for structured output. Object schemas are normalized for strict output.
--ref <ref>NoGit ref for the run. Overrides auto-detected CI ref.
--sha <sha>NoCommit SHA for the run. Overrides auto-detected CI SHA.
--base-ref <ref>NoBase/target branch for a pull request or merge request. Sent to the API as git.baseRef.
--head-ref <ref>NoHead/source branch for a pull request or merge request. Sent to the API as git.headRef.
--head-sha <sha>NoHead/source commit for a pull request or merge request. Sent to the API as git.headSha.
--checkout-ref <ref>NoExplicit ref used to initialize the workspace. This is the only source of git.checkoutRef.
--checkout-sha <sha>NoExplicit SHA used to initialize the workspace. This is the only source of git.checkoutSha.
--branch-name <name>NoExplicit task working branch. Sent to the API as git.branchName; this creates an explicit task branch binding.
--pr-number <number>NoPull request or merge request number. Must be a positive integer.
--issue-number <number>NoIssue number. Must be a positive integer.
--response-mode <stream|async>Nostream waits for completion; async only creates the run. Defaults to stream.
--timeout <seconds>NoHTTP read timeout; in stream mode it is also the total wait timeout. Defaults to 30 for async and 1800 for stream. Must be a positive integer. The connect timeout is fixed at 10 seconds.
--capability-profile <name>NoCapability profile passed to execution.
--runner-id <cloud-id|machine-id>Usually yesSpecific runner to use, for example cloud-default or machine-.... You can omit it only when your deployment has a default cloud runner or the selected companion agent is machine-bound.
--result-file <path>NoWrite run result JSON to this path.
--base-url <url>NoAgentrix API base URL override. Defaults to https://agentrix.xmz.ai; takes precedence over AGENTRIX_BASE_URL.
--api-key <api-key>Required unless AGENTRIX_API_KEY is setAgentrix API key. Prefer environment variables or CI secrets.
--metadata <key=value>NoAdd metadata to the run. Repeat the flag for multiple entries.
--helpNoPrint command help.

Repository JSON​

--repo accepts a JSON object with this shape:

{
"gitServerId": "github",
"owner": "xmz-ai",
"name": "agentrix"
}

You can also identify a repository by server-side repository ID:

{
"gitServerId": "github",
"serverRepoId": "repo-abc123"
}

When a CI provider is detected, explicit values in --repo override detected values.

Branch context and worker environment​

agentrix-run sends branch context to the API under CreateCiRunRequest.git:

Explicit CLI options always win. Automatic git.ref and git.sha detection describes the current CI job checkout only: GitHub uses GITHUB_REF and GITHUB_SHA; GitLab uses CI_COMMIT_REF_NAME and CI_COMMIT_SHA. Bridge variables never replace those fields.

CLI optionAPI fieldMeaning
--base-refgit.baseRefPR/MR target branch, for example main.
--head-refgit.headRefPR/MR source branch, for example feature/demo.
--head-shagit.headShaPR/MR source commit.
--checkout-refgit.checkoutRefRef used as the workspace start point.
--checkout-shagit.checkoutShaSHA used as the workspace start point.
--branch-namegit.branchNameExplicit task working branch override.

The API maps these values into controlled Agentrix task fields:

  • git.baseRef becomes task baseBranch.
  • git.headRef and git.headSha remain observed PR/MR head context.
  • git.ref and git.sha are current-job facts; they are not promoted into checkout instructions or MR head fields.
  • Only explicit git.checkoutRef and git.checkoutSha define the workspace initialization start point.
  • git.checkoutSha is used only when explicitly provided; git.sha and git.headSha are not promoted to it.
  • git.branchName becomes task branchName when provided.
  • If git.branchName is omitted, task branchName stays unset and branch binding stays none.

The worker initializes unbound CI workspaces from an explicit checkoutSha; otherwise it uses checkoutRef or the base branch without binding the task to that local branch. Explicit branchName tasks still use that branch as a strong task branch binding.

The final agent process receives protected environment variables derived from those task fields:

Worker envSource task fieldMeaning
AGENTRIX_BASE_REFbaseBranchTarget/base branch.
AGENTRIX_HEAD_REFheadRefObserved PR/MR source branch.
AGENTRIX_HEAD_SHAheadShaObserved PR/MR source commit.
AGENTRIX_CHECKOUT_REFcheckoutRefWorkspace initialization ref.
AGENTRIX_CHECKOUT_SHAcheckoutShaWorkspace initialization SHA.
AGENTRIX_TASK_BRANCHbranchNameBound task branch when one exists.
AGENTRIX_TASK_BRANCH_BINDINGbranchBindingTask branch binding mode.

These worker environment values are platform task context. They override user-provided agent environment variables with the same names.

Environment variables​

VariableUsed byDescription
AGENTRIX_BASE_URLCLI, GitHub Action child process, GitLab templateOptional Agentrix API base URL override. Defaults to https://agentrix.xmz.ai; ignored when --base-url is passed.
AGENTRIX_API_KEYCLI, GitHub Action child process, GitLab templateAPI key used as the bearer token. Ignored when --api-key is passed.
AGENTRIX_GIT_SERVER_IDCI auto-detectionGit server ID for the detected repository. Defaults to github in GitHub Actions and gitlab in GitLab CI.
CI_COMMIT_REF_NAME / CI_COMMIT_SHAGitLab CI auto-detectionCurrent GitLab job ref and commit. These are the only automatic sources for git.ref and git.sha.
GITHUB_REF / GITHUB_SHAGitHub Actions auto-detectionCurrent GitHub job ref and commit. These are the only automatic sources for git.ref and git.sha.
GITLAB_BRIDGE_EVENT_NAMEGitLab daemon webhook detectionNormalized event name emitted by the daemon bridge.
GITLAB_BRIDGE_EVENT_ACTIONGitLab daemon webhook detectionNormalized event action emitted by the daemon bridge.
GITLAB_BRIDGE_ISSUE_NUMBERGitLab daemon webhook detectionIssue number emitted for issue and issue comment events.
GITLAB_BRIDGE_PR_NUMBERGitLab daemon webhook detectionPull request number emitted for merge request and MR comment events.
GITLAB_BRIDGE_BASE_REF / GITLAB_BRIDGE_HEAD_REF / GITLAB_BRIDGE_HEAD_SHAGitLab daemon webhook detectionObserved MR context used only when standard GitLab MR variables are unavailable.
AGENTRIX_JOB_URLCI auto-detectionOverride detected job URL.
AGENTRIX_AGENTGitLab templateAgent ID or name.
AGENTRIX_PROMPTGitLab templatePrompt text.
AGENTRIX_TITLEGitLab templateCustom task title.
AGENTRIX_OUTPUT_SCHEMAGitLab templateJSON Schema string for structured output.
AGENTRIX_REPOGitLab templateJSON repository override.
AGENTRIX_BRANCH_NAMECLI, GitLab templateTask branch name override. Ignored when --branch-name is passed.
AGENTRIX_RESPONSE_MODEGitLab templatestream or async. Defaults to stream in the template.
AGENTRIX_TIMEOUTGitLab templateHTTP read timeout; in stream mode it is also the total wait timeout, in seconds. Defaults to 30 seconds for async and 1800 seconds for stream.
AGENTRIX_CAPABILITY_PROFILEGitLab templateCapability profile.
AGENTRIX_RUNNER_IDGitLab templateRunner ID. Required by the template above.
AGENTRIX_RESULT_FILEGitLab templateResult JSON file path.

agentrix-run does not infer checkout policy from issue or workflow phases. In daemon-triggered GitLab pipelines, GITLAB_BRIDGE_* supplies webhook event and observed MR context only. It never overrides the current job ref/SHA and never creates checkoutRef or checkoutSha.