The Problem
Training or fine‑tuning an existing AI agent often requires rewriting large portions of the agent code, adding custom training loops, or switching to a specific framework. Teams that already have production agents built with LangChain, AutoGen, CrewAI, or raw OpenAI calls must therefore invest significant engineering effort to experiment with reinforcement learning (RL) or prompt‑optimization techniques.
What This Does
agent-lightning provides a thin wrapper that injects a training interface around any Python‑based agent with virtually no code changes. The core logic lives in agentlightning/ – e.g., agentlightning/trainer/trainer.py orchestrates the RL loop, while agentlightning/algorithm/apo/apo.py implements the Automatic Prompt Optimization algorithm. The package discovers the agent’s run method via the generic adapter layer (adapter/base.py, adapter/messages.py).
A separate dashboard (dashboard/) built with React/TypeScript visualises traces, roll‑outs, and resource usage. The UI entry point is dashboard/src/App.tsx, compiled via the standard npm workflow defined in dashboard/package.json.
How To Use It
Setup
Python package pip install agentlightning # latest stable release Optional: install nightly build pip install --upgrade --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ --pre agentlightning
Dashboard (optional UI)
cd dashboard npm ci # uses package-lock.json npm run build # produces static assets in ./dist
Configuration
Environment variables are read by agentlightning/envvar.py (e.g., AGENTLIGHTNINGAPIKEY, AGENTLIGHTNINGDBURL). The YAML file agentlightning/verl/config.yaml holds default algorithm settings (learning rate, reward shaping). Adjustments can be made programmatically via agentlightning/config.py.
Running it
To launch the training server for a single agent:
python -m agentlightning.server \ --agent-path path/to/youragent.py \ --algorithm apo \ --config agentlightning/verl/config.yaml
The CLI entry point is defined in agentlightning/cli/init.py and agentlightning/cli/vllm.py. For a quick test of the built‑in RL loop:
python -m agentlightning.trainer.trainer \ --agent path/to/agent.py \ --episodes 100
If you want the visual dashboard, start the backend and serve the UI:
Backend
python -m agentlightning.server & UI cd dashboard && npm run dev # starts Vite dev server at http://localhost:5173
Real‑World Use
A SaaS product that offers “AI‑as‑a‑service” can wrap each customer’s LangChain agent with agentlightning. The service would:
from agentlightning.runner.agent import AgentRunner from agentlightning.trainer.trainer import Trainer
runner = AgentRunner(agentmodule="mycustomer.agent") trainer = Trainer(runner=runner, algorithm="apo") trainer.train(episodes=500)
During training, agentlightning/emitter/message.py streams step‑wise rewards to an observability backend (e.g., OpenTelemetry via tracer/otel.py), enabling live monitoring in the dashboard.
Code Health & Issues
Low – Missing type hints – many core modules (algorithm/.py, runner/.py) lack explicit type annotations, which can hinder IDE support. Medium – Limited test coverage – only 6 test files are present despite >200 source files; critical paths like store/mongo.py have no dedicated tests. Low – Hard‑coded env var names – env_var.py expects specific variables; documentation does not enumerate all required keys. Low – No explicit pyproject.toml – packaging relies on setup.cfg/setup.py (not listed), which may cause build inconsistencies across Python versions. Low – CI only runs unit tests – workflows (badge-unit.yml, tests.yml) do not enforce linting or security scanning; adding ruff or bandit would improve hygiene. Low – Dashboard build not integrated – UI build steps are manual; no CI job packages the dashboard with the Python wheel.
Overall, the repository includes a functional CI pipeline, a license file (MIT), and a pre‑commit config, indicating reasonable baseline quality.
The Bottom Line
agent-lightning delivers a practical, framework‑agnostic way to apply RL or prompt‑optimization to existing Python agents with minimal code changes. It is well‑suited for teams that already have production agents and need a rapid experimentation layer. Prospective adopters should be aware of modest test coverage and the need to manually manage the optional dashboard UI.