Skip to main content

A minimal, async-native, and unopinionated toolkit for modern LLM applications.

Project description

lingo library logo

A minimal, async-native, and unopinionated toolkit for modern LLM applications.

PyPI - Version PyPi - Python Version Github - Open Issues PyPi - Downloads (Monthly) Github - Commits

Stop wiring graphs. Start modeling conversations.

Lingo is a lightweight, type-safe Python framework for building LLM-powered applications. It moves beyond generic "agents" and "chains" to focus on Conversational Modeling—the discipline of defining exactly how a system perceives, processes, and advances a dialogue state.

It unifies three powerful paradigms in a single, typed architecture:

  1. Procedural Skills (Linear, script-like flows)
  2. Symbolic States (Deterministic FSMs)
  3. Reflexive Patterns (Event-driven guardrails)

⚡ Features

  • 💾 Stateful by Default: The Python stack is your state machine. Use await engine.ask() to pause execution and wait for user input naturally.
  • 🧠 Cognitive Architecture: Mix rigid business rules (States) with flexible reasoning (Skills).
  • 🛡️ Type-Safe: Built on Pydantic. All inputs, outputs, and tool calls are validated schemas.
  • 🌊 Low-Level Flow Control: Direct access to the underlying Flow graph for complex orchestration (Fork/Join, Retry, Loops).

🚀 Quickstart

Installation

pip install lingo-ai

The "Hello World" (Stateful Wizard)

Lingo allows you to model conversations as linear scripts. You don't need to manage session IDs or database steps manually—variables persist in memory across turns.

import asyncio
from lingo import Lingo

# Initialize the application
app = Lingo("Wizard", description="A helpful setup wizard")

@app.skill
async def onboarding(ctx, eng):
    # 1. Output a message
    await eng.reply(ctx, "Welcome to the system.")

    # 2. PAUSE execution and wait for user input
    # Lingo automatically suspends the stack here.
    # The variable 'name' is preserved in memory when the user replies!
    name = await eng.ask(ctx, "What is your name?")

    # 3. Resume and use context from previous turns
    email = await eng.ask(ctx, f"Hi {name}, what is your email?")

    # 4. Use structured decision making (LLM is forced to return bool)
    if await eng.decide(ctx, f"Is {email} a valid corporate email address?"):
        await eng.reply(ctx, "Registration complete.")
    else:
        await eng.reply(ctx, "Personal emails are not allowed.")

if __name__ == "__main__":
    from lingo.cli import loop
    loop(app)

🧠 The Three Modeling Paradigms

Lingo gives you the right abstraction for every type of logic.

1. Symbolic States (Finite State Machine)

Best for: Business Logic, Security Boundaries, Multi-Step Workflows.

Use the StateMachine to enforce strict rules about allowed transitions.

from lingo.fsm import StateMachine

# 1. Initialize the FSM with the bot's registry
fsm = StateMachine(app.registry)

@fsm.state
async def login(ctx, eng):
    await eng.reply(ctx, "Please log in.")
    # Deterministic transition to the next state
    fsm.goto(dashboard, restart=True)

@fsm.state
async def dashboard(ctx, eng):
    await eng.reply(ctx, "Welcome to your dashboard.")
    # Logic restricted to this state...

# Register the FSM as a skill
@app.skill
async def run_workflow(ctx, eng):
    await fsm.execute(ctx, eng)

2. Reflexive Patterns (Event-Driven)

Best for: Guardrails, Interruptions, Global Commands.

Use @app.when to define high-priority listeners that intercept messages before they reach skills.

@app.when("User wants to quit or cancel the operation")
async def emergency_stop(ctx, eng):
    await eng.reply(ctx, "Stopping immediately.")
    eng.stop() # Terminates the flow and clears the stack

3. Structured Flows (Low-Level Graph)

Best for: Parallel Processing, Retries, Complex Orchestration.

You can drop down to the Flow API to build complex execution graphs explicitly.

from lingo import Flow

# Define two sub-flows
research = Flow("Research").reply("Searching for info...")
draft = Flow("Draft").reply("Drafting content...")

# Build a flow that runs them in parallel (Fork)
# and summarizes the result
complex_flow = (
    Flow("ParallelWorker")
    .fork(
        research,
        draft,
        aggregator="Combine the research and draft into a final report."
    )
)

📦 Architecture

  • Context: Mutable ledger of the conversation history.
  • Engine: The "actuator" that drives the LLM. It exposes methods like .ask(), .decide(), .choose(), and .create().
  • Flow: The underlying graph representation of all skills.

🤝 Contribution

We welcome contributions! Please see CONTRIBUTING for details on how to set up your development environment and submit pull requests.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

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

lingo_ai-1.4.1.tar.gz (130.1 kB view details)

Uploaded Source

Built Distribution

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

lingo_ai-1.4.1-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file lingo_ai-1.4.1.tar.gz.

File metadata

  • Download URL: lingo_ai-1.4.1.tar.gz
  • Upload date:
  • Size: 130.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lingo_ai-1.4.1.tar.gz
Algorithm Hash digest
SHA256 c5e9ec44d7d554015be5930a38ab65c63994deedf20ed6fdc1658f4cf0bf9cb4
MD5 9fd8fda3554994b5f7886456b1310b59
BLAKE2b-256 7ba0cccb79d09c488f6a28b76bd453def4f2ed15d1546048c02fdf91cd39f5fc

See more details on using hashes here.

File details

Details for the file lingo_ai-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: lingo_ai-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lingo_ai-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 70bccc4a10c06dd38bc3b520276ce4cec634a9c90bdd9747d8bab8fb02e3cff9
MD5 f9556cdd4634545c3aee999d2e02bf11
BLAKE2b-256 2a5393211beef5767e4e32b2396f9fd4f87477e028ab1dfc77b9873c764acd7f

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