Skip to main content

Soni Framework - Open Source Conversational AI Framework with Auto-Optimization

Project description

🤖 Soni Framework

Open Source Conversational AI Framework with Prompt Optimization

Soni is a modern framework for building task-oriented dialogue systems that combines the power of DSPy for prompt optimization with LangGraph for robust dialogue management.

The Three Laws of Soni

  1. Declarative First: Define behavior, not implementation
  2. Optimizable: Learn from data through DSPy optimization
  3. No Black Boxes: Full transparency and explainability

Inspired by Asimov's vision of intelligent, helpful AI

Features

  • 🤖 Prompt Optimization - Uses DSPy's MIPROv2 to optimize NLU prompts
  • 🔄 Stateful Dialogue Management - Built on LangGraph for reliable conversation flows
  • 📝 YAML-Based Configuration - Declarative DSL for defining dialogue flows
  • Async-First Architecture - High-performance async/await throughout
  • 🎯 Zero-Leakage Design - Technical details don't leak into configuration
  • 📊 Streaming Support - Real-time token streaming with Server-Sent Events (SSE)
  • 🎯 Dynamic Scoping - Context-aware action filtering reduces tokens by 39.5%
  • 🔧 Slot Normalization - Automatic normalization improves validation by 11.11%
  • Performance Optimizations - Caching, connection pooling, and async checkpointing

Quick Start

Installation

# Clone the repository
git clone https://github.com/jmorenobl/soni.git
cd soni

# Install dependencies
uv sync

# Install the package
uv pip install -e .

# Set API key
export OPENAI_API_KEY="your-api-key-here"

Start the Server

# Run the example
uv run soni server --config examples/flight_booking/soni.yaml

Test the API

# Health check
curl http://localhost:8000/health

# Start a conversation
curl -X POST http://localhost:8000/chat/user-123 \
  -H "Content-Type: application/json" \
  -d '{"message": "I want to book a flight"}'

See Quickstart Guide for detailed instructions.

Example

The flight booking example demonstrates a complete dialogue system:

flows:
  book_flight:
    trigger:
      intents: [book_flight, i_want_to_book]
    steps:
      - step: collect_origin
        type: collect
        slot: origin
      - step: collect_destination
        type: collect
        slot: destination
      - step: search_flights
        type: action
        call: search_available_flights

See Flight Booking Example for a complete example.

Documentation

Requirements

  • Python 3.11+
  • OpenAI API key (or other supported LLM provider)

Code Quality

  • Coverage: 85% (exceeds 80% target) 🎯
  • Linting: ✅ Ruff passes (all checks)
  • Type Checking: ✅ Mypy passes (26 source files, no issues)
  • Tests: 198 passed, 13 skipped (some failures expected without LLM)

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE file for details.

Why "Soni"?

The name Soni is inspired by Sonny, the remarkable robot from Isaac Asimov's classic story collection "I, Robot". Like Sonny, who was special among robots—capable of learning, reasoning, and continuously optimizing his behavior—Soni represents a framework that learns and improves itself through automatic prompt optimization.

Just as Sonny questioned and refined his own programming, Soni uses DSPy to optimize conversational AI systems through manual optimization runs, making them smarter with each optimization cycle. The framework embodies Asimov's vision of intelligent, helpful AI that can be improved to better serve its purpose.

"The Three Laws of Robotics are built into the very foundation of Soni's architecture: to assist, to optimize, and to improve—all while maintaining transparency and control."

Acknowledgments

  • DSPy - For prompt optimization
  • LangGraph - For dialogue management
  • FastAPI - For the API framework
  • Typer - For the CLI interface

Built with ❤️ by the Soni Framework Contributors

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

soni-0.2.1.tar.gz (139.4 kB view details)

Uploaded Source

Built Distribution

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

soni-0.2.1-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file soni-0.2.1.tar.gz.

File metadata

  • Download URL: soni-0.2.1.tar.gz
  • Upload date:
  • Size: 139.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for soni-0.2.1.tar.gz
Algorithm Hash digest
SHA256 170e1b0222c3b3bf69e104b7d2a3fee3b8288928d09634eb4c03925d2b808556
MD5 2ace3998dba28003c983d39bc3c1b2cb
BLAKE2b-256 8649b86aa829a1eb23cd610de0d693bb3609540a75ebd25d4f11bd785c5e313d

See more details on using hashes here.

File details

Details for the file soni-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: soni-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 38.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for soni-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e14485b7b991d845f534b4415982303cdd7222f62548da67b0951a1d4367339
MD5 1e12429fd29b3811f3d61b3597f6ffd3
BLAKE2b-256 63b5ed2eaff445170ac0910dc965e5f88fdfd1a31eacc2222b3775d13fde2116

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