Skip to content

Template configuration

sweagent.agent.agents.TemplateConfig pydantic-model

Bases: BaseModel

This configuration is used to define almost all message templates that are formatted by the agent and sent to the LM.

Fields:

Validators:

system_template pydantic-field

system_template: str = ''

instance_template pydantic-field

instance_template: str = ''

next_step_template pydantic-field

next_step_template: str = 'Observation: {{observation}}'

next_step_truncated_observation_template pydantic-field

next_step_truncated_observation_template: str = 'Observation: {{observation[:max_observation_length]}}<response clipped><NOTE>Observations should not exceeded {{max_observation_length}} characters. {{elided_chars}} characters were elided. Please try a different command that produces less output or use head/tail/grep/redirect the output to a file. Do not use interactive pagers.</NOTE>'

Message template for when the agent's observation was truncated. Available variables: observation, max_observation_length, elided_chars

max_observation_length pydantic-field

max_observation_length: int = 100000

Truncate observation to this length if it exceeds it. This in measured in characters, i.e., as len(observation).

next_step_no_output_template pydantic-field

next_step_no_output_template: str = None

Template for the next step when the last output was empty. Defaults to next_step_template.

strategy_template pydantic-field

strategy_template: str | None = None

demonstration_template pydantic-field

demonstration_template: str | None = None

demonstrations pydantic-field

demonstrations: list[Path]

Paths to demonstrations. If path is not absolute, it is assumed to be relative to the SWE_AGENT_CONFIG_ROOT (if set) or the SWE-agent repository root

put_demos_in_history pydantic-field

put_demos_in_history: bool = False

If True, add demonstration to history instead of as a single message

shell_check_error_template pydantic-field

shell_check_error_template: str = 'Your bash command contained syntax errors and was NOT executed. Please fix the syntax errors and try again. This can be the result of not adhering to the syntax for multi-line commands. Here is the output of `bash -n`:\n{{bash_stdout}}\n{{bash_stderr}}'

Message template for when the agent's bash command contains syntax errors. Available variables: bash_stdout, bash_stderr

command_cancelled_timeout_template pydantic-field

command_cancelled_timeout_template: str = "The command '{{command}}' was cancelled because it took more than {{timeout}} seconds. Please try a different command that completes more quickly. Note: A common source of this error is if the command is interactive or requires user input (it is impossible to receive user input in the current environment, so the command will never complete)."

Message template for when the agent's command was cancelled because it took too long. Available variables: timeout, command

validate_template_jinja_syntax pydantic-validator

validate_template_jinja_syntax() -> Self
Source code in sweagent/agent/agents.py
123
124
125
126
127
128
129
@model_validator(mode="after")
def validate_template_jinja_syntax(self) -> Self:
    template_fields = [field for field in self.model_fields.keys() if field.endswith("_template")]
    for field in template_fields:
        value = getattr(self, field)
        _warn_probably_wrong_jinja_syntax(value)
    return self

warnings pydantic-validator

warnings() -> Self
Source code in sweagent/agent/agents.py
131
132
133
134
135
136
137
138
139
140
141
142
@model_validator(mode="after")
def warnings(self) -> Self:
    logger = get_logger("swea-config", emoji="🔧")
    if self.put_demos_in_history and self.demonstration_template is not None:
        logger.warning("demonstration_template is ignored when put_demos_in_history is True")
    if not self.system_template or not self.instance_template:
        logger.warning(
            "system_template/instance_template is not set, using empty string. Perhaps you were"
            " overwriting the default config? See https://swe-agent.com/latest/usage/cl_tutorial/"
            " for more information. Note: You can ignore this warning in human mode."
        )
    return self