Skip to content

feat(tools): add optional session_id to search, ask, and context tools#104

Open
leugenea wants to merge 2 commits into
plastic-labs:mainfrom
leugenea:feature/session-id-param
Open

feat(tools): add optional session_id to search, ask, and context tools#104
leugenea wants to merge 2 commits into
plastic-labs:mainfrom
leugenea:feature/session-id-param

Conversation

@leugenea

@leugenea leugenea commented May 31, 2026

Copy link
Copy Markdown

Summary

Adds an optional session_id parameter to three Honcho tools to allow session-scoped queries.

Changes

  • honcho_search_conclusions (tools/search.ts): filters semantic search to a specific session
  • honcho_ask (tools/ask.ts): limits Q&A to a specific session
  • honcho_context (tools/context.ts): limits context retrieval to a specific session

Behavior

  • session_id is optional — existing calls without it work unchanged
  • When provided, session_id is passed to the Honcho SDK as session: params.session_id
  • Backward compatibility: 100%

Tests

Added 7 new unit tests in test/tools.test.ts covering:

  • honcho_ask — session_id passed/omitted
  • honcho_search_conclusions — session_id passed/omitted
  • honcho_context — session_id in "full" mode (passed/omitted), and "card" mode ignores it

Verification

  • tsc compiles without errors
  • vitest run — 61/61 tests pass
  • Tools without session_id behave identically to before

Summary by CodeRabbit

  • New Features

    • Added an optional session_id parameter to ask, search, and context tools to enable session-scoped operations and more consistent session-aware results.
    • Tool executions now propagate session identifiers to participant/agent calls for improved session handling.
  • Tests

    • Added tests verifying session parameter propagation and correct tool behavior across session-scoped scenarios.

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a82d679d-c66f-4e41-b07d-2306764cb751

📥 Commits

Reviewing files that changed from the base of the PR and between 04053a0 and f2a3d94.

📒 Files selected for processing (1)
  • test/tools.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/tools.test.ts

Walkthrough

Three honcho tools (ask, search, context) now accept an optional session_id and forward it into their peer calls; a Vitest suite was added to verify session scoping and context-mode behavior.

Changes

Session ID propagation across honcho tools

Layer / File(s) Summary
Tool implementations with session_id support
tools/ask.ts, tools/search.ts, tools/context.ts
Input schemas and execute destructuring were extended to accept an optional session_id and pass session: session_id to agentPeer.chat (ask) and participantPeer.representation (search, context full).
Test harness and session_id propagation tests
test/tools.test.ts
Adds a Vitest module with mocked peers and captured registrations to assert that honcho_ask forwards session to agentPeer.chat, honcho_search_conclusions forwards session to participantPeer.representation, and honcho_context forwards session in detail: "full" but calls card (without session) in detail: "card".

🎯 3 (Moderate) | ⏱️ ~20 minutes

"I nibble through code, hopping lines with glee,
session_id tucked in pockets for agent and peer.
Tests pat my back, they watch each little hop,
full context carries it, card skips the stop.
A rabbit's round of checks—now everything's clear!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding an optional session_id parameter to three tools (search, ask, and context).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/tools.test.ts (1)

30-43: 💤 Low value

Mocks don't assert the SDK contract.

