memstate_set
Store simple configuration values, status flags, or version numbers at specific hierarchical keypaths for AI agent memory management.
Instructions
Set one keypath to a short value. Only for simple key=value facts like config, status, or version numbers.
USE THIS WHEN: You need to store ONE specific value at a known keypath (e.g. a port number, a status flag, a version string). NOT FOR: Task summaries, markdown, or text with multiple facts — use memstate_remember instead.
memstate_set(project_id="myapp", keypath="config.database.port", value="5432") memstate_set(project_id="myapp", keypath="status.deployment", value="production") memstate_set(project_id="myapp", keypath="version.current", value="2.1.0")
Value limit: 2,000 chars. If longer, use memstate_remember instead. Keypath is auto-prefixed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Required. Project to store in (e.g. 'myapp'). Auto-creates if new. | |
| keypath | Yes | Required. Hierarchical path like 'config.port' or 'status'. Auto-prefixed with 'project.{project_id}.' | |
| value | Yes | The value to store (max 2,000 chars). Short, simple values only — not markdown. | |
| category | No | Category: decision, preference, fact, task, context, requirement, note, code, learning | |
| topics | No | Optional additional topics/tags |
Implementation Reference
- skill/scripts/memstate_set.py:11-53 (handler)The actual handler logic for `memstate_set`, which sends a POST request to the Memstate API's /memories/remember endpoint.
def set_memory(project_id, keypath, value, category=None, topics=None): url = f"{BASE_URL}/memories/remember" headers = { "X-API-Key": API_KEY, "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" } data = { "project_id": project_id, "keypath": keypath, "content": value } if category: data["category"] = category if topics: data["topics"] = topics.split(",") req = urllib.request.Request(url, data=json.dumps(data).encode("utf-8"), headers=headers, method="POST") try: with urllib.request.urlopen(req) as response: result = json.loads(response.read().decode("utf-8")) print(json.dumps(result, indent=2)) return 0 except urllib.error.HTTPError as e: print(f"Error: {e.code} - {e.read().decode('utf-8')}", file=sys.stderr) return 1 except Exception as e: print(f"Error: {e}", file=sys.stderr) return 1 if __name__ == "__main__": parser = argparse.ArgumentParser(description="Set a single fact at a specific keypath") parser.add_argument("--project", required=True, help="Project ID") parser.add_argument("--keypath", required=True, help="Hierarchical path (e.g., config.port)") parser.add_argument("--value", required=True, help="Value to store") parser.add_argument("--category", help="Category (decision, fact, config, etc.)") parser.add_argument("--topics", help="Comma-separated list of topics") args = parser.parse_args() sys.exit(set_memory(args.project, args.keypath, args.value, args.category, args.topics))