Skip to content

CLI Reference

The PetalFlow CLI provides commands for running, validating, compiling, and serving workflow graphs. It also includes comprehensive tool management for native, HTTP, stdio, and MCP-based tools.

Terminal window
# Install the CLI
go install github.com/petal-labs/petalflow/cmd/petalflow@latest
# Verify installation
petalflow --version

These flags apply to all commands:

FlagDescription
--verboseEnable verbose/debug logging
--quietSuppress all output except errors
--no-colorDisable colored output
--help, -hShow help for any command

run

Execute a workflow file with input data.

compile

Compile agent workflow to graph IR.

validate

Validate workflow files without executing.

serve

Start HTTP daemon for workflow management.

tools

Register, inspect, and manage tools.


Execute a workflow file with input data. Supports both agent workflow files and graph IR files.

Terminal window
petalflow run [flags] <workflow-file>
FlagShortDescription
--input-iInline JSON input (e.g., '{"query": "hello"}')
--input-file-fRead input from JSON file
--output-oWrite output to file instead of stdout
--formatOutput format: json (default) or text
--timeout-tExecution timeout (e.g., 30s, 5m)
--dry-runValidate without executing
--env-eSet environment variables (can be repeated)
--provider-keyProvider API key in format provider=key
--store-pathPath to SQLite store for tool registry
--streamEnable streaming output via SSE
Terminal window
# Run with inline input
petalflow run workflow.yaml -i '{"message": "Hello, world!"}'
# Run with input file
petalflow run workflow.yaml -f input.json
# Run with timeout and output file
petalflow run workflow.yaml -i '{"query": "search"}' -t 30s -o result.json
# Run with provider key
petalflow run workflow.yaml -i '{}' --provider-key openai=sk-...
# Run with environment variables
petalflow run workflow.yaml -i '{}' -e API_URL=https://api.example.com
# Dry run (validate only)
petalflow run workflow.yaml -i '{}' --dry-run
# Stream output
petalflow run workflow.yaml -i '{}' --stream

The run command accepts input in multiple formats:

  1. Inline JSON (--input): Direct JSON string on the command line
  2. JSON file (--input-file): Path to a JSON file containing input data
  3. Stdin: If no input flag is provided, reads from stdin
Terminal window
# Read from stdin
echo '{"query": "hello"}' | petalflow run workflow.yaml
# Or use input redirection
petalflow run workflow.yaml < input.json

When --stream is enabled, the CLI outputs Server-Sent Events (SSE) format:

event: node_start
data: {"node": "classify", "timestamp": "2024-01-15T10:30:00Z"}
event: node_output
data: {"node": "classify", "output": {"category": "billing"}}
event: node_end
data: {"node": "classify", "duration_ms": 150}
event: complete
data: {"output": {"result": "..."}}

Compile an agent workflow file to graph IR (Intermediate Representation). This command only accepts agent workflow files, not graph IR files.

Terminal window
petalflow compile [flags] <agent-workflow-file>
FlagShortDescription
--output-oWrite compiled IR to file (default: stdout)
--prettyPretty-print the JSON output
--validate-onlyValidate without outputting IR
Terminal window
# Compile to stdout
petalflow compile agent-workflow.yaml
# Compile with pretty printing
petalflow compile agent-workflow.yaml --pretty
# Compile to file
petalflow compile agent-workflow.yaml -o compiled.json
# Validate only
petalflow compile agent-workflow.yaml --validate-only

PetalFlow supports two workflow file formats:

FormatExtensionDescription
Agent Workflow.yaml, .ymlHigh-level declarative format for agents
Graph IR.jsonLow-level graph intermediate representation

The compile command transforms agent workflows into graph IR. The run and validate commands accept both formats.


Validate a workflow file without executing it. Useful for CI/CD pipelines and pre-commit checks.

Terminal window
petalflow validate [flags] <workflow-file>
FlagDescription
--formatOutput format: text (default) or json
--strictEnable strict validation (additional checks)
Terminal window
# Basic validation
petalflow validate workflow.yaml
# JSON output for CI integration
petalflow validate workflow.yaml --format json
# Strict mode
petalflow validate workflow.yaml --strict

