Skip to main content

Serverless-native LLM orchestration framework for AWS Lambda

Project description

LambdaLLM

Serverless-native LLM orchestration framework for AWS Lambda.

Built by SubstrAI — Open-source GenAI frameworks for serverless infrastructure.

PyPI version Tests License: MIT Python 3.10+ Documentation codecov npm version

The Problem

Existing LLM frameworks (LangChain, LlamaIndex) assume long-running servers. They break on Lambda:

  • Cold starts: 500MB+ dependency trees add seconds
  • Stateless: No conversation memory between invocations
  • 15-min timeout: Long agent loops crash
  • 250MB limit: LangChain alone exceeds this

The Solution

LambdaLLM is purpose-built for Lambda's constraints:

from lambdallm import handler, Prompt, Model

summarize = Prompt(
    template="Summarize in {max_words} words:\n\n{document}",
    output_schema={"summary": str, "key_points": list}
)

@handler(model=Model.CLAUDE_3_HAIKU)
def lambda_handler(event, context):
    return summarize.invoke(
        _context=context,
        document=event["body"]["text"],
        max_words=100
    )

Features

  • < 5MB package size (vs 400MB+ for LangChain)
  • Cold-start optimized — lazy imports, connection pooling
  • DynamoDB-native state — conversation memory that survives stateless execution
  • Cost-aware routing — auto-select cheapest model that meets quality threshold
  • Multi-step chains — declarative pipelines with checkpoint/resume on timeout
  • AI Agents — ReAct-style agents with tool sandboxing and timeout awareness
  • One-command deploylambdallm deploy generates all AWS infrastructure
  • Timeout handling — checkpoint/resume for long chains
  • A/B testing — route traffic between prompt versions, compare metrics
  • Full observability — X-Ray tracing, CloudWatch metrics, cost tracking built-in

Installation

Python (primary)

pip install substrai-lambdallm

With AWS Bedrock support (recommended):

pip install "substrai-lambdallm[bedrock]"

With all optional dependencies:

pip install "substrai-lambdallm[all]"

npm

npm install substrai-lambdallm

Quick Start

# Initialize a new project
lambdallm init my-project --template basic
cd my-project

# Start local development server
lambdallm dev

# Test your handler
curl -X POST http://localhost:3000 -d '{"text": "Hello world"}'

# Deploy to AWS
lambdallm deploy --env dev

Available Templates

lambdallm init my-app --template basic   # Simple LLM handler
lambdallm init my-app --template chat    # Multi-turn chat with memory
lambdallm init my-app --template agent   # AI agent with tools
lambdallm init my-app --template rag     # Retrieval-augmented generation

Core Concepts

Handlers

from lambdallm import handler, Model

@handler(model=Model.CLAUDE_3_HAIKU, timeout_strategy="checkpoint")
def lambda_handler(event, context):
    result = context.invoke("Summarize: {text}", text=event["body"]["text"])
    return {"statusCode": 200, "body": result}

Chains

from lambdallm import Chain, Step

pipeline = Chain(
    name="analysis",
    steps=[
        Step("extract", prompt="Extract entities from: {input}"),
        Step("classify", prompt="Classify: {extract.output}"),
        Step("summarize", prompt="Summarize: {classify.output}"),
    ],
    timeout_strategy="checkpoint",
)

Agents

from lambdallm.agents import Agent, Tool

@Tool(description="Search the knowledge base")
def search(query: str, max_results: int = 5) -> list:
    # your implementation
    pass

agent = Agent(
    name="researcher",
    system_prompt="You are a research assistant.",
    tools=[search],
    max_iterations=5,
    timeout_buffer=30,
)

CLI Commands

Command Description
lambdallm init Scaffold a new project
lambdallm dev Start local development server
lambdallm deploy Deploy to AWS (SAM/CDK)
lambdallm test Run tests
lambdallm cost Show cost summary and forecast
lambdallm status Check deployment status
lambdallm rollback Rollback to previous version
lambdallm eject Export raw SAM/CDK templates
lambdallm logs Tail CloudWatch logs
lambdallm metrics Show key metrics

Documentation

License

MIT — see LICENSE

Author

Gaurav Kumar Sinha — Founder, SubstrAI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

substrai_lambdallm-1.0.1.tar.gz (93.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

substrai_lambdallm-1.0.1-py3-none-any.whl (87.0 kB view details)

Uploaded Python 3

File details

Details for the file substrai_lambdallm-1.0.1.tar.gz.

File metadata

  • Download URL: substrai_lambdallm-1.0.1.tar.gz
  • Upload date:
  • Size: 93.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for substrai_lambdallm-1.0.1.tar.gz
Algorithm Hash digest
SHA256 477c91550026a4bf5c8557f0c23f9f73266ee23593450891db4e82858fd065f2
MD5 ef836db166ceb621bc96398ab420fd03
BLAKE2b-256 f8fcac0a1653d8cbc2916b83930158df9d0156619f9e53125490f682b7dbb1a2

See more details on using hashes here.

File details

Details for the file substrai_lambdallm-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for substrai_lambdallm-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 84a4666aee97ce9833088b554ed3fdd87cf8395d66a0e99f4df9a13d8ece024c
MD5 54d052054b7ba0c10b5e869f8a2e47fa
BLAKE2b-256 2079c3074d675ae167f2a0fa64d29dec00d1d5ccc051a281d3b35af1a0bbf014

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page