Skip to content

RPirruccio/lightning-agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โšก Lightning Agents โšก

Dynamic agent instantiation using the Factory-of-Factories pattern with Claude Agent SDK.

Built for the Austin AI MUG Lightning Talk. ๐ŸŽค


๐Ÿค” What is Lightning Agents?

Lightning Agents demonstrates a pattern for dynamically loading, instantiating, and even generating AI agents from declarative JSON definitions. Instead of hardcoding agent configurations, you define blueprints that get transformed into factory functions at runtime.

๐Ÿ˜ค The Problem

Building AI agents typically involves:

  • ๐Ÿ“ Hardcoded system prompts scattered across files
  • ๐Ÿ”— Tightly coupled agent definitions and execution logic
  • ๐Ÿšซ No standardized way to add new agents without code changes
  • ๐Ÿ“‹ Manual configuration duplication when agents share patterns

โšก The Solution

Factory-of-Factories: A registry that loads agent definitions from JSON, builds factory functions for each, and provides a unified interface for instantiation with runtime context injection.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Definition  โ”‚ โ”€โ”€โ–ถ โ”‚   Factory   โ”‚ โ”€โ”€โ–ถ โ”‚  Registry   โ”‚ โ”€โ”€โ–ถ โ”‚  Instance   โ”‚
โ”‚   (JSON)    โ”‚     โ”‚  (Callable) โ”‚     โ”‚  (Unified)  โ”‚     โ”‚   (Ready)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

# Clone and setup
cd lightning-agents
uv sync

# Copy env template and configure
cp .env.example .env
# Edit .env with your SEARXNG_URL

# List available agents
lightning list

# Run an agent
lightning run basic_helper "What is the factory pattern?"

# Create a new agent with the architect
lightning architect "code reviewer for Python security"

๐Ÿ’ป CLI Commands

โšก List Agents

lightning list

Shows all available agents with descriptions and model info.

โšก Run Agent

lightning run <agent_id> "<prompt>"

Examples:

lightning run basic_helper "Explain dependency injection"
lightning run aimug_researcher "What RAG tutorials does AIMUG have?"
lightning run lab_finder "Find labs about LangGraph"

โšก Create New Agent

lightning architect "<task description>"

The architect agent generates a new agent definition, saves it to agents.json, and makes it immediately available.

lightning architect "meeting notes summarizer for action items"
# New agent created: meeting_summarizer
lightning run meeting_summarizer "Summarize: [transcript]"

๐Ÿค– Available Agents

Agent Description Model Tools
basic_helper General Q&A assistant haiku -
research_assistant Structured research summaries sonnet web_search
python_doc_writer Python function documentation haiku -
architect ๐Ÿ—๏ธ Designs new agent definitions (Voyager-style) sonnet db_agents (CRUD)
tool_architect ๐Ÿ”ง Designs new custom tools sonnet db_tools (CRUD)
aimug_researcher Searches AIMUG content (GitHub, docs, YouTube) sonnet web_search, url_read
lab_finder Finds AIMUG labs by topic haiku web_search
git_commit_writer โœ๏ธ Writes conventional commit messages haiku -
presentation_slide_writer ๐ŸŽจ Creates and manages PPTX presentations sonnet slides (CRUD), generate_pptx, Read, Bash
paper_researcher ๐Ÿ“„ Researches papers, downloads PDFs sonnet web_search, url_read, download_pdf

๐Ÿญ Factory vs Factory-of-Factories

Simple Factory

def create_agent(config):
    return Agent(config)

Factory-of-Factories (This Project) โšก

# Definition โ†’ Factory โ†’ Registry โ†’ Instance
registry = AgentRegistry.from_json("agents.json")  # Builds ALL factories
agent = registry.create("researcher", {"topic": "AI"})  # Gets instance

The registry is the factory-of-factories โ€” it produces factory functions from definitions, then uses those factories to produce instances.


๐Ÿ—๏ธ Architect Agents

The "Architect Agent" pattern: an agent that generates new agent definitions.

# Before: 6 agents
lightning list

# Use architect to create a new one
lightning architect "code reviewer for security vulnerabilities"

# After: 7 agents - new one saved to agents.json
lightning list

# Use it immediately
lightning run security_reviewer "Review this auth code..."

This enables self-expanding agent systems where the AI itself designs specialized agents for new tasks. ๐Ÿคฏ


๐ŸŽฎ Voyager Inspiration

This project draws inspiration from Voyager, an AI agent that plays Minecraft by building a skill library that grows over time. Instead of hardcoded behaviors, Voyager learns new skills and stores them for reuse.