representation/chat/card are plain vi.fn accepting any args, so these tests confirm the tools forward a session key but not that the real @honcho-ai/sdk recognizes that option name/type. Pair these with the SDK-signature verification noted on the tool files, or type the mocks against the SDK's option types to catch contract drift.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/tools.test.ts` around lines 30 - 43, Mocks makeParticipantPeer and
makeAgentPeer use bare vi.fn() so tests don't verify the SDK call signatures;
update these factory functions to assert the SDK contract by typing or verifying
args: makeParticipantPeer should have representation and card mocks that accept
a single options parameter typed as the SDK's
RepresentationOptions/ParticipantOptions (or assert the presence/type of
session), and makeAgentPeer.chat should accept an options param typed as
ChatOptions (or assert options.session exists and is passed). Adjust the mocks
to either use typed function signatures or to inspect their received args and
throw/assert when the expected option shape (e.g., session key) is missing,
matching the signatures referenced in the tool code (representation, card,
chat).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tools/ask.ts`:
- Around line 58-62: The call to agentPeer.chat in tools/ask.ts is using the
wrong session option key (opts.session) so the SDK ignores it; update the
options object passed to agentPeer.chat to use sessionId: session_id instead of
session: session_id, and make the same change for other similar calls that pass
session: session_id (e.g., the agentPeer.chat invocations in tools/search.ts and
tools/context.ts) so the SDK's session scoping works correctly.

---

Nitpick comments:
In `@test/tools.test.ts`:
- Around line 30-43: Mocks makeParticipantPeer and makeAgentPeer use bare
vi.fn() so tests don't verify the SDK call signatures; update these factory
functions to assert the SDK contract by typing or verifying args:
makeParticipantPeer should have representation and card mocks that accept a
single options parameter typed as the SDK's
RepresentationOptions/ParticipantOptions (or assert the presence/type of
session), and makeAgentPeer.chat should accept an options param typed as
ChatOptions (or assert options.session exists and is passed). Adjust the mocks
to either use typed function signatures or to inspect their received args and
throw/assert when the expected option shape (e.g., session key) is missing,
matching the signatures referenced in the tool code (representation, card,
chat).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ea4a43bc-6d10-42c3-8b53-b809472b7c47

📥 Commits

Reviewing files that changed from the base of the PR and between f35f9d4 and 04053a0.

📒 Files selected for processing (4)
  • test/tools.test.ts
  • tools/ask.ts
  • tools/context.ts
  • tools/search.ts

Comment thread tools/ask.ts
Comment on lines 58 to 62
const answer = await agentPeer.chat(query, {
target: participantPeer,
reasoningLevel,
session: session_id,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

@honcho-ai/sdk peer chat options session sessionId parameter representation

💡 Result:

In the @honcho-ai/sdk, the sessionId parameter is represented as a string used to scope chat interactions, session management, and context retrieval to a specific conversation thread [1][2][3]. Key aspects of the sessionId representation include: Scope and Usage: When calling the chat method on a peer, passing a sessionId allows the query to be scoped to that specific session [1][2][3]. For example: await alice.chat("What happened in our conversation?", { sessionId: session.id }); Object Mapping: The SDK session object itself is initialized using this ID (e.g., honcho.session("conversation-1")), and it provides methods for peer and message management within that scoped context [1][4][3]. Integration with Vercel AI SDK: When using the @honcho-ai/vercel-ai-sdk integration, the sessionId is passed as a property within the honcho.middleware configuration object [5]. It defaults to a lazily generated ID if omitted, though explicitly providing a stable sessionId is recommended for multi-user production traffic [5]. Migration Note: In transitions from earlier versions (v1.6.0 to v2.0.0), message objects were updated to use camelCase, where message.session_id became message.sessionId [6].

Citations:


🏁 Script executed:

#!/bin/bash
# Inspect installed SDK typings (if present) for the chat/representation session option
fd -t d '`@honcho-ai`' node_modules 2>/dev/null
rg -nP --type=ts -C3 '\b(chat|representation)\b' -g '**/@honcho-ai/**/*.d.ts' 2>/dev/null
rg -nP --type=ts -C2 '\bsession(Id)?\b' -g '**/@honcho-ai/**/*.d.ts' 2>/dev/null

Repository: plastic-labs/openclaw-honcho

Length of output: 54


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show relevant code and version info
echo "---- tools/ask.ts (around snippet) ----"
if [ -f tools/ask.ts ]; then
  sed -n '40,90p' tools/ask.ts | nl -ba
else
  echo "tools/ask.ts not found"
fi

echo "---- package.json ----"
if [ -f package.json ]; then
  cat package.json | nl -ba | sed -n '1,200p'
else
  echo "package.json not found"
fi

echo "---- lockfile hints ----"
ls -1 package-lock.json pnpm-lock.yaml yarn.lock bun.lockb 2>/dev/null || true

echo "---- Search for chat session option keys ----"
rg -n --hidden --no-ignore -S "agentPeer\.chat|\.chat\(" tools src . 2>/dev/null | head -n 50 || true
rg -n --hidden --no-ignore -S "\bsessionId\b|\bsession:" tools src . 2>/dev/null | head -n 50 || true

Repository: plastic-labs/openclaw-honcho

Length of output: 173


🌐 Web query:

@honcho-ai/sdk Peer.chat options sessionId session key name

💡 Result:

In the @honcho-ai/sdk, the peer.chat(query, options) method allows you to query a peer's representation—a synthesized view of conclusions Honcho has reasoned about them [1][2]. Key available options for peer.chat include: sessionId: A string used to scope the chat request to a specific session [3][4][5]. This ensures the context and reasoning are retrieved only from that session [3][4]. reasoningLevel: Controls the depth of the reasoning process and the budget allocated to the agent. Accepted values are 'minimal', 'low' (default), 'medium', 'high', and 'max' [1]. target: Specifies a target peer ID if you wish to query what one peer knows or has concluded about another [3][4][5][6]. Regarding "session key name," this is not a direct parameter in the peer.chat SDK method. However, in broader Honcho implementations (such as specific plugins or gateway integrations), session names or keys are used to bucket memory. For example, session names are often determined by the implementation strategy (e.g., 'per-directory', 'per-session', 'global') or manual mappings, and are used to manage which conversation bucket memory lands in [7]. Top results: [3][1][7][2][6]

Citations:


🌐 Web query:

honcho peer chat(sessionId) options reference

💡 Result:

In the Honcho memory system, the peer.chat(query, options) method allows you to query a peer's representation and synthesize natural language answers based on reasoned conclusions [1][2]. When using this endpoint, you can pass an options object to customize the request, including scoping the chat to a specific session [3][4]. Common options for peer.chat include: sessionId (string): Scopes the chat request to a specific session ID, allowing the agent to answer questions relevant to that conversation history [3][4]. target (string): Specifies a peer ID to query for its representation (e.g., asking what one peer knows about another) [3][5][4]. reasoningLevel (string): Controls the depth of the reasoning process and the associated cost/latency. Accepted values are minimal, low (default), medium, high, and max [1]. Additional configuration parameters often used in related context-retrieval operations (such as session.context) include: summary (boolean): Whether to include a conversation summary (default: true) [3][4]. tokens (integer): Sets a maximum token budget for the context window [3][4]. peer_target and peer_perspective: Used for multi-peer modeling to retrieve representations of a target peer from a specific perspective [3][4]. representationOptions: An object containing advanced search and conclusion filtering, such as: searchQuery (string): A query for semantic search within the peer's representation [3][4]. searchTopK (integer): Number of search results to return (1-100) [3][4]. searchMaxDistance (float): Defines the maximum semantic distance (0.0–1.0) [3][4]. includeMostFrequent (boolean): Toggles the inclusion of the most frequent conclusions [3][4]. maxConclusions (integer): Sets the maximum number of conclusions to return (1–100) [3][4]. For detailed implementation and the most up-to-date parameter surface, consult the official Honcho SDK reference [3][2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- tools/ask.ts (around snippet) ----"
sed -n '40,90p' tools/ask.ts | cat -n || true

echo "---- package.json ----"
if [ -f package.json ]; then
  sed -n '1,200p' package.json | cat -n
else
  echo "package.json not found"
fi

echo "---- lockfile (look for `@honcho-ai/sdk`) ----"
ls -1 package-lock.json pnpm-lock.yaml yarn.lock bun.lockb 2>/dev/null || true
rg -n "\"`@honcho-ai/sdk`\"|`@honcho-ai/sdk`" package-lock.json pnpm-lock.yaml yarn.lock bun.lockb 2>/dev/null | head -n 50 || true

echo "---- Search for agentPeer.chat and session option keys ----"
rg -n --hidden --no-ignore -S "agentPeer\.chat\(" tools src . 2>/dev/null | head -n 50 || true
rg -n --hidden --no-ignore -S "agentPeer\.chat\(|\bsession(Id)?\b|session\s*:" tools src . 2>/dev/null | head -n 80 || true

Repository: plastic-labs/openclaw-honcho

Length of output: 10298


🌐 Web query:

"@honcho-ai/sdk" "peer" "chat" "sessionId" options type

💡 Result:

In the @honcho-ai/sdk, the chat method on a peer object accepts an optional configuration object as its second argument [1][2]. This configuration object, defined in the SDK as part of the DialecticOptions [3], supports the sessionId property to scope the chat query to a specific session [1][2][3]. The signature for the chat method in the TypeScript SDK is: peer.chat(query: string, options?: DialecticOptions) [1][3] The DialecticOptions object includes the following properties: - sessionId (string | null): The ID of the session to which the representation and context should be scoped [3]. - target (string | null): An optional peer ID to get the representation for, from the perspective of the current peer [3]. - reasoningLevel (string): Controls the depth of reasoning applied to the request. Accepted values are 'minimal', 'low' (default), 'medium', 'high', and 'max' [4][3]. - stream (boolean): Whether to stream the response (defaults to false) [3]. Note that for streaming, developers are often encouraged to use the dedicated chatStream method in recent versions of the SDK [5][6]. Example usage: const sessionResponse = await alice.chat("What happened in our conversation?", { sessionId: session.id }); For complex queries, you can also combine these options, for example: const response = await alice.chat("Summarize what matters most to me.", { sessionId: "session-1", reasoningLevel: "high" }); [1][2]

Citations:


🌐 Web query:

"@honcho-ai/sdk" "peer.chat" options "session" vs "sessionId"

💡 Result:

In the @honcho-ai/sdk, the distinction between "session" and "sessionId" in peer.chat options relates to how you scope your conversational queries [1][2]. When calling peer.chat(query, options), you can use the options object to control the scope of the reasoning process [1][2]. 1. sessionId: This is the standard key used in the options object to provide a string-based identifier for a specific session [1][2]. By passing { sessionId: "your-session-id" }, you explicitly constrain the chat request to retrieve information or context associated with that specific session [1][2]. 2. session (Usage as a property): In some API versions or specific method signatures, you may see references to "session" used interchangeably with the session object itself or as a deprecated/shorthand key [1][2]. However, the current standard for passing an identifier in the chat options object is explicitly { sessionId: "id" } [1][2]. In summary: - Always prefer using { sessionId: "your-session-id" } when you need to constrain a chat query to a specific session [1][2]. - This approach ensures your agentic search is correctly scoped to the desired conversation thread, preventing context bleeding [3]. - Note that peer and session calls themselves are "get-or-create" operations; if you do not provide a session context, the SDK may default to global or lazily-generated session behaviors depending on your configuration [1][2][3].

Citations:


🌐 Web query:

site:github.com honcho-ai sdk peer chat sessionId

💡 Result:

In the Honcho AI SDK, sessionId is a key identifier used to define conversation threads and manage persistent memory across interactions [1][2][3]. Key details regarding session management: 1. Identification: A sessionId allows you to create explicit thread boundaries [1]. When omitted in certain SDK implementations (such as the Vercel AI SDK wrapper), the provider may lazily generate a session ID scoped to that instance [1]. 2. Configuration: You can set a sessionId explicitly to group messages and maintain context for specific conversations [1][3]. 3. Peer Interaction: When managing peer interactions within a session, you can retrieve, set, or update peer configurations (e.g., SessionPeerConfig) using the sessionId alongside a workspaceId and peerId [2][3][4]. 4. Context Retrieval: To interact with memory, the SDK provides methods such as session.context() (e.g., session.context(peer_target='user-123')) which relies on the active session context [1][5]. 5. Versioning Note: In recent SDK updates (e.g., v2.1.0+ for TypeScript), object properties such as sessionId use camelCase [6]. For developers, common operations include using the honcho.session(sessionId) method to initialize or retrieve a session object to perform tasks like chat, context retrieval, or adding peers [6][3]. If you are using middleware (such as with the Vercel AI SDK), you can pass the sessionId explicitly per request to prevent memory from bleeding across different user conversations [1].

Citations:


Fix agentPeer.chat session scoping option key (session -> sessionId)

In tools/ask.ts, the call uses session: session_id, but @honcho-ai/sdk peer.chat(..., options) scopes sessions via the sessionId option (string). Using session can be ignored at runtime, and the current unit tests only assert the mock call shape (opts.session), so they won’t catch the mismatch. Update to { sessionId: session_id } (and align other tools that pass session: session_id, e.g. tools/search.ts / tools/context.ts).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/ask.ts` around lines 58 - 62, The call to agentPeer.chat in
tools/ask.ts is using the wrong session option key (opts.session) so the SDK
ignores it; update the options object passed to agentPeer.chat to use sessionId:
session_id instead of session: session_id, and make the same change for other
similar calls that pass session: session_id (e.g., the agentPeer.chat
invocations in tools/search.ts and tools/context.ts) so the SDK's session
scoping works correctly.

@leugenea leugenea left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The SDK version used in this project is @honcho-ai/sdk v2.0.0, which uses the session option key for both peer.chat() and peer.representation(). The sessionId key was introduced in the v3 SDK and is not available here.

Installed types confirm this (node_modules/@honcho-ai/sdk/dist/peer.d.ts):

  • chat(query, options?: { session?: string | Session; ... }) — line 131-133
  • representation(options?: { session?: string | Session; ... }) — line 331-332

The current session: session_id is correct for this SDK version.


Re: nitpick about mock signatures in test/tools.test.ts — added guard assertions in mock implementations to catch unexpected option keys: https://github.com/plastic-labs/openclaw-honcho/pull/104/commits

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.

1 participant