Skip to content

The agent that grows with you

fix(session-search): forward detail through agent paths

blunkjamie-dev163d7af310be
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py
index 3f3404b40b0..e0c51fb3538 100644
--- a/agent/agent_runtime_helpers.py
+++ b/agent/agent_runtime_helpers.py
@@ -3076,6 +3076,7 @@ def invoke_tool(agent, function_name: str, function_args: dict, effective_task_i
around_message_id=next_args.get("around_message_id"),
window=next_args.get("window", 5),
sort=next_args.get("sort"),
+ detail=next_args.get("detail", "adaptive"),
db=session_db,
current_session_id=agent.session_id,
),
diff --git a/agent/tool_executor.py b/agent/tool_executor.py
index d0ce5621aab..bdf4efc2358 100644
--- a/agent/tool_executor.py
+++ b/agent/tool_executor.py
@@ -1975,6 +1975,7 @@ def execute_tool_calls_sequential(agent, assistant_message, messages: list, effe
around_message_id=next_args.get("around_message_id"),
window=next_args.get("window", 5),
sort=next_args.get("sort"),
+ detail=next_args.get("detail", "adaptive"),
db=session_db,
current_session_id=agent.session_id,
)
diff --git a/tests/run_agent/test_token_persistence_non_cli.py b/tests/run_agent/test_token_persistence_non_cli.py
index dd82395d237..7479c2af85c 100644
--- a/tests/run_agent/test_token_persistence_non_cli.py
+++ b/tests/run_agent/test_token_persistence_non_cli.py
@@ -80,9 +80,49 @@ def test_session_search_lazily_opens_db_when_entrypoint_did_not_pass_one(monkeyp
monkeypatch.setitem(sys.modules, "tools.session_search_tool", session_search_mod)
agent = _make_agent(None, platform="acp")
- result = json.loads(agent._invoke_tool("session_search", {"query": "Hermes"}, "task-id"))
+ result = json.loads(agent._invoke_tool(
+ "session_search",
+ {"query": "Hermes", "detail": "full"},
+ "task-id",
+ ))
assert result["success"] is True
assert captured["db"] is sentinel_db
assert captured["query"] == "Hermes"
+ assert captured["detail"] == "full"
assert agent._session_db is sentinel_db
+
+
+def test_sequential_session_search_forwards_detail(monkeypatch):
+ session_db = MagicMock()
+ captured = {}
+
+ session_search_mod = ModuleType("tools.session_search_tool")
+
+ def fake_session_search(**kwargs):
+ captured.update(kwargs)
+ return json.dumps({"success": True, "results": []})
+
+ session_search_mod.session_search = fake_session_search
+ monkeypatch.setitem(sys.modules, "tools.session_search_tool", session_search_mod)
+
+ agent = _make_agent(session_db, platform="acp")
+ tool_call = SimpleNamespace(
+ id="search-1",
+ function=SimpleNamespace(
+ name="session_search",
+ arguments=json.dumps({"query": "Hermes", "detail": "full"}),
+ ),
+ )
+ assistant_message = SimpleNamespace(tool_calls=[tool_call])
+ messages = []
+
+ agent._execute_tool_calls_sequential(
+ assistant_message,
+ messages,
+ "task-id",
+ )
+
+ assert captured["db"] is session_db
+ assert captured["query"] == "Hermes"
+ assert captured["detail"] == "full"
diff --git a/website/docs/user-guide/sessions.md b/website/docs/user-guide/sessions.md
index 3f02dd2be20..d08d8a4b850 100644
--- a/website/docs/user-guide/sessions.md
+++ b/website/docs/user-guide/sessions.md
@@ -612,9 +612,9 @@ routing is the only thing the repair changes. Back up first
## Session Search Tool
-The agent has a built-in `session_search` tool that performs full-text search across all past conversations using SQLite's FTS5 engine — and lets the agent scroll through any session it finds. No LLM calls, no summarization, no truncation. Every shape returns actual messages from the DB.
+The agent has a built-in `session_search` tool that performs full-text search across all past conversations using SQLite's FTS5 engine — and lets the agent scroll through any session it finds. It makes no LLM calls and returns bounded views of actual messages from the DB rather than generated summaries.
-### Three calling shapes
+### Four calling shapes
The tool infers what you want from which arguments you set. There's no `mode` parameter.
@@ -624,16 +624,18 @@ The tool infers what you want from which arguments you set. There's no `mode` pa
session_search(query="auth refactor", limit=3)
```
-Runs FTS5, dedupes hits by session lineage, returns the top N sessions. Each result carries:
+Runs FTS5, dedupes hits by session lineage, and returns the top N sessions. Discovery uses adaptive detail by default: the highest-ranked result includes its full context window and bookends, while lower-ranked results stay compact. Pass `detail="full"` to fully hydrate every result.
+
+Each result carries:
- `session_id`, `title`, `when`, `source`
- `snippet` — FTS5-highlighted match excerpt
-- `bookend_start` — first 3 user+assistant messages of the session (the goal/kickoff)
-- `messages` — ±5 messages around the FTS5 match, with the anchor message flagged (the hit in context)
-- `bookend_end` — last 3 user+assistant messages of the session (the resolution/decisions)
+- `detail` — `full` or `compact`
+- `bookend_start` / `bookend_end` — first/last 3 user+assistant messages for full results; empty lists for compact results
+- `messages` — ±5 messages around the FTS5 match for full results; only the flagged anchor message for compact results
- `match_message_id`, `messages_before`, `messages_after`
-Bookends + window together reconstruct goal → match → resolution without paying for the whole transcript. Typical wall time: 15–50ms on a real session DB.
+The top result reconstructs goal → match → resolution immediately. If another compact result looks more promising, use its session and message IDs with the scroll shape. Typical wall time is tens of milliseconds on a real session DB.
**2. Scroll — pass `session_id` + `around_message_id`:**
@@ -650,7 +652,15 @@ Returns a window of ±`window` messages centered on the anchor. No FTS5, no book
Typical wall time: 1–2ms per scroll call.
-**3. Browse — no args:**
+**3. Read — pass `session_id` without an anchor:**
+
+```python
+session_search(session_id="20260510_174648_805cc2")
+```
+
+Returns the whole session, or a bounded head/tail view for large sessions. This shape is also used to resolve an `@session:<profile>/<id>` link.
+
+**4. Browse — no args:**
```python
session_search()
@@ -670,6 +680,7 @@ The keyword mode supports standard FTS5 query syntax:
### Optional parameters
- `sort` — `newest` or `oldest`, on top of FTS5 ranking. Omit for relevance-only ordering (the default; suitable for exploratory recall). Use `newest` for "where did we leave X" questions, `oldest` for "how did X start" questions.
+- `detail` — `adaptive` (default) fully hydrates only the top discovery result; `full` hydrates every discovery result.
- `role_filter` — comma-separated roles to include. Discovery defaults to `user,assistant` (tool output is usually noise). Pass `user,assistant,tool` to include tool output (debugging tool behaviour) or `tool` to search tool output only.
### When It's Used