fix: exclude current session from session_search results

session_search was returning the current session if it matched the
query, which is redundant — the agent already has the current
conversation context. This wasted an LLM summarization call and a
result slot.

Added current_session_id parameter to session_search(). The agent
passes self.session_id and the search filters out any results where
either the raw or parent-resolved session ID matches. Both the raw
match and the parent-resolved match are checked to handle child
sessions from delegation.

Two tests added verifying the exclusion works and that other
sessions are still returned.
This commit is contained in:
teknium1
2026-03-04 06:06:40 -08:00
parent 021f62cb0c
commit 70a0a5ff4a
3 changed files with 70 additions and 2 deletions

View File

@@ -183,11 +183,13 @@ def session_search(
role_filter: str = None,
limit: int = 3,
db=None,
current_session_id: str = None,
) -> str:
"""
Search past sessions and return focused summaries of matching conversations.
Uses FTS5 to find matches, then summarizes the top sessions with Gemini Flash.
The current session is excluded from results since the agent already has that context.
"""
if db is None:
return json.dumps({"success": False, "error": "Session database not available."}, ensure_ascii=False)
@@ -238,11 +240,16 @@ def session_search(
break
return sid
# Group by resolved (parent) session_id, dedup
# Group by resolved (parent) session_id, dedup, skip current session
seen_sessions = {}
for result in raw_results:
raw_sid = result["session_id"]
resolved_sid = _resolve_to_parent(raw_sid)
# Skip the current session — the agent already has that context
if current_session_id and resolved_sid == current_session_id:
continue
if current_session_id and raw_sid == current_session_id:
continue
if resolved_sid not in seen_sessions:
result = dict(result)
result["session_id"] = resolved_sid
@@ -368,6 +375,7 @@ registry.register(
query=args.get("query", ""),
role_filter=args.get("role_filter"),
limit=args.get("limit", 3),
db=kw.get("db")),
db=kw.get("db"),
current_session_id=kw.get("current_session_id")),
check_fn=check_session_search_requirements,
)