Skip to main content

Agentic Knowledge Graph โ€” solve Context Bloat in multi-agent LLM pipelines using an Atomic Dual-Brain Paradigm with zero-loss reasoning.

Project description

๐Ÿง  AKG-Local

Agentic Knowledge Graph โ€” Solve Context Bloat in multi-agent LLM pipelines using an Atomic Dual-Brain Paradigm with zero-loss reasoning.

PyPI version License: MIT Python 3.10+


The Problem

In multi-agent LLM pipelines (PM โ†’ Dev โ†’ QA), every agent exchange bloats the context window with redundant information. Agent B re-reads everything Agent A already sent. Modify one function upstream and downstream agents silently break โ€” logic fragmentation.

The Solution: Dual-Brain Paradigm

AKG-Local shatters every document into atomic nodes and uses two graph "brains":

Brain Technology Purpose
The Library (Brain 1) Neo4j Stores raw text nodes + DEPENDS_ON relationships
The Ledger (Brain 2) NetworkX In-memory HAS_READ tracking โ€” who knows what

The Epistemic Router sits between agents: it diffs what the receiver already knows against what they need, and injects only the delta โ€” keeping context windows flat and minimal.

When an upstream node changes, Blast Radius Invalidation traverses dependencies, forces agents to "forget" impacted nodes, and the router automatically re-injects them on the next turn.


Installation

pip install akg-local

Prerequisites

A running Neo4j instance:

docker run -d \
  -p 7687:7687 \
  -p 7474:7474 \
  -e NEO4J_AUTH=neo4j/password \
  neo4j

Quick Start

from akg_local import AKGLibrary

# Connect to Neo4j
akg = AKGLibrary(
    neo4j_uri="bolt://localhost:7687",
    auth=("neo4j", "password"),
)

# Create pipeline state with agents
state = akg.create_state(agents=["pm", "dev", "qa"])

# Ingest a Python file โ†’ atomic nodes (functions, classes, imports)
nodes = akg.ingest_file("main.py", state=state)
print(f"Shattered into {len(nodes)} atomic nodes")

# Route knowledge to an agent (zero-loss diffing)
result = akg.route(
    state,
    sender="pm",
    receiver="dev",
    target_nodes=[n.id for n in nodes],
    task_instructions="Implement the helper function.",
)
# result["messages"] contains ONLY the nodes "dev" hasn't seen yet

# Second call โ†’ dev already knows everything โ†’ empty injection
result2 = akg.route(
    state,
    sender="pm",
    receiver="dev",
    target_nodes=[n.id for n in nodes],
)
assert result2["messages"] == []  # Zero redundancy!

# Modify a node โ†’ blast radius invalidation
akg.invalidate("fn_main", state, new_text="def main():\n    print('v2')")
# All downstream dependents are now "forgotten" by every agent
# The router will auto-re-inject them on the next routing pass

akg.close()

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    LangGraph Pipeline                โ”‚
โ”‚                                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚  โ”‚ PM  โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Epistemic Router โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Dev โ”‚      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ”‚                       โ”‚                              โ”‚
โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”‚
โ”‚              โ”‚   Delta Diff    โ”‚                    โ”‚
โ”‚              โ”‚ "What does Dev  โ”‚                    โ”‚
โ”‚              โ”‚  NOT know yet?" โ”‚                    โ”‚
โ”‚              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ”‚
โ”‚                       โ”‚                              โ”‚
โ”‚         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚
โ”‚         โ–ผ                            โ–ผ              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚  โ”‚  Brain 1    โ”‚          โ”‚   Brain 2    โ”‚         โ”‚
โ”‚  โ”‚  Neo4j      โ”‚          โ”‚   NetworkX   โ”‚         โ”‚
โ”‚  โ”‚  (Reality)  โ”‚          โ”‚  (Epistemic) โ”‚         โ”‚
โ”‚  โ”‚             โ”‚          โ”‚              โ”‚         โ”‚
โ”‚  โ”‚ Nodes +     โ”‚โ—€โ”€blastโ”€โ”€โ”‚ HAS_READ     โ”‚         โ”‚
โ”‚  โ”‚ DEPENDS_ON  โ”‚ radius  โ”‚ edges        โ”‚         โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Concepts

Atomic Granularity

No more document passing. Every artifact is shattered into atomic nodes:

  • A Python file โ†’ Function nodes, Class nodes, Import nodes
  • A requirements doc โ†’ Paragraph nodes
  • Custom text โ†’ Block nodes

Epistemic Router

from akg_local import ledger_router_node

# Drop this into your LangGraph StateGraph as a node
graph.add_node("router", ledger_router_node)

Blast Radius Invalidation

from akg_local import calculate_blast_radius_and_reset

# When fn_helper changes, find all downstream dependents and
# force every agent to forget them
state = calculate_blast_radius_and_reset(
    "fn_helper", state, library_graph
)

Agent Tools

# Give agents autonomous graph access
tools = akg.create_tools(state)
# Returns: [query_library, list_dependencies, list_dependents, update_node]

API Reference

AKGLibrary (Facade)

Method Description
create_state(agents, vault) Create a fresh AKGState
ingest_file(filepath, state) Shatter a file into atomic nodes
ingest_text(text, source_name, state) Ingest raw text
route(state, sender, receiver, target_nodes) Zero-loss epistemic routing
invalidate(node_id, state, new_text) Blast radius invalidation
create_tools(state) Get LangChain tools for agents

AKGConfig

Factory Description
AKGConfig.from_env() Build from AKG_NEO4J_* env vars
AKGConfig.from_dict(d) Build from a dictionary

Ingesters

Class Handles
PythonIngester .py files via AST
TextIngester .txt, .md, .rst by paragraphs

Environment Variables

Variable Default Description
AKG_NEO4J_URI bolt://localhost:7687 Neo4j Bolt URI
AKG_NEO4J_USER neo4j Neo4j username
AKG_NEO4J_PASSWORD password Neo4j password
AKG_BLAST_DEPTH 3 Max hops for blast radius
AKG_NEO4J_DATABASE (default) Neo4j database name

Development

# Clone
git clone https://github.com/mashhoodsiddiqui/akg-local.git
cd akg-local

# Install with dev deps
pip install -e ".[dev]"

# Run tests
pytest

# Lint
ruff check akg_local/

# Type check
mypy akg_local/

License

MIT โ€” see LICENSE.

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

akg_local-0.1.0.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

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

akg_local-0.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for akg_local-0.1.0.tar.gz
Algorithm Hash digest
SHA256 808d36b117c2f1ebad7c5f1b61338b424c4d2a88f9da35b6a0b3eff0a5b33219
MD5 feb93279fe6f83c9ab5cd2b412768c47
BLAKE2b-256 df7dd9e083dae36d74e276a2fcd68fee06fc21ed4058a7c5dc6b17951e32f87e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: akg_local-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for akg_local-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f6ef119bea72603d80ed8099abe494b2535ff1f944f10338b12d4ee661a5bd9
MD5 fb50a9efed03b185d116baefabbcefcd
BLAKE2b-256 f445d52c47e83a6cd8dd9a5719d945b7291471925c34792629badf9839dc3210

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