fix: forward search params through all paths and clean up LLM interfaces#265
fix: forward search params through all paths and clean up LLM interfaces#265nkanu17 wants to merge 1 commit intopr/docs-hybrid-search-referencesfrom
Conversation
Forward search_mode, offset, and optimize_query through resolve_tool_call, MCP tools, and hydrate_memory_prompt. Remove hybrid_alpha and text_scorer from LLM-facing interfaces (MCP, tool schemas, LangChain) since these are server-level hyperparameters that LLMs cannot reliably tune. Changes: - Forward search_mode, offset, optimize_query in _resolve_search_memory - Add search_mode to MCP memory_prompt and search_long_term_memory - Remove hybrid_alpha and text_scorer from MCP tools and client tool schemas (kept in developer-facing hydrate_memory_prompt) - Align max_results default from 5 to 10 in _resolve_search_memory - Add distance_threshold validation for non-semantic search modes - Fix deprecated function references in tool descriptions and docstrings (search_memory -> search_memory_tool, get_working_memory -> get_or_create_working_memory) - Correct optimize_query docstrings in API and MCP - Make error message name-agnostic in client - Update MCP docs for search mode support Tests: - Add test for search_mode forwarding through resolve_function_call - Add test for search_mode forwarding through LangChain tool - Both tests verify hybrid_alpha/text_scorer are NOT in tool schemas - Update MCP parameter passing tests Design context (from #251 discussion): - @nkanu17: Hyperparameters like alpha, recency, and scorer config should be set at the server/session level, not by the LLM - @abrookins: MCP interface is intentionally smaller than REST API. LLMs can reason about search mode selection (semantic vs keyword vs hybrid) but struggle with arbitrary numeric tuning values - @tylerhutcherson: Questioned whether LLMs should toggle these params, leading to the decision to expose only search_mode - @vishal-bala: Cataloged full MCP/REST gaps in #253, confirmed remaining items are out of scope for this PR Refs: #251, #253
|
@codex review |
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 668691c1f0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| search_mode: SearchModeEnum | str = SearchModeEnum.SEMANTIC, | ||
| hybrid_alpha: float | None = None, | ||
| text_scorer: str | None = None, | ||
| limit: int = 10, |
There was a problem hiding this comment.
Preserve positional argument order in hydrate_memory_prompt
Inserting search_mode, hybrid_alpha, and text_scorer before limit, offset, and optimize_query changes the positional calling contract of this public client method. Any existing caller using positional args (e.g., passing limit/offset positionally) will now bind those values to search_mode/hybrid_alpha instead, which can produce invalid payloads (such as search_mode="5") and 4xx errors at runtime. To avoid a silent breaking change, keep new optional params after the old ones or make these options keyword-only.
Useful? React with 👍 / 👎.
Summary
Forward
search_mode,offset, andoptimize_querythrough all search paths (resolve_tool_call, MCP tools,hydrate_memory_prompt). Removehybrid_alphaandtext_scorerfrom LLM-facing interfaces since these are server-level hyperparameters.This is Part 2 of 2 PRs split from #251. It builds on #264 (docs). After #264 merges, retarget this PR to
main.Changes
Search param forwarding
search_mode,offset,optimize_queryin_resolve_search_memorysearch_modeparam to MCPmemory_promptandsearch_long_term_memorysearch_modeandhybrid_alphatohydrate_memory_prompt(developer API)max_resultsdefault from 5 to 10 in_resolve_search_memorydistance_thresholdvalidation for non-semantic search modesLLM interface cleanup
hybrid_alphaandtext_scorerfrom MCP tool signatureshybrid_alphaandtext_scorerfrom client tool schemashybrid_alphaandtext_scorerfrom LangChain integrationhydrate_memory_promptwhere developers can set them explicitlyDeprecated ref and docstring fixes
search_memorytosearch_memory_tool,get_working_memorytoget_or_create_working_memory)optimize_querydocstrings in API and MCPMCP docs
docs/mcp.mdto reference keyword and hybrid search modesTests
search_modeflows throughresolve_function_callcorrectlysearch_modeflows through LangChain tool correctlyhybrid_alpha/text_scorerare NOT in tool schemasFiles Changed (8)
agent-memory-client/agent_memory_client/client.py(param forwarding, tool schema, deprecated refs)agent-memory-client/agent_memory_client/integrations/langchain.py(remove hyperparams)agent_memory_server/mcp.py(add search_mode, remove hyperparams, fix docstrings)agent_memory_server/api.py(fix optimize_query docstring)docs/mcp.md(search mode docs)tests/test_client_tool_calls.py(new: search_mode forwarding test)tests/test_mcp.py(updated: param passing assertions)agent-memory-client/tests/test_langchain_integration.py(new: search_mode forwarding test)Design Decision
Per discussion on #251:
search_modeRefs: #251 (superseded by #264 and this PR), #253 (tracking issue for remaining MCP/REST gaps)
Note
Medium Risk
Medium risk because it changes tool/MCP/LangChain function signatures and default search behavior (e.g.,
max_resultsdefault), which can affect downstream integrations and search results across clients.Overview
Ensures long-term memory search options are forwarded consistently across client tool-call resolution, LangChain tools, MCP tools, and
hydrate_memory_prompt, includingsearch_mode, pagination (offset), andoptimize_query.Simplifies LLM-facing interfaces by removing tuning knobs like
hybrid_alphaandtext_scorerfrom tool schemas/MCP/LangChain while keeping hybrid configuration server/developer-side, and tightens validation sodistance_thresholdis only allowed in semantic mode.Cleans up tool/docs wording (deprecated
get_working_memory, renamed lazy/eager create tool descriptions, updatedoptimize_querydocs) and adds/updates tests to verifysearch_modeis forwarded and removed params are not exposed.Written by Cursor Bugbot for commit 668691c. This will update automatically on new commits. Configure here.