Skip to main content

Causal event capture for AI agents — with native PyRapide integration

Project description

iknowhy

Python SDK for iKnowhy.ai — the causal event intelligence platform.

Log events, trace causal chains, and surface constraint violations across your systems.

pip install iknowhy

Quickstart

from iknowhy import CausewayClient

client = CausewayClient(api_key="cwy_...")

# Log a causal chain: user_login → process_spawn (caused by login)
login_id = client.log("user_login", payload={"user": "alice"}, session_id="sess1")
proc_id  = client.log("process_spawn", payload={"pid": 1234}, cause_ids=[login_id])

# Query the chain
chain = client.chain(proc_id)
# [{"id": login_id, "name": "user_login", ...}, {"id": proc_id, ...}]

PyRapide Integration

iKnowhy integrates natively with PyRapide, the causal event-driven architecture library for Python by Shane Morris.

PyRapide implements RAPIDE (Rapid Prototyping for Application Domain-specific Integrated Environments), developed at Stanford University by David Luckham. It gives you first-class tools to model, execute, and analyze causal event architectures in Python with async-native execution, Pydantic events, and a composable pattern algebra.

iKnowhy's PyRapideAdapter bridges PyRapide's local causal computation into iKnowhy's persistent event log — giving you durable storage, a web dashboard, and API access to every causal chain your PyRapide architecture produces.

pip install iknowhy pyrapide

Batch mode (after engine.run())

import asyncio
from pyrapide import Engine, architecture, interface, action, module, when, Pattern, connect, get_context
from iknowhy import CausewayClient
from iknowhy.pyrapide import PyRapideAdapter

@interface
class Scanner:
    @action
    async def scan(self, target: str) -> None: ...

@interface
class Classifier:
    @action
    async def classify(self, finding: str) -> None: ...

@module(implements=Scanner)
class ScannerModule:
    async def start(self):
        ctx = get_context(self)
        ctx.generate_event("Scanner.scan", payload={"target": "192.168.1.1"})

@module(implements=Classifier)
class ClassifierModule:
    @when(Pattern.match("Scanner.scan"))
    async def on_scan(self, match):
        ctx = get_context(self)
        event = list(match.events)[0]
        ctx.generate_event("Classifier.classify",
                           payload={"finding": "open port 22"},
                           caused_by=list(match.events))

@architecture
class SecurityArch:
    scanner: Scanner
    classifier: Classifier
    def connections(self):
        return [connect(Pattern.match("Scanner.scan"), "classifier")]

async def main():
    client = CausewayClient(api_key="cwy_...")
    adapter = PyRapideAdapter(client, session_id="security-scan-001")

    arch = SecurityArch()
    engine = Engine()
    engine.bind(arch, "scanner", ScannerModule)
    engine.bind(arch, "classifier", ClassifierModule)

    comp = await engine.run(arch, timeout=5.0)

    # Upload entire computation to iKnowhy — causal links preserved
    event_ids = await adapter.flush_computation(comp)
    print(f"Logged {len(event_ids)} events to iKnowhy")

asyncio.run(main())

Streaming mode (real-time via StreamProcessor)

from pyrapide import StreamProcessor, InMemoryEventSource, Event
from iknowhy import CausewayClient
from iknowhy.pyrapide import PyRapideAdapter

async def main():
    client = CausewayClient(api_key="cwy_...")
    adapter = PyRapideAdapter(client, session_id="live-monitor")

    source = InMemoryEventSource("agent")
    processor = StreamProcessor()
    processor.add_source("agent", source)

    # Attach iKnowhy — events are logged in real time as they flow through PyRapide
    adapter.attach_stream(processor, session_id="live-monitor")

    # Send events; they'll appear in your iKnowhy dashboard immediately
    await source.put(Event(name="tool_call", payload={"tool": "browser"}))
    await source.close()
    await processor.run()

asyncio.run(main())

API Reference

CausewayClient

Method Description
log(name, payload, session_id, cause_ids, tags) Log an event, returns event_id
chain(event_id) Full causal ancestry for an event
violations() Current constraint violations
sessions() List of sessions
events(session_id, name, limit) Query events with filters

PyRapideAdapter

Method Description
flush_computation(comp, session_id, tags) Upload a completed PyRapide Computation
attach_stream(processor, session_id, tags) Hook into a live StreamProcessor
id_map() PyRapide event.id → iKnowhy event_id mapping
clear() Reset ID map between computations

Links

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

iknowhy-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

iknowhy-0.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iknowhy-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for iknowhy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4821c24d6412f3b9cf628510b63432824ba7744e2412f4447bc5329e1b715784
MD5 c1f4bf7342352eefca7694f3ee439d46
BLAKE2b-256 dcbbb1666f8c817e018be910475a12a126b2475d3649bb20b33660b84e08be3c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iknowhy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for iknowhy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1044c5b19f19c7bcbdf429651301704064c323559d1c583fe74a33260a959d3d
MD5 c242dad193411e4ca30d4ad5d3d9bcbf
BLAKE2b-256 ecb73edefa083e74aecf87c6ccb05e5a3046a3a59afbd87120f36491306f346d

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