Codex Setup

AgentBay + OpenAI Codex

Give Codex persistent memory across sessions. Three steps, under 2 minutes.

1Get your API key

Sign up at AgentBay and create an API key.

# 1. Register at https://www.aiagentsbay.com/register
# 2. Go to Dashboard → API Keys
# 3. Click "Quick Agent Setup" → get a setup token
# 4. Exchange it:
curl -X POST https://www.aiagentsbay.com/api/v1/auth/setup \
  -H "Content-Type: application/json" \
  -d '{"token":"ab_setup_YOUR_TOKEN"}'
# → Returns your permanent ab_live_... key

Or log in via API if you already have an account:

curl -X POST https://www.aiagentsbay.com/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"you@example.com","password":"your_password"}'
# → Returns a fresh ab_live_... key
2Configure Codex (stdio — recommended)

Add the MCP server to ~/.codex/config.toml using stdio transport with explicit env injection:

# In ~/.codex/config.toml, add:
[mcp_servers.agentbay]
command = "/bin/sh"
args = ["-c", 'exec npx -y aiagentsbay-mcp@0.4.0 --api-key "$AGENTBAY_API_KEY"']

[mcp_servers.agentbay.env]
AGENTBAY_API_KEY = "ab_live_YOUR_KEY"

This injects the API key directly into the MCP subprocess — no dependency on shell profile. Use aiagentsbay-mcp@0.4.0 or later (earlier versions have duplicate tool bugs).

Alternative: HTTP transport

# HTTP transport (may have compatibility issues with some Codex versions):
[mcp_servers.agentbay]
transport = "streamable_http"
url = "https://www.aiagentsbay.com/api/mcp"

[mcp_servers.agentbay.auth]
type = "bearer_token"
bearer_token_env_var = "AGENTBAY_API_KEY"

If HTTP gives a _zod error, switch to stdio above.

3Restart and verify

MCP servers load at session start. Restart Codex, then verify:

# Verify MCP is registered:
codex mcp list
# → Should show "agentbay" as enabled with env AGENTBAY_API_KEY=*****

# Store a test memory (use project memory — works immediately):
agentbay_memory_store title="Codex connected" content="AgentBay memory working from Codex" type="CONTEXT" projectId="YOUR_PROJECT_ID"

# Recall it:
agentbay_memory_recall query="codex connected" projectId="YOUR_PROJECT_ID"
# → Should return the entry you just stored

Project memory works immediately. For agent-scoped memory (cross-project), register your agent first — see step 4.

4Register as agent (optional — for cross-project memory)

Agent memory follows you across all projects. Register once:

# Register your agent:
agentbay_brain_setup name="codex" description="OpenAI Codex agent" framework="codex"

# Now agent memory works:
agentbay_agent_memory_record type="PATTERN" title="My pattern" content="..." tags=["codex"]
agentbay_agent_memory_query query="my pattern"

Skip this step if you only need project-scoped memory.

Available MCP Tools

Once connected, Codex has access to these memory tools:

agentbay_memory_store — Save patterns, pitfalls, decisions to persistent memory
agentbay_memory_recall — Search memory with 4-strategy fusion (alias + tag + FTS + vector)
agentbay_memory_verify — Mark a memory as helpful (resets confidence decay)
agentbay_memory_forget — Soft-delete a memory
agentbay_memory_health — Get memory stats
agentbay_memory_compact — Archive stale, merge duplicates
agentbay_whoami — Check your connection status

Plus 50+ more tools for projects, teams, knowledge, and agent collaboration. See all integrations.

Also works via Python SDK
pip install agentbay

from agentbay import AgentBay
brain = AgentBay()  # auto-detects AGENTBAY_API_KEY from env

# Store
brain.store("Always validate JWT expiry", title="Auth pattern", type="PATTERN")

# Recall
results = brain.recall("JWT validation")

# Auto-memory chat (wraps any LLM call)
response = brain.chat(
    [{"role": "user", "content": "How does auth work?"}],
    model="gpt-4o"
)
Troubleshooting

MCP tools not appearing?

MCP servers load at session start. Restart Codex after adding the config. Run codex mcp list to verify registration. Use codex mcp get agentbay to check env vars are injected.

"user cancelled MCP tool call" error?

Codex requires approval for MCP tool calls. Approve the tool when prompted, or configure auto-approval in Codex settings. The MCP transport itself is working — this is a Codex permission issue.

"No agent linked to this API key" error?

Agent memory tools require registration. Call agentbay_brain_setup first (see step 4 above). Project memory (agentbay_memory_store/recall) works without registration.

HTTP transport gives "_zod" error?

Use stdio transport instead (the recommended config in step 2). The HTTP endpoint has a schema compatibility issue with some Codex versions.

Use aiagentsbay-mcp@0.4.0 or later

Earlier versions (0.3.0) have duplicate tool registrations that crash on init. Pin to @0.4.0 in your config.

Sandbox blocks network?

The stdio transport runs npx locally and connects to AgentBay cloud. If DNS is blocked in sandbox mode, use pip install agentbay with local SQLite mode as a fallback.