Text format (default):

Validating workflow.yaml...
OK: workflow is valid

JSON format:

{
"valid": true,
"file": "workflow.yaml",
"schema": "agent_workflow",
"errors": [],
"warnings": []
}

The validator performs these checks:

  • Schema compliance (agent workflow or graph IR)
  • Node reference integrity (edges point to valid nodes)
  • Entry point existence
  • Required field presence
  • Type correctness for node configurations
  • Cycle detection in non-iterative graphs

In strict mode, additional checks include:

  • Unused node detection
  • Unreachable node warnings
  • Best practice recommendations

Start an HTTP daemon server for managing workflows and tools. The server provides REST APIs for workflow execution, tool registration, and real-time streaming.

Terminal window
petalflow serve [flags]
FlagDefaultDescription
--port8080HTTP server port
--host127.0.0.1Host address to bind
--cors-originAllowed CORS origins (comma-separated)
--sqlite-pathPath to SQLite database
--configPath to server config file
--provider-keyProvider API key (provider=key)
--tls-certPath to TLS certificate file
--tls-keyPath to TLS key file
--read-timeout30sHTTP read timeout
--write-timeout60sHTTP write timeout
--max-body10MBMaximum request body size
--workflow-schedule-poll10sPolling interval for scheduled workflows
Terminal window
# Start on default port
petalflow serve
# Start on custom port with CORS
petalflow serve --port 3000 --cors-origin "http://localhost:5173"
# Start with TLS
petalflow serve --tls-cert cert.pem --tls-key key.pem
# Start with SQLite persistence
petalflow serve --sqlite-path /var/lib/petalflow/data.db
# Start with provider keys
petalflow serve --provider-key openai=sk-... --provider-key anthropic=sk-ant-...

The server exposes these REST endpoints:

MethodPathDescription
GET/healthServer health check
MethodPathDescription
GET/api/workflowsList all workflows
POST/api/workflowsCreate/upload workflow
GET/api/workflows/:idGet workflow by ID
DELETE/api/workflows/:idDelete workflow
POST/api/workflows/:id/runExecute workflow
MethodPathDescription
GET/api/runsList all runs
GET/api/runs/:idGet run status/output
GET/api/runs/:id/streamStream run events (SSE)
DELETE/api/runs/:idCancel running workflow
MethodPathDescription
GET/api/toolsList registered tools
POST/api/toolsRegister new tool
GET/api/tools/:nameGet tool manifest
DELETE/api/tools/:nameUnregister tool
POST/api/tools/:name/testTest tool invocation
MethodPathDescription
GET/api/node-typesList available node types

Create a YAML configuration file for complex setups:

petalflow-server.yaml
server:
host: 0.0.0.0
port: 8080
cors_origins:
- http://localhost:3000
- https://app.example.com
tls:
cert: /etc/petalflow/cert.pem
key: /etc/petalflow/key.pem
storage:
sqlite_path: /var/lib/petalflow/data.db
providers:
openai: ${OPENAI_API_KEY}
anthropic: ${ANTHROPIC_API_KEY}
timeouts:
read: 30s
write: 60s
workflow_poll: 10s
Terminal window
petalflow serve --config petalflow-server.yaml

Manage tools for workflow execution. Tools can be native Go functions, HTTP endpoints, stdio executables, or MCP (Model Context Protocol) servers.

Terminal window
petalflow tools <subcommand> [flags]
SubcommandDescription
registerRegister a new tool
listList all registered tools
inspectShow tool manifest details
unregisterRemove a tool from registry
configSet or show tool configuration
testTest a tool invocation
refreshRe-discover MCP tool actions
overlaySet or clear MCP overlay
healthRun tool health checks

Register a new tool with the tool registry.

