LLMConfig - AG2
LLMConfig
``autogen.LLMConfig [
LLMConfig(*configs, top_p=None, temperature=None, max_tokens=None, check_every_ms=None, allow_format_str_template=None, response_format=None, timeout=None, seed=None, cache_seed=None, parallel_tool_calls=None, tools=(), functions=(), routing_method=None, config_list=(), **kwargs)
Initializes the LLMConfig object.
| PARAMETER | DESCRIPTION |
|---|---|
*configs |
A list of LLM configuration entries or dictionaries. TYPE: ConfigItemDEFAULT:() |
config_list |
A list of LLM configuration entries or dictionaries. TYPE:`Iterable[ConfigItem] |
temperature |
The sampling temperature for LLM generation. TYPE:`float |
check_every_ms |
The interval (in milliseconds) to check for updates TYPE:`int |
allow_format_str_template |
Whether to allow format string templates. TYPE:`bool |
response_format |
The format of the response (e.g., JSON, text). TYPE:`str |
timeout |
The timeout for LLM requests in seconds. TYPE:`int |
seed |
The random seed for reproducible results. TYPE:`int |
cache_seed |
The seed for caching LLM responses. TYPE:`int |
parallel_tool_calls |
Whether to enable parallel tool calls. TYPE:`bool |
tools |
A list of tools available for the LLM. TYPE: Iterable[Any]DEFAULT:() |
functions |
A list of functions available for the LLM. TYPE: Iterable[Any]DEFAULT:() |
max_tokens |
The maximum number of tokens to generate. TYPE:`int |
top_p |
The nucleus sampling probability. TYPE:`float |
routing_method |
The method used to route requests (e.g., fixed_order, round_robin). TYPE:`Literal['fixed_order', 'round_robin'] |
**kwargs |
Additional keyword arguments for future extensions. TYPE: AnyDEFAULT:{} |
Examples:
# Example 1: create config from one model dictionary
config = LLMConfig({
"model": "gpt-5-mini",
"api_key": os.environ["OPENAI_API_KEY"],
})
# Example 2: create config from list of dictionaries
config = LLMConfig(
{
"model": "gpt-5-mini",
"api_key": os.environ["OPENAI_API_KEY"],
},
{
"model": "gpt-4",
"api_key": os.environ["OPENAI_API_KEY"],
},
)
# Example 3 (deprecated): create config from `kwargs` options
config = LLMConfig(
model="gpt-5-mini",
api_key=os.environ["OPENAI_API_KEY"],
)
# Example 4 (deprecated): create config from `config_list` dictionary
config = LLMConfig(
config_list={
"model": "gpt-5-mini",
"api_key": os.environ["OPENAI_API_KEY"],
}
)
# Example 5 (deprecated): create config from `config_list` list
config = LLMConfig(
config_list=[
{
"model": "gpt-5-mini",
"api_key": os.environ["OPENAI_API_KEY"],
},
{
"model": "gpt-5",
"api_key": os.environ["OPENAI_API_KEY"],
},
]
)
``config_listinstance-attribute
config_list
``ensure_configclassmethod
ensure_config(config)
Transforms passed objects to LLMConfig object.
Method to use for Agent(llm_config={...}) cases.
LLMConfig.ensure_config(LLMConfig(...)) LLMConfig(...) LLMConfig.ensure_config(LLMConfigEntry(...)) LLMConfig(LLMConfigEntry(...)) LLMConfig.ensure_config({"model": "gpt-o3"}) LLMConfig(OpenAILLMConfigEntry(model="o3")) LLMConfig.ensure_config([{"model": "gpt-o3"}, ...]) LLMConfig(OpenAILLMConfigEntry(model="o3"), ...) (deprecated) LLMConfig.ensure_config({"config_list": [{ "model": "gpt-o3" }, ...]}) LLMConfig(OpenAILLMConfigEntry(model="o3"), ...)
``get_current_llm_configclassmethod
get_current_llm_config(llm_config=None)
``from_jsonclassmethod
from_json(*, env=None, path=None, file_location=None, filter_dict=None, **kwargs)
where
where(*, exclude=False, **kwargs)
model_dump
model_dump(*args, exclude_none=True, **kwargs)
model_dump_json
model_dump_json(*args, exclude_none=True, **kwargs)
model_validate
model_validate(*args, **kwargs)
model_validate_json
model_validate_json(*args, **kwargs)
model_validate_strings
model_validate_strings(*args, **kwargs)
get
get(key, default=None)
copy
copy()
deepcopy
deepcopy(memo=None)
items
items()
keys
keys()
values
values()