Skip to main content

Persistent memory layer for AI agents โ€” survives sessions, learns patterns, enables continuity

Project description

๐Ÿง  Cognex

Persistent memory layer for AI agents โ€” survives sessions, learns patterns, enables continuity.

Give your AI coding assistant long-term memory, decision tracking, and trust management.

PyPI version Python 3.10+ License: MIT MCP Compatible


Why Use It?

You: "Remember I prefer pytest over unittest"

Next session:
AI: "Got it โ€” I'll use pytest for your tests instead."

Your AI forgets everything between sessions. Cognex fixes that.

Features

Feature What It Does
Persistent Memory Remembers preferences, facts, patterns across sessions
Decision Ledger Tracks choices made and their outcomes
Trust Engine Learns which tools you approve vs deny
Teleportation Export your brain, load it on another machine
Swarm Mode Turn natural language into multi-agent plans

Quick Install

Option A โ€” One command (Terminal)

Mac/Linux:

curl -fsSL https://raw.githubusercontent.com/Gaurav7974/cognex/main/install.sh | sh

Windows (PowerShell):

irm https://raw.githubusercontent.com/Gaurav7974/cognex/main/install.ps1 | iex

These scripts automatically:

  • Install cognex via pip
  • Detect your AI tool (Claude Code, OpenCode, Cursor, Codex)
  • Write the correct config file
  • Print confirmation when done

Option B โ€” Paste this prompt into your AI agent

If you're already inside Claude Code, OpenCode, Cursor or any MCP-compatible tool, just paste this prompt and your AI will configure everything:

Install and configure the cognex MCP server on my system.

Steps:
1. Run: pip install cognex
2. Detect which AI tool I am using (Claude Code / OpenCode / Cursor / Codex / VS Code)
3. Find the correct MCP config file for this tool
4. Add cognex to the config:
   - command: "cognex"
   - no extra args needed
5. Tell me to restart my AI tool
6. After I restart, call substrate_start_session with session_id "setup-verify" to confirm it works

Copy that prompt โ†’ paste into your AI tool โ†’ it handles the rest.


Option C โ€” Manual (full control)

See the Configuration section below for step-by-step setup per tool.


Supported AI Tools

Tool Works?
Claude Code โœ…
Claude Desktop โœ…
OpenCode โœ…
Cursor โœ…
Codex โœ…
Any MCP-compatible tool โœ…

Installation (Choose One)

Option 1: uvx (Recommended โ€” no install needed)

uvx cognex

Verify installation

uvx cognex --help
# Should show: usage: cognex [-h] [--db-path ...] [--project ...] [--name ...] [--debug]

Option 2: pipx (isolated environment)

pipx install cognex

Verify installation

uvx cognex --help
# Should show: usage: cognex [-h] [--db-path ...] [--project ...] [--name ...] [--debug]

Option 3: pip (system-wide install)

pip install cognex

Verify installation

uvx cognex --help
# Should show: usage: cognex [-h] [--db-path ...] [--project ...] [--name ...] [--debug]

Option 4: Install from source (development)

git clone https://github.com/Gaurav7974/cognex
cd cognex
pip install -e .

Verify installation

uvx cognex --help
# Should show: usage: cognex [-h] [--db-path ...] [--project ...] [--name ...] [--debug]

Configuration

Claude Code

Config file: ~/.claude.json (global) or .mcp.json (project root)

Add via CLI (recommended):

claude mcp add cognex -- uvx cognex

Or manually add to ~/.claude.json:

{
  "mcpServers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"]
    }
  }
}

Or add to .mcp.json in your project root (team-shared):

{
  "mcpServers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"]
    }
  }
}

Note: .mcp.json in project root is version-controlled and shared with your team. ~/.claude.json is user-specific and works across all projects.


Claude Desktop

Config file: Windows: %APPDATA%\Claude\claude_desktop_config.json Mac: ~/Library/Application Support/Claude/claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"]
    }
  }
}

OpenCode

