feat: add long-term memory#754
Conversation
…ong-term memory tools
Coverage Report •
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
looks like long term memory tools are invisible in FUNCTION_CALLING / STRUCTURED_OUTPUT modes. |
| Returns: | ||
| dict: A dictionary representation of the connection instance. | ||
| """ | ||
| # Swallow `include_secure_params` if a caller forwards it down — the |
There was a problem hiding this comment.
Lets shorten the large comments
| query_norm = np.linalg.norm(query) or 1.0 | ||
|
|
||
| scored: list[tuple[Fact, float]] = [] | ||
| for fact_id, fact in self._facts.items(): |
There was a problem hiding this comment.
Is it possible to do more efiicienly? I think it is better to vectorize it.
| - {"query": "food preferences"} | ||
| - {"query": "what does the user do for work?", "limit": 3} | ||
| - {"query": "timezone or schedule constraints", "limit": 10} | ||
| """ |
There was a problem hiding this comment.
I think it makes sense to ask model to produce mutltiple queiries. Since it is semantic search it depends on phrasing and can improve accuracy.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 611ea39. Configure here.
| if not _run_extra_tools.get(): | ||
| return self._tools, self._response_format | ||
| return self._build_inference_schemas(self._runtime_tools) | ||
|
|
There was a problem hiding this comment.
Prompt template excludes tool blocks when only LTM tools exist
Medium Severity
The has_tools flag in _init_prompt_blocks only checks self.tools and skills, but doesn't account for self.long_term_memory. When an agent has no static tools but has LTM configured, has_tools is False at init time, so build_react_prompt builds a template without tool-related blocks. At runtime, even though _setup_prompt_and_stop_sequences passes tool_description as a kwarg, the template has no placeholder for it — making LTM tools invisible in XML/ReAct inference modes.
Reviewed by Cursor Bugbot for commit 611ea39. Configure here.


Note
Medium Risk
Stores per-user facts in external DBs and binds tools per request; cross-user delete is blocked in code, but mis-scoped
user_idor backend config could leak or mix data—mitigated by tests for isolation and concurrent runs.Overview
Adds user-scoped long-term memory for agents: durable facts with embedding-backed remember, recall, and programmatic forget, separate from short-term conversation
memory.A shared
LongTermMemoryBackendimplements dedup (normalized content hash per user), optional semantic upsert when cosine similarity exceedsupsert_threshold, and user isolation on search/delete. Storage ships as in-memory, Postgres + pgvector, and Qdrant backends with scoped CRUD and vector search.Agents gain optional
LongTermMemoryConfig(enabled, backend, which tools to expose). Whenuser_idis present on a run,remember_fact/recall_factstools are built withuser_idbaked in and exposed only for that execution via aContextVaroverlay—so concurrentexecute()calls do not mutate sharedtoolsor leak another user’s tools. Tool lists, prompts, and function-calling schemas read_runtime_tools; the LTM embedder is initialized ininit_components.BaseConnection.to_dictnow strips forwardedinclude_secure_paramsso serialization through backends/tools does not breakmodel_dump.Unit and integration tests cover backend behavior, tools, and agent concurrency/isolation.
Reviewed by Cursor Bugbot for commit 611ea39. Bugbot is set up for automated code reviews on this repo. Configure here.