SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Warn if templates don't use jinja syntax
Kilian Lieret01ee05a4095d
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 09694acc..fb0da727 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -8,7 +8,7 @@ from pathlib import Pathfrom typing import Anyfrom jinja2 import Template-from pydantic import BaseModel, ConfigDict, Field+from pydantic import BaseModel, ConfigDict, Field, model_validatorfrom simple_parsing.helpers.fields import fieldfrom swerex.exceptions import BashIncorrectSyntaxError, CommandTimeoutError, SweRexceptionfrom tenacity import RetryError@@ -40,6 +40,18 @@ from sweagent.utils.log import get_loggerfrom sweagent.utils.patch_formatter import PatchFormatter+def _warn_probably_wrong_jinja_syntax(template: str | None) -> None:+ if template is None:+ return+ if "{" not in template:+ return+ for s in ["{%", "{ %", "{{"]:+ if s in template:+ return+ logger = get_logger("swea-config", emoji="⚙️")+ logger.warning("Probably wrong Jinja syntax in template: %s. Make sure to use {{var}} instead of {var}.", template)++class TemplateConfig(BaseModel):"""This configuration is used to define almost all message templates that areformatted by the agent and sent to the LM.@@ -86,6 +98,18 @@ class TemplateConfig(BaseModel):if self.next_step_no_output_template is None:self.next_step_no_output_template = self.next_step_template+ @model_validator(mode="after")+ @classmethod+ def validate_template_jinja_syntax(cls, data: Any) -> Any:+ template_fields = [field for field in cls.model_fields.keys() if field.endswith("_template")]+ for field in template_fields:+ if isinstance(data, dict):+ value = data[field]+ else:+ value = getattr(data, field)+ _warn_probably_wrong_jinja_syntax(value)+ return data+class AgentConfig(BaseModel):"""This configuration object specifies the behavior of an agent."""