langchain-ai/deepagents · error · TypeError
Summarizer returned a {type(summary_message).__name__} summa
Error message
Summarizer returned a {type(summary_message).__name__} summary message; expected HumanMessage. What it means
After forced compaction, the SDK's summarizer is expected to produce a `HumanMessage` as the summary message; the offload event stores this message in the checkpoint. `_forced_compaction_update` raises TypeError if the summarizer returns any other message type, since a schema-violating summary would break later compaction rounds that read the event back as their base.
Source
Thrown at libs/code/deepagents_code/offload_middleware.py:1570
TypeError: If the summarizer's first message is not the
`HumanMessage` the event schema declares.
"""
summary_message = summarization._build_new_messages_with_path(
summary, file_path
)[0]
if not isinstance(summary_message, HumanMessage):
# `_build_new_messages_with_path` is annotated `list[AnyMessage]`
# but documents (and the SDK's own call site assumes, with a type
# suppression) that element 0 is the summary `HumanMessage`. Check
# rather than suppress: the node turns this into a visible
# "Compaction failed" instead of checkpointing an event whose
# `summary_message` violates its own schema.
msg = (
"Summarizer returned a "
f"{type(summary_message).__name__} summary message; expected "
"HumanMessage."
)
raise TypeError(msg)
return {
"_summarization_event": {
# Absolute, not relative: a second `/offload` on the same thread
# reads this back as its base.
"cutoff_index": state_cutoff,
"summary_message": summary_message,
"file_path": file_path,
},
"_summarization_session_id": session_id,
}
def _create_cli_compaction_middleware(
model: str | BaseChatModel,
backend: BackendProtocol,
*,
cli_max_retries: int | None = None,
summarization_model_spec: str | None = None,View on GitHub (pinned to a1af029e6e)
Solutions
- Restore/keep dcode's summarizer configuration so the summary is produced as a HumanMessage.
- Inspect the summarizer's output parsing; add a coercion step that wraps the summary text in a HumanMessage.
- Check for an SDK upgrade that changed summary-message type and align dcode's expectations or pin the SDK.
Example fix
// before
cutoff, summary = summarizer.summarize(messages)
return build_update(cutoff, summary) # summary is AIMessage -> TypeError
// after
if not isinstance(summary, HumanMessage):
summary = HumanMessage(content=summary.content)
return build_update(cutoff, summary) Defensive patterns
Strategy: type-guard
Validate before calling
summary_message = summarizer_output.summary_message
assert isinstance(summary_message, HumanMessage), f"got {type(summary_message).__name__}" Type guard
from langchain_core.messages import HumanMessage
def is_human_summary(msg: object) -> bool:
return isinstance(msg, HumanMessage) Try / catch
try:
result = await offload(thread_id)
except TypeError as e:
if "expected HumanMessage" in str(e):
restore_default_summarizer_config() # custom model/prompt broke the schema
raise Prevention
- Keep dcode's default summarizer model and prompt; custom overrides must emit the documented schema.
- Add a unit test running the summarizer over a fixture conversation and asserting HumanMessage output.
- When upgrading the SDK, diff SummarizationMiddleware's summary-message construction.
When it happens
Trigger: A custom or upgraded summarization model/prompt whose output is parsed into an AIMessage, SystemMessage, or other message class instead of HumanMessage during `/offload` forced compaction.
Common situations: Swapping the summarizer model for one with different response parsing; overriding summarization prompts so the structured summary schema is violated; SDK version changes to SummarizationMiddleware's summary-message construction.
Related errors
- Could not parse embedded resource block. Block expected eith
- {question_type} question {question_text!r} must not define '
- Compact session start stopped by hook
- Offload server returned a non-object response.
- Offload server returned an invalid operation response.
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/e504753e4b82231b.
Report an issue: GitHub.