Appearance
Headless Mode
FreshSource: Letta Code Headless
Overview
Headless mode enables non-interactive execution suitable for scripting, CI/CD integration, and UNIX tool composition.
Basic Usage
One-Shot Query
bash
letta -p "Look around this repo and write a README.md documenting it"Piped Input
bash
echo "Explain this error" | letta -pOutput Formats
Text (Default)
Plain text agent responses:
bash
letta -p "What is the main entry point?"JSON
Structured output with metadata:
bash
letta -p "What is the main entry point?" --output-format json | jq '.result'JSON output includes: agent ID, conversation ID, and token usage statistics.
Stream JSON
Line-delimited JSON events for real-time streaming and timeout prevention:
bash
letta -p "Explain the architecture" --output-format stream-jsonEach message includes otid (output turn ID) and incrementing seq_id for token-level tracking.
Bidirectional Mode
Enable full programmatic control via JSON on stdin/stdout:
bash
letta --input-format stream-json --output-format stream-jsonInput Message Types
| Type | Description |
|---|---|
| User message | Send with role and content |
| Control request | Initialize, interrupt, etc. |
Output Message Types
| Type | Description |
|---|---|
| System initialization | Setup events |
| Control responses | Replies to control requests |
| Permission requests | Tool usage approval |
| Streaming messages | Incremental output |
| Results | Final turn results |
Interactive Tool Behavior
| Mode | AskUserQuestion | EnterPlanMode | ExitPlanMode |
|---|---|---|---|
One-shot (-p) | Excluded | Proceeds | Requires approval |
| Bidirectional | control_request | control_request | control_request |
Agent Management
bash
# Use last agent, default conversation
letta -p "query"
# New conversation
letta -p "query" --new
# New agent
letta -p "query" --new-agent
# Specific agent
letta -p "query" --agent agent-123
# Specific conversation
letta -p "query" --conversation conv-456
# Resume by name
letta -p "query" -n "my-agent"Configuration Options
Model Selection
bash
letta -p "query" --model sonnet
letta -p "query" --model auto
letta -p "query" -m gpt-5-codexEmbedding Model
bash
letta -p "query" --embedding letta/letta-freeNote
Embedding model can only be set when creating a new agent.
Permission Control
bash
# Bypass all prompts (except ExitPlanMode)
letta -p "Fix all lint errors" --yolo
# Restrict available tools
letta -p "Review code" --tools "Read,Glob,Grep"
# Set permission mode
letta -p "Refactor" --permission-mode acceptEdits
letta -p "Plan migration" --permission-mode planSystem Prompt
bash
# Use preset
letta -p "query" --system letta-claude
# Custom prompt
letta -p "query" --system-custom "You are a security auditor."Memory Blocks
bash
letta -p "query" --init-blocks "persona,project" \
--block-value "persona=Security specialist" \
--block-value "project=E-commerce platform"Advanced Features
Token-Level Streaming
bash
letta -p "Explain" --include-partial-messages --output-format stream-jsonWraps chunks in stream_event objects for real-time display.
Toolset Override
bash
letta -p "query" --toolset codex
letta -p "query" --toolset gemini
letta -p "query" --toolset defaultAgentFile Import
bash
letta -p "query" --import ./my-agent.af
letta -p "query" --import @author/agent-nameUsage Examples
Automated Linting
bash
letta -p "Run the linter and fix any errors" --yoloStructured Output for Scripts
bash
letta -p "What is the main entry point?" --output-format json | jq '.result'Read-Only Analysis
bash
letta -p "Review for security issues" --tools "Read,Glob,Grep"Cron Scheduling
bash
# Daily code review
0 9 * * 1-5 letta -p "Review yesterday's commits" --output-format json >> /var/log/reviews.json
# Weekly dependency check
0 10 * * 1 letta -p "Check for outdated dependencies" --yoloVerification Checklist
- [ ]
letta -p "test"returns a response - [ ] JSON output parses correctly
- [ ] Stream JSON delivers incremental events
- [ ]
--toolsflag restricts available tools - [ ]
--yolobypasses interactive prompts - [ ] Agent/conversation selection works as expected
See Also
- Scheduling - Automated recurring tasks
- Channels - Messaging platform integration
- SDK Overview - Programmatic access