Skip to main content

Intuitive Python SDK for Lyzr Agent API - Build AI agents with ease

Project description

Lyzr SDK

Python 3.8+ License: MIT

The official Python SDK for Lyzr - Build production-ready AI agents in minutes

Create powerful AI agents with a clean, intuitive API. Supports multiple LLM providers, knowledge bases (RAG), structured outputs, and streaming.

✨ Features

  • 🚀 Simple & Intuitive - agent.run("message") - that's it!
  • 🎯 Type-Safe - Full Pydantic v2 validation with autocomplete
  • 🔌 Modular - Use what you need, extend what you want
  • 🤖 Multi-Provider - OpenAI, Anthropic, Google, Groq, Perplexity, AWS Bedrock
  • 📚 Knowledge Bases - Built-in RAG for documents, PDFs, websites
  • 🎨 Structured Outputs - Type-safe responses with Pydantic models
  • Streaming - Real-time response streaming
  • 📦 Production-Ready - Robust error handling, retries, validation

📦 Installation

pip install sumiki

🔑 Getting Your API Key

Get your free API key from studio.lyzr.ai

Set it as an environment variable:

export LYZR_API_KEY="your-api-key-here"

🚀 Quick Start

from lyzr import Studio

# Initialize (uses LYZR_API_KEY from environment)
studio = Studio()

# Or pass API key directly
studio = Studio(api_key="your-api-key-here")

# Create an agent
agent = studio.create_agent(
    name="Customer Support Agent",
    provider="openai/gpt-4o-mini"
)

# Run the agent
response = agent.run("What are your business hours?")
print(response.response)

📖 Core Features

1. Smart Agents

Agents are intelligent objects with built-in methods:

# Create
agent = studio.create_agent(
    name="Sales Assistant",
    provider="openai/gpt-4o",
    temperature=0.7
)

# Run
response = agent.run("Hello!")

# Stream
for chunk in agent.run("Tell me about your products", stream=True):
    print(chunk.content, end="")

# Update
agent = agent.update(temperature=0.5)

# Clone
new_agent = agent.clone("Sales Assistant V2")

# Delete
agent.delete()

2. Structured Outputs with Pydantic

Get type-safe, validated responses:

from pydantic import BaseModel
from typing import Literal

class SentimentAnalysis(BaseModel):
    sentiment: Literal["positive", "negative", "neutral"]
    confidence: float
    reasoning: str

agent = studio.create_agent(
    name="Sentiment Analyzer",
    provider="openai/gpt-4o",
    response_model=SentimentAnalysis
)

# Get typed response
result: SentimentAnalysis = agent.run("I love this product!")
print(result.sentiment)  # "positive" - fully typed!
print(result.confidence)  # 0.95

3. Knowledge Bases (RAG)

Create knowledge bases and use them with agents:

# Create knowledge base
kb = studio.create_knowledge_base(
    name="product_docs",
    vector_store="qdrant"
)

# Add documents
kb.add_pdf("user_manual.pdf")
kb.add_docx("policies.docx")
kb.add_website("https://docs.mycompany.com", max_pages=50)
kb.add_text("FAQ: Business hours are 9am-5pm", source="faq.txt")

# Query directly
results = kb.query("How do I reset my password?", top_k=3)

# Use with agent at runtime
agent = studio.create_agent(
    name="Support Bot",
    provider="openai/gpt-4o"
)

response = agent.run(
    "What are your business hours?",
    knowledge_bases=[kb]  # ← Pass KB at runtime
)

4. Multiple Providers

# OpenAI
agent = studio.create_agent(name="Bot", provider="openai/gpt-4o")

# Anthropic
agent = studio.create_agent(name="Bot", provider="anthropic/claude-sonnet-4-5")

# Google
agent = studio.create_agent(name="Bot", provider="google/gemini-2.5-pro")

# Auto-detect provider
agent = studio.create_agent(name="Bot", provider="gpt-4o")

🌟 Supported Models

LLM Providers

  • OpenAI: GPT-4o, GPT-5, o3, o4-mini
  • Anthropic: Claude Sonnet 4.5, Claude Opus 4.5
  • Google: Gemini 2.5 Pro, Gemini 3 Pro Preview
  • Groq: Llama 3.3, Llama 4
  • Perplexity: Sonar, Sonar Pro (with web search)
  • AWS Bedrock: Amazon Nova, Claude via Bedrock

Vector Stores (Knowledge Bases)

  • Qdrant, Weaviate, PG-Vector, Milvus, Amazon Neptune

📚 Examples

See the /examples folder for complete working examples:

  • quickstart.py - Basic agent creation and usage
  • structured_responses.py - Pydantic models for typed outputs
  • knowledge_base_basic.py - Creating and managing knowledge bases
  • kb_with_agent.py - Using KBs with agents at runtime

🛠️ Advanced Usage

Multiple Knowledge Bases

products_kb = studio.create_knowledge_base(name="products")
policies_kb = studio.create_knowledge_base(name="policies")

# Use multiple KBs with custom config
response = agent.run(
    "What's the refund policy for Product X?",
    knowledge_bases=[
        products_kb.with_config(top_k=5, score_threshold=0.8),
        policies_kb.with_config(top_k=3, retrieval_type="mmr")
    ]
)

Session Management

# Auto-generated session
response = agent.run("Hello")

# Explicit session for continuity
session_id = "user_123"
response1 = agent.run("Question 1", session_id=session_id)
response2 = agent.run("Follow-up", session_id=session_id)

🐛 Error Handling

from lyzr.exceptions import (
    AuthenticationError,
    ValidationError,
    NotFoundError,
    InvalidResponseError
)

try:
    agent = studio.create_agent(name="Bot", provider="invalid/model")
except ValidationError as e:
    print(f"Error: {e.message}")

🤝 Contributing

Contributions welcome! Please submit a Pull Request.

📄 License

MIT License - see LICENSE file

🔗 Links

💬 Support


Built with ❤️ by Lyzr

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

sumiki-0.1.0.tar.gz (131.9 kB view details)

Uploaded Source

Built Distribution

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

sumiki-0.1.0-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file sumiki-0.1.0.tar.gz.

File metadata

  • Download URL: sumiki-0.1.0.tar.gz
  • Upload date:
  • Size: 131.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for sumiki-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aa8c4bc1768356b2b1601c14b108b6e76a3a0b2d287fc9020efa147f9c3bfe68
MD5 b3b9c877c9f46a98ab087e3312d51c7b
BLAKE2b-256 b2c864f625166cd144476fc12a2bbde71f0da57962a94177102666d7c1394f90

See more details on using hashes here.

File details

Details for the file sumiki-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sumiki-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for sumiki-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 419aebb820a7bbdbc2e17608b6596fc44727e39bf016740b52922e67f6612018
MD5 140a963c800b84c343e13f07c09f5aa1
BLAKE2b-256 ee7fcb762825cc8551b4ca4d957eadef60c1550c78112761ff34c2372f382ce4

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