Terminal window
petalflow tools register [flags] <tool-name>
FlagDescription
--typeTool type: native, http, stdio, mcp
--manifestPath to tool manifest JSON file
--endpointHTTP endpoint URL (for http type)
--commandExecutable command (for stdio/mcp types)
--argCommand arguments (can be repeated)
--envEnvironment variables (can be repeated)
--transport-modeMCP transport: stdio or sse
--overlayMCP overlay configuration
Terminal window
# Register HTTP tool
petalflow tools register weather-api \
--type http \
--endpoint https://api.weather.com/v1
# Register stdio tool
petalflow tools register code-formatter \
--type stdio \
--command /usr/local/bin/prettier \
--arg --stdin \
--arg --parser=json
# Register MCP tool
petalflow tools register mcp-filesystem \
--type mcp \
--command npx \
--arg @modelcontextprotocol/server-filesystem \
--arg /path/to/allowed/directory \
--transport-mode stdio
# Register from manifest file
petalflow tools register my-tool --manifest tool-manifest.json
{
"name": "weather-lookup",
"type": "http",
"description": "Look up weather for a location",
"endpoint": "https://api.weather.com/v1/current",
"actions": [
{
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name"
}
},
"required": ["city"]
}
}
]
}

List all registered and built-in tools.

Terminal window
petalflow tools list [flags]
FlagDescription
--formatOutput format: table (default), json
--typeFilter by tool type
Terminal window
# List all tools
petalflow tools list
# List as JSON
petalflow tools list --format json
# Filter by type
petalflow tools list --type mcp
NAME TYPE ACTIONS STATUS
weather-api http 2 healthy
code-formatter stdio 1 healthy
mcp-filesystem mcp 5 healthy
[built-in] echo native 1 healthy
[built-in] sleep native 1 healthy

Show detailed information about a registered tool.

Terminal window
petalflow tools inspect [flags] <tool-name>
FlagDescription
--actionsShow detailed action schemas
Terminal window
# Basic inspection
petalflow tools inspect weather-api
# With action details
petalflow tools inspect weather-api --actions
Tool: weather-api
Type: http
Endpoint: https://api.weather.com/v1
Status: healthy
Actions:
- get_current: Get current weather conditions
- get_forecast: Get 7-day forecast
Config:
api_key: [set]
timeout: 30s

Remove a tool from the registry.

Terminal window
petalflow tools unregister <tool-name>
Terminal window
petalflow tools unregister weather-api

Set or show tool configuration values.

Terminal window
petalflow tools config [flags] <tool-name>
FlagDescription
--setSet a config value (key=value)
--set-secretSet a secret config value (prompted or key=value)
--showShow current configuration
Terminal window
# Show current config
petalflow tools config weather-api --show
# Set a config value
petalflow tools config weather-api --set timeout=30s
# Set a secret (will prompt for value)
petalflow tools config weather-api --set-secret api_key
# Set a secret with value
petalflow tools config weather-api --set-secret api_key=sk-...

Test a tool invocation with sample input.

Terminal window
petalflow tools test [flags] <tool-name> <action-name>
FlagDescription
--inputInline JSON input
--input-jsonPath to JSON input file
Terminal window
# Test with inline input
petalflow tools test weather-api get_weather --input '{"city": "Seattle"}'
# Test with input file
petalflow tools test code-formatter format --input-json test-input.json
Testing weather-api.get_weather...
Input: {"city": "Seattle"}
Output: {"temperature": 62, "conditions": "Partly Cloudy", "humidity": 75}
Duration: 234ms
Status: success

Re-discover actions for MCP tools. Use this after updating an MCP server.

Terminal window
petalflow tools refresh <tool-name>
Terminal window
petalflow tools refresh mcp-filesystem

This reconnects to the MCP server and updates the action registry with any new or modified tool definitions.


Set or clear an MCP overlay configuration. Overlays allow you to customize tool behavior without modifying the original MCP server.

Terminal window
petalflow tools overlay [flags] <tool-name>
FlagDescription
--setSet overlay configuration (JSON)
--clearClear existing overlay
Terminal window
# Set an overlay
petalflow tools overlay mcp-filesystem --set '{"allowed_paths": ["/home/user/safe"]}'
# Clear overlay
petalflow tools overlay mcp-filesystem --clear

Run health checks on registered tools.

