Skip to main content

Python client for the MindGraph Cloud API

Project description

mindgraph

PyPI License: MIT

Python client for the MindGraph Cloud API — a structured semantic memory graph for AI agents.

Install

pip install mindgraph-sdk

Quick Start

from mindgraph import MindGraph

with MindGraph("https://api.mindgraph.cloud", api_key="mg_...") as graph:
    # Add a node
    node = graph.add_node(
        label="User prefers dark mode",
        node_type="Preference",
    )

    # Search
    results = graph.search("what does the user prefer?")

    # Connect knowledge
    graph.add_link(
        from_uid=node["uid"],
        to_uid="user_abc",
        edge_type="BelongsTo",
    )

API Reference

Constructor

MindGraph(base_url, *, api_key=None, jwt=None, timeout=30.0)

Supports context manager protocol (with statement) for automatic cleanup.

Reality Layer

Method Description
capture(**kwargs) Capture a source, snippet, or observation
entity(**kwargs) Create, alias, resolve, or merge entities
find_or_create_entity(label, props?, agent_id?) Convenience: create or find an entity by label (generic fallback)
find_or_create_person(label, props?, agent_id?) Find or create a Person entity
find_or_create_organization(label, props?, agent_id?) Find or create an Organization entity
find_or_create_nation(label, props?, agent_id?) Find or create a Nation entity
find_or_create_event(label, props?, agent_id?) Find or create an Event entity
find_or_create_place(label, props?, agent_id?) Find or create a Place entity
find_or_create_concept(label, props?, agent_id?) Find or create a Concept entity
add_claim(label, content, confidence?, agent_id?) Add a Claim node via the argument endpoint
add_evidence(label, description, agent_id?) Add an Evidence node attached to a claim
add_observation(label, description, agent_id?) Add an Observation node

Typed entity example:

person = graph.find_or_create_person("Marie Curie", props={"nationality": "Polish"})
org = graph.find_or_create_organization("CERN", props={"org_type": "intergovernmental"})
concept = graph.find_or_create_concept("Nuclear Physics")

# find_or_create_entity() still works as a generic fallback for any entity type
entity = graph.find_or_create_entity("Some Entity")

Epistemic Layer

Method Description
argue(**kwargs) Construct a full argument: claim + evidence + warrant + edges
inquire(**kwargs) Add hypothesis, theory, paradigm, anomaly, assumption, or question
structure(**kwargs) Add concept, pattern, mechanism, model, analogy, theorem, etc.

Intent Layer

Method Description
commit(**kwargs) Create a goal, project, or milestone
deliberate(**kwargs) Open decisions, add options/constraints, resolve decisions
resolve_decision(...) Resolve with optional informs_uid, as_of_date, session_id, and retrieval_trace_id linkage

Action Layer

Method Description
procedure(**kwargs) Build flows, add steps, affordances, and controls
risk(**kwargs) Assess risk or retrieve existing assessments

Memory Layer

Method Description
session(**kwargs) Open a session, record traces, or close a session
journal(label, props?, *, summary?, session_uid?, ...) Record a journal entry linked to an optional session
distill(**kwargs) Create a Summary (default) or Lesson with source provenance (output_type="lesson")
memory_config(**kwargs) Set/get preferences and memory policies

Agent Layer

Method Description
plan(**kwargs) Create tasks, plans, plan steps, update status
governance(**kwargs) Create policies, set safety budgets, request/resolve approvals
execution(**kwargs) Track execution lifecycle and register agents

Synthesis (Projects)

Scope a corpus to a Project (via commit(action="project", ...) then link documents with PartOfProject), then mine cross-document signals and generate synthesis articles.

Method Description
signals(project_uid, *, signals?, target_types?) Mine cross-document structural signals for a project
run_synthesis(project_uid) Spawn async synthesis job that turns top clusters into Article nodes; returns {"job_id": ...}
project = graph.commit(action="project", label="Q2 China strategy")
# ...link documents to the project via PartOfProject edges...
signals = graph.signals(project["uid"], signals="clustered_claim_hubs,dialectical_pairs")
job = graph.run_synthesis(project["uid"])
status = graph.get_job(job["job_id"])

Operational Ontology (Layer 7)

Define typed domain objects (Customer, Order, Contract…) as a semantic contract and either bind them to a SQL database or extract them from documents — fused onto one object. Connecting a database (credentials/sync) is done in the dashboard; the SDK proposes/reviews schemas, queries, and lists the generated agent read tools.

