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


lingo provides a powerful, three-layered API for building, testing, and deploying complex LLM workflows with precision and clarity.

The Philosophy: A Three-Layer API

lingo is built on the idea that developers need different levels of abstraction for different tasks.

  1. The High-Level Lingo API: For purely declarative, ready-to-use LLM assistants. This is the fastest way to get a chatbot running.
  2. The Mid-Level Flow API: For declarative, reusable context engineering workflows. This allows you to define complex, composable logic with branching, tool use, and subroutines.
  3. The Low-Level (LLM, Engine, Context) API: For direct, explicit context engineering. This gives you full, imperative control over the message history and LLM interactions.

Installation

pip install lingo-ai

You will also need to set your environment variables (e.g., in a .env file) for your LLM provider:

# Example for OpenAI
MODEL="gpt-4o"
API_KEY="sk-..."

Quickstart: A 5-Line Chatbot

This is the fastest way to get a lingo assistant running using the high-level Lingo class.

from lingo import Lingo
import dotenv

# Load .env variables (API_KEY, MODEL)
dotenv.load_dotenv()

# 1. Initialize the assistant
bot = Lingo(
    name="Assistant",
    description="A simple, helpful chatbot."
)

# 2. Run the chat loop in your terminal
bot.loop()

That's it! You now have a fully interactive chatbot.

Name: Assistant
Description: A simple, helpful chatbot.

[Press Ctrl+D to exit]

>>> Hello!
Hello! How can I help you today?
>>>

The Three API Layers

lingo gives you the flexibility to choose the right level of abstraction.

1. High-Level API: The Lingo Class

This is the "batteries-included" approach. The Lingo class manages the LLM, Engine, and Flow for you. You just define skills (reusable flows) and tools, and lingo handles routing the conversation to the correct one.

This is the recommended starting point for most applications.

from lingo import Lingo, Context, Engine
import dotenv

dotenv.load_dotenv()

bot = Lingo(
    name="Greeter",
    description="A bot that just says hello."
)

# A "skill" is a complete, self-contained workflow
@bot.skill
async def greet(context: Context, engine: Engine):
    """A skill to greet the user."""
    await engine.reply(
        context,
        "You are a friendly greeter. Reply with a warm welcome."
    )

bot.loop()

2. Mid-Level API: The Flow Class

The Flow class provides a fluent, chainable interface for declaratively building reusable workflows. You define the steps of the conversation, and lingo handles the execution. This is perfect for defining complex, stateful logic.

import asyncio
from lingo import Lingo, Flow, Message, Engine
from lingo.tools import tool

llm = LLM(model="gpt-4o")

@tool
async def get_weather(location: str) -> str:
    """Gets the current weather for a specified location."""
    return "It's 75°F and sunny."

# A flow is a composable, reusable blueprint
weather_flow = (
    Flow(name="Weather")
    .system("You only answer with the weather.")
    .invoke(get_weather)  # -> ToolResult is added to context
    .reply()              # -> LLM generates reply based on ToolResult
)

# You can nest flows inside other flows
main_flow = (
    Flow(name="Main")
    .choose(
        prompt="Is the user asking about weather or stocks?",
        choices={
            "weather": weather_flow,
            "stocks": Flow().reply("I don't know about stocks."),
        }
    )
)

async def main():
    engine = Engine(llm)
    messages = [Message.user("What's the weather like?")]

    # Run the flow
    final_context = await main_flow(engine, messages)
    print(final_context.messages[-1].content)

asyncio.run(main())

3. Low-Level API: LLM, Engine, & Context

For maximum control, you can use the imperative API.

  • Context: A simple, mutable object holding the list[Message].
  • LLM: The client for interacting with the LLM API (e.g., chat, create).
  • Engine: The "behavior" layer. It holds the LLM and performs operations on a Context (e.g., engine.reply(context), engine.invoke(context, tool)).

This is ideal for building custom chatbot loops or integrating lingo into an existing application.

import asyncio
from lingo import LLM, Engine, Context, Message

async def main():
    # 1. Setup the components
    llm = LLM(model="gpt-4o")
    engine = Engine(llm)

    # 2. The Context is a pure, mutable state object
    context = Context([
        Message.system("You are a helpful assistant.")
    ])

    # 3. Manually build the conversation
    user_input = "Hello!"
    context.append(Message.user(user_input))

    # 4. Call the Engine to perform an LLM operation
    response = await engine.reply(context)

    # 5. Mutate the context with the new message
    context.append(response)

    print(f"Bot: {response.content}")

asyncio.run(main())

Contributing

Contributions are welcome! lingo is an open-source project, and we'd love your help in making it better. Please feel free to open an issue or submit a pull request.

License

lingo 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-0.2.3.tar.gz (50.2 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-0.2.3-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lingo_ai-0.2.3.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"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-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c22a07295add8d6cbc6effbe8174fe8becacb97b5a0efef142ef16624f155a49
MD5 0964ae5c50d4e4b5c76ce2e596bfd56f
BLAKE2b-256 450dd60d2733e7d36b79c9ed5f1694a1ae2bd92d009b57d6d00fd407c5573795

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lingo_ai-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"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-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ac5f8c19cfb18a63414e8eb7a2b37bcec558b1fe40a621f94985e8e41e3305c
MD5 14cb2c29e74e20704f1d88d44d2b5d8c
BLAKE2b-256 0673342db03865404d55eec5c333fee5c83ebb47a0b2c42264fcacc7c01da5df

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