Skip to main content

Python client for cntxgraph-core

Project description

cntxgraph-client

Python client for cntxgraph-core.

Install

pip install cntxgraph-client

Quickstart

Agent loop (without MCP)

from cntxgraph_client import AsyncCntxgraphClient, StackTraceEntry

sg = AsyncCntxgraphClient(url="http://localhost:8000")

# Traverse the knowledge hierarchy
result = await sg.think.query("how do we handle NDA renewals?")
print(result.node_path)           # e.g. ["Sales", "Enterprise"]
print(result.skills_activated)    # list of Skill objects

# Record reference resolution (use_reference equivalent)
await sg.stack_traces.append_entry(
    result.stack_trace_id,
    StackTraceEntry(depth=-1, node="Renewal Script", decision="activate", rationale="Resolved reference"),
)

# Submit new knowledge, linked back to this traversal
await sg.queue.submit(
    summary="NDAs over $500k require legal sign-off",
    processes=[{"name": "NDA Review", "description": "Review process for high-value NDAs"}],
    stack_trace_id=result.stack_trace_id,
    agent_id="my-agent-v1",
)

Approver workflow

from cntxgraph_client import CntxgraphClient, CntxgraphNotFoundError

with CntxgraphClient(url="http://localhost:8000") as sg:
    try:
        plan = sg.plans.pending()
        print(f"Plan {plan.id}: {len(plan.operations)} operations")
        approved = sg.plans.approve(plan.id)
        print(f"Applied: {approved.status}")
    except CntxgraphNotFoundError:
        print("No plan pending review")

Resources

Resource Methods
client.think query(prompt)
client.queue submit(summary, processes, raw_transcript?, stack_trace_id?, agent_id?), status(), flush()
client.plans list(status?), get(id), pending(), approve(id), defer(id), defer_submission(plan_id, sub_id), rollback(id), delete(id)
client.nodes get(node_id, include?), subtree(node_id?, depth?), children(node_id)
client.stack_traces get(trace_id), append_entry(trace_id, entry)

Both CntxgraphClient (sync) and AsyncCntxgraphClient (async) provide identical resources.

Error handling

from cntxgraph_client import CntxgraphNotFoundError, CntxgraphServerError

try:
    plan = sg.plans.get("bad-id")
except CntxgraphNotFoundError as e:
    print(e.status_code, e.request_url)
except CntxgraphServerError as e:
    print(e.raw_body)

Development

pip install -e ".[dev]"
python -m pytest
ruff check cntxgraph_client/ tests/

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

cntxgraph_client-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

cntxgraph_client-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cntxgraph_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aaa0e75918d2f9b18f450eced15e19031a97abc51c3adc13bf79ab288cecc1a5
MD5 43e2b7b87f22f01accaaabbe71a12aff
BLAKE2b-256 8d69c33b1d31b4dba665ef036b6b86c88eaac79defecf470ca650de7b168d5a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cntxgraph_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40fae3c6130fea33accde5d0d57f6ec350e23d1b47f36ef3a47acca6bccb3474
MD5 79f082d78c4127ee168aabb37afeacf4
BLAKE2b-256 17a7c8ef9836c26aebf242ffef7979532c45158ac56e2d81cd9ba1f23e53ec20

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