AgentFile Syntax Reference
Complete reference for AgentFile — the domain-specific language (DSL) that defines how AI agent execution environments are configured in AgentsMesh.
What is AgentFile?
AgentFile is a declarative DSL for configuring AI agent execution environments, similar to how Dockerfile defines container builds. Each agent in AgentsMesh has an AgentFile that specifies the CLI command, environment variables, configuration options, and build logic needed to launch the agent.
Structure
An AgentFile consists of two types of statements: declarations and build logic.
Declarations (UPPERCASE)
Top-level keywords that define the agent's identity, configuration schema, environment, and integrations. Examples: AGENT, CONFIG, ENV, MODE, MCP.
Build Logic (lowercase)
Imperative statements that construct CLI arguments, write files, and apply conditional logic at build time. Examples: arg, file, mkdir, if/else, for/in.
Declaration Keywords
Declarations define the agent's configuration schema and runtime environment. They are written in UPPERCASE.
AGENT
The CLI command used to launch the agent. Accepts a quoted string with the command and optional default arguments.
AGENT "claude-code"
AGENT "aider --model opus"EXECUTABLE
The name of the executable binary. Used by the Runner to verify the agent is installed.
EXECUTABLE "claude"CONFIG
Defines a user-configurable option. Types: BOOL, STRING, NUMBER, SECRET, SELECT("opt1","opt2"). Optionally set a default value with = .
CONFIG model STRING = "sonnet"
CONFIG verbose BOOL = false
CONFIG max_tokens NUMBER = 4096
CONFIG api_key SECRET
CONFIG mode SELECT("fast","balanced","quality") = "balanced"ENV
Declares an environment variable. Use SECRET for sensitive values, TEXT for plain text, OPTIONAL to mark it non-required. Use = "value" for static values.
ENV ANTHROPIC_API_KEY SECRET
ENV DEBUG TEXT OPTIONAL
ENV NODE_ENV = "production"MODE
Sets the execution mode. 'pty' runs the agent in a PTY terminal. 'acp' uses the Agent Communication Protocol with optional arguments.
MODE pty
MODE acp --model opusCREDENTIAL
Specifies which credential profile to use. Use a quoted profile name or 'runner_host' to use the Runner machine's credentials.
CREDENTIAL "my-anthropic-profile"
CREDENTIAL runner_hostPROMPT / PROMPT_POSITION
Sets the initial prompt sent to the agent. PROMPT_POSITION controls where the prompt is injected: prepend (before user prompt), append (after), or none (disabled).
PROMPT "Fix the login bug in auth.ts"
PROMPT_POSITION prepend # prepend | append | noneREPO / BRANCH / GIT_CREDENTIAL
REPO sets the repository by slug or URL. BRANCH sets the branch name. GIT_CREDENTIAL selects the Git authentication method: http, ssh, or token.
REPO "my-org/my-repo"
BRANCH "feature/new-auth"
GIT_CREDENTIAL http # http | ssh | tokenMCP
Enables or disables MCP tool integration. When ON, an optional FORMAT can specify the protocol format (e.g., streamable-http).
MCP ON
MCP ON FORMAT streamable-http
MCP OFFSKILLS
Attaches reusable skill definitions to the agent. Skills are referenced by their slug, separated by commas.
SKILLS code-review, deploy-helperSETUP
A shell script that runs before the agent starts. Use heredoc syntax (<<LABEL...LABEL). Optional timeout= parameter sets the maximum execution time in seconds.
SETUP timeout=60 <<SCRIPT
npm install
npm run build
SCRIPTREMOVE
Removes a previously defined item. Can remove ENV variables, SKILLS, CLI arguments (arg), or files (file).
REMOVE ENV DEBUG
REMOVE SKILLS deploy-helper
REMOVE arg --verbose
REMOVE file /tmp/cacheBuild Logic
Build logic statements are lowercase and execute during the AgentFile evaluation phase. They construct CLI arguments, write files, and apply conditional logic.
# Variable assignment
model_flag = "--model " + config.model
# arg — append CLI argument
arg model_flag
# file — write a file
file ".env" "NODE_ENV=production"
# mkdir — create a directory
mkdir sandbox.work_dir + "/output"
# if / else
if config.verbose {
arg "--verbose"
} else {
arg "--quiet"
}
# for / in
for server in mcp.servers {
arg "--mcp-server " + server
}
# when — shorthand conditional
when config.verbose arg "--verbose"Expressions
AgentFile supports a variety of expression types that can be used in build logic and declarations.
| Type | Example |
|---|---|
| Strings | "hello" + " world" |
| Numbers | 42, 3.14 |
| Booleans | true, false |
| Dot access | config.model, sandbox.root |
| Operators | +, ==, !=, and, or, not |
| Functions | json(...), str_replace(...), env(...) |
Built-in Variables
These variables are automatically available during AgentFile evaluation and provide access to configuration values and runtime context.
| Variable | Description |
|---|---|
| config.* | User-provided configuration values defined by CONFIG declarations |
| sandbox.root | Root directory of the sandbox environment |
| sandbox.work_dir | Working directory inside the sandbox (may differ from root when a repo is cloned) |
| mcp.enabled | Boolean indicating whether MCP is enabled |
| mcp.servers | List of MCP server configuration paths |
| mcp.format | The MCP protocol format string |
| mode | Current execution mode ('pty' or 'acp') |
String Escaping
AgentFile strings support standard escape sequences inside double-quoted strings:
\\ → backslash
\" → double quote
\n → newline
\t → tabFull Example
Here is a complete AgentFile for Claude Code, showing declarations, configuration, build logic, and setup script:
# Claude Code AgentFile
AGENT "claude-code"
EXECUTABLE "claude"
# Execution mode: PTY terminal
MODE pty
# User-configurable options
CONFIG model STRING = "sonnet"
CONFIG permission_mode SELECT("default","plan","acceptEdits","dontAsk","bypassPermissions") = "bypassPermissions"
CONFIG verbose BOOL = false
# Environment variables
ENV ANTHROPIC_API_KEY SECRET
ENV CLAUDE_CODE_USE_BEDROCK TEXT OPTIONAL
# MCP tools enabled
MCP ON
# Build the CLI arguments
arg "--model " + config.model
if config.permission_mode != "default" and config.permission_mode != "" {
arg "--permission-mode" config.permission_mode
}
when config.verbose arg "--verbose"
# Inject MCP server configuration
for server in mcp.servers {
arg "--mcp-config " + server
}
# Setup script runs before the agent starts
SETUP timeout=30 <<INIT
echo "Workspace ready at $(pwd)"
INIT