Lár: The PyTorch for Agents. A 'define-by-run' agentic framework.
Project description
Lár: The PyTorch for Agents
Lár by SnathAI™ (Irish for "core" or "center") is an open source "define-by-run" agentic framework for building auditable and reliable AI systems.
It is engineered as a robust alternative to static, "black box" frameworks, which obscure logic, inhibit debugging, and fail unpredictably. Lár implements a "glass box" architecture, inspired by the dynamic graphs of PyTorch, where every step of an agent's reasoning process is explicit, inspectable, and logged by default.
This framework provides a deterministic, stateful, and node-based system for orchestrating complex agentic behavior, including self-correction, dynamic branching, and tool-use loops.
Core Philosophy: "Glass Box" vs. "Black Box"
The primary challenge in production-grade AI is a lack of traceability. When a multi-step agent fails, it's often impossible to determine why.
-
The "Black Box" (Other Frameworks): Relies on a "magic"
AgentExecutorthat tries to do everything at once. When this magic fails, it's a complex black box that is nearly impossible to debug. -
The "Glass Box" (Lár): Lár is, by design, a simple, explicit loop. The
GraphExecutorruns one node at a time, logs the exact state change, and then pauses.
This "define-by-run" approach transforms debugging from an art into a science. You can visually trace the execution, inspect the diff of the state at every transition, and pinpoint the exact node where logic failed. Lár's "flight data recorder" (history) isn't an add-on; it's the core output of the engine.
Key Features
-
Define-by-Run Architecture: The execution graph is created dynamically, step-by-step. This naturally enables complex, stateful logic like loops and self-correction.
-
Total Auditability: The
GraphExecutorproduces a complete, step-by-step history of every node executed, the state before the run, and the state after. -
Deterministic Logic: Replace "prompt-chaining" with explicit, testable Python code. Use the
RouterNodefor clear, auditable "if/else" branching. -
Testable Units: Every node is a standalone class. You can unit test your
ToolNode(your "hands") and yourRouterNode(your "logic") completely independently of an LLM call. -
Snath™Visualizer: A built-in Streamlit app (snath_app.py) that provides a live, step-by-step, interactive debugger for your agents.
Installation
This project is managed with Poetry.
-
Clone the repository:
git clone https://github.com/snath-ai/lar.git cd lar
-
Install dependencies: This command creates a virtual environment and installs all packages from
pyproject.toml.poetry install
Quick Start: The Snath™ Visualizer
The best way to understand lar is to use the interactive Snath debugger.
-
Set your API key: Create a
.envfile in the project root.# .env GOOGLE_API_KEY='YOUR_API_KEY_HERE' -
Run the app:
poetry run streamlit run snath_app.py
This app allows you to execute a self-correcting agent step-by-step. At each step, it renders the graph's current state and provides a "diff" of the GraphState, showing exactly what was added, removed, or modified by the last node.
The Lár Architecture: Core Primitives
You can build any agent with four core components:
-
GraphState: A simple, unified object that holds the "memory" of the agent. It is passed to every node, allowing one node to write data (state.set(...)) and the next to read it (state.get(...)). -
BaseNode: The abstract class (the "contract") for all executable units. It enforces a single method:execute(self, state). Theexecutemethod's sole responsibility is to perform its logic and return the nextBaseNodeto run, orNoneto terminate the graph. -
GraphExecutor: The "engine" that runs the graph. It is a Python generator that runs one node, yields the execution log for that step, and then pauses, waiting for the next call. -
Node Implementations: The "building blocks" of your agent.
LLMNode: The "Thinker." Calls an LLM (e.g., Gemini) to generate text, modify plans, or correct code.ToolNode: The "Actor." Executes any deterministic Python function (e.g., run code, search a database, call an API). It supports separate routing forsuccessanderror.RouterNode: The "Choice." Executes a simple Python function to inspect the state and returns a string key, which deterministically routes execution to the next node. This is your "if/else" statement.ClearErrorNode: A utility node that cleans up state (e.g., removeslast_error) to prevent infinite loops.
Example: A Self-Correcting Agent
The following graph defines an agent that writes, tests, and debugs its own code. This kind of stateful loop is trivial in lar but extremely complex in a linear-chain framework.
This agent will:
- Write Code (using
LLMNode) - Test Code (using
ToolNode) - Judge Result (using
RouterNode) - If the test fails, it loops back to an
LLMNode(the "Corrector") with the error message, clears the error, and tries again.
Graph Architecture
Building the Graph
from lar import *
# 1. Define the tools and logic
def run_generated_code(code_string: str) -> str:
# ... (executes code, raises ValueError on logic error)
pass
def judge_function(state: GraphState) -> str:
# ... (checks state for "last_error", returns "failure" or "success")
pass
# 2. Define the agent's nodes
success_node = AddValueNode(key="final_status", value="SUCCESS", next_node=None)
tester_node = ToolNode(tool_function=run_generated_code, ...)
clear_error_node = ClearErrorNode(next_node=tester_node)
corrector_node = LLMNode(
prompt_template="Fix this code: {code_string}. Error: {last_error}",
output_key="code_string",
next_node=clear_error_node
)
judge_node = RouterNode(
decision_function=judge_function,
path_map={"success": success_node, "failure": corrector_node}
)
# Set the tester node's paths
tester_node.next_node = judge_node
tester_node.error_node = judge_node
Project Vision: lar & Snath™
This project follows a professional Open-Core model.
-
lar(The Core Engine): This repository. Thelarlibrary is, and always will be, free and open-source (MIT License). It is the core framework for building and running agents. -
Snath™(The Commercial Platform): The future commercial, managed platform for teams and enterprises, available atsnath.ai.Snath™will provide a hosted, collaborative environment for deploying, managing, monitoring, and debugginglar-based agents at scale. Thesnath_app.pyin this repo is the first prototype of this platform.
Contributing
We welcome contributions to lar. Please open an issue or submit a pull request for any bugs, features, or documentation improvements.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lar_engine-0.1.1.tar.gz.
File metadata
- Download URL: lar_engine-0.1.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.9 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95a637689a53b8d79e2b07b5bc949a51a0681f4818f74b62db9387e639079a5b
|
|
| MD5 |
f147a103f0c0164a1fb3553b4aaa0422
|
|
| BLAKE2b-256 |
bffb318f07e01c10e551c0da48fec5a7ba57cb9584b62196c677616c76d1fdee
|
File details
Details for the file lar_engine-0.1.1-py3-none-any.whl.
File metadata
- Download URL: lar_engine-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.9 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1bfe17314bd28f29bd6be909ee43e71b1ed527fdce72bf2e286049d33fb98fd
|
|
| MD5 |
7074f256b0cdf5b6311b9d565ad9b8ff
|
|
| BLAKE2b-256 |
19f610ce800d31de3c5b6bb855b368d5f38e586e01c993017b480e87a2c58244
|