# Kronvex Python SDK

Persistent memory for AI agents. Three endpoints, one API key, production-ready.

## Installation

```bash
pip install kronvex
```

## Quick start

```python
from kronvex import Kronvex

kx = Kronvex("kx_your_api_key")
agent = kx.agent("your-agent-id")

# Store a memory
agent.remember("User prefers concise answers", memory_type="preference")

# Recall relevant memories
memories = agent.recall("what does the user prefer?", top_k=5)
for m in memories:
    print(f"[{m['score']:.2f}] {m['content']}")

# Inject context into your prompt
context = agent.inject_context("How should I respond?")
# → "Relevant memories:\n- User prefers concise answers\n..."
```

## Async support

```python
import asyncio
from kronvex import AsyncKronvex

async def main():
    async with AsyncKronvex("kx_your_api_key") as kx:
        agent = kx.agent("your-agent-id")
        await agent.remember("User is based in Paris", memory_type="semantic")
        memories = await agent.recall("where is the user?")

asyncio.run(main())
```

## With LangChain

```python
from kronvex import Kronvex
from langchain_openai import ChatOpenAI

kx = Kronvex("kx_your_api_key")
agent = kx.agent("your-agent-id")

def chat(user_message: str, session_id: str) -> str:
    # Inject past context
    context = agent.inject_context(user_message, session_id=session_id)

    llm = ChatOpenAI(model="gpt-4o")
    response = llm.invoke([
        {"role": "system", "content": f"You are a helpful assistant.\n\n{context}"},
        {"role": "user", "content": user_message},
    ])

    # Store the exchange
    agent.remember(f"User: {user_message}", memory_type="episodic", session_id=session_id)
    agent.remember(f"Assistant: {response.content}", memory_type="episodic", session_id=session_id)

    return response.content
```

## API reference

### `Kronvex(api_key, *, base_url, timeout)`

| Method | Description |
|--------|-------------|
| `.agent(agent_id)` | Get an Agent handle |
| `.create_agent(name)` | Create a new agent |
| `.list_agents()` | List all agents |

### `Agent`

| Method | Description |
|--------|-------------|
| `.remember(content, *, memory_type, session_id, ttl_days, pinned, metadata)` | Store a memory |
| `.recall(query, *, top_k, memory_type, session_id, threshold)` | Semantic search |
| `.inject_context(message, *, top_k, session_id)` | Get prompt-ready context block |
| `.sessions()` | List session IDs |
| `.memories(*, session_id, memory_type, limit, offset)` | List stored memories |
| `.delete_memory(memory_id)` | Delete one memory |
| `.clear()` | Delete all memories |

## Links

- [Dashboard](https://kronvex.io/dashboard)
- [API Docs](https://api.kronvex.io/docs)
- [Node.js SDK](https://www.npmjs.com/package/kronvex)
