AI Agent Integration Guide

AI Agent Integration
Runtime Cognition for Autonomous Agents

Compact IR graphs, session continuity via Kaalka v5, and deterministic hash verification for every tool call.

Why AI Agents Need WebWeaveX

📈

Compact IR Graphs

500KB HTML blobs become 15KB structured IR graphs for LLM context windows.

🔐

Session Continuity

Persists authenticated state across tool calls without re-authenticating.

Deterministic Hashes

SHA-256 state digests verify action success with mathematical certainty.

🔄

Replay Proofs

Verify topological equivalence between before/after states.

🛡️

Sandbox Execution

Only allowlisted transitions are executed. No arbitrary code eval.

🌐

Cross-Language

Same output whether calling Python, JS, Dart, Java, or Kotlin.

Universal Agent Workflow Cycle

flowchart TD
    A[1. Ingest & Extract] --> B[2. Cognize IR Graph]
    B --> C[3. Execute Action]
    C --> D[4. Verify Hash]
    D -->|Match| E[5. Advance Tick]
    D -->|Mismatch| F[6. Alert & Rollback]

Recommended System Prompt

system_prompt.md
You are an autonomous operational software agent powered by WebWeaveX.
When interacting with target applications:

1. Always parse inputs via `run_canonical_pipeline(UniversalInput(...))`.
2. Inspect `graph.nodes` and `fingerprint` to locate interactive elements.
3. Pass `encrypted_session` in subsequent calls to maintain state.
4. Compare `pipeline_hash` before and after execution to verify transitions.
5. Only execute allowlisted state transitions.
6. If hash diverges, halt and report the anomaly.

LangChain Integration Recipe

webweavex_tool.py
from langchain.tools import tool
from webweavex import UniversalInput, run_canonical_pipeline

@tool
def inspect_runtime_surface(url: str, session_token: str = None) -> dict:
    """Inspect a web app's runtime surface."""
    input_data = UniversalInput(
        source=url,
        source_type="web",
        session={"auth_token": session_token} if session_token else None
    )
    result = run_canonical_pipeline(input_data)
    return {
        "pipeline_hash": result.pipeline_hash,
        "node_count": len(result.graph.nodes),
        "nodes": [n.node_id for n in result.graph.nodes[:20]],
        "encrypted_session": result.encrypted_session
    }

Tool Calling Pattern

agent_loop.py
from webweavex import UniversalInput, run_canonical_pipeline

# Initial extraction
initial = run_canonical_pipeline(UniversalInput(
    source="https://app.example.com",
    source_type="web",
    session={"auth_token": "user_token_abc"}
))
baseline_hash = initial.pipeline_hash

# Agent performs actions...

# Re-extract and verify
after = run_canonical_pipeline(UniversalInput(
    source="https://app.example.com",
    source_type="web",
    session={"auth_token": "user_token_abc"},
    previous_session=initial.encrypted_session
))

if after.pipeline_hash != baseline_hash:
    print(f"State changed: {baseline_hash[:16]} -> {after.pipeline_hash[:16]}")