#2668·agentscope

[Bug]: ContextConfig does not check summary_template against summary_schema, so a trimmed schema crashes compression with KeyError

Author: wangtaotaotao95Created Sep 17, 2026Updated Sep 17, 2026

AgentScope is an open-source project. To involve a broader community, we recommend asking your questions in English.

Describe the bug

ContextConfig.summary_template and ContextConfig.summary_schema are independently configurable, but nothing checks that they agree. When a compression summary is generated, the template is rendered with the fields the schema declares:

python
# src/agentscope/agent/_agent.py, inside _apply_change()
new_summary = cfg.summary_template.format(**res.content)

If the schema does not declare a field the template still references, this raises a bare KeyError — and it is raised while rendering the summary, i.e. in the middle of a reply, long after the configuration was built. Nothing in the traceback points at the configuration that caused it.

_apply_change() runs as a task and is awaited with asyncio.shield, with only asyncio.CancelledError handled, so the KeyError propagates and the agent's reply fails.

Related: #1388 reported this on 1.x. On 2.x the default summary_schema (from SummarySchema) declares every field the default template uses, and jsonschema.validate enforces required, so the default pair is consistent. The crash is still reachable on 2.x through the documented, independent summary_schema override — trimming the schema is exactly what you would do to stop paying for a field you do not want.

To Reproduce

python
from agentscope.agent import ContextConfig

schema = ContextConfig().summary_schema
schema["properties"].pop("next_steps")  # drop one field the template renders

config = ContextConfig(summary_schema=schema)  # currently accepted
config.summary_template.format(**{k: "" for k in schema["properties"]})
# KeyError: 'next_steps'

The final line is what _agent.py does with the model's structured response. jsonschema.validate accepts the trimmed schema, so the summary is generated successfully and the failure happens only at render time.

Expected behavior

The mismatch should be reported when the configuration is built, naming the offending field(s), instead of surfacing as an opaque KeyError mid-reply. Whether that is a hard configuration error or a tolerated (logged) condition is a design call — but the current behavior, failing only once compression actually runs, is the worst of both.

Note this is deliberately not a proposal to silently render missing fields as empty strings; that was the approach in #2032, which was closed. Failing fast keeps the two fields honest.

Error messages

KeyError: 'next_steps'

Environment

  • AgentScope Version: 2.0.8 (main at 20228d5c)
  • Python Version: 3.13
  • OS: macOS

Source: agentscope-ai/agentscope