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.

Diagram

yes

no

⌨️ –max-tokens N

🔍 typed on
command line?

✅ _max_tokens_explicit=True

🏆 wins over YAML
& per-agent budgets

⚙️ built-in default 16000

Quick Start

  1. 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
  2. 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.

Diagram
AgentConfig ResolverCLI ParserYouAgentConfig ResolverCLI ParserYouhonoured verbatim–max-tokens 16000sentinel present → _max_tokens_explicit=Truemax_tokens=16000 (explicit)cap = 16000 (overrides YAML)

Precedence

The most specific source that you actually set wins.

Where setWins when
--max-tokens N on the command line (any N, including 16000)You typed the flag.
Per-agent max_tokens: in YAMLYou did not type --max-tokens.
Nested workflow YAML budgetYou did not type --max-tokens and no per-agent value applies.
Built-in default (16000)Nothing else set it.

Usage

bash
praisonai "<prompt>" --max-tokens <number> [options]
OptionDescriptionDefault
--max-tokensMaximum output tokens16000

Common Patterns

Short Response

bash
praisonai "Summarize in brief" --max-tokens 500

Long-form Content

bash
praisonai "Write comprehensive documentation" --max-tokens 32000

With Research

bash
praisonai "Deep research on AI" --research --max-tokens 20000

Token Limits by Model

ModelMax Output Tokens
gpt-4o16,384
gpt-4o-mini16,384
claude-3-5-sonnet8,192
gemini-2.0-flash8,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.


Related