Method Description
propose_ontology_schema(...) Draft a schema from a description (+ optional sample docs); returns {"schema_id", "job_id"}
activate_ontology_schema(id) / get_ontology_schema(id) / list_ontology_schemas() Schema lifecycle
list_ontology_proposals(...) / approve_ontology_proposal(id) / reject_ontology_proposal(id) Review extracted-object proposals
query_ontology(query=..., schema_id=...) Typed retrieval with the cognitive overlay fused in
list_ontology_tools() The generated read-tool manifest (search_/get_/summarize_<obj>) the MCP server renders
res = graph.propose_ontology_schema(description="Clients, orders, contracts.")
graph.activate_ontology_schema(res["schema_id"])
tools = graph.list_ontology_tools()
ctx = graph.query_ontology(query="Which customers are a churn risk?", schema_id=res["schema_id"])

See the Operational Ontology and Connect a database docs.

CRUD

Method Description
get_node(uid) Get a node by UID
add_node(label, node_type?, props?, agent_id?) Add a generic node
update_node(uid, **kwargs) Update node fields
delete_node(uid) Tombstone a node and all connected edges
add_link(from_uid, to_uid, edge_type, agent_id?) Add a typed edge
get_edges(from_uid?, to_uid?) Get edges by source or target

Search

Method Description
search(query, node_type?, layer?, limit?) Full-text search
hybrid_search(query, k?, node_types?, layer?, explain?) BM25 + vector search with rank fusion; explain=True attaches per-leg contributions (legs: which legs surfaced each result, the within-leg rank the fusion used, and the leg's raw score)
merge_candidates() Pending duplicate pairs recorded by the dedup pipeline, awaiting merge/dismiss

Traversal

Method Description
reasoning_chain(uid, max_depth=5) Follow epistemic edges from a node
neighborhood(uid, max_depth=1) Get all nodes within N hops

Ingestion & Retrieval

Method Description
ingest_chunk(content, *, chunk_type?, ...) Ingest a single text chunk (sync): stores, embeds, and runs LLM extraction
ingest_document(content, *, title?, ...) Ingest a full document (async): chunks text, returns job ID
ingest_session(content, *, session_uid?, ...) Ingest a session transcript (async): links to session, returns job ID
retrieve_context(query, *, graph_expansion_limit?, graph_max_depth?, ...) Direct retrieval plus optional cheapest-first graph expansion
get_job(job_id) Get async job status and progress
clear_graph() Clear all graph data

Lifecycle Shortcuts

Method Description
tombstone(uid, reason?, agent_id?) Soft-delete a node
restore(uid, agent_id?) Restore a tombstoned node

Cross-cutting

Method Description
retrieve(**kwargs) Unified retrieval: text search, active goals, open questions, weak claims
traverse(**kwargs) Budgeted min-cost traversal; response depth is witness-path hops
evolve(**kwargs) Lifecycle mutations: update, tombstone, restore, decay, history

Health & Stats

Method Description
health() Health check
stats() Graph-wide statistics

Account sign-up, login, and API key management live in the MindGraph dashboard — not the SDK. Get your API key there, then pass it to the MindGraph constructor.

Examples

See examples/ for runnable demos, including a research continuity scenario showing cross-session memory retrieval.

Error Handling

All methods raise MindGraphError on HTTP errors:

from mindgraph import MindGraphError

try:
    graph.get_node("nonexistent")
except MindGraphError as e:
    print(e.status, e.body)

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

mindgraph_sdk-0.12.0.tar.gz (40.4 kB view details)

Uploaded Source

Built Distribution

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

mindgraph_sdk-0.12.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file mindgraph_sdk-0.12.0.tar.gz.

File metadata

  • Download URL: mindgraph_sdk-0.12.0.tar.gz
  • Upload date:
  • Size: 40.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mindgraph_sdk-0.12.0.tar.gz
Algorithm Hash digest
SHA256 cf36031cf6be556df8d17e37b233ba34eda859cbe75b6aeb57927960d2964210
MD5 d70c815ed02d6acdd708ea6f6e768a87
BLAKE2b-256 1ed389a56c7289d1852583c39a8e1b76cd2944492122ad83e8b4ab792587ea5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mindgraph_sdk-0.12.0.tar.gz:

Publisher: publish.yml on shuruheel/mindgraph-py

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

File details

Details for the file mindgraph_sdk-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: mindgraph_sdk-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mindgraph_sdk-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1693b2d75ce8614e43e1e544422b2ce9e9efb4d9b6d43debadc8fcc4d99c16e
MD5 19bde5a9dcc408f4a0d58e56b86322d2
BLAKE2b-256 1e59b9373414b1af9419a67d616e39782e73649691e0b01100f5b90057cb6d76

See more details on using hashes here.

Provenance

The following attestation bundles were made for mindgraph_sdk-0.12.0-py3-none-any.whl:

Publisher: publish.yml on shuruheel/mindgraph-py

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