{"id":"48a80053-4afd-474c-ae96-14238befd601","shortId":"3wHDZG","kind":"skill","title":"agent-lightning","tagline":"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.","description":"# Agent Lightning\n\nMicrosoft's framework for training AI agents with reinforcement learning, automatic prompt optimization, and supervised fine-tuning.\n\n## Quick Start\n\n### Installation\n\n```bash\npip install agentlightning\n```\n\nFor nightly builds:\n```bash\npip install --upgrade --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ --pre agentlightning\n```\n\n### Minimal Integration (Zero Code Change)\n\nAdd `agl.emit_xxx()` helpers to your existing agent:\n\n```python\nimport agentlightning as agl\n\n# Your existing agent code\ndef my_agent(task):\n    agl.emit_input(task)  # Track input\n    \n    response = llm.generate(task)\n    agl.emit_output(response)  # Track output\n    \n    reward = evaluate(response)\n    agl.emit_reward(reward)  # Track reward\n    \n    return response\n```\n\n## Core Concepts\n\n### Architecture Flow\n\n```\nAgent (your code) → agl.emit_xxx() → Spans → LightningStore → Algorithm → Updated Resources\n```\n\n### Key Components\n\n| Component | Purpose |\n|-----------|---------|\n| `LightningStore` | Central hub for traces, tasks, and resources |\n| `Tracer` | Collects spans from agent execution |\n| `Algorithm` | Consumes traces, produces improvements |\n| `Trainer` | Orchestrates training loop |\n\n## Instrumentation\n\n### Emit Functions\n\n```python\nimport agentlightning as agl\n\n# Basic emissions\nagl.emit_input(prompt)           # Track input to agent\nagl.emit_output(response)        # Track agent output\nagl.emit_reward(score)           # Track reward signal\nagl.emit_tool_call(name, args)   # Track tool usage\nagl.emit_tool_result(result)     # Track tool results\n```\n\n### Tracer Context\n\n```python\nfrom agentlightning import Tracer\n\ntracer = Tracer(store=store)\n\nwith tracer.trace_context(task_id=\"task-123\"):\n    # All emissions within this context are grouped\n    result = agent.run(task)\n    \n# Retrieve trace after execution\ntrace = tracer.get_last_trace()\n```\n\n### OpenTelemetry Integration\n\nAgent Lightning integrates with OpenTelemetry:\n\n```python\nfrom agentlightning.utils.otel import get_tracer\n\ntracer = get_tracer()  # Returns OTel tracer for \"agentlightning\"\n```\n\n## LightningStore\n\n### In-Memory Store (Development)\n\n```python\nfrom agentlightning.store.memory import InMemoryLightningStore\n\nstore = InMemoryLightningStore()\n```\n\n### Client-Server Store (Production)\n\n```python\nfrom agentlightning.store.client_server import (\n    LightningStoreServer,\n    LightningStoreClient\n)\n\n# Server side\nserver = LightningStoreServer(store, host=\"0.0.0.0\", port=8080)\nawait server.start()\n\n# Client side\nclient = LightningStoreClient(\"http://localhost:8080\")\n```\n\n### Store Operations\n\n```python\n# Add rollouts (tasks for the agent)\nawait store.enqueue_rollout(task=task, config=RolloutConfig())\n\n# Query rollouts\nrollouts = await store.query_rollouts(status_in=[\"completed\"])\n\n# Add resources (updated prompts, weights)\nawait store.add_resources(resources)\n\n# Get latest resources\nresources = await store.get_latest_resources()\n```\n\n## Training\n\n### Basic Trainer Setup\n\n```python\nimport agentlightning as agl\n\ntrainer = agl.Trainer(\n    n_runners=8,           # Parallel rollout workers\n    algorithm=algorithm,   # Your chosen algorithm\n    store=store           # Optional, creates InMemory if not provided\n)\n\ntrainer.run()\n```\n\n### Custom Algorithm\n\n```python\nfrom agentlightning import LightningStore\nfrom agentlightning.types import ExecutionEvent\n\nasync def my_algorithm(store: LightningStore, event: ExecutionEvent):\n    # Fetch completed rollouts\n    rollouts = await store.query_rollouts(status_in=[\"completed\"])\n    \n    # Process traces, compute gradients, etc.\n    new_resources = optimize(rollouts)\n    \n    # Push updated resources\n    await store.add_resources(new_resources)\n```\n\n### Runner Function\n\n```python\nasync def my_runner(store: LightningStore, worker_id: int, event: ExecutionEvent):\n    while not event.is_set():\n        rollout = await store.dequeue_rollout()\n        if rollout:\n            result = execute_task(rollout.task)\n            await store.update_rollout(\n                rollout_id=rollout.id,\n                status=\"completed\",\n                result=result\n            )\n```\n\n## Algorithms\n\n### Reinforcement Learning (GRPO/PPO)\n\nFor RL training with vLLM backend:\n\n```python\nfrom agentlightning.algorithm.verl import VeRLAlgorithm\n\nalgorithm = VeRLAlgorithm(\n    model=\"your-model\",\n    learning_rate=1e-5,\n    batch_size=32\n)\n```\n\n### Automatic Prompt Optimization (APO)\n\n```python\nfrom agentlightning.algorithm.apo import APOAlgorithm\n\nalgorithm = APOAlgorithm(\n    optimizer_model=\"gpt-4\",\n    target_model=\"gpt-3.5-turbo\"\n)\n```\n\n## Framework Adapters\n\n### LangChain\n\n```python\nfrom agentlightning.instrumentation.langchain import instrument_langchain\n\ninstrument_langchain()  # Auto-traces all LangChain calls\n```\n\n### OpenAI SDK\n\n```python\nfrom agentlightning.instrumentation.openai import instrument_openai\n\ninstrument_openai()  # Auto-traces OpenAI API calls\n```\n\n### vLLM\n\n```python\nfrom agentlightning.instrumentation.vllm import instrument_vllm\n\ninstrument_vllm()  # Instrument vLLM for token-level tracing\n```\n\n## Logging & Debugging\n\n### Configure Logging\n\n```python\nfrom agentlightning import setup_logging\n\nsetup_logging(\n    level=\"DEBUG\",\n    submodule_levels={\n        \"agentlightning.store\": \"INFO\",\n        \"agentlightning.tracer\": \"DEBUG\"\n    }\n)\n```\n\n### Metrics\n\nAgent Lightning emits Prometheus-compatible metrics:\n\n- `agl.store.total` - Store operation counts\n- `agl.store.latency` - Store operation latencies\n- `agl.rollouts.total` - Rollout counts by status\n- `agl.rollouts.duration` - Rollout execution times\n\n## Common Patterns\n\n### Reward Function Design\n\n```python\ndef compute_reward(task, response):\n    \"\"\"Good rewards are: normalized, dense when possible, aligned with goals.\"\"\"\n    \n    correctness = check_correctness(task, response)  # 0-1\n    efficiency = measure_efficiency(response)         # 0-1\n    \n    return 0.7 * correctness + 0.3 * efficiency\n```\n\n### Multi-Agent Training\n\nTrain specific agents in a multi-agent system:\n\n```python\nwith tracer.trace_context(agent_id=\"planner\"):\n    plan = planner.run(task)\n\nwith tracer.trace_context(agent_id=\"executor\"):\n    result = executor.run(plan)\n    \n# Only the executor's traces are used for training\n```\n\n### Checkpoint & Resume\n\n```python\n# Save checkpoint\nawait store.add_resources(\n    checkpoint=True,\n    resources=current_resources\n)\n\n# Load latest\nresources = await store.get_latest_resources()\n```\n\n## Integration with JavaScript Agents\n\nFor JavaScript/TypeScript agents (like Claude-based apps), you have two options:\n\n### Option 1: Python Training Service\n\nCreate a Python microservice that:\n1. Receives trace events from your JS app via HTTP\n2. Stores them in LightningStore\n3. Runs training algorithms\n4. Returns optimized prompts\n\n### Option 2: REST API Integration\n\nUse `LightningStoreServer` as a REST backend:\n\n```javascript\n// JavaScript client\nconst response = await fetch('http://localhost:8080/rollouts', {\n    method: 'POST',\n    body: JSON.stringify({\n        task: { prompt: userMessage },\n        config: { max_retries: 3 }\n    })\n});\n```\n\n## Resources\n\n- [Documentation](https://microsoft.github.io/agent-lightning/)\n- [GitHub](https://github.com/microsoft/agent-lightning)\n- [arXiv Paper](https://arxiv.org/abs/2508.03680)\n- [Discord Community](https://discord.gg/RYk7CdvDR7)\n\n## Troubleshooting\n\n| Issue | Solution |\n|-------|----------|\n| Import errors | Ensure `pip install agentlightning` succeeded |\n| Store connection failed | Check server is running, verify endpoint URL |\n| No traces collected | Verify `emit_xxx()` calls are within trace context |\n| Training not converging | Check reward function normalization, increase rollouts |","tags":["agent","lightning","coco","rkz91","agent-skills","agents-md","ai-agents","claude-code","codex","cursor","developer-tools","llm-tools"],"capabilities":["skill","source-rkz91","skill-agent-lightning","topic-agent-skills","topic-agents-md","topic-ai-agents","topic-claude-code","topic-codex","topic-cursor","topic-developer-tools","topic-llm-tools","topic-mcp","topic-pm-tools","topic-product-management","topic-productivity"],"categories":["coco"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/rkz91/coco/agent-lightning","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add rkz91/coco","source_repo":"https://github.com/rkz91/coco","install_from":"skills.sh"}},"qualityScore":"0.453","qualityRationale":"deterministic score 0.45 from registry signals: · indexed on github topic:agent-skills · 7 github stars · SKILL.md body (7,753 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T19:14:05.172Z","embedding":null,"createdAt":"2026-05-18T13:21:36.494Z","updatedAt":"2026-05-18T19:14:05.172Z","lastSeenAt":"2026-05-18T19:14:05.172Z","tsv":"'-1':646,652 '-123':239 '-3.5':523 '-4':519 '/abs/2508.03680)':812 '/agent-lightning/)':803 '/microsoft/agent-lightning)':807 '/ryk7cdvdr7)':817 '/simple/':78,85 '0':645,651 '0.0.0.0':310 '0.3':656 '0.7':654 '1':736,745 '1e-5':501 '2':755,769 '3':760,798 '32':504 '4':764 '8':376 '8080':312,320 '8080/rollouts':787 'adapt':526 'add':93,324,346 'agent':2,8,12,22,25,39,47,100,108,112,141,167,194,199,260,329,595,660,664,669,675,684,722,725 'agent-lightn':1 'agent.run':248 'agentlightn':65,87,103,183,226,278,369,398,580,826 'agentlightning.algorithm.apo':511 'agentlightning.algorithm.verl':490 'agentlightning.instrumentation.langchain':530 'agentlightning.instrumentation.openai':546 'agentlightning.instrumentation.vllm':561 'agentlightning.store':590 'agentlightning.store.client':299 'agentlightning.store.memory':287 'agentlightning.tracer':592 'agentlightning.types':402 'agentlightning.utils.otel':267 'agl':105,185,371 'agl.emit':94,114,122,130,144,188,195,201,207,215 'agl.rollouts.duration':615 'agl.rollouts.total':610 'agl.store.latency':606 'agl.store.total':602 'agl.trainer':373 'ai':7,46 'algorithm':38,148,169,380,381,384,395,408,478,493,514,763 'align':637 'api':556,771 'apo':508 'apoalgorithm':513,515 'app':730,752 'architectur':139 'arg':211 'arxiv':808 'arxiv.org':811 'arxiv.org/abs/2508.03680)':810 'async':405,443 'auto':537,553 'auto-trac':536,552 'automat':51,505 'await':313,330,340,351,359,417,435,459,468,704,715,784 'backend':487,778 'base':729 'bash':62,69 'basic':186,364 'batch':502 'bodi':790 'build':68 'call':209,541,557,844 'central':156 'chang':92 'check':641,831,852 'checkpoint':699,703,707 'chosen':383 'claud':728 'claude-bas':727 'client':293,315,317,781 'client-serv':292 'code':91,109,143 'collect':164,840 'common':619 'communiti':814 'compat':600 'complet':345,414,422,475 'compon':152,153 'comput':425,626 'concept':138 'config':335,795 'configur':28,576 'connect':829 'const':782 'consum':170 'context':223,235,244,674,683,848 'converg':851 'core':137 'correct':640,642,655 'count':605,612 'creat':388,740 'current':710 'custom':394 'debug':575,587,593 'def':110,406,444,625 'dens':634 'design':623 'develop':284 'discord':813 'discord.gg':816 'discord.gg/ryk7cdvdr7)':815 'document':800 'effici':647,649,657 'emiss':187,241 'emit':179,597,842 'endpoint':836 'ensur':823 'error':822 'etc':427 'evalu':128 'event':411,452,748 'event.is':456 'execut':168,253,465,617 'executionev':404,412,453 'executor':686,692 'executor.run':688 'exist':99,107 'extra':80 'extra-index-url':79 'fail':830 'fetch':413,785 'fine':57 'fine-tun':56 'flow':140 'framework':14,43,525 'function':32,180,441,622,854 'get':269,272,355 'github':804 'github.com':806 'github.com/microsoft/agent-lightning)':805 'goal':639 'good':630 'gpt':518,522 'gradient':426 'group':246 'grpo/ppo':481 'helper':96 'host':309 'http':754 'hub':157 'id':237,450,472,676,685 'implement':30 'import':102,182,227,268,288,301,368,399,403,491,512,531,547,562,581,821 'improv':173 'in-memori':280 'increas':856 'index':74,81 'index-url':73 'info':591 'inmemori':389 'inmemorylightningstor':289,291 'input':115,118,189,192 'instal':61,64,71,825 'instrument':24,178,532,534,548,550,563,565,567 'int':451 'integr':89,259,262,719,772 'issu':819 'javascript':721,779,780 'javascript/typescript':724 'js':751 'json.stringify':791 'key':151 'langchain':527,533,535,540 'last':256 'latenc':609 'latest':356,361,713,717 'learn':17,50,480,499 'level':572,586,589 'lightn':3,13,40,261,596 'lightningstor':29,147,155,279,400,410,448,759 'lightningstorecli':303,318 'lightningstoreserv':302,307,774 'like':726 'llm.generate':120 'load':712 'localhost':319,786 'log':574,577,583,585 'loop':177 'max':796 'measur':648 'memori':282 'method':788 'metric':594,601 'microservic':743 'microsoft':10,41 'microsoft.github.io':802 'microsoft.github.io/agent-lightning/)':801 'minim':88 'model':495,498,517,521 'multi':659,668 'multi-ag':658,667 'n':374 'name':210 'new':428,438 'night':67 'normal':633,855 'openai':542,549,551,555 'opentelemetri':258,264 'oper':322,604,608 'optim':6,34,53,430,507,516,766 'option':387,734,735,768 'orchestr':175 'otel':275 'output':123,126,196,200 'paper':809 'parallel':377 'pattern':620 'pip':63,70,824 'plan':678,689 'planner':677 'planner.run':679 'port':311 'possibl':636 'post':789 'pre':86 'process':423 'produc':172 'product':296 'prometheus':599 'prometheus-compat':598 'prompt':35,52,190,349,506,767,793 'provid':392 'purpos':154 'push':432 'pypi.org':84 'pypi.org/simple/':83 'python':101,181,224,265,285,297,323,367,396,442,488,509,528,544,559,578,624,671,701,737,742 'queri':337 'quick':59 'rate':500 'receiv':746 'reinforc':16,49,479 'resourc':150,162,347,353,354,357,358,362,429,434,437,439,706,709,711,714,718,799 'respons':119,124,129,136,197,629,644,650,783 'rest':770,777 'result':217,218,221,247,464,476,477,687 'resum':700 'retri':797 'retriev':250 'return':135,274,653,765 'reward':31,127,131,132,134,202,205,621,627,631,853 'rl':483 'rl/apo':37 'rollout':325,332,338,339,342,378,415,416,419,431,458,461,463,470,471,611,616,857 'rollout.id':473 'rollout.task':467 'rolloutconfig':336 'run':761,834 'runner':375,440,446 'save':702 'score':203 'sdk':543 'server':294,300,304,306,832 'server.start':314 'servic':739 'set':20,457 'setup':366,582,584 'side':305,316 'signal':206 'size':503 'skill' 'skill-agent-lightning' 'solut':820 'source-rkz91' 'span':146,165 'specif':663 'start':60 'status':343,420,474,614 'store':231,232,283,290,295,308,321,385,386,409,447,603,607,756,828 'store.add':352,436,705 'store.dequeue':460 'store.enqueue':331 'store.get':360,716 'store.query':341,418 'store.update':469 'submodul':588 'succeed':827 'supervis':55 'system':670 'target':520 'task':113,116,121,160,236,238,249,326,333,334,466,628,643,680,792 'test.pypi.org':77 'test.pypi.org/simple/':76 'time':618 'token':571 'token-level':570 'tool':208,213,216,220 'topic-agent-skills' 'topic-agents-md' 'topic-ai-agents' 'topic-claude-code' 'topic-codex' 'topic-cursor' 'topic-developer-tools' 'topic-llm-tools' 'topic-mcp' 'topic-pm-tools' 'topic-product-management' 'topic-productivity' 'trace':27,159,171,251,254,257,424,538,554,573,694,747,839,847 'tracer':163,222,228,229,230,270,271,273,276 'tracer.get':255 'tracer.trace':234,673,682 'track':117,125,133,191,198,204,212,219 'train':4,23,45,176,363,484,661,662,698,738,762,849 'trainer':174,365,372 'trainer.run':393 'troubleshoot':818 'true':708 'tune':58 'turbo':524 'two':733 'updat':149,348,433 'upgrad':72 'url':75,82,837 'usag':214 'use':9,18,696,773 'usermessag':794 'verifi':835,841 'verlalgorithm':492,494 'via':753 'vllm':486,558,564,566,568 'weight':350 'within':242,846 'worker':379,449 'xxx':95,145,843 'your-model':496 'zero':90","prices":[{"id":"192ad111-fa70-494e-b7bf-071bea351041","listingId":"48a80053-4afd-474c-ae96-14238befd601","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"rkz91","category":"coco","install_from":"skills.sh"},"createdAt":"2026-05-18T13:21:36.494Z"}],"sources":[{"listingId":"48a80053-4afd-474c-ae96-14238befd601","source":"github","sourceId":"rkz91/coco/agent-lightning","sourceUrl":"https://github.com/rkz91/coco/tree/main/skills/agent-lightning","isPrimary":false,"firstSeenAt":"2026-05-18T13:21:36.494Z","lastSeenAt":"2026-05-18T19:14:05.172Z"}],"details":{"listingId":"48a80053-4afd-474c-ae96-14238befd601","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"rkz91","slug":"agent-lightning","github":{"repo":"rkz91/coco","stars":7,"topics":["agent-skills","agents-md","ai","ai-agents","claude-code","codex","cursor","developer-tools","llm-tools","mcp","pm-tools","product-management","productivity","prompt-engineering","workflow-automation"],"license":"mit","html_url":"https://github.com/rkz91/coco","pushed_at":"2026-04-26T01:51:27Z","description":"Open-source library of AI superpowers — 59 skills, 34 commands, 10 agents + 24 GSD subagents, 3 system bundles. An entire team, wherever your AI lives. Vendor-neutral across Claude Code, Cursor, Codex, and any AGENTS.md tool.","skill_md_sha":"378a01f1f0bd2d8afc79b1757043018d847e783b","skill_md_path":"skills/agent-lightning/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/rkz91/coco/tree/main/skills/agent-lightning"},"layout":"multi","source":"github","category":"coco","frontmatter":{"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."},"skills_sh_url":"https://skills.sh/rkz91/coco/agent-lightning"},"updatedAt":"2026-05-18T19:14:05.172Z"}}