Skip to main content

Graphmind Context Graphs — Python SDK

A "Director's Commentary" middleware for LangChain Python agents. Captures why agents make decisions, not just what they did.

Installation

pip install graphmind-context-graphs

Prerequisites

# Graphmind database
docker run -d --name graphmind -p 8080:8080 fabischk/graphmind:latest

# LangChain + provider
pip install langchain langchain-core langgraph langchain-openai

Quick Start

from langchain.agents import create_agent
from graphmind_context_graphs import (
    create_context_graph,
    ContextGraphConfig,
    EmbeddingConfig,
)

# Your embedding provider (must implement embed, embed_batch, dimensions)
embedding_provider = MyEmbeddingProvider()

# Initialize
cg = create_context_graph(ContextGraphConfig(
    tenant="my_company",
    project="support",
    agent="support-agent",
    embedding=EmbeddingConfig(provider=embedding_provider, dimensions=1536),
    observer_model="openai:gpt-4.1-mini",  # Optional: for LLM-powered extraction
))

# Create agent with middleware + brain-mapping tools
agent = create_agent(
    "openai:gpt-4.1",
    tools=[*my_tools, *cg.tools],
    middleware=cg.middleware,
)

# Use — context captured and injected automatically
result = agent.invoke({"messages": [{"role": "user", "content": "My account is locked"}]})

# Evolve knowledge
cg.lifecycle.validate_trace(trace_id, ValidationResult(trace_id=trace_id, success=True))
cg.lifecycle.synthesize_rules()

Features

  • Decision Trace Capture — Intent/Constraint/Action/Justification triplets
  • Dynamic Brain Mapping — Agents create entities (CodeFile, Contract, etc.) and relationships
  • Schema Awareness — Agent-scoped; only domain entities shown
  • LLM-Powered Extraction — Observer model extracts domain, concepts, constraints
  • Knowledge Lifecycle — Capture → Validate → Synthesize → Prune
  • Multi-Agent — Shared, isolated, or selective context sharing
  • Vector Search — Semantic similarity via Graphmind SEARCH clause

API Mirror

This SDK mirrors the TypeScript SDK. Both use the same Graphmind database and Cypher queries. Agents running in different languages can share context graphs.

TypeScript Python
createContextGraph() create_context_graph()
cg.middleware cg.middleware
cg.tools cg.tools
cg.lifecycle.validateTrace() cg.lifecycle.validate_trace()
cg.store.getSchemaOverview() cg.store.get_schema_overview()

License

Apache License 2.0

Metadata

Release files for graphmind-context-graphs 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphmind-context-graphs 0.2.0
File Size Uploaded
graphmind_context_graphs-0.2.0.tar.gz 198.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for graphmind-context-graphs 0.2.0
File Interpreter ABI Platform
graphmind_context_graphs-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 230.9 kB

Release files / graphmind_context_graphs-0.2.0.tar.gz

Download URL graphmind_context_graphs-0.2.0.tar.gz
Size 198.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1453dc5a3583a5fc5a29f053489a56cdb4648d25ed11f15568184122b8a05bdd
BLAKE2b-256 checksum
How to use checksums
5dc35e923028edad21eaf73e5cfe33cdd3a9c8771a2460c553480e1313c06e70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 30, 2026.

Transparency log

Release files / graphmind_context_graphs-0.2.0-py3-none-any.whl

Download URL graphmind_context_graphs-0.2.0-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d314db2d9332701a6f129f5a7a8397184d3581c5fb77e07a69e1b61db27b4ad
BLAKE2b-256 checksum
How to use checksums
d15417a7a435841bdbb5a8f33d9b5101add8363e2be4f4aa0cb7a688d93524eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page