Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(session): restore working memory creation error propagation (#5624)

Mohammad Hijjawie873b9ded464
diff --git a/openviking/session/session.py b/openviking/session/session.py
index 2c97e777e..85b265f0a 100644
--- a/openviking/session/session.py
+++ b/openviking/session/session.py
@@ -2967,58 +2967,47 @@ class Session:
f"branch=CREATE (prior={'legacy' if latest_archive_overview else 'none'} "
f"{len(latest_archive_overview or '')}B)"
)
- try:
- prompt = render_prompt(
- "compression.ov_wm_v2",
- {
- "messages": formatted,
- "latest_archive_overview": latest_archive_overview or "",
- "checkpoint_instructions": checkpoint_instructions,
- "output_language": output_language,
+ prompt = render_prompt(
+ "compression.ov_wm_v2",
+ {
+ "messages": formatted,
+ "latest_archive_overview": latest_archive_overview or "",
+ "checkpoint_instructions": checkpoint_instructions,
+ "output_language": output_language,
+ },
+ )
+ if checkpoint_requests:
+ response = await vlm.get_completion_async(
+ prompt=prompt,
+ tools=[WM_CREATE_WITH_CHECKPOINTS_TOOL],
+ tool_choice={
+ "type": "function",
+ "function": {"name": "create_working_memory"},
},
)
- if checkpoint_requests:
- response = await vlm.get_completion_async(
- prompt=prompt,
- tools=[WM_CREATE_WITH_CHECKPOINTS_TOOL],
- tool_choice={
- "type": "function",
- "function": {"name": "create_working_memory"},
- },
- )
- if not (
- getattr(response, "has_tool_calls", False)
- and getattr(response, "tool_calls", None)
- ):
- raise ValueError(
- "Working Memory creation returned no create_working_memory tool call"
- )
- args = response.tool_calls[0].arguments
- if isinstance(args, str):
- args = json.loads(args)
- if not isinstance(args, dict):
- raise ValueError("create_working_memory arguments must be an object")
- working_memory = args.get("working_memory")
- if not isinstance(working_memory, str) or not working_memory.strip():
- raise ValueError("create_working_memory.working_memory is empty")
- return _ArchiveSummaryResult(
- overview=working_memory,
- checkpoint_summaries=wm.parse_required_checkpoint_summaries(
- args,
- len(checkpoint_requests),
- ),
+ if not (
+ getattr(response, "has_tool_calls", False)
+ and getattr(response, "tool_calls", None)
+ ):
+ raise ValueError(
+ "Working Memory creation returned no create_working_memory tool call"
)
- return await vlm.get_completion_async(prompt)
- except Exception as e:
- wm.wm_debug(f"creation failed: {e}")
- logger.warning(f"WM creation failed: {e}")
- if checkpoint_requests:
- raise
- turn_count = len([m for m in messages if is_user_query(m)])
- return (
- f"# Session Summary\n\n"
- f"**Overview**: {turn_count} turns, {len(messages)} messages"
+ args = response.tool_calls[0].arguments
+ if isinstance(args, str):
+ args = json.loads(args)
+ if not isinstance(args, dict):
+ raise ValueError("create_working_memory arguments must be an object")
+ working_memory = args.get("working_memory")
+ if not isinstance(working_memory, str) or not working_memory.strip():
+ raise ValueError("create_working_memory.working_memory is empty")
+ return _ArchiveSummaryResult(
+ overview=working_memory,
+ checkpoint_summaries=wm.parse_required_checkpoint_summaries(
+ args,
+ len(checkpoint_requests),
+ ),
)
+ return await vlm.get_completion_async(prompt)
# -------- Branch 2: has prior WM v2 -> tool_call incremental update --------
wm.wm_debug(f"branch=UPDATE (prior WM={len(latest_archive_overview)}B)")