Overview
ModelSettings is a configuration class from the agents library that controls LLM behavior including temperature, token limits, and other generation parameters. It’s used with the Agentor class to fine-tune model responses.
Import
Usage
Common Parameters
WhileModelSettings is defined in the agents library, here are the commonly used parameters:
Controls randomness in outputs. Lower values (0.0-0.3) make outputs more focused and deterministic. Higher values (0.7-1.0) make outputs more creative and varied.
0.0-0.3: Precise, consistent, factual responses0.4-0.6: Balanced creativity and consistency0.7-1.0: Creative, diverse, exploratory responses
Maximum number of tokens to generate in the response. Limits the length of the model’s output.
Nucleus sampling parameter. Controls diversity by limiting cumulative probability. Alternative to temperature.
0.1-0.5: More focused, deterministic0.9-1.0: More diverse outputs
Penalizes tokens based on whether they appear in the text so far. Range: -2.0 to 2.0.
- Positive values encourage new topics
- Negative values encourage staying on topic
Penalizes tokens based on their frequency in the text. Range: -2.0 to 2.0.
- Positive values reduce repetition
- Negative values allow more repetition
Sequences where the model will stop generating. Maximum of 4 sequences.
Examples
Creative Writing
Precise Technical Responses
Concise Responses
Reducing Repetition
From Markdown File
You can also specify temperature in markdown frontmatter:Parameter Selection Guide
By Use Case
| Use Case | Temperature | Top P | Max Tokens | Notes |
|---|---|---|---|---|
| Code generation | 0.0-0.2 | 0.1 | 2000+ | Deterministic, precise |
| Technical writing | 0.3-0.5 | 0.5 | 1500 | Balanced, accurate |
| Creative writing | 0.8-1.0 | 0.95 | 2000+ | Diverse, imaginative |
| Summarization | 0.3-0.5 | 0.5 | 500 | Concise, factual |
| Conversation | 0.7-0.9 | 0.9 | 1000 | Natural, engaging |
| Data extraction | 0.0-0.1 | 0.1 | 500 | Consistent, accurate |
Combining Parameters
Notes
ModelSettingsis imported from theagentslibrary but re-exported byagentorfor convenience- If not provided, Agentor uses sensible defaults via
get_default_model_settings() - Temperature and top_p are alternative sampling methods - typically you should adjust one or the other, not both
- Different models may interpret these parameters differently
- Some parameters may not be supported by all model providers
Related
- Agentor - Main agent class that uses ModelSettings
- LLM - Lightweight LLM client
- LitellmModel - Custom model wrapper