create-rule
Create Cursor rules for persistent AI guidance. Use when the user wants to create a rule, add coding standards, set up project…
Train and optimize AI agents using Microsoft's Agent Lightning framework with reinforcement learning. Use when setting up agent training, instrumenting agents with tracing, configuring LightningStore, implementing reward functions, or optimizing prompts with RL/APO algorithms.
Claude Code
$ npx -y skills add coco-research/coco --skill agent-lightning --agent claude-code
Codex
$ npx skills add coco-research/coco --skill agent-lightning -a codex -y
Cursor
$ npx skills add coco-research/coco --skill agent-lightning -a cursor -y
Gemini CLI
$ npx skills add coco-research/coco --skill agent-lightning -a gemini-cli -y
GitHub Copilot
$ npx skills add coco-research/coco --skill agent-lightning -a github-copilot -y
OpenCode
$ npx skills add coco-research/coco --skill agent-lightning -a opencode -y
Windsurf
$ npx skills add coco-research/coco --skill agent-lightning -a windsurf -y
name: agent-lightning description: Train and optimize AI agents using Microsoft's Agent Lightning framework with reinforcement learning. Use when setting up agent training, instrumenting agents with tracing, configuring LightningStore, implementing reward functions, or optimizing prompts with RL/APO algorithms. domain: engineering
Microsoft's framework for training AI agents with reinforcement learning, automatic prompt optimization, and supervised fine-tuning.
pip install agentlightning
For nightly builds:
pip install --upgrade --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ --pre agentlightning
Add `agl.emit_xxx()` helpers to your existing agent:
import agentlightning as agl
# Your existing agent code
def my_agent(task):
agl.emit_input(task) # Track input
response = llm.generate(task)
agl.emit_output(response) # Track output
reward = evaluate(response)
agl.emit_reward(reward) # Track reward
return responseAgent (your code) → agl.emit_xxx() → Spans → LightningStore → Algorithm → Updated Resources
| Component | Purpose | |-----------|---------| | `LightningStore` | Central hub for traces, tasks, and resources | | `Tracer` | Collects spans from agent execution | | `Algorithm` | Consumes traces, produces improvements | | `Trainer` | Orchestrates training loop |
import agentlightning as agl # Basic emissions agl.emit_input(prompt) # Track input to agent agl.emit_output(response) # Track agent output agl.emit_reward(score) # Track reward signal agl.emit_tool_call(name, args) # Track tool usage agl.emit_tool_result(result) # Track tool results
from agentlightning import Tracer
tracer = Tracer(store=store)
with tracer.trace_context(task_id="task-123"):
# All emissions within this context are grouped
result = agent.run(task)
# Retrieve trace after execution
trace = tracer.get_last_trace()Agent Lightning integrates with OpenTelemetry:
from agentlightning.utils.otel import get_tracer tracer = get_tracer() # Returns OTel tracer for "agentlightning"
from agentlightning.store.memory import InMemoryLightningStore store = InMemoryLightningStore()
from agentlightning.store.client_server import (
LightningStoreServer,
LightningStoreClient
)
# Server side
server = LightningStoreServer(store, host="0.0.0.0", port=8080)
await server.start()
# Client side
client = LightningStoreClient("http://localhost:8080")# Add rollouts (tasks for the agent) await store.enqueue_rollout(task=task, config=RolloutConfig()) # Query rollouts rollouts = await store.query_rollouts(status_in=["completed"]) # Add resources (updated prompts, weights) await store.add_resources(resources) # Get latest resources resources = await store.get_latest_resources()
import agentlightning as agl
trainer = agl.Trainer(
n_runners=8, # Parallel rollout workers
algorithm=algorithm, # Your chosen algorithm
store=store # Optional, creates InMemory if not provided
)
trainer.run()from agentlightning import LightningStore
from agentlightning.types import ExecutionEvent
async def my_algorithm(store: LightningStore, event: ExecutionEvent):
# Fetch completed rollouts
rollouts = await store.query_rollouts(status_in=["completed"])
# Process traces, compute gradients, etc.
new_resources = optimize(rollouts)
# Push updated resources
await store.add_resources(new_resources)async def my_runner(store: LightningStore, worker_id: int, event: ExecutionEvent):
while not event.is_set():
rollout = await store.dequeue_rollout()
if rollout:
result = execute_task(rollout.task)
await store.update_rollout(
rollout_id=rollout.id,
status="completed",
result=result
)For RL training with vLLM backend:
from agentlightning.algorithm.verl import VeRLAlgorithm
algorithm = VeRLAlgorithm(
model="your-model",
learning_rate=1e-5,
batch_size=32
)from agentlightning.algorithm.apo import APOAlgorithm
algorithm = APOAlgorithm(
optimizer_model="gpt-4",
target_model="gpt-3.5-turbo"
)from agentlightning.instrumentation.langchain import instrument_langchain instrument_langchain() # Auto-traces all LangChain calls
from agentlightning.instrumentation.openai import instrument_openai instrument_openai() # Auto-traces OpenAI API calls
from agentlightning.instrumentation.vllm import instrument_vllm instrument_vllm() # Instrument vLLM for token-level tracing
from agentlightning import setup_logging
setup_logging(
level="DEBUG",
submodule_levels={
"agentlightning.store": "INFO",
"agentlightning.tracer": "DEBUG"
}
)Agent Lightning emits Prometheus-compatible metrics:
495 personas across 13 departments, 229 skills[^installed] and 388 commands in the full catalog (coco 1.9.0, 2026-10-21). Agent skills, slash commands and subagents for Claude Code, Cursor, Codex and other AI coding agents.
Create Cursor rules for persistent AI guidance. Use when the user wants to create a rule, add coding standards, set up project…
Guides users through creating effective Agent Skills for Cursor. Use when the user wants to create, write, or author a new skill,…
Create custom subagents for specialized AI tasks. Use when the user wants to create a new type of subagent, set up task-specific…
Convert 'Applied intelligently' Cursor rules (.cursor/rules/*.mdc) and slash commands (.cursor/commands/*.md) to Agent Skills…
Modify Cursor/VSCode user settings in settings.json. Use when the user wants to change editor settings, preferences,…
Post-run self-evaluation system that scores agent output on correctness, clarity, actionability, and conciseness. Use after /team…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.