Skip to main content

Lore SDK — inject organizational memory into any AI agent

Project description

loremem — Python SDK for Lore

Inject your company's organizational memory into any AI agent in 3 lines of code.

Lore captures every human correction of an AI output, structures it into a company knowledge graph, and feeds it back to your AI agents so they stop making the same mistakes twice.

loremem is the Python SDK for accessing Lore's Context Injection API.


Installation

# From PyPI (when published)
pip install loremem

# From GitHub (MVP — no PyPI publish required)
pip install git+https://github.com/mr-shakib/lore#subdirectory=sdk/python

Quickstart (3 minutes)

from loremem import LoreClient

client = LoreClient(
    api_key="sk-lore-xxxx",          # from POST /v1/auth/api-keys
    workspace_id="ws_yourworkspace",  # your Lore workspace ID
)

# ── Step 1: Get context before your LLM call ──────────────────────────────────

ctx = client.get_context(
    query="Draft an MSA for Acme Corp",
    tool="contract-drafting-agent",
    hints={"jurisdiction": "US", "customer_tier": "enterprise"},
    entities=["Acme Corp"],
)

# Prepend to your system prompt
system_prompt = ctx.formatted_injection + "\n\n" + YOUR_BASE_SYSTEM_PROMPT
response = openai_client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "system", "content": system_prompt}, ...],
)

# ── Step 2: Report corrections so Lore learns ─────────────────────────────────

# When a human edits the AI output:
client.report_correction(
    ai_output_id="draft_acme_msa_v1",
    summary="Changed indemnity clause from UK to US_STANDARD template",
    tool="contract-drafting-agent",
    context_tags={"customer": "Acme Corp", "document_type": "MSA"},
    actor_id="james@company.com",
)

# When a human approves the AI output without changes (positive signal):
client.report_output(
    output_id="draft_acme_msa_v2",
    tool="contract-drafting-agent",
    summary="MSA draft approved — no changes needed",
    actor_id="james@company.com",
)

After a few corrections, Lore automatically proposes rules like:

"US clients require the US_STANDARD indemnity template"

Confirm the rule once → it's injected into every future AI call automatically.


Async usage

For async agent frameworks (LangChain, CrewAI, FastAPI-based agents):

from loremem import AsyncLoreClient

client = AsyncLoreClient(api_key="sk-lore-xxxx", workspace_id="ws_acme")

ctx = await client.get_context(
    query="Route this support ticket",
    tool="support-triage-agent",
)

await client.report_correction(
    ai_output_id="ticket_001",
    summary="Re-routed from Tier 1 to Enterprise team",
    tool="support-triage-agent",
)

Never-throw guarantee

Every method in LoreClient and AsyncLoreClient is designed to never raise exceptions. If Lore is unavailable, misconfigured, or rate-limited:

  • get_context() returns an empty ContextResponse (.formatted_injection == "")
  • report_correction() and report_output() return ReportResult(accepted=False)
  • A WARNING is logged via Python's standard logging module

Lore's unavailability will never cause your AI agent to break.

import logging
logging.getLogger("loremem").setLevel(logging.WARNING)  # optional: see SDK warnings

API reference

LoreClient(api_key, workspace_id, base_url?)

Parameter Type Description
api_key str Lore API key (sk-lore-...)
workspace_id str Your workspace ID
base_url str Default: production Lore API. Set to http://localhost:8000 for local dev

get_context(query, tool, hints?, entities?, max_rules?, max_tokens?)

Returns a ContextResponse:

Field Type Description
formatted_injection str Ready-to-use string — prepend to system prompt
context_id str Unique ID for this context response
rules list[dict] Active rules that matched
entities list[dict] Entity profiles that matched
decisions list[dict] Decision records that matched
cached bool True if served from 15-min cache

report_correction(ai_output_id, summary, tool, context_tags?, actor_id?)

Call when a human edits or overrides an AI output.

report_output(output_id, tool, summary?, context_tags?, actor_id?)

Call when a human approves an AI output unchanged (positive signal).


Getting an API key

# Create a key (requires Clerk JWT from the dashboard, or bootstrap via Supabase directly)
curl -X POST https://lore-m0st.onrender.com/v1/auth/api-keys \
  -H "Authorization: Bearer <clerk_jwt>" \
  -H "Content-Type: application/json" \
  -d '{"name": "Production SDK key"}'

Local development

client = LoreClient(
    api_key="sk-lore-xxxx",
    workspace_id="ws_test",
    base_url="http://localhost:8000",  # local FastAPI server
)

License

MIT

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

loremem-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

loremem-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file loremem-0.1.0.tar.gz.

File metadata

  • Download URL: loremem-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for loremem-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b8bf7a82ccd72279b8c629bb3f0ca7b070549d335bace0ebc3cd3946d9ce735a
MD5 e16a7cc2b7092af70cbd797c6c4e92ce
BLAKE2b-256 e8a3f93e18d515d0ce02ba8e2307ebbd13b15ad85876782e4fad2528c4b9b1e2

See more details on using hashes here.

File details

Details for the file loremem-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: loremem-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for loremem-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65cbd495f5c18ea27a7f26e6e62d67ffcf40ed8e40c55e56de1fbc976f473742
MD5 d224c24a68499bcf5bc2a385dbc22584
BLAKE2b-256 603c10e41b32599a48c279de87267ff209b8c01360705af073ab13b79abed39b

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