feat(tools): add optional session_id to search, ask, and context tools#104
feat(tools): add optional session_id to search, ask, and context tools#104leugenea wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThree honcho tools (ask, search, context) now accept an optional ChangesSession ID propagation across honcho tools
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/tools.test.ts (1)
30-43: 💤 Low valueMocks don't assert the SDK contract.
representation/chat/cardare plainvi.fnaccepting any args, so these tests confirm the tools forward asessionkey but not that the real@honcho-ai/sdkrecognizes 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
📒 Files selected for processing (4)
test/tools.test.tstools/ask.tstools/context.tstools/search.ts
| const answer = await agentPeer.chat(query, { | ||
| target: participantPeer, | ||
| reasoningLevel, | ||
| session: session_id, | ||
| }); |
There was a problem hiding this comment.
🧩 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:
- 1: https://honcho.dev/docs/v3/documentation/reference/sdk
- 2: https://docs.honcho.dev/v3/documentation/reference/sdk
- 3: https://docs.honcho.dev/v2/documentation/reference/sdk
- 4: https://dev.to/andrew-ooo/honcho-review-plastic-labs-agent-memory-layer-2026-2kb4
- 5: https://honcho.dev/docs/v3/guides/integrations/vercel-ai-sdk
- 6: https://mcp.directory/skills/migrate-honcho-ts
🏁 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/nullRepository: 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 || trueRepository: 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:
- 1: https://honcho.dev/docs/v3/documentation/features/chat
- 2: https://honcho.dev/docs/v3/api-reference/endpoint/peers/chat
- 3: https://docs.honcho.dev/v3/documentation/reference/sdk
- 4: https://honcho.dev/docs/v3/documentation/reference/sdk
- 5: https://docs.honcho.dev/v2/documentation/reference/sdk
- 6: https://dev.to/andrew-ooo/honcho-review-plastic-labs-agent-memory-layer-2026-2kb4
- 7: https://github.com/NousResearch/hermes-agent/blob/main/plugins/memory/honcho/README.md
🌐 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:
- 1: https://honcho.dev/docs/v3/documentation/features/chat
- 2: https://github.com/plastic-labs/honcho
- 3: https://honcho.dev/docs/v3/documentation/reference/sdk
- 4: https://docs.honcho.dev/v3/documentation/reference/sdk
- 5: https://dev.to/andrew-ooo/honcho-review-plastic-labs-agent-memory-layer-2026-2kb4
🏁 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 || trueRepository: 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:
- 1: https://honcho.dev/docs/v3/documentation/reference/sdk
- 2: https://docs.honcho.dev/v3/documentation/reference/sdk
- 3: https://honcho.dev/docs/v3/api-reference/endpoint/peers/chat
- 4: https://honcho.dev/docs/v3/documentation/features/chat
- 5: https://mcp.directory/skills/migrate-honcho-ts
- 6: https://honcho.dev/docs/changelog/compatibility-guide
🌐 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:
- 1: https://docs.honcho.dev/v3/documentation/reference/sdk
- 2: https://honcho.dev/docs/v3/documentation/reference/sdk
- 3: https://github.com/plastic-labs/vercel-ai-sdk
🌐 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:
- 1: https://github.com/plastic-labs/vercel-ai-sdk
- 2: https://github.com/hekmon/go-honcho
- 3: https://github.com/NousResearch/hermes-agent/blob/main/plugins/memory/honcho/session.py
- 4: https://github.com/plastic-labs/honcho-node-core/
- 5: Agent Zero Integration: Honcho Conversational Memory Plugin honcho#411
- 6: https://github.com/plastic-labs/honcho/blob/main/.claude/skills/migrate-honcho-ts/DETAILED-CHANGES.md
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
left a comment
There was a problem hiding this comment.
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-133representation(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
Summary
Adds an optional
session_idparameter to three Honcho tools to allow session-scoped queries.Changes
honcho_search_conclusions(tools/search.ts): filters semantic search to a specific sessionhoncho_ask(tools/ask.ts): limits Q&A to a specific sessionhoncho_context(tools/context.ts): limits context retrieval to a specific sessionBehavior
session_idis optional — existing calls without it work unchangedsession_idis passed to the Honcho SDK assession: params.session_idTests
Added 7 new unit tests in
test/tools.test.tscovering:honcho_ask— session_id passed/omittedhoncho_search_conclusions— session_id passed/omittedhoncho_context— session_id in "full" mode (passed/omitted), and "card" mode ignores itVerification
tsccompiles without errorsvitest run— 61/61 tests passsession_idbehave identically to beforeSummary by CodeRabbit
New Features
Tests