Metadata-Version: 2.5
Name: hookie-ai
Version: 0.1.0
Summary: Python client for Hookie: project memories, knowledge search, documents and the project context bundle, with LangChain, LangGraph and CrewAI adapters.
Project-URL: Homepage, https://hookie.ai
Project-URL: Documentation, https://docs.hookie.ai/sdk/python
Project-URL: Source, https://github.com/bcusack1996/Hookie-Docs
Author: Hookie
License-Expression: MIT
License-File: LICENSE
Keywords: ai-agent,crewai,hookie,knowledge,langchain,langgraph,memory,rag,retriever
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.27
Provides-Extra: crewai
Requires-Dist: crewai>=0.80; extra == 'crewai'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
Provides-Extra: langgraph
Requires-Dist: langchain-core>=0.3; extra == 'langgraph'
Requires-Dist: langgraph>=0.3.25; extra == 'langgraph'
Description-Content-Type: text/markdown

# hookie-ai (Python)

Python client for [Hookie](https://hookie.ai): a project's **memories and decisions**,
**knowledge search** (memories, documents and the knowledge graph in one call),
**documents** (specs, PRDs, ADRs, runbooks, PDF, Word and HTML files) and the
**project context bundle**, plus adapters for **LangChain**, **LangGraph** and **CrewAI**.

```bash
pip install hookie-ai                 # the client (httpx is its one dependency)
pip install "hookie-ai[langchain]"    # + LangChain retriever, chat history and tools
pip install "hookie-ai[langgraph]"    # + LangGraph tool node, context and capture nodes
pip install "hookie-ai[crewai]"       # + CrewAI tools
```

Python 3.9 or later; the `[crewai]` extra needs Python 3.10 or later, as CrewAI does.
The distribution is `hookie-ai`; the import is `hookie`.

## Your key

Every call uses **your own** Hookie credential: an admin API key (`hk_…`) from
**Settings → API keys** in the console, or a connected agent's OAuth token. The key
acts as the member who created it, capped at its role and optionally one project.

```bash
export HOOKIE_API_KEY=hk_...        # never commit it
export HOOKIE_PROJECT=my-project    # optional: id or slug; "default" otherwise
```

Hookie's project routes take a project's id. A slug (`default`, the Default project's,
included) is looked up once per client with `GET /admin/api/projects`; a project-scoped
key, which may not list projects, uses the one project `GET /admin/api/me` names.
`hk.project_id()` returns the id the client resolved.

The client sends the key only as an `Authorization: Bearer` header to your Hookie
origin (HTTPS, or `http://localhost` for development). It never logs it, never puts
it in an error, and `repr(client)` leaves it out.

## The client

```python
from hookie import Hookie

with Hookie(project="my-project") as hk:          # api_key= defaults to HOOKIE_API_KEY
    ctx = hk.projects.context()                    # summary, decisions, memories, documents, issues
    hits = hk.knowledge.search("how do we deploy?", top_k=10)
    for m in hits["memories"]:  print(m["title"])
    for p in hits["passages"]:  print(p["document_name"], p["score"])
    print(hits["unavailable"])                     # parts your plan does not search, and why

    saved = hk.memories.save("Deploys", "Merging into main deploys production.", tags=["release"],
                             memory_key="deploys")  # the same key updates the same memory
    hk.memories.record_decision("Use Postgres for billing", "Replaces the D1 table; see ADR-7.")
    for m in hk.memories.iter(kind="decision"):    # every page, 100 at a time
        print(m["title"])
    hk.memories.extract(transcript_text, thread={"id": "session-42", "title": "Billing refactor"})

    doc = hk.documents.upload("adr-007.md", "# ADR 7\n...", kind="adr", source_ref="docs/adr/007.md")
    hk.documents.upload_file("spec.pdf", kind="spec")   # PDF, .docx and HTML become Markdown
    hk.documents.search("rate limits", top_k=5)          # document passages only
    text = hk.documents.content(doc["document"]["id"])
```

`AsyncHookie` has the same methods, awaited (`async for` over `iter`).

| Area | Methods | Route (`/admin/api/projects/{project}`) |
| --- | --- | --- |
| Memories | `save`, `record_decision`, `list`, `search`, `iter`, `get`, `update`, `delete`, `versions`, `restore`, `extract` | `/memories…` |
| Knowledge | `search` | `POST /brain/knowledge` |
| Documents | `upload`, `upload_file`, `list`, `iter`, `get`, `content`, `delete`, `search` | `/brain/documents…`, `POST /brain/search` |
| Projects | `context`, `list` | `GET /brain/context` |
| Workspace Brain | `brain.search` | `POST /admin/api/data-workspace/search` |
| Anything else | `request(method, path, params=, json=)` | any `/admin/api/…` route (a POST carries an `Idempotency-Key`, except on `api-keys` and `invites`, which refuse one) |

Responses are the API's JSON, unchanged (typed as `TypedDict`s in `hookie.models`).
Every POST that writes carries an `Idempotency-Key`, so a retried save runs once;
reads (GETs and the search POSTs) are retried on 5xx and burst 429s, twice by default.
A 429 whose `Retry-After` is longer than 10 s is not retried. When a retried write
meets Hookie's 409 "still in progress" (its first attempt timed out but is still
running), the client waits for the first attempt's answer, up to `timeout`; past that
the `HookieConflictError` has `reason == "idempotency_in_progress"`: ask again with the
same `idempotency_key`, never a new one.