Config file: ~/.config/opencode/opencode.json (global) opencode.json in project root (project-specific)

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "cognex": {
      "type": "local",
      "command": ["uvx", "cognex"],
      "enabled": true
    }
  }
}

Note: OpenCode uses "mcp" key (not "mcpServers") and requires "type": "local" for stdio servers. Config files are merged, not replaced โ€” safe to add to existing config.


Cursor

Config file: Windows: %USERPROFILE%\.cursor\mcp.json Mac/Linux: ~/.cursor/mcp.json

{
  "mcpServers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"]
    }
  }
}

Note: Cursor caps at 40 tools per config. Cognex uses 18 tools, well within limit.


VS Code (GitHub Copilot Agent Mode)

Config file: .vscode/mcp.json in your workspace (team-shared) Or run: MCP: Open User Configuration from Command Palette (global)

Note: VS Code uses "servers" key not "mcpServers"

{
  "servers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"]
    }
  }
}

Cline (VS Code Extension)

Config file: Managed via Cline UI Windows: %APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json Mac: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

Open Cline โ†’ click MCP Servers icon โ†’ Configure tab โ†’ Edit Config

Add under mcpServers:

{
  "mcpServers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"],
      "disabled": false,
      "alwaysAllow": []
    }
  }
}

Kilo Code (VS Code Extension)

Same format as Cline. Open Kilo Code โ†’ MCP Servers โ†’ Configure.

{
  "mcpServers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"],
      "disabled": false
    }
  }
}

Windsurf

Config file: ~/.codeium/windsurf/mcp_config.json

{
  "mcpServers": {
    "cognex": {
      "command": "uvx",
      "args": ["cognex"]
    }
  }
}

Zed

Config file: ~/.config/zed/settings.json

Add under context_servers key:

{
  "context_servers": {
    "cognex": {
      "command": {
        "path": "uvx",
        "args": ["cognex"]
      }
    }
  }
}

Config format reference

Tool Key Config file
Claude Code mcpServers ~/.claude.json or .mcp.json
Claude Desktop mcpServers claude_desktop_config.json
OpenCode mcp opencode.json
Cursor mcpServers ~/.cursor/mcp.json
VS Code Copilot servers .vscode/mcp.json
Cline mcpServers cline_mcp_settings.json
Kilo Code mcpServers cline_mcp_settings.json
Windsurf mcpServers mcp_config.json
Zed context_servers settings.json

Key difference: OpenCode uses "mcp" and VS Code uses "servers". All others use "mcpServers".


After adding config

Completely close and reopen your AI tool. You should see 18 new cognex tools available.

To verify in Claude Code:

/mcp
โ†’ Should show: cognex: connected

To verify in OpenCode:

Type /mcp in the chat
โ†’ Should show cognex listed with Connected status

Restart Your AI Tool

After adding the config, completely close and reopen your AI tool. You should see 18 new tools available.


The 18 Tools

๐Ÿ—“๏ธ Session Management

Tool Description
substrate_start_session Start a new work session
substrate_end_session End session with summary/metrics
substrate_process_transcript Extract memories from conversation
substrate_report Get memory health report

๐Ÿ’พ Memory

Tool Description
memory_add Add a memory (fact, preference, decision, pattern)
memory_search Search memories with filters
memory_get_context Get relevant context for current work
memory_decay Age memories (auto-cleanup old ones)

๐Ÿ›ก๏ธ Trust Engine

Tool Description
trust_check Check if tool needs approval
trust_record Record approval/denial/violation
trust_get Get trust score for a tool
trust_summary Get trust overview

๐Ÿ“– Decision Ledger

Tool Description
ledger_record Record a decision made
ledger_outcome Record what happened after
ledger_find_similar Find similar past decisions

๐Ÿš€ Teleportation

Tool Description
teleport_create_bundle Export your brain to JSON
teleport_rehydrate Import brain from another machine

๐Ÿ Swarm

Tool Description
swarm_compile_intent Turn "build me an API" into a multi-agent plan

Example Usage

Remember a Preference

You: "I prefer using type hints everywhere"
AI: (calls memory_add)
โ†’ Saved to your memory bank

