Metadata-Version: 2.4
Name: spokest-langchain
Version: 1.0.0
Summary: LangChain integration for Spokest Brain memory
Home-page: https://github.com/spokest/spokest-langchain
Author: Spokest
Author-email: hello@spokest.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: spokest>=1.0.0
Requires-Dist: langchain-core>=0.2.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# spokest-langchain

LangChain memory integration for [Spokest Brain](https://spokest.com). Give your LangChain chains persistent, associative memory powered by the Spokest Brain API.

## Install

```bash
pip install spokest-langchain
```

## Usage

```python
from langchain_openai import ChatOpenAI
from langchain.chains import ConversationChain
from spokest_langchain import SpokestMemory

memory = SpokestMemory(
    api_key="sk-your-spokest-api-key",
    base_url="https://brain-api.spokest.com",  # optional, this is the default
)

llm = ChatOpenAI(model="gpt-4o")
chain = ConversationChain(llm=llm, memory=memory)

response = chain.invoke({"input": "What did we discuss about the product launch?"})
print(response["response"])
```

## Configuration

| Parameter | Default | Description |
|-----------|---------|-------------|
| `api_key` | (required) | Your Spokest Brain API key |
| `base_url` | `https://brain-api.spokest.com` | Brain API base URL |
| `memory_key` | `memories` | Key used in the chain's memory variables |

## How it works

- **`load_memory_variables`** -- Calls `/v1/memory/recall` with the current user input to retrieve relevant memories. Returns them formatted as a bulleted list under the configured `memory_key`.
- **`save_context`** -- Calls `/v1/memory/store` with the full conversation turn (user input + assistant output) after each chain invocation.
- **`clear`** -- Logs a warning. Spokest Brain memories are permanent by design and cannot be deleted.

## License

MIT
