Learning Environment for Agent Reasoning Networks — Unified framework for specifying, composing, optimizing, and evaluating LLM-based systems
Project description
learn
Learning Environment for Agent Reasoning Networks
A unified framework for specifying, composing, optimizing, and evaluating LLM-based systems through natural language.
What is learn?
learn is PyTorch, but for text-space optimization and multi-agent systems. It unifies four research communities — workflow optimization, self-evolving agents, textual gradient descent, and agentic workflow automation — under one composable API.
| PyTorch | learn | Role |
|---|---|---|
torch.Tensor |
Variable |
Text container + computation graph node |
nn.Parameter |
Parameter |
Learnable text variable |
nn.Module |
Component / Agent |
Composable unit |
nn.Sequential |
Program |
Composition of units |
optim.SGD |
TGD |
Optimizer (textual gradient descent) |
loss.backward() |
loss.backward(engine) |
Gradient computation |
optimizer.step() |
optimizer.step() |
Parameter update |
| Training loop | Trainer |
Orchestration |
Installation
pip install learn-env
With optional engine support:
pip install learn-env[engines] # OpenAI, Anthropic, Google
pip install learn-env[memory] # ChromaDB vector memory
pip install learn-env[dev] # Development tools
Or install from source with uv:
git clone https://github.com/ngotrnghia1811/learn.git
cd learn
uv sync --extra dev
Quick Start
from learn.env.engine import MockEngine
from learn.env.program import Variable, Parameter, Program
from learn.agent import Generator
# 1. Create an engine (swap MockEngine for OpenAICompatibleEngine in production)
engine = MockEngine()
# 2. Define a learnable system prompt
system_prompt = Parameter(
value="You are a helpful assistant that answers questions concisely.",
name="system_prompt",
)
# 3. Build an agent
agent = Generator(name="qa_agent", engine=engine, prompt=system_prompt)
# 4. Run inference
question = Variable("What is textual gradient descent?", name="question")
answer = agent(question)
print(answer.value)
Training Loop
from learn.optim.txt import TGD
# Create optimizer
optimizer = TGD(parameters=[system_prompt], engine=engine)
# Training step (analogous to PyTorch)
loss = some_loss_function(prediction, target)
loss.backward(engine) # Compute textual gradients
optimizer.step() # Update parameters with natural language feedback
Architecture
learn
├── learn.env Programs, engines, management, Trainer
├── learn.agent Generator, Reviewer, Reviser, Router, Ensemble, MetaAgent...
├── learn.optim TGD, OPRO, evolutionary optimizers, weight-space (SFT/DPO/PPO)
└── learn.benchmark Tasks, scoring, evaluation protocols, statistics
Dependency Rules
These are strict and enforced:
learn.optim → depends on NOTHING
learn.benchmark → depends on NOTHING
learn.env.engine → depends on NOTHING
learn.agent → may depend on learn.optim
learn.env.program → depends on learn.env.engine + learn.agent
learn.env → orchestrates all others
Key Components
Agents — Generator, Reviewer, Reviser, Router, Ensemble, MetaAgent, Programmer, Retriever, Custom. Each agent has sub-systems for memory (8 types), tools (10+ types), reasoning (CoT, ReAct, ToT, LATS, Reflexion), and profiles.
Optimizers — Four families:
- Textual —
TGD,TSGD-M,TextBFGS,GDPO,REMO(gradient descent in text space) - Numerical —
OPRO,MIPROv2,Bootstrap,CAPO,BanditSelector - Evolutionary —
CMAESEvolution,MCTSEvolution,NoveltySearch, island models - Weight-space —
SFT,DPO,PPO,GRPO,REINFORCE
Engines — MockEngine (testing), OpenAICompatibleEngine, OpenRouterEngine, EnginePool (multi-model routing), CachedEngine, InstrumentedEngine, RetryEngine.
Programs — DAG-based composition with typed edges (DataFlow, ControlFlow, Conditional, Communication, Delegation, Feedback), shared memory, and topology presets (Complete, Star, Layered, Ring, Learned).
Benchmark — ExactMatch, TokenF1, LLMJudge, StandardProtocol, MultiRunProtocol, BootstrapCI, EffectSize.
Development
# Run tests (806 unit tests)
uv run pytest -m "not integration"
# Lint
uv run ruff check src/
# Type check
uv run mypy src/
# Format
uv run ruff format src/
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 learn_env-0.1.0.tar.gz.
File metadata
- Download URL: learn_env-0.1.0.tar.gz
- Upload date:
- Size: 174.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccfdd4dd7c88dead78f054bb6b9a5293bc09ba1b0a7b5101aad0ace67a551aaa
|
|
| MD5 |
b0caa97f1297cdef813ca6bc0cde6fe7
|
|
| BLAKE2b-256 |
50826998ebd36abdd4e2f6954684b65bad407c90ff95420c2307821add7ffa83
|
File details
Details for the file learn_env-0.1.0-py3-none-any.whl.
File metadata
- Download URL: learn_env-0.1.0-py3-none-any.whl
- Upload date:
- Size: 272.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48da1d57e8eaf7249c02eccd3f3bb7eab211f96d3def5db5b23d6b5b1602094f
|
|
| MD5 |
a119ab0008cf279bd48f804651df427b
|
|
| BLAKE2b-256 |
89c2ae4bc2413fc2a73747ead66b89f7304c7027cc8e5b0993dfa26d55dc460f
|