Lightning Agents applies this concept to agent systems:

  • Skill Library โ†’ Agent Registry: Agents stored as reusable definitions
  • Learning New Skills โ†’ Architect Agent: Creates new agents on demand
  • Tool Acquisition โ†’ Tool Architect: Creates new tools when needed

The result: a system that grows organically based on actual needs, not pre-planned capabilities.


๐Ÿงช Hypotheses

H1: Declarative > Imperative for Agent Configuration

JSON definitions separate what an agent is from how it runs. Easier to version, diff, and review.

H2: Runtime Context Injection Enables Reusability

The same definition can serve multiple contexts by injecting different runtime parameters.

H3: Architect Agents Enable Organic Growth

Instead of manually writing every agent definition, let Claude design agents for new tasks. The system grows based on actual needs.


๐Ÿ“ Project Structure

lightning-agents/
โ”œโ”€โ”€ .env.example              # Environment template
โ”œโ”€โ”€ .env                      # Your config (gitignored)
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ CLAUDE.md                 # Developer notes
โ”œโ”€โ”€ db/                       # Data (decoupled from source)
โ”‚   โ”œโ”€โ”€ agents.json           # Agent blueprints
โ”‚   โ””โ”€โ”€ tools.json            # Custom tool definitions
โ”œโ”€โ”€ src/lightning_agents/     # Main package
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ cli.py                # CLI entry point
โ”‚   โ”œโ”€โ”€ runner.py             # Agent execution with MCP
โ”‚   โ”œโ”€โ”€ registry.py           # Factory-of-Factories pattern
โ”‚   โ”œโ”€โ”€ agent_factory.py      # Definition โ†’ Instance
โ”‚   โ”œโ”€โ”€ mcp_config.py         # MCP server configs
โ”‚   โ””โ”€โ”€ tools/                # Custom MCP tools
โ”‚       โ”œโ”€โ”€ download_pdf.py   # PDF download tool
โ”‚       โ”œโ”€โ”€ db_agents.py      # Agent CRUD operations
โ”‚       โ”œโ”€โ”€ db_tools.py       # Tool CRUD operations
โ”‚       โ””โ”€โ”€ presentation.py   # Slide manipulation tools
โ””โ”€โ”€ presentation/             # PPTX slide generator
    โ”œโ”€โ”€ generate_slides.py
    โ”œโ”€โ”€ slide_content.py
    โ”œโ”€โ”€ styles.py
    โ””โ”€โ”€ output/
        โ””โ”€โ”€ lightning-agents.pptx

๐ŸŽจ Generating Slides

Use the presentation_slide_writer agent to manage slides:

# List current slides
lightning run presentation_slide_writer "List the slides"

# Add a new slide
lightning run presentation_slide_writer "Add a bullets slide about MCP integration"

# Generate PPTX and PDF
lightning run presentation_slide_writer "Generate the presentation"

# Output: presentation/output/lightning-agents.pptx + .pdf

Edit presentation/slide_content.py directly for bulk changes. Supports **bold** and `code` markup.


โš™๏ธ Configuration

Environment Variables

Copy .env.example to .env and configure:

# SearXNG MCP server URL (for web search agents)
SEARXNG_URL=http://localhost:8888

MCP Tools

Agents can use MCP tools by declaring them in their tools array:

SearXNG (Web Search):

  • mcp__searxng__searxng_web_search - Web search
  • mcp__searxng__web_url_read - Read web page content

Custom Tools (Built-in MCP Server):

  • mcp__custom-tools__download_pdf - Download PDFs from URLs
  • mcp__custom-tools__db_list_agents / db_get_agent / db_create_agent / db_update_agent / db_delete_agent - Agent CRUD
  • mcp__custom-tools__db_list_tools / db_get_tool / db_create_tool / db_update_tool / db_delete_tool - Tool CRUD
  • mcp__custom-tools__list_slides / add_slide / update_slide / delete_slide / generate_pptx - Presentation management

SDK Primitives: Agents can also use built-in Claude SDK tools: Read, Write, Edit, Bash, Grep, Glob, WebFetch, WebSearch


๐Ÿ“‹ Requirements

  • Python 3.13+
  • uv package manager
  • SearXNG instance (for search-enabled agents)

๐Ÿ“„ License

MIT


โšก Built for the Austin AI MUG lightning talk on dynamic agent instantiation patterns. โšก

Agents creating agents creating agents... ๐Ÿค–โžก๏ธ๐Ÿค–โžก๏ธ๐Ÿค–

About

Factory-of-Factories pattern for dynamic AI agent instantiation with Claude Agent SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages