Skip to content

fix: handle missing fields in summary_template.format() to prevent KeyError#1401

Open
octo-patch wants to merge 3 commits intoagentscope-ai:mainfrom
octo-patch:fix/issue-1388-summary-template-key-error
Open

fix: handle missing fields in summary_template.format() to prevent KeyError#1401
octo-patch wants to merge 3 commits intoagentscope-ai:mainfrom
octo-patch:fix/issue-1388-summary-template-key-error

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Fixes #1388

Problem

When memory compression is enabled and the compression model generates a summary without all expected fields (e.g., omitting next_steps), the call to summary_template.format(**last_chunk.metadata) raises a KeyError. This causes the agent to crash intermittently during _compress_memory_if_needed().

File "agentscope/agent/_react_agent.py", line 1111, in _compress_memory_if_needed
    self.compression_config.summary_template.format(
KeyError: 'next_steps'

Solution

Build a dict with empty-string defaults for all template placeholder fields before calling .format(). Known metadata values always override the defaults, so no existing field is dropped. This ensures partial summaries are formatted gracefully instead of crashing.

Testing

Reproduce by running a ReActAgent with compression_config enabled and a model that occasionally omits fields from its structured output. After the fix, the agent handles missing fields without raising KeyError.

fixes agentscope-ai#1392)

The mcp python-sdk renamed `streamablehttp_client` to `streamable_http_client`
in the streamable_http transport module. Update both the stateful and stateless
HTTP MCP clients to use the new function name.
…agent (fixes agentscope-ai#1391)

MCP registers tools with underscore names (tavily_search, tavily_extract) but
the DeepResearch agent used hyphenated names (tavily-search, tavily-extract).
This mismatch caused the follow-up extraction to never trigger and led to
repeated redundant searches.
…yError (fixes agentscope-ai#1388)

When the compression model omits optional fields like 'next_steps' from its
structured output, calling summary_template.format(**metadata) raises a
KeyError. Provide empty-string defaults for all expected template fields so
partial summaries are formatted gracefully instead of crashing.
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Apr 2, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Agent compress memory: summary_template can not handle summary without 'next_steps'

1 participant