Skip to main content
The Agent class provides extensive configuration options to customize behavior, performance, and capabilities.

Core Parameters

Model Configuration

str
default:"gpt-5.4"
The name of the language model to use. Supports any model from OpenAI, Anthropic, Groq, Cohere, and more via LiteLLM.
Any
default:"None"
Pre-configured LLM instance. If not provided, will be created automatically based on model_name.
float
default:"0.5"
Controls randomness in model outputs (0.0 = deterministic, 1.0 = creative).
int
default:"16000"
Maximum number of tokens to generate in a single response.
The constructor default is actually None. When left unset, self.max_tokens resolves during __init__ to the model’s real max-output-tokens (via _default_max_tokens()), falling back to 16000 only if that lookup fails. Pass max_tokens explicitly to override the resolved value.
int
default:"None"
Maximum context window size, used as the denominator for the ContextCompressor threshold check (see Agent Memory).
The value you pass is respected: self.context_length is only replaced by a model-derived default when you leave it as None. (An earlier release did overwrite it unconditionally; that is fixed.)
bool
default:"False"
Enable provider-side prompt caching. When True, the stable prefix of each request (system prompt, tools, and last message) is cached and re-billed at a large discount. Applies to the Anthropic model family (Claude on Anthropic / Bedrock / Vertex); OpenAI and other auto-caching providers are left untouched. See the full Prompt Caching guide.
dict
default:"None"
Fine-grained prompt-caching options; only consulted when prompt_caching=True. Keys (all optional): ttl ("5m" | "1h"), cache_system_prompt (bool), cache_messages (bool), cache_tools (bool), override (bool | None — force injection on/off), and OpenAI-only prompt_cache_key / prompt_cache_retention ("in_memory" | "24h").

Agent Identity

str
default:"swarm-worker-01"
Unique name for the agent. Used in multi-agent systems and logging. Omitted, it defaults to the literal string "swarm-worker-01" — the same value for every agent that doesn’t set one.
Because MEMORY.md is keyed on agent_name, every agent left at the default name reads and writes the same memory folder. Always give long-running or persistent-memory agents a unique agent_name.
str
default:"Auto-generated"
Description of the agent’s purpose and capabilities.
str
default:"Default system prompt"
The system prompt that defines agent behavior and expertise.

Execution Control

Union[int, str]
default:"1"
Number of execution loops. Set to “auto” for autonomous mode.
int
default:"0"
Delay in seconds between loops.
int
default:"3"
Number of retry attempts for failed LLM calls.

Output Configuration

str
default:"str-all-except-first"
Format for agent output. Options: “str”, “list”, “json”, “dict”, “yaml”, “xml”.
bool
default:"False"
Enable basic streaming with formatted panels.
bool
default:"False"
Enable detailed token-by-token streaming with metadata.
Callable
default:"None"
Callback function to receive streaming tokens in real-time.

Streaming Methods

In addition to the streaming flags above, the Agent exposes two streaming methods that yield tokens as a generator. They are real LLM streaming — tokens are forwarded the moment LiteLLM emits them, across every loop of the agent (tool-call turns, synthesis turns, autonomous plan/execute/summary phases).

agent.run_stream(task) -> Iterator[str]

Sync generator that yields tokens. The agent runs in a background thread; tokens are pushed onto a queue and yielded to the caller in order.

agent.arun_stream(task) -> AsyncIterator[str]

Async generator. Same semantics as run_stream, but the agent loop runs in a thread executor while tokens are forwarded through an asyncio.Queue, so the caller’s event loop is never blocked.
Both methods stream tokens through every internal loop, including tool calls, synthesis turns after a tool returns, and the autonomous plan/execute/summary cycle when max_loops="auto".
bool
default:"False"
Enable detailed logging output.
bool
default:"True"
Enable printing of agent responses.

Memory and History

To get the full conversation history instead of just the final response, use the output_type parameter (e.g. output_type="list" or output_type="dict") rather than a dedicated history flag — see Structured Outputs.
str
default:"Human"
Name to use for user messages in conversation history.
bool
default:"True"
Automatically manage context window to prevent overflow.

Advanced Features

bool
default:"False"
Randomly adjust temperature between loops for varied outputs.
bool
default:"True"
Add reasoning prompts to guide multi-step thinking.
bool
default:"False"
Enable interactive mode for conversational agents.
bool
default:"False"
Display agent dashboard on initialization.

State Management

bool
default:"False"
Automatically save agent state after each execution.
str
default:"Auto-generated"
Path to save agent state. save() writes here when called with no argument.
Earlier releases accepted this argument and then overwrote self.saved_state_path during initialization with an auto-generated {api_key}_state.json filename, so a custom path had no effect. It is now honoured; omit it to keep the auto-generated name.
Pass a file path, not a directory. The value is used as a filename, so a trailing slash such as "./agent_states/" resolves to ./agent_states/.json — a hidden file. While the argument was ignored this was harmless; now that it is honoured it is not.
str
default:"None"
Path to load previous agent state from.

Reliability

List[str]
default:"None"
List of fallback models to try if primary model fails.

Performance

str
default:"standard"
Agent execution mode. Options: “interactive”, “fast”, “standard”.
float
default:"None"
Nucleus sampling parameter for model generation. When left as None, no top_p value is sent in the request and the provider’s own default applies.

Example Configurations

Production Agent

Research Agent

Fast Batch Processing Agent

Next Steps

Agent Memory

Configure conversation history and memory

Agent Tools

Add tools to extend capabilities

Reference

Location in source: swarms/structs/agent.py:309-411 (the Agent.__init__ signature)