Skip to content

docs + refactor: Session API documentation and AI SDK decoupling#1280

Merged
threepointone merged 4 commits intomainfrom
docs/session-api-documentation
Apr 10, 2026
Merged

docs + refactor: Session API documentation and AI SDK decoupling#1280
threepointone merged 4 commits intomainfrom
docs/session-api-documentation

Conversation

@mattzcarey
Copy link
Copy Markdown
Contributor

@mattzcarey mattzcarey commented Apr 9, 2026

Summary

  • Adds comprehensive documentation for the experimental Session API (agents/experimental/memory/session) covering Session, SessionManager, context blocks (all 4 provider types), compaction, AI tools, search, storage schema, custom providers, and exported utilities
  • Includes a "Gotchas and Quirks" section noting 10 surprising behaviors
  • Removes dead session API surface: MessageQueryOptions, needsCompaction(), maxContextMessages()
  • Decouples Session from AI SDK runtime dependency:
    • Defines minimal SessionMessage/SessionMessagePart types — Vercel AI SDK's UIMessage is structurally compatible
    • Swaps jsonSchema() from ai to z.fromJSONSchema() from zod (matching MCPClientManager.getAITools() pattern)
    • Keeps ToolSet as type-only import (zero runtime cost)
  • Fixes getBranches() doc (returns children, not siblings)
  • Adds sessions.md to docs/index.md
  • Removes stale maxContextMessages reference from session-multichat README

Test plan

  • npm run check passes (all 73 projects typecheck)
  • Review doc accuracy against source code
  • Verify code examples compile/run

Comprehensive guide covering Session, SessionManager, context blocks,
compaction, AI tools, search, storage, and custom providers.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 9, 2026

⚠️ No Changeset found

Latest commit: af5be1d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

- Remove MessageQueryOptions (exported type, never accepted by any method)
- Remove needsCompaction (redundant with compactAfter auto-compaction)
- Remove maxContextMessages builder method and field (only fed needsCompaction)
- Update docs to reflect removals
devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

export type { SkillProvider } from "./skills";
export { isSkillProvider, R2SkillProvider } from "./skills";
export type { MessageQueryOptions, SessionOptions } from "./types";
export type { SessionOptions } from "./types";
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Missing changeset for public API removal from packages/agents

AGENTS.md requires: "Changes to packages/ that affect the public API or fix bugs need a changeset." This PR removes three public API items from packages/agents/ — the MessageQueryOptions type export (packages/agents/src/experimental/memory/session/index.ts:52), the maxContextMessages() builder method, and the needsCompaction() method on SessionManager (packages/agents/src/experimental/memory/session/manager.ts) — but does not add a changeset file describing these removals. While a pending agents: patch changeset exists from PR #1278, it documents unrelated changes (lifecycle hooks, dynamic context). Users relying on these exports (however unlikely given they were dead code) would not see the removal documented in the changelog. Additionally, experimental/session-multichat/README.md:75 still references the removed .maxContextMessages(count) method.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1280

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1280

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1280

hono-agents

npm i https://pkg.pr.new/hono-agents@1280

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1280

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1280

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1280

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1280

commit: af5be1d

Replace all runtime imports from the `ai` package in the Session module
with library-agnostic alternatives:

Message types:
- Define minimal SessionMessage/SessionMessagePart types that capture
  only what the Session internals actually access at runtime
- Replace all `import type { UIMessage } from "ai"` with SessionMessage
  across 7 session source files, 2 test files
- UIMessage from the AI SDK is structurally compatible — it can be
  passed directly without conversion
- Clean up `as Record<string, unknown>` casts in session.ts since
  SessionMessagePart now has the fields directly

Tool schemas:
- Swap `jsonSchema()` from `ai` to `z.fromJSONSchema()` from zod in
  context.ts and manager.ts, matching the pattern from MCPClientManager
- Keep `import type { ToolSet } from "ai"` as type-only (zero runtime
  cost, erased at compile time)

Consumer boundary casts:
- Add `as UIMessage[]` casts in Think, experimental session examples,
  and test agents where SessionMessage[] flows into UIMessage[] sites
- Safe because underlying objects round-trip through JSON unchanged

Documentation fixes:
- Fix getBranches() doc: returns children, not siblings
- Add sessions.md to docs/index.md
- Remove stale maxContextMessages reference from session-multichat README
- Update doc to describe SessionMessage type and structural compatibility
- Add SessionMessage/SessionMessagePart to exports listing

Made-with: Cursor
@threepointone threepointone changed the title docs: Session API documentation docs + refactor: Session API documentation and AI SDK decoupling Apr 10, 2026
@threepointone threepointone merged commit fdafa43 into main Apr 10, 2026
4 checks passed
@threepointone threepointone deleted the docs/session-api-documentation branch April 10, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants