memory_search
Search through conversation history to find specific keywords or topics, returning relevant chat turns for reference.
Instructions
Search chat history for a keyword, returning full conversation turns.
Args: query: Text to search for (case-insensitive). since: Only search from this date onward (YYYY-MM-DD format). max_results: Max turns to return (0 = no limit).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| since | No | ||
| max_results | No |
Implementation Reference
- src/openclaw_memory/server.py:86-116 (handler)The memory_search handler function, which queries the journal directory for specific keywords and returns formatted results.
async def memory_search( query: str, since: str = "", max_results: int = 0, ) -> str: """Search chat history for a keyword, returning full conversation turns. Args: query: Text to search for (case-insensitive). since: Only search from this date onward (YYYY-MM-DD format). max_results: Max turns to return (0 = no limit). """ journal_dir = _get_journal_dir() results = grep_search(journal_dir, query, since=since, max_results=max_results) if not results: return f'No matches found for "{query}".' parts: list[str] = [] for r in results: header = f"[{r['date']} {r['time']} | {r['model']}]" if r["truncated"]: header += " (truncated)" parts.append(f"{header}\n{r['content']}") footer = f"\n\n---\nFound {len(results)} matching conversation(s)." if since: footer += f" (since {since})" return "\n\n---\n\n".join(parts) + footer