{"record":{"id":"71228c6b750ab8c2","repo":"huggingface/smolagents","slug":"the-system-prompt-property-is-read-only-use-se","errorCode":null,"errorMessage":"The 'system_prompt' property is read-only. Use 'self.prompt_templates[\"system_prompt\"]' instead.","messagePattern":"The 'system_prompt' property is read-only\\. Use 'self\\.prompt_templates\\[\"system_prompt\"\\]' instead\\.","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"src/smolagents/agents.py","lineNumber":360,"sourceCode":"        self.task: str | None = None\n        self.memory = AgentMemory(self.system_prompt)\n\n        if logger is None:\n            self.logger = AgentLogger(level=verbosity_level)\n        else:\n            self.logger = logger\n\n        self.monitor = Monitor(self.model, self.logger)\n        self._setup_step_callbacks(step_callbacks)\n        self.stream_outputs = False\n\n    @property\n    def system_prompt(self) -> str:\n        return self.initialize_system_prompt()\n\n    @system_prompt.setter\n    def system_prompt(self, value: str):\n        raise AttributeError(\n            \"\"\"The 'system_prompt' property is read-only. Use 'self.prompt_templates[\"system_prompt\"]' instead.\"\"\"\n        )\n\n    def _validate_name(self, name: str | None) -> str | None:\n        if name is not None and not is_valid_name(name):\n            raise ValueError(f\"Agent name '{name}' must be a valid Python identifier and not a reserved keyword.\")\n        return name\n\n    def _setup_managed_agents(self, managed_agents: list | None = None) -> None:\n        \"\"\"Setup managed agents with proper logging.\"\"\"\n        self.managed_agents = {}\n        if managed_agents:\n            assert all(agent.name and agent.description for agent in managed_agents), (\n                \"All managed agents need both a name and a description!\"\n            )\n            self.managed_agents = {agent.name: agent for agent in managed_agents}\n            # Ensure managed agents can be called as tools by the model: set their inputs and output_type\n            for agent in self.managed_agents.values():","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/agents.py#L342-L378","documentation":"smolagents agents expose a read-only system_prompt property computed from the prompt_templates each time. Assigning agent.system_prompt = '...' raises AttributeError because the stored template would silently diverge from the computed prompt.","triggerScenarios":"Executing agent.system_prompt = 'You are...' on any agent (ToolCallingAgent, CodeAgent, ManagedAgent); the setter always raises.","commonSituations":"Developers used to mutable prompt fields on other LLM frameworks try to tweak the system prompt after construction; attempting to customize a ManagedAgent's system prompt per-run by assignment.","solutions":["Set the template instead: agent.prompt_templates['system_prompt'] = 'your new template' (Jinja2-renderable)","Or pass prompt_templates={'system_prompt': ...} / system_prompt at construction time","Note templates are rendered with variables (tool descriptions, authorized imports), so use Jinja placeholders where needed"],"exampleFix":"# before\nagent.system_prompt = \"You are a helpful assistant.\"\n\n# after\nagent.prompt_templates[\"system_prompt\"] = \"You are a helpful assistant. Tools: {{ tool_descriptions }}\"","handlingStrategy":"validation","validationCode":"def set_system_prompt(agent, template: str):\n    agent.prompt_templates[\"system_prompt\"] = template  # correct mutation point\n    assert agent.system_prompt  # recompute/read works","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat system_prompt as read-only derived state","Do all prompt customization via prompt_templates or constructor args"],"tags":["smolagents","read-only-property","system-prompt","attributeerror"],"backgroundTag":"readonly-property-assignment","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}