Max Tokens
Control maximum output tokens for agent responses
--max-tokens caps the model’s output length. When you pass it explicitly, PraisonAI honours it verbatim — even when the value equals the built-in default.
graph LR
Flag[⌨️ --max-tokens N] --> Sentinel{🔍 typed on<br/>command line?}
Sentinel -->|yes| Explicit[✅ _max_tokens_explicit=True]
Explicit --> Wins[🏆 wins over YAML<br/>& per-agent budgets]
Sentinel -->|no| Default[⚙️ built-in default 16000]
classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
classDef check fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef ok fill:#10B981,stroke:#7C90A0,color:#fff
classDef cfg fill:#189AB4,stroke:#7C90A0,color:#fff
class Flag input
class Sentinel check
class Explicit,Wins ok
class Default cfgQuick Start
- Set a budget from your agent
python from praisonaiagents import Agent agent = Agent(name="Writer", instructions="Write a detailed essay.") agent.start("Explain zero-shot prompting in depth.") # praisonai "Explain zero-shot prompting in depth." --max-tokens 8000 - Cap output from the CLI
bash praisonai "Write a detailed essay" --max-tokens 8000
How It Works
The parser tracks whether you actually typed the flag, so an explicit value always wins — regardless of what it equals.
sequenceDiagram
participant You
participant Parser as CLI Parser
participant Resolver as Config Resolver
participant Agent
You->>Parser: --max-tokens 16000
Parser->>Parser: sentinel present → _max_tokens_explicit=True
Parser->>Resolver: max_tokens=16000 (explicit)
Resolver->>Agent: cap = 16000 (overrides YAML)
Note over Agent: honoured verbatimPrecedence
The most specific source that you actually set wins.
| Where set | Wins when |
|---|---|
--max-tokens N on the command line (any N, including 16000) | You typed the flag. |
Per-agent max_tokens: in YAML | You did not type --max-tokens. |
| Nested workflow YAML budget | You did not type --max-tokens and no per-agent value applies. |
| Built-in default (16000) | Nothing else set it. |
Usage
praisonai "<prompt>" --max-tokens <number> [options]| Option | Description | Default |
|---|---|---|
--max-tokens | Maximum output tokens | 16000 |
Common Patterns
Short Response
praisonai "Summarize in brief" --max-tokens 500Long-form Content
praisonai "Write comprehensive documentation" --max-tokens 32000With Research
praisonai "Deep research on AI" --research --max-tokens 20000Token Limits by Model
| Model | Max Output Tokens |
|---|---|
| gpt-4o | 16,384 |
| gpt-4o-mini | 16,384 |
| claude-3-5-sonnet | 8,192 |
| gemini-2.0-flash | 8,192 |
Best Practices
Type the flag when you mean it
An explicit --max-tokens N always wins — including --max-tokens 16000. You no longer need workarounds like --max-tokens 16001.
Let YAML own per-agent budgets
Omit --max-tokens to let each agent’s max_tokens: in YAML apply. The CLI default only fills in when nothing else set a budget.
Stay under the model cap
Values above the model’s output limit are capped automatically, so match your budget to the model you run.