Terminal window
petalflow tools health [flags] [tool-name]
FlagDescription
--allCheck all registered tools
Terminal window
# Check specific tool
petalflow tools health weather-api
# Check all tools
petalflow tools health --all
Checking tool health...
weather-api OK (234ms)
code-formatter OK (12ms)
mcp-filesystem OK (156ms)
broken-tool FAIL connection refused
3/4 tools healthy

PetalFlow supports four types of tools:

Go functions registered directly with the runtime. These are the fastest but require code changes to add new tools.

registry.Register(tools.Tool{
Name: "calculate",
Func: func(ctx context.Context, args CalcArgs) (CalcResult, error) {
return CalcResult{Sum: args.A + args.B}, nil
},
})

REST API endpoints that accept JSON input and return JSON output.

Terminal window
petalflow tools register api-tool \
--type http \
--endpoint https://api.example.com/v1/action

Command-line executables that communicate via stdin/stdout.

Terminal window
petalflow tools register formatter \
--type stdio \
--command /usr/bin/jq \
--arg .

Model Context Protocol servers providing tool capabilities. Supports both stdio and SSE transport modes.

Terminal window
# Stdio transport
petalflow tools register mcp-tool \
--type mcp \
--command npx \
--arg @example/mcp-server \
--transport-mode stdio
# SSE transport
petalflow tools register mcp-remote \
--type mcp \
--endpoint https://mcp.example.com/sse \
--transport-mode sse

The CLI uses these exit codes:

CodeNameDescription
0SuccessCommand completed successfully
1ValidationWorkflow validation failed
2RuntimeRuntime error during execution
3FileNotFoundSpecified file not found
4InputParseFailed to parse input JSON
5ProviderLLM provider error
6WrongSchemaWrong workflow schema type
10TimeoutExecution timeout exceeded
#!/bin/bash
petalflow run workflow.yaml -i '{}'
case $? in
0) echo "Success" ;;
1) echo "Validation error - check workflow syntax" ;;
2) echo "Runtime error - check logs" ;;
3) echo "File not found" ;;
4) echo "Invalid input JSON" ;;
5) echo "Provider error - check API keys" ;;
6) echo "Wrong schema type" ;;
10) echo "Timeout - increase --timeout value" ;;
*) echo "Unknown error" ;;
esac

VariableDescription
PETALFLOW_SQLITE_PATHDefault SQLite database path
PETALFLOW_TOOLS_STORE_PATHDefault tools registry path
PETALFLOW_CONFIGDefault config file path
PETALFLOW_LOG_LEVELLog level: debug, info, warn, error
PETALFLOW_NO_COLORDisable colored output (1 or true)

Provider API keys can also be set via environment variables:

VariableProvider
OPENAI_API_KEYOpenAI
ANTHROPIC_API_KEYAnthropic
GEMINI_API_KEYGoogle Gemini
OLLAMA_HOSTOllama (local)

Create ~/.petalflow/config.yaml for persistent settings:

~/.petalflow/config.yaml
defaults:
timeout: 60s
format: json
store_path: ~/.petalflow/tools.db
providers:
openai: ${OPENAI_API_KEY}
anthropic: ${ANTHROPIC_API_KEY}
logging:
level: info
format: text
output:
color: true
verbose: false

When running workflows with human-in-the-loop nodes, the CLI operates in auto-approve mode by default. This means approval requests are automatically accepted.

For interactive approval, use the serve command and interact via the REST API or a connected UI client.

Terminal window
# Auto-approve mode (default CLI behavior)
petalflow run workflow-with-approval.yaml -i '{}'
# Interactive mode via server
petalflow serve --port 8080
# Then use UI or API to handle approvals

PracticeRecommendation
Validation firstRun validate before run in CI pipelines
Use timeoutsAlways set --timeout for production runs
Store provider keysUse environment variables or config, not CLI flags
Health checksRun tools health --all periodically
Streaming for long runsUse --stream for workflows > 30 seconds
Exit code handlingCheck exit codes in scripts and automation

Examples

Production workflow examples. Examples