Skip to main content

Chainless is a lightweight, modular framework to build task-oriented AI agents and orchestrate them in intelligent flows

Project description

Chainless 🧠 – A Minimalistic Framework for Agentic Workflows

Chainless is a lightweight, extensible framework for building agent-based systems on top of large language models (LLMs). Designed to be modular, composable, and developer-friendly, Chainless provides an intuitive abstraction layer over LangChain and similar LLM orchestration libraries.


Overview

Chainless introduces three core primitives:

  • Tool – Wraps callable functions with structured metadata
  • Agent – Manages reasoning, tool execution, and LLM interactions
  • TaskFlow – Enables orchestrated multi-step workflows with sequential or parallel logic

Whether you're building AI assistants, workflow chains, or multi-agent environments, Chainless gives you the control and simplicity to iterate fast.


Key Features

  • 🧩 Modular design – Agents and tools are decoupled and reusable
  • ⚙️ LangChain-compatible – Use any BaseChatModel and native LangChain tools
  • 🔁 Supports sequential and parallel task execution
  • 🧠 Customizable prompts and reasoning flows via decorators
  • 🛠 Minimal dependencies and simple integration
  • ✅ Typed, testable, and developer-centric

Installation

pip install chainless

Note: Chainless requires LangChain and an LLM provider (e.g., OpenAI, Anthropic). Make sure to configure credentials as needed.


📘 Usage Examples

Below are a few examples of how to use Chainless in increasing complexity.


🔹 Example 1: Simple Tool Call via Agent

from chainless import Tool, Agent
from langchain_openai import ChatOpenAI

# Define a simple tool
reverse_tool = Tool("Reverser", "Reverses a string", lambda input: input[::-1])

# Set up LLM
llm = ChatOpenAI()

# Create agent
agent = Agent(
    name="SimpleReverser",
    llm=llm,
    tools=[reverse_tool],
    system_prompt="Use the Reverser tool to reverse the input string."
)

# Run agent
response = agent.start("Hello world")
print(response["output"])

🔸 Example 2: Parallel Tool Usage in a TaskFlow

from chainless import Tool, Agent, TaskFlow

# Define tools
wiki_tool = Tool("WikiTool", "Searches Wikipedia", lambda q: f"Wikipedia info: {q}")
yt_tool = Tool("YTTool", "Fetches YouTube transcript", lambda q: f"Transcript of {q}")

# Create agents
wiki_agent = Agent("WikipediaAgent", llm=llm, tools=[wiki_tool])
yt_agent = Agent("YouTubeAgent", llm=llm, tools=[yt_tool])

# Build TaskFlow
flow = TaskFlow("ParallelSearch")

flow.add_agent("WikipediaAgent", wiki_agent)
flow.add_agent("YouTubeAgent", yt_agent)

flow.step("WikipediaAgent", input_map={"input": "{{input}}"})
flow.step("YouTubeAgent", input_map={"input": "{{input}}"})

flow.parallel(["WikipediaAgent", "YouTubeAgent"])

result = flow.run("Artificial Intelligence")
print(result)

🟠 Example 3: Custom Reasoning with a Summarizer Agent

from chainless import Agent
from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate

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

summary_agent = Agent(
    name="Summarizer",
    llm=llm,
    system_prompt="Summarize input in 2 sentences."
)

@summary_agent.custom_start
def start(input: str, tools, system_prompt):
    prompt = ChatPromptTemplate.from_messages([
        ("system", system_prompt),
        ("human", "{input}")
    ])
    chain = llm | prompt
    return chain.invoke(input)

result = summary_agent.start("Chainless is a lightweight agentic orchestration library...")
print(result["output"])

🔴 Example 4: Multi-Agent TaskFlow with Conditional Data Routing

from chainless import TaskFlow

# Reuse wiki_agent, yt_agent, summary_agent from previous examples
report_agent = Agent(
    name="Reporter",
    llm=llm,
    system_prompt="""
    Combine the given summaries into a JSON report:
    {
      "topic": ...,
      "wikipedia": ...,
      "youtube": ...
    }
    """
)

@report_agent.custom_start
def start(wikipedia_ozet: str, youtube_ozet: str, tools, system_prompt):
    content = f"Wikipedia: {wikipedia_ozet}nYouTube: {youtube_ozet}"
    return llm.invoke(content)

flow = TaskFlow("MultiModalSummarization")

flow.add_agent("WikipediaAgent", wiki_agent)
flow.add_agent("YouTubeAgent", yt_agent)
flow.add_agent("WikiSummary", summary_agent)
flow.add_agent("YouTubeSummary", summary_agent)
flow.add_agent("Reporter", report_agent)

flow.step("WikipediaAgent", input_map={"input": "{{input}}"})
flow.step("YouTubeAgent", input_map={"input": "{{input}}"})
flow.parallel(["WikipediaAgent", "YouTubeAgent"])

flow.step("WikiSummary", input_map={"input": "{{WikipediaAgent.output.output}}"})
flow.step("YouTubeSummary", input_map={"input": "{{YouTubeAgent.output.output}}"})

flow.step("Reporter", input_map={
    "wikipedia_ozet": "{{WikiSummary.output}}",
    "youtube_ozet": "{{YouTubeSummary.output}}"
})

output = flow.run("Quantum Computing")
print(output["output"]["content"])

Architecture

Chainless follows a simple but powerful pattern:

  • Tool: Smallest executable unit. Synchronous, stateless.
  • Agent: Wraps an LLM and optionally calls tools. Supports custom reasoning logic.
  • TaskFlow: Manages execution of agents in steps, supports references, retries, and callbacks.

The framework is ideal for:

  • Custom LLM agents with tool use
  • Multi-step conversational agents
  • Parallel agent execution
  • Complex logic workflows without DAG complexity

Roadmap

  • ✅ Decorator-based agent customization
  • ✅ Async tool support
  • ⏳ Built-in memory support
  • ⏳ CLI for flow testing

Contributing

We welcome contributions from the community. If you have ideas, bug reports, or suggestions, please open an issue or a pull request.

For larger changes, please open a discussion first.


License

This project is licensed under the MIT License.


Authors

Maintained by Onur Artan / Trymagic. Inspired by LangChain’s ecosystem and the need for leaner abstraction models in agentic applications.

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

chainless-0.1.1.tar.gz (97.5 kB view details)

Uploaded Source

Built Distribution

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

chainless-0.1.1-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file chainless-0.1.1.tar.gz.

File metadata

  • Download URL: chainless-0.1.1.tar.gz
  • Upload date:
  • Size: 97.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for chainless-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fa8a4b2f4b1d47c90036a529cc1aac40d30b49c287bf09f39933f3d640eab6dc
MD5 2771ea6b2cf3eb1387b7aeb63112273a
BLAKE2b-256 3758d67c377b2db11677526773ea6c958f5e7fa375e57d8b28828123580c58e6

See more details on using hashes here.

File details

Details for the file chainless-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: chainless-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for chainless-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab064613ce0c6dfb305c79826e10272f59c615dda44e05bf0a101e43bb2efb15
MD5 b3cc29d8907c40a1a103adc14ecf4293
BLAKE2b-256 e9a8a084022b74b80a77ae5164f17a65ca13a22aeecc3b0b760c444c1a573afa

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