enrich_solution
Add new context to a saved solution to refine it with reusable insights. Use after follow-up clarifications to improve reusability across projects.
Instructions
Append new context to an already-saved solution.
Call this when a conversation reveals additional details AFTER a solution was already saved — for example, a follow-up clarification that makes the solution more reusable across projects.
This is NOT for failures (use add_edge_case for those). This is for enrichment: new facts, patterns, or context that improve the answer.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entry_id | Yes | The id returned by save_solution, confirm_solution, or search_similar. | |
| context | Yes | New information that refines or extends the saved solution. Write as a reusable insight: state the general pattern first, then give specific details. E.g.: 'Port 4181 is used when 4180 is already taken by another auth proxy in the same stack.' |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/longmem/server.py:486-526 (handler)MCP tool handler for enrich_solution. Receives entry_id and context, delegates to store.enrich_solution(), returns JSON with updated status or error.
@mcp.tool() async def enrich_solution( entry_id: Annotated[ str, Field(description="The id returned by save_solution, confirm_solution, or search_similar."), ], context: Annotated[ str, Field( description=( "New information that refines or extends the saved solution. " "Write as a reusable insight: state the general pattern first, " "then give specific details. E.g.: 'Port 4181 is used when 4180 " "is already taken by another auth proxy in the same stack.'" ) ), ], ) -> str: """ Append new context to an already-saved solution. Call this when a conversation reveals additional details AFTER a solution was already saved — for example, a follow-up clarification that makes the solution more reusable across projects. This is NOT for failures (use add_edge_case for those). This is for enrichment: new facts, patterns, or context that improve the answer. """ try: store, *_ = await _get_deps() try: await store.enrich_solution(entry_id, context) except ValueError as exc: return json.dumps({"updated": False, "error": str(exc)}, indent=2) return json.dumps({ "updated": True, "id": entry_id, "message": "Solution enriched. Future retrievals will include the new context.", }, indent=2) except Exception as exc: return _db_error(exc) - src/longmem/server.py:485-486 (registration)Registration of enrich_solution as an MCP tool via @mcp.tool() decorator on FastMCP instance.
# ── tool: enrich_solution ──────────────────────────────────────────────────── @mcp.tool() - src/longmem/server.py:488-502 (schema)Input schema for enrich_solution: entry_id (str) and context (str) with Pydantic Field descriptions.
entry_id: Annotated[ str, Field(description="The id returned by save_solution, confirm_solution, or search_similar."), ], context: Annotated[ str, Field( description=( "New information that refines or extends the saved solution. " "Write as a reusable insight: state the general pattern first, " "then give specific details. E.g.: 'Port 4181 is used when 4180 " "is already taken by another auth proxy in the same stack.'" ) ), ], - src/longmem/store.py:489-509 (helper)Storage-layer implementation: fetches the entry by ID, appends additional_context (separated by '---'), updates the LanceDB table, and re-syncs the FTS index.
async def enrich_solution(self, entry_id: str, additional_context: str) -> None: """Append new context to an existing solution's text (not a failure — a refinement).""" sid = self._safe_id(entry_id) rows = await ( self._table.query() .where(f"id = '{sid}'") .limit(1) .to_list() ) if not rows: raise ValueError(f"Entry {entry_id!r} not found") current_solution: str = rows[0].get("solution") or "" updated_solution = current_solution + "\n\n---\n" + additional_context await self._table.update( updates={"solution": updated_solution, "updated_at": _now()}, where=f"id = '{sid}'", ) if self._fts: await self._fts_resync(entry_id)