Skip to main content

Director's Commentary middleware for AI agents — captures decision traces, builds dynamic brain maps, and evolves institutional wisdom

Project description

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

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

graphmind_context_graphs-0.2.0.tar.gz (198.9 kB view details)

Uploaded Source

Built Distribution

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

graphmind_context_graphs-0.2.0-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file graphmind_context_graphs-0.2.0.tar.gz.

File metadata

  • Download URL: graphmind_context_graphs-0.2.0.tar.gz
  • Upload date:
  • Size: 198.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for graphmind_context_graphs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1453dc5a3583a5fc5a29f053489a56cdb4648d25ed11f15568184122b8a05bdd
MD5 7b5d0d3cd9df1d6ef0951c0f44d62e65
BLAKE2b-256 5dc35e923028edad21eaf73e5cfe33cdd3a9c8771a2460c553480e1313c06e70

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphmind_context_graphs-0.2.0.tar.gz:

Publisher: publish-pypi.yml on fab679/graphmind-context-graphs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file graphmind_context_graphs-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for graphmind_context_graphs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d314db2d9332701a6f129f5a7a8397184d3581c5fb77e07a69e1b61db27b4ad
MD5 633b834b05577c1d23f1eb37f13b5c7a
BLAKE2b-256 d15417a7a435841bdbb5a8f33d9b5101add8363e2be4f4aa0cb7a688d93524eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphmind_context_graphs-0.2.0-py3-none-any.whl:

Publisher: publish-pypi.yml on fab679/graphmind-context-graphs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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