Metadata-Version: 2.5
Name: llama-index-memory-bilinc
Version: 0.1.0
Summary: LlamaIndex memory block backed by Bilinc agent memory.
Project-URL: Homepage, https://bilinc.space
Project-URL: Documentation, https://bilinc.space/docs
Project-URL: Repository, https://github.com/ReARCLabs/bilinc-llamaindex
Project-URL: Issues, https://github.com/ReARCLabs/bilinc-llamaindex/issues
Author: ReARC Labs Inc.
License-Expression: MIT
License-File: LICENSE
Keywords: agents,bilinc,llama-index,memory
Requires-Python: <4.0,>=3.11
Requires-Dist: bilinc<3,>=2.7.3
Requires-Dist: llama-index-core<0.15,>=0.13.0
Description-Content-Type: text/markdown

# LlamaIndex Memory Integration: Bilinc

`BilincMemoryBlock` is a long-term memory block for LlamaIndex's `Memory`, backed by [Bilinc](https://bilinc.space) agent memory.

- When `Memory` flushes old messages out of short-term memory, the block saves them to Bilinc as one episodic memory per flush, under the chat's session ID.
- When `Memory` builds the prompt, the block recalls the memories most relevant to the latest user message and inserts them as text.

It wraps the official [`bilinc`](https://pypi.org/project/bilinc/) Python SDK.

Source: <https://github.com/ReARCLabs/bilinc-llamaindex>

## Install

```bash
pip install llama-index-memory-bilinc
```

## Credentials

Pass `api_key=`, or set `BILINC_API_KEY`. If neither is set, the SDK uses the key saved by `bilinc login`. Get a key at [bilinc.space/signup](https://bilinc.space/signup).

## Usage

```python
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.memory import Memory
from llama_index.llms.anthropic import Anthropic
from llama_index.memory.bilinc import BilincMemoryBlock

memory = Memory.from_defaults(
    session_id="user-123",
    token_limit=40000,
    memory_blocks=[BilincMemoryBlock(key_prefix="my-agent.chat", recall_limit=5)],
)

agent = FunctionAgent(tools=[], llm=Anthropic(model="claude-sonnet-5-5"))
response = await agent.run("Remember that I prefer short answers.", memory=memory)
```

## Options

| Option | Default | Meaning |
| --- | --- | --- |
| `api_key` | env / saved login | Bilinc API key |
| `base_url` | SDK default | Override the Bilinc Cloud URL |
| `client` | built on first call | A pre-built `bilinc.CloudClient` |
| `key_prefix` | `llamaindex.chat` | Prefix of written keys: `<prefix>.<session_id>.<hash>` |
| `write_memory_type` | `episodic` | Memory type of written entries |
| `importance` | `0.5` | Importance of written entries |
| `recall_limit` | `5` | Memories recalled per prompt |
| `profile` | `balanced` | Recall profile (`fast`, `balanced`, `verified`, `deep`; depends on plan) |
| `memory_types` | all | Limit recall to these types |
| `write_enabled` | `True` | `False` makes the block read-only |
| `priority` | `0` | `Memory` truncation priority (0 = never truncate) |
| `session_id` | none | Session for writes; when set, it wins over the session `Memory` passes |

Each flush is written once, with an idempotency key derived from its session and content. Keys are `<prefix>.<session>.<hash>`. The session is the block's `session_id` when it is set; otherwise it is the one `Memory` passes (`Memory` always passes its own `session_id`). The same messages in two sessions are saved as two memories.

Session IDs are trimmed, and a blank one is ignored. The key and `sessionId` always carry the same session value. That value is the ID itself up to 256 characters (Bilinc's limit for `sessionId`), and its hash for a longer ID. If the key would pass Bilinc's 512-character limit, the hash is used in both. If the key is still too long, because `key_prefix` itself is very long, a warning is logged and the write is skipped.

Bilinc failures never break the agent's turn. A missing key, a rate limit, a connection error or a validation error is logged as a warning (logger `llama_index.memory.bilinc.base`). A read then returns no memories, and a write is skipped. Saves and recalls use Bilinc credits; see [pricing](https://bilinc.space/pricing).

## Why a memory block

New LlamaIndex code uses `Memory` with memory blocks; the older `ChatMemoryBuffer` family is marked deprecated in `llama_index.core.memory`. A block lets Bilinc sit next to the built-in short-term chat history and other blocks, instead of replacing the whole memory.

## Development

```bash
pip install -e . pytest pytest-asyncio
pytest
```

The tests replace the SDK transport with a fake and never reach the network.

## License

MIT for this package. The `bilinc` SDK it depends on has its own license (BUSL-1.1).
