-
Notifications
You must be signed in to change notification settings - Fork 58
fix: prevent recovery cascade and improve Stop-scenario reasoning lookup #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c1161bf
1f52adc
aa522c9
53a8aff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,17 @@ def tool_call_ids(message: dict[str, Any]) -> list[str]: | |
| return ids | ||
|
|
||
|
|
||
| def tool_call_names(message: dict[str, Any]) -> list[str]: | ||
| names: list[str] = [] | ||
| for tool_call in message.get("tool_calls") or []: | ||
| if not isinstance(tool_call, dict): | ||
| continue | ||
| function = tool_call.get("function") | ||
| if isinstance(function, dict) and function.get("name"): | ||
| names.append(str(function["name"])) | ||
| return names | ||
|
|
||
|
|
||
| def message_signature(message: dict[str, Any]) -> str: | ||
| tool_calls = [ | ||
| normalize_tool_call(tool_call) | ||
|
|
@@ -172,6 +183,10 @@ def store_assistant_message(self, message: dict[str, Any], scope: str) -> int: | |
| for tool_call in (message.get("tool_calls") or []) | ||
| if isinstance(tool_call, dict) | ||
| ) | ||
| keys.extend( | ||
| f"scope:{scope}:tool_name:{tool_name}" | ||
| for tool_name in tool_call_names(message) | ||
| ) | ||
| for key in keys: | ||
| self.put(key, reasoning, message) | ||
| return len(keys) | ||
|
|
@@ -192,6 +207,10 @@ def lookup_for_message(self, message: dict[str, Any], scope: str) -> str | None: | |
| ) | ||
| if reasoning is not None: | ||
| return reasoning | ||
| for tool_name in tool_call_names(message): | ||
| reasoning = self.get(f"scope:{scope}:tool_name:{tool_name}") | ||
| if reasoning is not None: | ||
| return reasoning | ||
|
||
| return None | ||
|
|
||
| def clear(self) -> int: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tool_call_names()can return duplicate names when a single assistant message includes multiple tool calls to the same function. That will add duplicatescope:{scope}:tool_name:...keys, causing redundant SQLite writes (and inflating the returned key count). Consider de-duping tool names (or de-dupingkeysoverall) before callingput()to avoid unnecessary DB churn.