Engineering18 min readDecember 6, 2026

Six CrewAI examples for 1.15.50, each with the check to run before you trust it

CrewAI examples for 1.15.50: a one-file crew, a custom tool, Pydantic output, a Flow with a router, and Ollama. agents.yaml now needs --classic.

Charafeddine Mouzouni
Charafeddine Mouzouni
Diagram of a CrewAI Flow for support tickets: a ticket goes to a triage crew that returns a Pydantic Triage object, then a router written in plain Python sends it either to the human queue (urgent, sensitive or failed) or to a reply crew that drafts a reply under 120 words

The smallest working CrewAI example is one Python file: two Agent objects, two Task objects, a Crew with Process.sequential, and crew.kickoff(inputs={...}). Install it with pip install crewai on Python 3.10 to 3.13, set OPENAI_API_KEY, and run the file. This page has six complete CrewAI examples for CrewAI 1.15.50, the current release (4 December 2026): that one-file crew, the project the CLI creates, a custom tool, structured output with a Pydantic model, a Flow with state and a router, and the same crew on a local model through Ollama. Every sample was checked line by line on 6 December 2026 against the 1.15.50 source code and documentation.

Two changes break older tutorials. crewai create crew now writes a JSON-first project with crew.jsonc and agents/*.jsonc, and the --classic flag brings back agents.yaml, tasks.yaml and crew.py. The official crewAI-examples repository is archived (last updated April 2026) and targets version 0.152.0. For local models, LLM(model="ollama/qwen3.5:9b") talks to Ollama on port 11434 with no extra package, but Ollama defaults to a 4K window on GPUs under 24 GiB, so start it with OLLAMA_CONTEXT_LENGTH=64000.

Our own 2025 guide to CrewAI for support bots tells you that crewai create crew my_project sets up agents.yaml and tasks.yaml for you to edit. It also says CrewAI supports Python 3.10 to 3.12. Both lines were right when they were written.

Run that command on 1.15.50 and the YAML files are gone. A wizard asks for roles, goals, a model and tools, then writes JSONC files. Someone following a tutorial from last year can lose half an hour wondering what they did wrong, and the answer is nothing. The framework moved, and it moves fast: five releases shipped between 30 November and 4 December.

This page gives you six examples written for the release that is current today, and next to each one it names the thing to check before you believe the output. I kept one case throughout, a support desk triaging tickets, so each example adds one idea to the last.

What is current in CrewAI on 6 December 2026

Start with the facts that decide whether a tutorial still works. Each row below was read at source today.

QuestionAnswer for 1.15.50
Current release1.15.50, published 4 December 2026 on PyPI
Python3.10 to 3.13 (>=3.10,<3.14), so Python 3.14 is unsupported
Library installpip install crewai or uv add crewai
CLI installuv tool install crewai
crewai create crewJSON-first project; --classic for the YAML layout
Default modelthe MODEL environment variable, else gpt-6-luna
Ollamabuilt-in client on http://localhost:11434/v1
crewAI-examples repoarchived (last updated April 2026), written for 0.152.0

The default model row matters more than it looks. An Agent with no llm reads MODEL, then MODEL_NAME, then OPENAI_MODEL_NAME, and falls back to the constant in the 1.15.50 source. Leave all three unset and every agent calls OpenAI, which is why the first example needs an OpenAI key.

Example 1: the smallest CrewAI crew in one Python file

Two agents, two tasks, run in order. The first agent sorts a ticket, the second drafts a reply from that triage. Put this in crew_min.py.

from crewai import Agent, Crew, Process, Task

triager = Agent(
    role="Support triager",
    goal="Classify each ticket and say what it needs",
    backstory="You sort tickets for a small SaaS team.",
)
writer = Agent(
    role="Support writer",
    goal="Draft a short, accurate first reply",
    backstory="You never promise refunds or dates.",
)

triage = Task(
    description=(
        "Classify this ticket: {ticket}\n"
        "Give a category (billing, bug, how-to, other), "
        "a priority from 1 (urgent) to 4, and one line "
        "on what the customer needs."
    ),
    expected_output="Category, priority, one line of need.",
    agent=triager,
)
reply = Task(
    description="Draft a first reply under 120 words.",
    expected_output="A reply a human can review and send.",
    agent=writer,
)

crew = Crew(
    agents=[triager, writer],
    tasks=[triage, reply],
    process=Process.sequential,
    verbose=True,
)

result = crew.kickoff(inputs={
    "ticket": "I was charged twice in March. Order 1042.",
})
print(result.raw)
print(result.token_usage.total_tokens, "tokens")

Then install and run it from a fresh virtual environment.

python3 --version        # must be 3.10 to 3.13
pip install crewai
export OPENAI_API_KEY="sk-..."
python crew_min.py

What it does: {ticket} in the description is filled from inputs at kickoff. In a sequential crew, a task with no context set receives the output of every task before it, which you can see in _get_context in the crew source. That is how the writer sees the triage without you wiring anything.

What to expect: With verbose=True you see each agent's turn in the terminal, then the reply. result.raw holds the last task's text, result.tasks_output holds one entry per task, and result.token_usage holds the token totals and the request count.

What to watch: The token line. Two agents means at least two model calls per ticket, and each agent prompt carries its role, goal, backstory and the earlier output. Print the number on day one so the cost of adding a third agent is a measured figure later on.

Example 2: the CLI project, crew.jsonc and agents.yaml

The CLI is where tutorials and the current release disagree most. Install it once, then create a project.

uv tool install crewai
crewai create crew ticket_triage
cd ticket_triage

The wizard asks for a provider and model, then for each agent's role, goal, backstory and tools, then for each task. Its last question is "Enable crew memory?", and the default answer is yes. The installation page shows what you get.

JSON-first (default)Classic (--classic)
crew.jsonc: crew, tasks, process, inputssrc/<name>/crew.py with @CrewBase
agents/<name>.jsonc, one file per agentconfig/agents.yaml
tasks inside crew.jsoncconfig/tasks.yaml
tools/<name>.py, used as custom:<name>tools/custom_tool.py
no main.py; crewai run reads the JSONmain.py with run, train, replay, test

Here is a two-agent version of our crew in the JSON layout. Comments are allowed, which is what the C in JSONC means. First agents/triager.jsonc, and agents/writer.jsonc follows the same shape.

{
  "role": "Support triager",
  "goal": "Classify each ticket and say what it needs",
  "backstory": "You sort tickets for a small SaaS team.",
  // provider/model, as in the generated template
  "llm": "openai/gpt-6-luna",
  "tools": [],
  "settings": {
    "verbose": false,
    "allow_delegation": false
  }
}

Then crew.jsonc, where each name in agents loads the matching file in agents/.

{
  "name": "ticket_triage",
  "agents": ["triager", "writer"],
  "tasks": [
    {
      "name": "triage_task",
      "description": "Classify this ticket: {ticket}",
      "expected_output": "Category, priority 1-4, need.",
      "agent": "triager"
    },
    {
      "name": "reply_task",
      "description": "Draft a first reply under 120 words.",
      "expected_output": "A reply a human can send.",
      "agent": "writer",
      "context": ["triage_task"],
      "output_file": "output/reply.md"
    }
  ],
  "process": "sequential",
  "verbose": true,
  "memory": false,
  "inputs": {}
}
crewai install
crewai run --inputs '{"ticket": "Charged twice, order 1042"}'

What to expect: Without --inputs, crewai run prompts for any {placeholder} it cannot fill, and exits if one is still missing. The reply lands in output/reply.md.

What to watch: I set "memory": false on purpose. With memory on, CrewAI embeds what the crew learns, and with no embedder configured it uses OpenAI's text-embedding-3-large, according to the memory docs. If you answered yes in the wizard and later move the agents to another provider, memory still sends text to OpenAI for embedding. Turn it on when you know what it should remember.

If you prefer YAML, crewai create crew ticket_triage --classic gives the layout older guides describe, with the same crewai install and crewai run.

Example 3: a CrewAI custom tool

The triage agent guesses about billing because it cannot see the order. A tool fixes that. The @tool decorator turns a typed function into a tool, and its docstring becomes the description the model reads. In 1.15.50 a function without a docstring raises ValueError, as the tool source shows.

import json

from crewai import Agent, Crew, Task
from crewai.tools import tool

ORDERS = {
    "1042": {"status": "paid", "charges": 2, "eur": 49},
    "1043": {"status": "refunded", "charges": 1, "eur": 19},
}

@tool("Order lookup", max_usage_count=3)
def order_lookup(order_id: str) -> str:
    """Look up an order by its id, such as 1042.
    Returns status, number of charges and amount."""
    order = ORDERS.get(order_id.strip())
    if order is None:
        raise KeyError(f"no order {order_id}")
    return json.dumps(order)

billing = Agent(
    role="Billing triager",
    goal="Check the order before judging a billing ticket",
    backstory="You confirm facts in the order system.",
    tools=[order_lookup],
)
check = Task(
    description=(
        "Ticket: {ticket}\n"
        "Look up the order, then say whether the customer "
        "was charged twice."
    ),
    expected_output="Yes or no, with the order facts.",
    agent=billing,
)

crew = Crew(agents=[billing], tasks=[check])
result = crew.kickoff(inputs={
    "ticket": "Charged twice in March, order 1042.",
})
print(result.raw)
if result.has_tool_failures:
    for record in result.tool_failures:
        print("TOOL FAILED:", record.summary())

Swap the dictionary for your database or API call and keep the rest. max_usage_count=3 caps how many times the tool can be used, which stops a confused agent from looping on a paid API.

What to watch: A failed tool call does not stop the crew. The tools page says the default policy records the failure and carries on, so the agent can narrate around it and still produce a confident answer. That is why the last three lines exist. If a wrong answer is worse than no answer, set tool_failure_policy=ToolFailurePolicy.RAISE on the task, imported from crewai.tools.tool_failure.

In the JSON project, a tool referenced as "custom:order_lookup" loads tools/order_lookup.py, and that file must define a BaseTool subclass. A decorated function is skipped there, because the JSON loader looks for a class. The loader also runs that file as Python when the crew loads, so treat a JSON crew from someone else like any code you download.

Example 4: structured output with a Pydantic model

Text is fine for a human. A program that routes tickets needs fields. output_pydantic on a task asks for output that validates against your model, and the result comes back as an object. This file, triage.py, is reused by the next two examples.

from typing import Literal

from pydantic import BaseModel, Field
from crewai import Agent, Crew, Task

class Triage(BaseModel):
    category: Literal["billing", "bug", "how-to", "other"]
    priority: int = Field(ge=1, le=4)
    needs_human: bool
    summary: str

def make_triage_crew(llm=None) -> Crew:
    triager = Agent(
        role="Support triager",
        goal="Classify each ticket and say what it needs",
        backstory="You sort tickets for a small SaaS team.",
        llm=llm,
    )
    task = Task(
        description=(
            "Classify this ticket: {ticket}\n"
            "Priority 1 is urgent. Set needs_human for "
            "money disputes, legal threats or outages."
        ),
        expected_output="The triage fields.",
        agent=triager,
        output_pydantic=Triage,
    )
    return Crew(agents=[triager], tasks=[task])

if __name__ == "__main__":
    out = make_triage_crew().kickoff(inputs={
        "ticket": "How do I export invoices to CSV?",
    })
    t = out.pydantic
    if t is None:
        raise ValueError("no valid triage: " + out.raw[:200])
    print(t.category, t.priority, t.needs_human)

What to expect: out.pydantic is a Triage instance, so t.priority is an integer between 1 and 4. The tasks page also allows out["category"] and out.to_dict().

What to watch: The None check is the important line. When the model's answer cannot be converted to your model, CrewAI logs a warning, keeps the raw text and leaves pydantic empty, and the crew still reports success. You can see it in convert_with_instructions in the converter source. Code that reads out.pydantic.priority without the check will fail later, somewhere less obvious.

For rules a schema cannot express, add a guardrail. It is a function that takes the task output and returns (True, value) or (False, reason). On False the reason goes back to the agent for another try, up to guardrail_max_retries, which defaults to 3. After the last failure the task raises an exception.

from crewai import TaskOutput

def under_120_words(out: TaskOutput):
    n = len(out.raw.split())
    if n > 120:
        return (False, f"{n} words. Cut it to 120.")
    return (True, out.raw)

# on the reply task:
# Task(..., guardrail=under_120_words,
#      guardrail_max_retries=2)

Example 5: a CrewAI Flow with state and a router

A crew decides how to do a task. A Flow decides which task happens at all, in plain Python you can read and test. CrewAI's own guide to choosing recommends Flows around crews when the work is complex and the output has to be precise.

This Flow keeps the ticket and the triage in typed state, runs the triage crew, then routes. Urgent or sensitive tickets go to a person with no model involved. Routine ones go to a second crew that drafts the reply. It imports triage.py from Example 4.

from typing import Literal

from pydantic import BaseModel
from crewai import Agent, Crew, Task
from crewai.flow import Flow, listen, router, start

from triage import Triage, make_triage_crew

class TicketState(BaseModel):
    ticket: str = ""
    triage: Triage | None = None
    reply: str = ""

def make_reply_crew() -> Crew:
    writer = Agent(
        role="Support writer",
        goal="Draft a short, accurate first reply",
        backstory="You never promise refunds or dates.",
    )
    task = Task(
        description=(
            "Ticket: {ticket}\nTriage: {summary}\n"
            "Draft a first reply under 120 words."
        ),
        expected_output="A reply a human can send.",
        agent=writer,
    )
    return Crew(agents=[writer], tasks=[task])

class SupportFlow(Flow[TicketState]):
    @start()
    def classify(self):
        out = make_triage_crew().kickoff(
            inputs={"ticket": self.state.ticket})
        self.state.triage = out.pydantic

    @router(classify)
    def route(self) -> Literal["human", "draft"]:
        t = self.state.triage
        if t is None or t.needs_human or t.priority == 1:
            return "human"
        return "draft"

    @listen("human")
    def escalate(self):
        return "Sent to the human queue."

    @listen("draft")
    def draft(self):
        out = make_reply_crew().kickoff(inputs={
            "ticket": self.state.ticket,
            "summary": self.state.triage.summary,
        })
        self.state.reply = out.raw
        return self.state.reply

flow = SupportFlow()
print(flow.kickoff(inputs={
    "ticket": "How do I export invoices to CSV?",
}))

What it does: kickoff(inputs=...) merges the inputs into the state model, so self.state.ticket is set before classify runs. The router's return value picks which @listen method runs next. kickoff returns the output of the last method that finished, according to the Flows page.

What to watch: Look at what the router does with a failed triage. When pydantic is None, the ticket goes to a person. The fallback is the safe branch, and it is one line of Python a reviewer can read. The Literal return type also lets flow.plot() draw both branches.

I'd build most support automation this way. The model reads and writes, and ordinary code holds the decisions that cost money when they go wrong. It also makes the second-order cost visible: every ticket that reaches draft pays for two crews, and every ticket that goes to human pays for one.

Example 6: a CrewAI Ollama example on a local model

Point the triage crew at Ollama and the model calls stay on your machine. In 1.15.50, the ollama/ prefix is handled by CrewAI's built-in OpenAI-compatible client, with http://localhost:11434/v1 as the default address and OLLAMA_HOST read if set. That is in the provider source, and it means no LiteLLM. The LLM page still says to add crewai[litellm] for Ollama, which does no harm and is no longer needed.

Prepare the server first. Ollama's context-length page gives 4K tokens to GPUs under 24 GiB, 32K from 24 to 48 GiB, and 256K above, and asks for at least 64,000 tokens for agents.

ollama pull qwen3.5:9b
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
# in another terminal, after the first request:
ollama ps     # check the CONTEXT column

If the Ollama desktop app is already running, quit it before ollama serve, or set the same value with the context slider in the app's settings.

Then pass a local LLM to the crew from Example 4.

from crewai import LLM
from triage import make_triage_crew

local = LLM(model="ollama/qwen3.5:9b", temperature=0.2)

out = make_triage_crew(llm=local).kickoff(inputs={
    "ticket": "Upload fails on every PNG since Monday.",
})
print(out.pydantic or out.raw)

qwen3.5:9b is the model the 1.15.50 CLI writes for --provider ollama, and its library page lists tools and a 256K window for a 6.6 to 7.6 GB download. Our best Ollama models guide picks by GPU memory if yours is smaller or larger.

What to watch: The context window is the usual failure. This client calls Ollama's OpenAI-compatible endpoint, and Ollama's compatibility page says that API has no way to set the context size per request. So the window comes from the server variable above, or from a model you build with PARAMETER num_ctx in a Modelfile. Leave it at 4K and a long agent prompt can be cut to fit with no error, a behavior our Ollama API reference walks through.

SettingWhy it matters on Ollama
OLLAMA_CONTEXT_LENGTH4K default under 24 GiB of VRAM
a model with the tools badgeExample 3 needs tool calls
memory off, or an Ollama embedderdefault memory embeds with OpenAI
CREWAI_DISABLE_TELEMETRY=trueCrewAI telemetry is on by default
CREWAI_TRACING_ENABLED=falsetracing has its own switch

The last three rows matter if "local" is the reason you chose Ollama. The telemetry page says the default collects agent roles and tool names and no prompt content, and it lists both switches. If you want memory on a local crew, the memory docs show an Ollama embedder, and it needs uv add "crewai[chromadb]". For the same model behind LangChain instead, see LangChain with Ollama.

When a crew is the wrong tool

Six examples in, it is worth saying when to stop adding agents. A crew earns its cost when the work splits into parts that need different context or different tools. When one agent with the right tools can see everything it needs, a second agent adds a hand-off, another prompt and another place for a fact to get lost.

Anthropic's write-up of its own multi-agent research system gives a public number on that trade. On breadth-first research queries, an Opus 4 lead with Sonnet 4 subagents beat a single Opus 4 agent by 90.2% on Anthropic's internal eval, and multi-agent systems used about 15 times the tokens of a chat. The same post names domains where agents share context or depend on each other heavily as a poor fit.

Your work looks likeStart with
one job, the right tools, one contextone Agent and agent.kickoff()
fixed steps you could draw todaya Flow with plain Python and single model calls
steps that need different tools or contexta small crew, inside a Flow if it branches
a process that lives only in people's headswriting it down

The last row is the expensive one. A crew mirrors a process: roles, hand-offs, rules for exceptions. If the rules live in people's heads, the agents inherit the gaps and fill them with confident guesses. I wrote about that pattern in You Cannot Automate a Mess, and it applies to a two-agent crew as much as to twelve.

For the longer argument, with a decision table and the costs of hand-offs, read when one agent beats many. A useful test before you add an agent: run the one-agent version and the two-agent version on the same twenty tickets and compare answers and token_usage. If the second agent does not change the answers, it is only changing the bill.

How to test a crew before you trust it

A crew that produced one good reply has passed one test. The structured output from Example 4 is what makes real testing cheap, because you can grade fields with code and leave the prose to a person.

from triage import make_triage_crew

CASES = [
    ("I was charged twice in March.", "billing"),
    ("How do I export invoices to CSV?", "how-to"),
    ("Upload fails on every PNG since Monday.", "bug"),
]
RUNS = 3

def passes_every_run(ticket: str, want: str) -> bool:
    for _ in range(RUNS):
        out = make_triage_crew().kickoff(
            inputs={"ticket": ticket})
        t = out.pydantic
        if t is None or t.category != want:
            return False
    return True

ok = sum(passes_every_run(t, w) for t, w in CASES)
print(f"{ok}/{len(CASES)} cases passed all {RUNS} runs")

Each case must pass every run, because a ticket classified right two times out of three will also be classified wrong in production, some of the time. A failed conversion counts as a failure, never as a pass. Replace the three cases with fifty real tickets your team has already labeled, and keep the ones that broke the crew.

CrewAI ships two commands for this. crewai test -n 5 runs a classic project five times and scores each task from 1 to 10 with a judge model, and the CLI still accepts only OpenAI models for that judge. crewai eval sends a run's trace to CrewAI AMP, their hosted platform, for grading, and needs a CrewAI account, so your traces leave the machine. A judge's score is still a model's opinion, so check it against labeled cases before you let it gate a release.

Our guide to evaluating AI agents covers the rest: grading the world state an agent leaves behind, measuring reliability across repeated runs, and validating a judge before you rely on it.

Where to find more CrewAI examples

The crewAI-examples repository is still the best reading for project shapes: trip planners, stock analysis, a lead-scoring Flow with a human review step. It is archived, and its README says every example uses CrewAI 0.152.0, so expect imports and the project layout to differ from what you install today.

Two maintained sources sit closer to the current release. crewai template list shows ready projects from CrewAI's template organization, and crewai create template <name> downloads one. The crewAI-quickstarts repository collects feature demos. And the docs folder in the main repo keeps a copy of the documentation for each recent release, so you can read the page that matches the version you pinned.

If you are choosing between frameworks, Orchestrator agents explains when one agent beats many, with the evidence on both sides. How to evaluate AI agents turns the test above into a full eval stack. LangChain with Ollama runs the same local models through LangChain's tool calling and structured output.

What I'd do

Pin crewai==1.15.50 in your project so a release next week cannot change your crew under you, and start from Example 1 in a single file. Add structured output before you add a third agent, check pydantic for None and has_tool_failures on every run, and put the branching in a Flow where a reviewer can read it. Turn memory off until you know what it should store and where it embeds. Build twenty labeled tickets before you show anyone a demo, and run each one three times. Write the process down first, in a file the agents and your team both read, which is the habit at the center of an AI Operating System. If you want to build the agent loop itself, with permissions, approvals and a journal you control, Building Accountable AI Agents writes that harness in Python, and the Engineering Series takes it from the model gateway to a production server. For a team rolling agents out across departments, our team programs run this review on your own workflows.

FAQ

What is a simple CrewAI example?

Two agents and two tasks in one file: a triager that classifies a support ticket and a writer that drafts the reply, run with Crew(agents=[...], tasks=[...], process=Process.sequential) and crew.kickoff(inputs={"ticket": ...}). In a sequential crew the second task sees the first task's output automatically. Install with pip install crewai on Python 3.10 to 3.13.

Does crewai create crew still make agents.yaml and tasks.yaml?

Only with --classic. In CrewAI 1.15.50, crewai create crew <name> writes crew.jsonc for tasks and settings and one agents/<name>.jsonc per agent. crewai create crew <name> --classic writes config/agents.yaml, config/tasks.yaml, crew.py and main.py. Both run with crewai run.

How do I create a custom tool in CrewAI?

Decorate a typed function with @tool("Name") from crewai.tools and give it a docstring, which becomes the description the model reads. Pass it in the agent's tools list. For a JSON project referenced as custom:<name>, write a BaseTool subclass in tools/<name>.py. Check result.has_tool_failures after each run.

How do I use CrewAI with Ollama?

Create LLM(model="ollama/qwen3.5:9b") and pass it as an agent's llm. In 1.15.50 it connects to http://localhost:11434/v1 with no extra package. Start Ollama with OLLAMA_CONTEXT_LENGTH=64000, because the default window on GPUs under 24 GiB is 4K tokens, and keep crew memory off or give it an Ollama embedder.

What is the difference between a CrewAI crew and a Flow?

A crew is a team of agents working through tasks, where the agents decide how to do each task. A Flow is ordinary Python with typed state, @start, @listen and @router methods, which decides what runs and in what order. A common production shape is a Flow that calls small crews and routes on their structured output.

Where are the official CrewAI examples on GitHub?

In crewAIInc/crewAI-examples, which is archived (last updated April 2026) and targets CrewAI 0.152.0, so read it for project ideas and expect API changes. For current projects use crewai template list, the crewAI-quickstarts repository, and the versioned docs in the main crewAIInc/crewAI repository.

Last year's tutorial was right about its own release, and this page will age the same way within a few months. Pin the version, keep the checks, and the examples will keep telling you when something underneath them moved.

A crew is only as trustworthy as the checks you run around it.

Charafeddine MouzouniDecember 6, 2026

The script works. Production is a different sport.

The AI OS letter covers the part tutorials skip: verification, trust, what breaks with real users. One idea, every Saturday, from CM, Cohorte's founder, who has shipped 60+ AI systems.

Free weekly. No spam. Unsubscribe in one click.

Subscribed ✓

The next letter arrives Saturday. Go finish the build.