Inputs: one crew, many tickets
A task with {question} in its description is a template. kickoff(inputs=...) fills it in, so one crew answers any ticket, and kickoff_for_each runs a list of them.
Lesson 4's task had the customer's question typed into its description. A support desk needs the same crew for every ticket.
from crewai import Agent, Crew, Task
from shop_llm import ShopLLM
agent = Agent(
role="Support agent",
goal="Answer customers of a small online shop",
backstory="You have worked the shop's support desk for years.",
llm=ShopLLM(model="shop"),
)
task = Task(
description="Answer the customer: {question}",
expected_output="One short, friendly sentence.",
agent=agent,
)
crew = Crew(agents=[agent], tasks=[task])The description now contains {question}, a placeholder in curly braces. The agent is lesson 4's.
result = crew.kickoff(inputs={"question": "Where is my order A17?"})
print(result.raw)inputs is a dictionary. Before the crew runs, CrewAI puts each value in place of the placeholder with the same name, in task descriptions, expected outputs and the agent's role, goal and backstory.
A misspelled input
crew.kickoff(inputs={"q": "Where is my order A17?"})A placeholder with no value in inputs stops the run before any model is called, and the error names the missing variable. Calling kickoff() with no inputs at all is different: nothing is filled in, and the agent is asked about the literal text {question}.
Many tickets
tickets = [
{"question": "Where is my order A17?"},
{"question": "Hello, can you help me?"},
]
for result in crew.kickoff_for_each(inputs=tickets):
print(result.raw)kickoff_for_each runs the crew once per dictionary and returns the results in the same order. The first ticket names an order; the second does not, so the model asks which one.
- Put
{question}in the agent's goal as well and run the first example. - Add a third ticket about C40 to the list.
- Call
crew.kickoff()with no inputs, then printtask.description.
Little by little, you're building something great.