langchain-ai/deepagents · error · ValueError
trusted_compaction_tool must be named compact_conversation
Error message
trusted_compaction_tool must be named compact_conversation
What it means
Like the ask_user check, the optional `trusted_compaction_tool` passed to `AutoModeHITLMiddleware` must be named exactly `compact_conversation`, because the middleware dispatches on that name to treat compaction as a trusted operation. `__init__` raises this ValueError if a tool with a different name is supplied.
Source
Thrown at libs/code/deepagents_code/auto_mode.py:2168
trusted_ask_user_tool: Built-in tool allowed to create consent receipts.
trusted_compaction_tool: Built-in tool that performs conversation
compaction.
Raises:
ValueError: If a trusted tool has an unexpected name.
"""
if (
trusted_ask_user_tool is not None
and trusted_ask_user_tool.name != "ask_user"
):
msg = "trusted_ask_user_tool must be named ask_user"
raise ValueError(msg)
if (
trusted_compaction_tool is not None
and trusted_compaction_tool.name != "compact_conversation"
):
msg = "trusted_compaction_tool must be named compact_conversation"
raise ValueError(msg)
# The review deadline is a security control's budget, so reject a
# nonsensical one at the boundary rather than trusting every caller:
# a zero, negative, or NaN timeout expires immediately, silently turning
# Auto into "deny every gated batch, then escalate". Callers that read
# user config go through `resolve_auto_classifier_timeout`, which bounds
# the value; this guards programmatic construction.
for name, budget in (
("classifier_timeout_seconds", classifier_timeout_seconds),
(
"classifier_construction_timeout_seconds",
classifier_construction_timeout_seconds,
),
):
if not math.isfinite(budget) or budget <= 0:
msg = f"{name} must be a positive finite number, got {budget!r}"
raise ValueError(msg)
interrupt_map = dict(interrupt_on)
interrupt_map["create_temp_artifact"] = {View on GitHub (pinned to a1af029e6e)
Solutions
- Set the tool's `.name` to exactly 'compact_conversation' before passing it.
- Leave `trusted_compaction_tool` unset (None) to use the default built-in compaction tool.
- Check argument order: ensure the ask_user tool is bound to `trusted_ask_user_tool` and the compaction tool to `trusted_compaction_tool`.
Example fix
// before mw = AutoModeHITLMiddleware(trusted_compaction_tool=compaction_tool.with_config(name='summarize_thread')) // after mw = AutoModeHITLMiddleware(trusted_compaction_tool=compaction_tool) # name must be 'compact_conversation'
Defensive patterns
Strategy: validation
Validate before calling
tool = get_trusted_compaction_tool()
if tool is not None and tool.name != 'compact_conversation':
raise ValueError(f"fix: trusted_compaction_tool name is {tool.name!r}") Type guard
def is_trusted_compaction_tool(tool: BaseTool | None) -> bool:
return tool is None or tool.name == 'compact_conversation' Try / catch
try:
mw = AutoModeHITLMiddleware(trusted_compaction_tool=tool)
except ValueError as e:
if 'trusted_compaction_tool must be named compact_conversation' in str(e):
tool.name = 'compact_conversation'
mw = AutoModeHITLMiddleware(trusted_compaction_tool=tool)
else:
raise Prevention
- Keep compaction tool name exactly 'compact_conversation'.
- Bind constructor arguments by keyword to avoid mixing up trusted_ask_user_tool and trusted_compaction_tool.
- Prefer leaving the parameter unset to use the built-in compaction tool.
When it happens
Trigger: Constructing `AutoModeHITLMiddleware(trusted_compaction_tool=<tool>)` where `<tool>.name != 'compact_conversation'` — e.g. a renamed compaction tool or a wrapper object with a different `.name`.
Common situations: Customizing the compaction tool's name for clarity; wrapping the standard compaction tool so `.name` changes; mixing up the order of the two trusted-tool constructor arguments.
Related errors
- trusted_ask_user_tool must be named ask_user
- Invalid agent name: {agent_name!r} is reserved for dcode's o
- tool_call_id must not be empty
- deny decisions require a reason
- trusted thread, turn, and tool-call identity are required
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/fc91271e7cccb597.
Report an issue: GitHub.