|
| 1 | +# Neocortex Agno Plugin |
| 2 | + |
| 3 | +Agno plugin for **Neocortex-powered memories** in Agno agents. Gives your agents persistent memory (save, recall, delete) via the Neocortex/TinyHumans API, with credentials kept out of tool parameters. |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +- Python 3.9+ |
| 8 | +- [Agno](https://pypi.org/project/agno/) ≥ 2.0 |
| 9 | +- [httpx](https://www.python-httpx.org/) (brought in as a dependency) for talking to the Alphahuman backend. |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +```bash |
| 14 | +pip install neocortex-agno |
| 15 | +``` |
| 16 | + |
| 17 | +Or from the repo: |
| 18 | + |
| 19 | +```bash |
| 20 | +pip install -e ./neocortex/packages/plugin-agno |
| 21 | +``` |
| 22 | + |
| 23 | +## Quick start |
| 24 | + |
| 25 | +```python |
| 26 | +from agno.agent import Agent |
| 27 | +from agno.models.openai import OpenAIResponses |
| 28 | +from neocortex_agno import NeocortexTools |
| 29 | + |
| 30 | +agent = Agent( |
| 31 | + model=OpenAIResponses(id="gpt-4o-mini"), |
| 32 | + tools=[NeocortexTools(token="YOUR_ALPHAHUMAN_API_KEY")], |
| 33 | + instructions="Use the memory tools to remember and recall user preferences and context.", |
| 34 | + markdown=True, |
| 35 | +) |
| 36 | + |
| 37 | +# Agent can now save and recall memories |
| 38 | +agent.print_response("Remember that I prefer dark mode and my name is Alex.", stream=True) |
| 39 | +agent.print_response("What theme do I prefer?", stream=True) |
| 40 | +``` |
| 41 | + |
| 42 | +## Available tools |
| 43 | + |
| 44 | +The `NeocortexTools` toolkit exposes three tools to the agent: |
| 45 | + |
| 46 | + |
| 47 | +| Tool | Description | |
| 48 | +| --------------- | --------------------------------------------------------------------- | |
| 49 | +| `save_memory` | Save or update a memory (key, content, namespace, optional metadata). | |
| 50 | +| `recall_memory` | Recall relevant memories for a natural-language query in a namespace. | |
| 51 | +| `delete_memory` | Delete one or more memories by key/keys or delete all in a namespace. | |
| 52 | + |
| 53 | + |
| 54 | +Credentials (`token`, `model_id`, `base_url`) are set when constructing `NeocortexTools` and are **never** passed as tool arguments, so the LLM cannot see or override them. |
| 55 | + |
| 56 | +## Configuration |
| 57 | + |
| 58 | +- **token** (required): Alphahuman / Neocortex memory API token (e.g. `ALPHAHUMAN_API_KEY`). |
| 59 | +- **base_url** (optional): Alphahuman API base URL. If omitted, uses the `ALPHAHUMAN_BASE_URL` env var or the default `https://staging-api.alphahuman.xyz`. |
| 60 | + |
| 61 | +## Error handling |
| 62 | + |
| 63 | +On API failures, the underlying client raises `TinyHumanError`. You can catch it for logging or user-facing messages: |
| 64 | + |
| 65 | +```python |
| 66 | +from neocortex_agno import NeocortexTools, AlphahumanError |
| 67 | + |
| 68 | +try: |
| 69 | + agent.print_response("Remember that I like Python.", stream=True) |
| 70 | +except AlphahumanError as e: |
| 71 | + print(f"Memory API error: {e} (status={e.status})") |
| 72 | +``` |
| 73 | + |
| 74 | +## Example |
| 75 | + |
| 76 | +An example script is included. Set `ALPHAHUMAN_API_KEY`, `ALPHAHUMAN_BASE_URL`, and `OPENAI_API_KEY`, then: |
| 77 | + |
| 78 | +```bash |
| 79 | +python example.py |
| 80 | +``` |
| 81 | + |
0 commit comments