🧠 What You’ll Build

In this tutorial, you’ll learn how to:

  • Define a Tool (a function with metadata)
  • Create an Agent (a smart assistant that can use tools)
  • Compose a TaskFlow (a sequential pipeline of agents)

This is the ideal place to begin your journey with chainless.


πŸ“¦ File Structure

Create a file named:

first_flow.py

πŸ”§ Step 1 β€” Define a Tool

Tools are simple functions wrapped with structure. Think of them as utilities your agents can use.

from chainless import Tool

def search_wikipedia(query: str):
    return f"Mocked Wikipedia result for: {query}"

wiki_tool = Tool(
    name="Wikipedia",
    description="Searches Wikipedia for a given topic.",
    func=search_wikipedia
)

🧠 Step 2 β€” Create an Agent

Agents can use tools and interact with language models.

from chainless import Agent
from langchain_openai import ChatOpenAI

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

research_agent = Agent(
    name="Researcher",
    llm=llm,
    tools=[wiki_tool],
    system_prompt="You're a research assistant. Answer based on facts and use tools when needed."
)

πŸ”— Step 3 β€” Compose with TaskFlow

A TaskFlow runs agents in sequence and carries the input/output through the pipeline.

from chainless import TaskFlow

flow = TaskFlow(name="SimpleResearchFlow")

# Add agents
flow.add_agent("ResearcherAgent", research_agent)

# Define steps
flow.step("ResearcherAgent", {"input": "{{input}}"})

result = flow.run("Tell me about the history of computing.")
print(result)

πŸ§ͺ Full Code: first_flow.py

first_flow.py
from chainless import Tool, Agent, TaskFlow
from langchain_openai import ChatOpenAI

# Tool
def search_wikipedia(query: str):
    return f"Mocked Wikipedia result for: {query}"

wiki_tool = Tool(
    name="Wikipedia",
    description="Searches Wikipedia for a given topic.",
    func=search_wikipedia
)

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

# Agent
research_agent = Agent(
    name="Researcher",
    llm=llm,
    tools=[wiki_tool],
    system_prompt="You're a research assistant. Answer based on facts and use tools when needed."
)

# Flow
flow = TaskFlow(name="SimpleResearchFlow")

# Add agents
flow.add_agent("ResearcherAgent", research_agent)

# Define steps
flow.step("ResearcherAgent", {"input": "{{input}}"})

# Run
result = flow.run("What is quantum computing?")
print(result)

βš™οΈ Running the Flow

1

Create a virtual environment

python3 -m venv .venv
source .venv/bin/activate
2

Install dependencies

pip install chainless langchain_openai 
3

Set your API key

.env
OPENAI_API_KEY=sk-***
4

Run your script

python first_flow.py

βœ… Output Example

[Researcher]: Using tool Wikipedia...
Mocked Wikipedia result for: quantum computing

πŸš€ What’s Next?

  • Add more tools like WebSearch, DocumentReader, etc.
  • Create custom behaviors with custom_start
  • Use TaskFlow to chain multiple agents together (e.g., researcher β†’ summarizer β†’ reporter)

Let your agents do the thinking. Build once, automate forever ⚑