Metadata-Version: 2.5
Name: langflow-recallic
Version: 0.1.0
Summary: Recallic memory components for Langflow: self-hosted, no LLM calls for memory, says when it has no record.
Project-URL: Homepage, https://www.recallic.com
Project-URL: Source, https://github.com/Recallic/Recallic/tree/main/integrations/langflow
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: lfx>=1.13
Requires-Dist: recallic>=0.3.0
Description-Content-Type: text/markdown

# langflow-recallic: Recallic memory components for Langflow

Website: [recallic.com](https://www.recallic.com)

Long-term memory for [Langflow](https://www.langflow.org) flows and agents, backed by a self-hosted
[Recallic](https://github.com/Recallic/Recallic) server. Two components:

* **Recallic Recall** looks up what a user told your flow before. When no stored memory answers the question, it
  returns a note saying there is no record (and that the model should not guess about the user's past) instead of
  near-misses.
* **Recallic Save** stores what the user said, so later runs can recall it.

No LLM calls are made for memory: storing and searching use Recallic's local models. Your data stays on your server,
separated per user and per agent.

This integration is Apache-2.0. The Recallic server is source-available.

## Install

Run Recallic ([quickstart](../../docs/quickstart.md)) and create a key with role `service`, which acts for each of
your users (or use a user's own key and leave User ID empty):

```bash
python -m backend.tools.keys create --user my-langflow-app --role service
```

Then add the components to Langflow in one of three ways.

**1. As a Langflow extension (Langflow 1.13 or newer).** Install the package into the same Python environment as
Langflow and restart it. The components appear in the sidebar under **Recallic**.

```bash
pip install langflow-recallic
```

**2. From a components folder.** Copy the `recallic` folder from
[`src/langflow_recallic/components/`](src/langflow_recallic/components/) into a folder of your own and start Langflow
with that folder on its components path:

```bash
LANGFLOW_COMPONENTS_PATH=/path/to/my-components langflow run
```

**3. Pasted as a custom component.** In a flow, add a **Custom Component**, open its code editor, and replace the
code with the whole of [`recallic_recall.py`](src/langflow_recallic/components/recallic/recallic_recall.py) (or
[`recallic_save.py`](src/langflow_recallic/components/recallic/recallic_save.py)). Each file is self-contained: it uses
the `recallic` Python package when Langflow's environment has it, and plain HTTP when it does not.

## Usage

A chat flow with memory:

```
Chat Input ──► Recallic Recall (Query) ──► Prompt {memories} ──► Language Model ──► Chat Output
     └───────► Recallic Save (Message)
```

1. Connect **Chat Input** to the Query of **Recallic Recall** and to the Message of **Recallic Save**.
2. Set Recallic URL, Recallic API Key (store it as a Langflow global variable) and User ID on both. In a multi-user
   app, connect the User ID to whatever carries your user's id (for example the session id).
3. Put `{memories}` in your Prompt and connect the **Memories** output to it. The prompt gets either the memories,
   newest facts first with the date each was said, or the no-record note.

Langflow does not promise which of the two branches runs first. That is fine: a stored question is not taken as an
answer to itself.

For an **Agent**, turn on **Tool Mode** on either component and connect it to the Agent's Tools. The agent then
fills in the Query (or Message) itself.

To check the components from Python, outside Langflow:

```python
import asyncio
from langflow_recallic import RecallicRecallComponent, RecallicSaveComponent

conn = dict(recallic_url="http://localhost:8000", api_key="rx_...", recallic_user_id="alice")
print(asyncio.run(RecallicSaveComponent(**conn, message="I moved to Pune in March.").save_message()).text)
print(asyncio.run(RecallicRecallComponent(**conn, query="Which city did I move to?").recall_message()).text)
```

### Recallic Recall

| Input | Default | What it does |
|---|---|---|
| Query | required | What to look up, usually the user's latest message. |
| User ID | empty | Whose memory to read. Needed with a service key; leave empty with a user's own key. |
| Recallic URL | `http://localhost:8000` | Your Recallic server. |
| Recallic API Key | required | A Recallic key (a secret field). |
| Agent ID (advanced) | `langflow` | Recallic agent id; each agent reads back what it wrote (and what any agent shared). |
| Mode (advanced) | Server default | `cautious` declines more (more "I don't know"); `helpful` answers more counting, ordering and "how long between" questions. |
| Max Memories (advanced) | 5 | Memories returned per lookup. |
| Timeout (advanced) | 30 | Seconds per request to Recallic. |

| Output | What it returns |
|---|---|
| Memories (Message) | The memories as text for a prompt, or the no-record note when nothing answers the query. |
| Memory Data (Data list) | One Data per memory (`text`, `id`, `timestamp`, `score`, `agent_id`); an empty list when nothing answers. |

### Recallic Save

Same User ID, Recallic URL, Recallic API Key, Agent ID and Timeout inputs, plus:

| Input | Default | What it does |
|---|---|---|
| Message | required | What to remember, in the user's words. |
| Memory Type (advanced) | `private` | `shared` makes it readable by all of the user's agents. |

Output **Status** (Message): `Saved.`, `Already remembered.` (an exact repeat is skipped) or `Not stored (...)`.

## Notes

* The user field is named `recallic_user_id` in code, because Langflow components already have a `user_id` (the
  Langflow user running the flow).
* Recallic Recall makes one request per run, shared by both of its outputs.
* Needs Recallic server 0.2.5 or newer. Tested with lfx 1.13.4 (the package that holds Langflow's component classes).

## Tests

Against a running Recallic: `RECALLIC_URL=http://127.0.0.1:8000 RECALLIC_SERVICE_KEY=rx_... pytest tests`.
They run the components' outputs against the server and load them the three ways above (installed extension,
components folder, pasted code).

Licence: Apache-2.0.