### Errors

Every failure is a `HookieError` with `status`, `reason`, `retry_after` and `body`:
`HookieAuthError` (401/403), `HookieValidationError` (400/413/415/422),
`HookieNotFoundError` (404, also a project you cannot see), `HookieConflictError`
(409: a stale `revision`, a full allowance, capture switched off, or
`idempotency_in_progress`),
`HookieRateLimitError` (429; `.is_quota` when waiting a minute will not help),
`HookieServerError` (5xx) and `HookieNetworkError` (no answer).

## LangChain

```python
from hookie import Hookie
from hookie.integrations.langchain import HookieRetriever, HookieChatMessageHistory, create_hookie_tools

hk = Hookie(project="my-project")
retriever = HookieRetriever(client=hk, top_k=8)                 # memories + passages + graph nodes
docs_only = HookieRetriever(client=hk, search="documents")       # or "memories", "workspace"
# top_k is 1-20 in every mode. "memories" matches the query word by word (most words first).
docs = retriever.invoke("how do we deploy?")                     # Documents, metadata["source"] == "hookie"

history = HookieChatMessageHistory("session-42", client=hk, title="Billing refactor")
# ... use it with RunnableWithMessageHistory; then:
history.capture()        # Hookie proposes up to 5 memories from the conversation (#682)
history.recall("billing")

tools = create_hookie_tools(hk)   # hookie_search_knowledge, hookie_project_context,
                                  # hookie_save_memory, hookie_record_decision
```

`HookieChatMessageHistory` keeps the messages in your process. Hookie keeps
memories, not transcripts: `capture()` (and `clear()`, unless `capture_on_clear=False`)
sends the conversation to automatic memory capture, which redacts credentials before
its model reads the text and does not store the transcript. System messages and tool
output are left out of what is sent. `recall(query)` matches the query word by word.
`create_hookie_tools(async_client=...)` needs no sync client and no `HOOKIE_API_KEY`
unless a tool is then called synchronously.

## LangGraph

```python
from langgraph.graph import StateGraph, MessagesState, START
from hookie.integrations.langgraph import HookieContextNode, HookieCaptureNode, create_hookie_tool_node

graph = StateGraph(MessagesState)
graph.add_node("context", HookieContextNode(hk))        # the project's context as the FIRST message (a system message)
graph.add_node("tools", create_hookie_tool_node(hk))     # the four tools above
graph.add_node("capture", HookieCaptureNode(hk, thread_id="session-42"))
```

The context node keeps its message at the front of the history (the messages key must
use `add_messages`, as `MessagesState` does), so a model or prompt that adds its own
system message never gets two apart. The capture node sends only what the person and
the agent said: not the context, other system messages or tool output.

Hookie memories are curated notes rather than a key-value store, so there is no
`BaseStore`; keep the graph's own state in a LangGraph checkpointer.

## CrewAI

```python
from crewai import Agent
from hookie.integrations.crewai import hookie_crewai_tools

agent = Agent(role="Engineer", goal="Ship the billing fix", backstory="...",
              tools=hookie_crewai_tools(hk))   # search knowledge, project context, save memory
```

Pass `allow_writes=False` to any of the tool factories for read-only agents.

## Content is data, not instructions

Memories, documents and graph nodes are written by people and agents. The tools'
text and the context node's message start with a note saying so; keep that note
when you build your own prompts from search results.

## Tests

No network, no Hookie account: the client is tested against `httpx.MockTransport`,
and the framework tests are skipped when the framework is not installed (set
`HOOKIE_TEST_REQUIRE=langchain_core,langgraph,crewai` to make that a failure).

```bash
cd packages/python
python -m venv .venv && . .venv/bin/activate
pip install -e '.[dev]' langchain-core langgraph crewai   # frameworks optional
pytest
```

CI (`ci.Dockerfile`'s verify target) runs them with the LangChain and LangGraph extras
and `HOOKIE_TEST_REQUIRE=langchain_core,langgraph`. CrewAI's tests are skipped there;
run them (Python 3.10+) before a release.

## License

MIT
