Skip to content

feat(session_context): reference previous sessions as context#3320

Merged
dgageot merged 2 commits into
mainfrom
feat/session-context-toolset
Jun 30, 2026
Merged

feat(session_context): reference previous sessions as context#3320
dgageot merged 2 commits into
mainfrom
feat/session-context-toolset

Conversation

@Sayt-0

@Sayt-0 Sayt-0 commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

Adds a read-only session_context toolset that lets an agent reference a previous session as context, removing the manual export-to-HTML and re-attach workaround described in #1675.

Two tools:

Tool Description
list_sessions List previous sessions (most recent first). The running session is never included. Optional limit (default 20, capped at 100).
read_session Return a previous session's transcript by id, or by a relative reference like -1. Returns an error for the current session or an unresolved/missing one.

Long transcripts are truncated from the oldest messages (the most recent are usually the most useful for continuing work), with a note recording how many were omitted, so a large history cannot overflow the context window.

Issue expectations mapping

#1675 expectation Status
Reference a previous session without manual export/import Done, via read_session
Discover available sessions Done, via list_sessions
No manual @mention of an exported HTML file Done, the agent calls the tools directly

Design notes

  • Wired exactly like the session_plan toolset: the toolset advertises tool metadata only, and the runtime owns the handlers (pkg/runtime/sessioncontext_handlers.go) so they can reach the live session store and exclude the running session.
  • Only the latest config schema is updated (agent-schema.json, both toolset-type enums). Older pkg/config/vN versions stay frozen.
  • Reuses the existing session.Store (GetSessionSummaries, GetSession) and session.ResolveSessionID (relative refs).

Open design questions for maintainers

  1. Tool-driven access (this PR) vs an @session mention syntax in the editor. This PR takes the tool route as it is less invasive and agent-driven.
  2. Raw (truncated) transcript vs an LLM summary of the referenced session. This PR returns the raw transcript; summarizing via the existing compaction path could be a follow-up.

Tests / verification

Check Result
Unit tests for pkg/tools/builtin/sessioncontext Pass locally
go vet / gofmt on new files Clean
Full task build / task test / task lint Not run locally (module cache could not be refreshed in the dev environment); relying on CI for the full build, test and lint pass

Files: new sessioncontext toolset package and runtime handlers, registry + schema wiring, an example (examples/session_context.yaml), and docs.

Refs #1675

…context

Add a read-only session_context toolset with two tools:

- list_sessions: list previous sessions (most recent first; the current
  session is never included)
- read_session: return a previous session's transcript by id or by a
  relative reference like -1, truncated from the oldest messages to fit
  the context budget

This removes the manual export-to-HTML and re-attach workaround for
reusing earlier sessions as context.

The toolset is wired like session_plan: it advertises tool metadata
only, and the runtime owns the handlers so they can reach the live
session store and exclude the running session. Only the latest config
schema is updated; older versions stay frozen.

Refs #1675
@Sayt-0 Sayt-0 requested a review from a team as a code owner June 30, 2026 10:32
@aheritier aheritier added area/config For configuration parsing, YAML, environment variables area/docs Documentation changes area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) area/tools For features/issues/fixes related to the usage of built-in and MCP tools kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Jun 30, 2026
- use t.Context() instead of context.Background() in the test
- iterate with slices.Backward when trimming the transcript to budget
@dgageot dgageot merged commit da142df into main Jun 30, 2026
11 checks passed
@dgageot dgageot deleted the feat/session-context-toolset branch June 30, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config For configuration parsing, YAML, environment variables area/docs Documentation changes area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) area/tools For features/issues/fixes related to the usage of built-in and MCP tools kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants