Models
Tutorial
Please see the model section in the installation guide for an overview of the different models and how to configure them.
This page documents the configuration objects used to specify the behavior of a language model (LM).
In most cases, you will want to use the GenericAPIModelConfig
object.
API LMs
sweagent.agent.models.GenericAPIModelConfig
pydantic-model
Bases: BaseModel
This configuration object specifies a LM like GPT4 or similar.
The model will be served with the help of the litellm
library.
Config:
extra
:'forbid'
Fields:
-
name
(str
) -
per_instance_cost_limit
(float
) -
total_cost_limit
(float
) -
per_instance_call_limit
(int
) -
temperature
(float
) -
top_p
(float | None
) -
api_base
(str | None
) -
api_version
(str | None
) -
api_key
(SecretStr | None
) -
stop
(list[str]
) -
completion_kwargs
(dict[str, Any]
) -
convert_system_to_user
(bool
) -
retry
(RetryConfig
) -
delay
(float
) -
fallbacks
(list[dict[str, Any]]
) -
choose_api_key_by_thread
(bool
) -
id
(str
)
api_base
pydantic-field
api_base: str | None = None
api_key
pydantic-field
api_key: SecretStr | None = None
API key to the model. We recommend using environment variables to set this instead
or putting your environment variables in a .env
file.
You can concatenate more than one key by separating them with :::
, e.g.,
key1:::key2
.
If field starts with $
, it will be interpreted as an environment variable.
api_version
pydantic-field
api_version: str | None = None
choose_api_key_by_thread
pydantic-field
choose_api_key_by_thread: bool = True
Whether to choose the API key based on the thread name (if multiple are configured). This ensures that with run-batch, we use the same API key within a single-thread so that prompt caching still works.
completion_kwargs
pydantic-field
completion_kwargs: dict[str, Any] = {}
Additional kwargs to pass to litellm.completion
convert_system_to_user
pydantic-field
convert_system_to_user: bool = False
Whether to convert system messages to user messages. This is useful for models that do not support system messages like o1.
delay
pydantic-field
delay: float = 0.0
Minimum delay before querying (this can help to avoid overusing the API if sharing it with other people).
fallbacks
pydantic-field
fallbacks: list[dict[str, Any]] = []
List of fallbacks to try if the main model fails See https://docs.litellm.ai/docs/completion/reliable_completions#fallbacks-sdk for more information.
id
property
pydantic-field
id: str
name
pydantic-field
name: str
Name of the model.
per_instance_call_limit
pydantic-field
per_instance_call_limit: int = 0
Per instance call limit.
per_instance_cost_limit
pydantic-field
per_instance_cost_limit: float = 3.0
Cost limit for every instance (task).
retry
pydantic-field
retry: RetryConfig
Retry configuration: How often to retry after a failure (e.g., from a rate limit) etc.
stop
pydantic-field
stop: list[str] = []
Custom stop sequences
temperature
pydantic-field
temperature: float = 0.0
Sampling temperature
top_p
pydantic-field
top_p: float | None = 1.0
Sampling top-p
total_cost_limit
pydantic-field
total_cost_limit: float = 0.0
Total cost limit.
choose_api_key
choose_api_key() -> str | None
Chooses an API key based on the API keys explicitly set in this config. If no API keys are set, returns None (which means that the API key will be taken from the environment variables/.env file).
Source code in sweagent/agent/models.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
get_api_keys
get_api_keys() -> list[str]
Returns a list of API keys that were explicitly set in this config. Does not return API keys that were set via environment variables/.env
Source code in sweagent/agent/models.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
Manual models for testing
The following two models allow you to test your environment by prompting you for actions. This can also be very useful to create your first demonstrations.
sweagent.agent.models.HumanModel
HumanModel(config: HumanModelConfig, tools: ToolConfig)
Bases: AbstractModel
Model that allows for human-in-the-loop
Source code in sweagent/agent/models.py
307 308 309 310 311 312 313 314 315 316 317 318 |
|
config
instance-attribute
config: HumanModelConfig = config
logger
instance-attribute
logger = get_logger('swea-lm', emoji='🤖')
multi_line_command_endings
instance-attribute
multi_line_command_endings = {name: _5SqhtMpfor command in commands if end_name is not None}
stats
instance-attribute
stats = InstanceStats()
query
query(history: History, action_prompt: str = '> ', n: int | None = None, **kwargs) -> dict | list[dict]
Wrapper to separate action prompt from formatting
Source code in sweagent/agent/models.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
sweagent.agent.models.HumanThoughtModel
HumanThoughtModel(config: HumanModelConfig, tools: ToolConfig)
Bases: HumanModel
Source code in sweagent/agent/models.py
307 308 309 310 311 312 313 314 315 316 317 318 |
|
query
query(history: History, **kwargs) -> dict
Logic for handling user input (both thought + action) to pass to SWEEnv
Source code in sweagent/agent/models.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
|
Replay model for testing and demonstrations
sweagent.agent.models.ReplayModel
ReplayModel(config: ReplayModelConfig, tools: ToolConfig)
Bases: AbstractModel
Model used for replaying a trajectory (i.e., taking all the actions for the .traj
file
and re-issuing them.
Source code in sweagent/agent/models.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
|
config
instance-attribute
config = config
logger
instance-attribute
logger = get_logger('swea-lm', emoji='🤖')
stats
instance-attribute
stats = InstanceStats()
submit_command
instance-attribute
submit_command = submit_command
use_function_calling
instance-attribute
use_function_calling = use_function_calling
query
query(history: History) -> dict
Logic for tracking which replay action to pass to SWEEnv
Source code in sweagent/agent/models.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|