Get Context Next Session

You: (start new session)
AI: (calls memory_get_context with "coding style")
โ†’ Returns: "I prefer using type hints everywhere"
AI: "Got it โ€” I'll add type hints throughout."

Track a Decision

You: "FastAPI or Flask?"
AI: "FastAPI has better type safety."
AI: (calls ledger_record)

Later...
You: "Did that work out?"
AI: (calls ledger_outcome with success: true)

Tool Trust Check

AI wants to run: rm -rf /
AI: (calls trust_check)
โ†’ {requires_approval: true, trust_level: 0.2}
AI asks: "Can I delete everything?"

Where Data is Stored

All data stays local on your machine in SQLite:

Linux/Mac: ~/.cognex/cognex.db Windows: %USERPROFILE%\.cognex\cognex.db

Contains:

  • memories โ€” persistent memories
  • sessions โ€” session history
  • trust_records โ€” tool approval history
  • decisions โ€” decision ledger

Troubleshooting

"command not found" or "cognex" not recognized

Fix: Make sure you installed it:

pip install cognex

Or use uvx in your config:

"command": ["uvx", "cognex"]

Tools not appearing

  1. Check the AI tool's developer console for errors
  2. Try restarting the AI tool completely
  3. Verify your JSON config is valid (use a JSON validator)

Development

git clone https://github.com/Gaurav7974/cognex
cd cognex
pip install -e ".[dev]"
pytest tests/ -v

File Structure

cognex/
โ”œโ”€โ”€ .github/
โ”‚   โ”œโ”€โ”€ workflows/
โ”‚   โ”‚   โ”œโ”€โ”€ ci.yml
โ”‚   โ”‚   โ””โ”€โ”€ publish.yml
โ”‚   โ””โ”€โ”€ ISSUE_TEMPLATE/
โ”‚       โ”œโ”€โ”€ bug_report.md
โ”‚       โ””โ”€โ”€ feature_request.md
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ configuration.md
โ”‚   โ”œโ”€โ”€ tools.md
โ”‚   โ””โ”€โ”€ examples.md
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ basic_usage.py
โ”‚   โ”œโ”€โ”€ session_workflow.py
โ”‚   โ””โ”€โ”€ teleport_example.py
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ substrate/         โ† Core memory system
โ”‚   โ””โ”€โ”€ substrate_mcp/     โ† MCP server with 18 tools
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_substrate.py
โ”‚   โ”œโ”€โ”€ test_layers.py
โ”‚   โ””โ”€โ”€ test_mcp_server.py
โ”œโ”€โ”€ demo/
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ CHANGELOG.md
โ”œโ”€โ”€ CONTRIBUTING.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ mcp.example.json       โ† copy this to configure
โ””โ”€โ”€ pyproject.toml

License

MIT โ€” free to use, modify, and distribute.


Need Help?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cognex-0.1.1.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cognex-0.1.1-py3-none-any.whl (46.2 kB view details)

Uploaded Python 3

File details

Details for the file cognex-0.1.1.tar.gz.

File metadata

  • Download URL: cognex-0.1.1.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cognex-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4997f2b28d29d0e4050f557ac76974722af4e36f1145b634054b9e4d0ec9d529
MD5 315439f9f4d9ea3e8b45f4f5f6ed35f5
BLAKE2b-256 87c76ff6d8db78e7d48099455b6d60c75c46a8449c0ea5c49933873166622192

See more details on using hashes here.

Provenance

The following attestation bundles were made for cognex-0.1.1.tar.gz:

Publisher: publish.yml on Gaurav7974/cognex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cognex-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cognex-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 46.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cognex-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c43385e3231dd2f1fd2e94ec9fa9d060c75abdc1cd01b0c9d313a7cbc394a22c
MD5 34b85fb71aa940cb484fcc20a92f83c7
BLAKE2b-256 fd253f2f632b5e7769b5b1e15ef5711c15305ecb7f9b8a5e8ae2e96fb014f1ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for cognex-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Gaurav7974/cognex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page