CLI Commands Reference
AgentMap provides a command-line interface (CLI) for managing workflows, with powerful scaffolding capabilities for custom agents and functions.
Installationâ
pip install agentmap
Basic Commandsâ
Run a Graphâ
agentmap run --graph GraphName --state '{"input": "value"}'
Options:
--graph
,-g
: Name of the graph to run--state
,-s
: Initial state as JSON string--csv
: Optional path to CSV file--autocompile
,-a
: Automatically compile the graph--config
,-c
: Path to custom config file
View Configurationâ
agentmap config
Options:
--path
,-p
: Path to config file to display
Scaffolding Commandsâ
The scaffolding functionality is one of AgentMap's most powerful features, allowing you to quickly generate starter code for custom agents and functions.
Scaffold Agents and Functionsâ
agentmap scaffold [OPTIONS]
Options:
--graph
,-g
: Graph name to scaffold agents for--csv
: CSV path override--config
,-c
: Path to custom config file
How Scaffolding Worksâ
The scaffolding command:
- Analyzes your CSV file to find agent types and functions that aren't built-in
- Generates Python files for each custom agent and function
- Places them in the configured directories (default:
agentmap/agents/custom
andagentmap/functions
)
Example:
MyGraph,WeatherNode,,Get weather data,Weather,NextNode,,location,weather,Get weather for {location}
Running agentmap scaffold
will generate:
agentmap/agents/custom/weather_agent.py
- A starter agent implementation
Scaffold Outputâ
For custom agents, the scaffold generates:
from agentmap.agents.base_agent import BaseAgent
from typing import Dict, Any
class WeatherAgent(BaseAgent):
"""
Get weather data
Node: WeatherNode
Expected input fields: location
Expected output field: weather
Default prompt: Get weather for {location}
"""
def process(self, inputs: Dict[str, Any]) -> Any:
"""
Process the inputs and return the output value.
Args:
inputs (dict): Contains the input values with keys: location
Returns:
The value for weather
"""
# Access input fields directly from inputs dictionary
location = inputs.get("location")
# Implement your agent logic here
# ...
# Return just the output value (not the whole state)
return "Your WeatherAgent implementation here"
For functions, it generates:
from typing import Dict, Any
def choose_route(state: Any, success_node="SuccessPath", failure_node="FailurePath") -> str:
"""
Decision function to route between success and failure nodes.
Args:
state: The current graph state
success_node (str): Node to route to on success
failure_node (str): Node to route to on failure
Returns:
str: Name of the next node to execute
Node: DecisionNode
Node Context: Decision node description
Available in state:
- input: Input from previous node
"""
# TODO: Implement routing logic
# Determine whether to return success_node or failure_node
# Example implementation (replace with actual logic):
if state.get("last_action_success", True):
return success_node
else:
return failure_node
Custom Scaffolding Directoriesâ
You can customize the directories where scaffolds are generated:
### In agentmap_config.yaml
paths:
custom_agents: "path/to/custom/agents"
functions: "path/to/functions"
Or override them with environment variables:
export AGENTMAP_CUSTOM_AGENTS_PATH="path/to/custom/agents"
export AGENTMAP_FUNCTIONS_PATH="path/to/functions"
Best Practices for Scaffoldingâ
- Write clear Context descriptions - These become class docstrings
- Use descriptive Node names - These are used in error messages and logs
- Specify Input_Fields and Output_Field - These generate typed method signatures
- Include helpful Prompts - These provide guidance in the scaffolded code
Export and Compile Commandsâ
Export a Graphâ
agentmap export -g GraphName -o output.py
Options:
--graph
,-g
: Graph name to export--output
,-o
: Output file path--format
,-f
: Format (python, pickle, source)--csv
: CSV path override--state-schema
,-s
: State schema type--config
,-c
: Path to custom config file
Compile Graphsâ
agentmap compile [OPTIONS]
Options:
--graph
,-g
: Compile a single graph--output
,-o
: Output directory for compiled graphs--csv
: CSV path override--state-schema
,-s
: State schema type--config
,-c
: Path to custom config file
Storage Configurationâ
agentmap storage-config [OPTIONS]
Options:
--init
,-i
: Initialize a default storage configuration file--path
,-p
: Path to storage config file--config
,-c
: Path to custom config file
Common Usage Patternsâ
Development Workflowâ
-
Create CSV workflow
# Create your workflow.csv file with your favorite editor
vim customer_workflow.csv -
Validate workflow structure
agentmap validate-csv --csv customer_workflow.csv
# Expected output:
# â CSV validation successful
# â Found 5 nodes in workflow
# â All required columns present -
Scaffold missing agents
agentmap scaffold --csv customer_workflow.csv
# Expected output:
# â Generated WeatherAgent in custom_agents/weather_agent.py
# â Generated PaymentAgent in custom_agents/payment_agent.py
# âšī¸ Edit generated files to implement your logic -
Implement custom agents
# Edit generated files in custom_agents/
code custom_agents/weather_agent.py -
Test workflow
agentmap run --graph CustomerWorkflow --csv customer_workflow.csv
# Expected output:
# â Graph execution completed successfully
# â Execution time: 2.34s
# â All 5 nodes executed successfully -
Compile for production
agentmap compile --graph CustomerWorkflow --output ./compiled/
# Expected output:
# â Graph compiled successfully
# â Output saved to: ./compiled/CustomerWorkflow.pkl
# â Ready for production deployment
Configuration Managementâ
# View current configuration
agentmap config
# Expected output:
# Configuration loaded from: /path/to/agentmap_config.yaml
# â
CSV Path: ./workflows/
# â
Custom Agents: ./custom_agents/
# â
Compiled Graphs: ./compiled/
# â
Storage: Local file system
# View specific configuration section
agentmap config --section execution
# Expected output:
# Execution Configuration:
# â
Auto-compile: true
# â
Tracking enabled: false
# â
Success policy: all_nodes
# Use custom config file
agentmap run --config ./configs/production.yaml --graph ProductionFlow
# Initialize storage configuration
agentmap storage-config --init
# Expected output:
# â
Storage configuration initialized
# â
Created: agentmap_storage_config.yaml
# âšī¸ Edit the file to configure cloud storage
Debugging and Developmentâ
# Run with debug logging
agentmap run --graph TestFlow --log-level DEBUG
# Expected output:
# DEBUG: Loading graph definition from CSV
# DEBUG: Resolving agent dependencies
# DEBUG: [Node: start] Executing with inputs: {...}
# DEBUG: [Node: start] Completed in 0.123s
# â
Graph execution completed
# Run with detailed execution tracking
agentmap run --graph TestFlow --track-detailed
# Expected output:
# â
Graph execution completed
# đ Execution Summary:
# Total time: 2.45s
# Nodes executed: 4
# Success rate: 100%
# Auto-compile before running
agentmap run --graph TestFlow --autocompile
# Expected output:
# âšī¸ Auto-compiling graph...
# â
Compilation completed
# â
Graph execution completed
# Export for inspection
agentmap export --graph TestFlow --format source --output ./debug/
# Expected output:
# â
Graph exported to: ./debug/TestFlow_source.py
# âšī¸ Review the generated code for debugging
Environment Variablesâ
AgentMap respects several environment variables for configuration:
AGENTMAP_CONFIG_PATH
: Default configuration file pathAGENTMAP_CSV_PATH
: Default CSV file pathAGENTMAP_CUSTOM_AGENTS_PATH
: Custom agents directoryAGENTMAP_FUNCTIONS_PATH
: Functions directoryAGENTMAP_LOG_LEVEL
: Logging level (DEBUG, INFO, WARNING, ERROR)
Error Handlingâ
Common CLI Errorsâ
- Graph not found: Verify graph name matches CSV GraphName column
- Missing agents: Run scaffold command to generate missing custom agents
- Configuration errors: Check config file syntax and required fields
- Permission errors: Ensure write access to output directories
Debugging Tipsâ
- Use
--log-level DEBUG
for verbose output - Verify CSV syntax with a CSV validator
- Check that custom agents are in the correct directory
- Ensure all required environment variables are set
Monitoring and Operationsâ
Health Checksâ
# Check system health
agentmap diagnose
# Expected output:
# đ AgentMap System Diagnosis
# â
Configuration: Valid
# â
Dependencies: All available
# â
Storage: Accessible
# â
Custom agents: 3 found
# â
Compiled graphs: 2 found
# Validate specific workflow
agentmap validate-csv --csv production_workflow.csv
# Expected output:
# â
CSV structure valid
# â
All agent types available
# â
Dependency chain complete
# â ī¸ Warning: Large prompt in node 'process_data'
# Check configuration validity
agentmap validate-config
# Expected output:
# â
Configuration file syntax valid
# â
All required paths exist
# â
Storage configuration valid
# â Error: Invalid LLM API key format
Performance Monitoringâ
# Run with performance profiling
agentmap run --graph MyWorkflow --profile
# Expected output:
# â
Graph execution completed
# đ Performance Profile:
# Node 'validate_input': 0.045s
# Node 'process_data': 1.234s â ī¸ (slow)
# Node 'generate_output': 0.123s
# Total execution: 1.402s
# Monitor execution over time
agentmap run --graph MyWorkflow --monitor
# Expected output:
# đ Monitoring mode enabled
# â
Execution 1: 1.23s (success)
# â
Execution 2: 1.18s (success)
# â Execution 3: failed (error in process_data)
# đ Average: 1.21s, Success rate: 66.7%
Troubleshooting Commandsâ
# Inspect graph structure
agentmap inspect --graph MyWorkflow
# Expected output:
# đ Graph Structure: MyWorkflow
# Nodes: 5
# Edges: 4
# Entry points: 1 (start_node)
# Exit points: 1 (end_node)
#
# Flow diagram:
# start_node â validate_input â process_data â generate_output â end_node
# Check dependencies
agentmap validate-dependencies --graph MyWorkflow
# Expected output:
# â
All required agents available
# â
All custom functions found
# â ī¸ Warning: WeatherAgent uses deprecated API
# âšī¸ Suggestion: Update to use WeatherService v2
# Clear cache and rebuild
agentmap clear-cache
agentmap compile --graph MyWorkflow --force
# Expected output:
# â
Cache cleared
# â
Force compilation completed
# âšī¸ All compiled graphs refreshed
Advanced CLI Featuresâ
Batch Operationsâ
# Compile all graphs in directory
agentmap compile-all --csv-dir ./workflows/
# Expected output:
# â
Compiled: CustomerOnboarding (3.2s)
# â
Compiled: OrderProcessing (2.1s)
# â Failed: PaymentWorkflow (missing WeatherAgent)
# đ Summary: 2/3 successful
# Validate all workflows
agentmap validate-all --csv-dir ./workflows/
# Expected output:
# â
CustomerOnboarding.csv: Valid
# â ī¸ OrderProcessing.csv: 1 warning
# â PaymentWorkflow.csv: 2 errors
Integration with CI/CDâ
# Validate for CI/CD pipeline
agentmap validate-all --format json --output validation_report.json
# Generates JSON report for automated processing
# Export deployment package
agentmap package --graph ProductionWorkflow --output deployment.tar.gz
# Expected output:
# â
Packaging workflow for deployment
# â
Including: compiled graph, dependencies, config
# â
Package created: deployment.tar.gz (2.3MB)
Output Formats and Loggingâ
JSON Output for Automationâ
# Get machine-readable output
agentmap run --graph MyWorkflow --format json
# Output:
# {
# "success": true,
# "execution_time": 1.234,
# "nodes_executed": 5,
# "result": {...},
# "errors": []
# }
# Structured validation output
agentmap validate-csv --csv workflow.csv --format json
# Output:
# {
# "valid": true,
# "errors": [],
# "warnings": ["Large prompt in node 'process'"],
# "statistics": {
# "nodes": 5,
# "agents_used": ["input", "llm", "output"]
# }
# }
Logging Configurationâ
# Set log level for detailed debugging
AGENTMAP_LOG_LEVEL=DEBUG agentmap run --graph MyWorkflow
# Log to file
agentmap run --graph MyWorkflow --log-file execution.log
# Structured logging for monitoring systems
agentmap run --graph MyWorkflow --log-format json
Security and Productionâ
Secure Executionâ
# Run in sandbox mode (limited permissions)
agentmap run --graph MyWorkflow --sandbox
# Validate security before deployment
agentmap security-check --graph MyWorkflow
# Expected output:
# đ Security Analysis: MyWorkflow
# â
No file system access outside workspace
# â
No network access to sensitive endpoints
# â ī¸ Warning: Custom agent executes shell commands
# âšī¸ Review: custom_agents/system_agent.py:45
Production Deploymentâ
# Create production build
agentmap build --graph MyWorkflow --env production
# Expected output:
# â
Production build created
# â
Optimizations applied
# â
Security validations passed
# đĻ Build artifacts in: ./dist/MyWorkflow/
# Deploy to production
agentmap deploy --build ./dist/MyWorkflow/ --target production
See Alsoâ
- CSV Schema Reference - CSV workflow format documentation
- Agent Types Reference - Available agent types and configurations
- Quick Start Guide - Build your first workflow
- Configuration Guide - Configuration options and setup
- Execution Tracking - Monitoring and debugging workflows
- Testing Patterns - Testing strategies for CLI workflows