{"record":{"id":"1d7638d94720585f","repo":"agentscope-ai/agentscope","slug":"the-injection-template-must-contain-the-runtime","errorCode":null,"errorMessage":"The injection template must contain the '{runtime_state}' placeholder, got {value!r}.","messagePattern":"The injection template must contain the '(.+?)' placeholder, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/agent/_config.py","lineNumber":244,"sourceCode":"at this point of the conversation. Anything stated earlier is outdated, and a \\\nlater reminder, if any, supersedes this one:\n{runtime_state}\n</system-reminder>\"\"\",\n        description=(\n            \"The template to wrap the injected runtime state, where the \"\n            \"'{runtime_state}' placeholder will be replaced by the injected \"\n            \"fields.\"\n        ),\n    )\n    \"\"\"The template to wrap the injected runtime state, which must contain the\n    ``{runtime_state}`` placeholder.\"\"\"\n\n    @field_validator(\"template\")\n    @classmethod\n    def _check_template(cls, value: str) -> str:\n        \"\"\"Ensure the template won't silently drop the injected fields.\"\"\"\n        if \"{runtime_state}\" not in value:\n            raise ValueError(\n                \"The injection template must contain the '{runtime_state}' \"\n                f\"placeholder, got {value!r}.\",\n            )\n        return value\n\n    injection_source: str = Field(\n        title=\"Injection Source\",\n        default='{\"label\": \"System\", \"sublabel\": \"Runtime State\"}',\n        description=(\n            \"The source of the injected hint block, which is also used to \"\n            \"identify the previous injections within the context.\"\n        ),\n    )\n    \"\"\"The source of the injected hint block, used to identify the agent's own\n    injections when scanning the context.\"\"\"\n\n    task_tool_names: list[str] = Field(\n        title=\"Task Tool Names\",","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/agent/_config.py#L226-L262","documentation":"Pydantic field validator error raised when configuring an injection template (context/state injection) that lacks the required '{runtime_state}' placeholder. Without the placeholder, injected runtime state would be silently dropped, so configuration is rejected up front.","triggerScenarios":"Setting the template field of the injection config to a string that does not contain '{runtime_state}', e.g. 'User context: {history}' or escaping braces accidentally.","commonSituations":"Customizing the state-injection prompt template and forgetting the placeholder; using doubled braces '{{runtime_state}}' from an f-string that escapes it; copying a template from an older version with a different placeholder name.","solutions":["Add the literal '{runtime_state}' placeholder to your template string","If building the template with f-strings or .format, escape other braces and keep '{runtime_state}' intact","Check the config field docs for the exact expected placeholder name"],"exampleFix":"# before\nconfig = InjectionConfig(template=\"Context:\\n{history}\")\n\n# after\nconfig = InjectionConfig(template=\"Context:\\n{runtime_state}\")","handlingStrategy":"validation","validationCode":"def template_ok(template: str) -> bool:\n    return \"{{runtime_state}}\".replace(\"{{\", \"{\").replace(\"}}\", \"}\") in template or \"{runtime_state}\" in template","typeGuard":null,"tryCatchPattern":"from pydantic import ValidationError\ntry:\n    cfg = InjectionConfig(template=t)\nexcept ValidationError as e:\n    if \"runtime_state\" in str(e):\n        t = t + \"\\n{runtime_state}\"\n        cfg = InjectionConfig(template=t)","preventionTips":["Always end custom templates with the '{runtime_state}' placeholder","Unit-test template construction during config loading","Beware f-string brace escaping producing '{{runtime_state}}'"],"tags":["agentscope","config","pydantic","template","validation"],"backgroundTag":"missing-template-placeholder","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}