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:"4096"
Maximum number of tokens to generate in a single response.
int
default:"Based on model"
Maximum context window size. Automatically set based on the model.
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.
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.
int
default:"1"
Delay in seconds between retry attempts.
int
default:"None"
Timeout in seconds for agent execution.
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, theAgent 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
bool
default:"False"
Return full conversation history instead of just final response.
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.
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:"0.90"
Nucleus sampling parameter for model generation.
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:352-454