Skip to main content

Python SDK for Korely Agents — memory for AI agents with bi-temporal typed facts.

Project description

korely-memory

The Python SDK for Korely Agents — memory for AI agents, with bi-temporal typed facts and contradiction checking built in.

A typed, zero-dependency client over the Korely REST API. Every method maps 1:1 onto an endpoint, so anything you can do with curl you can do here, and the JSON shapes in the API reference are the attribute shapes you get back. All the intelligence — embeddings, entity and typed-fact extraction, contradiction checking, bi-temporal validity — runs server-side, so your install stays small and your process stays light.

Install

pip install korely-memory

Python 3.9 or later.

Quickstart

from korely_memory import Korely

korely = Korely(api_key="kor_live_...", region="eu")
# or read the key from the environment (KORELY_API_KEY)
korely = Korely(region="eu")

# Remember — the write path extracts facts and resolves contradictions
korely.add("User prefers TypeScript with strict mode", agent_id="coding-assistant")
korely.add("Actually I switched to Rust", agent_id="coding-assistant")

# Recall — superseded facts drop out automatically
for hit in korely.search("user's preferred language", limit=5):
    print(hit.id, hit.score, hit.snippet)

# One-call, prompt-ready context for your LLM
ctx = korely.get_context(query="plan the project", user_id="dana", token_budget=800)
messages = [{"role": "system", "content": f"You are helpful.\n\n{ctx.context}"}]

Methods

Every method wraps exactly one REST endpoint.

Method Endpoint
add(content, *, agent_id=, user_id=, run_id=, metadata=) POST /v1/memories
search(query, *, user_id=, agent_id=, limit=) POST /v1/memories/search
get_all(*, user_id=, agent_id=, limit=, offset=) GET /v1/memories
get(memory_id) GET /v1/memories/:id
update(memory_id, *, content, expected_updated_at=) PATCH /v1/memories/:id
delete(memory_id) DELETE /v1/memories/:id
delete_all(*, user_id) DELETE /v1/users/:user_id/memories
get_facts(*, subject=, entity=, predicate=, predicate_family=, include_invalidated=, as_of=, …) GET /v1/facts
get_context(*, query, user_id=, agent_id=, token_budget=) GET /v1/context
batch(memories) POST /v1/batch
batch_status(job_id) GET /v1/batch/:id

Bi-temporal facts

The differentiator: typed (subject, predicate, object) facts with validity over time. Ask what was true on any date.

# Current state
facts = korely.get_facts(entity="Northwind Hosting")
print(facts[0].object)      # 50 euro per month
print(facts[0].invalid_at)  # None — active

# Point-in-time: what did we believe on June 1?
facts = korely.get_facts(entity="Northwind Hosting", as_of="2026-06-01")
print(facts[0].object)      # 40 euro per month

Scoping

Three identifiers, three levels of scope — the same everywhere (SDK, REST, MCP):

  • agent_id — your application or agent (one namespace per product surface)
  • user_id — your end user (free-form string; unlimited on every tier)
  • run_id — one session or run (sub-scope inside a user)
korely.add("Asked to be contacted on Slack", agent_id="support-bot", user_id="customer-4812")
results = korely.search("contact preference", user_id="customer-4812")

Always pass user_id on reads in multi-tenant products. Filters are additive (AND); a search without user_id spans every end user in the namespace.

Error handling

The SDK raises typed exceptions that map onto the REST error codes; all subclass KorelyError.

import time
from korely_memory import Korely, AuthenticationError, NotFoundError, QuotaExceededError

korely = Korely(api_key="kor_live_...")
try:
    memory = korely.get("mem_8f2c1a")
except AuthenticationError:
    raise                       # 401 — check or rotate the key
except NotFoundError:
    memory = None               # 404 — forgotten or never existed
except QuotaExceededError as err:
    time.sleep(err.retry_after) # 429 — back off and retry
    memory = korely.get("mem_8f2c1a")
Exception Status
AuthenticationError 401
NamespaceForbiddenError 403
NotFoundError 404
StaleWriteError 409
QuotaExceededError (.retry_after) 429
APIError other

Links

MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

korely_memory-0.1.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

korely_memory-0.1.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file korely_memory-0.1.1.tar.gz.

File metadata

  • Download URL: korely_memory-0.1.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for korely_memory-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f41f038ef526635dfc02d0a8e3c8ae6eed693da07c4eb06a0639709268f08d66
MD5 7722a7da06d499b05d364e9f121efbaa
BLAKE2b-256 abd70d220db05900a1ae83e2f4a4726d7e89ea4bd6fe89aa1beb814892ae8148

See more details on using hashes here.

File details

Details for the file korely_memory-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: korely_memory-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for korely_memory-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7bbc1b52ef741811d8452f5801a1b6f1a301e2223b3966f33aacc6478d23378f
MD5 d2e21e33103df7bd7da7d64ceabfb6f1
BLAKE2b-256 1ec170a655e251727fbdec7785d7f3111fc8439d0abb1d8cfa18f1ee54916eca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page