build-flow
БесплатноБез исполняемых скриптовНе проверенBuilding CrewAI Flows on crewai 1.15.x: structured (Pydantic) vs dict state and state.id, @start/@listen/@router wiring, or_/and_ semantics, router labels vs…
от crewAIInc★ 51 звезда на GitHubОб этом скилле
Build a CrewAI Flow
How to write a Flow that wires correctly, keeps typed state, persists and resumes, and calls crews and agents, on the current API.
Verified against crewai 1.15.22 and 1.15.23 on 2026-10-01.
Live-tested on CrewAI AMP and real LLMs on 2026-10-01.
Run crewai version first; if the major/minor differs from 1.15, re-verify version-sensitive rows with the ask-docs skill before trusting them.
1. Scaffold and run a flow project
crewai create flow lead-router # the package is still lead_router
cd lead_router
crewai install # uv sync; writes uv.lock
crewai run # runs the `kickoff` script in pyproject.toml
crewai flow plot # runs the `plot` script
What the scaffold gives you:
| File | Contents |
|---|---|
pyproject.toml |
[project.scripts] kickoff, run_crew (both <pkg>.main:kickoff), plot, run_with_trigger; [tool.crewai] type = "flow" |
src/<pkg>/main.py |
A Flow[ContentState] subclass plus kickoff() and plot() functions; from crewai.flow import Flow, listen, start |
src/<pkg>/crews/content_crew/ |
A classic @CrewBase crew with config/agents.yaml and config/tasks.yaml; its agents set no llm, so they use the default OpenAI model |
.env |
OPENAI_API_KEY=YOUR_API_KEY - a placeholder; a run with it fails with 401 ... Incorrect API key provided. An OPENAI_API_KEY exported in the shell takes precedence over .env: with a valid key exported, the unmodified scaffold's crewai run ran its three agents on gpt-4.1-mini and wrote output/post.md |
AGENTS.md, CLAUDE.md, GEMINI.md (plus CURSOR.md from 1.15.23), README.md, tests/ |
Coding-assistant instructions and an empty tests folder |
.git/ |
crewai create runs git init (no commit, no remote) |
To use another provider, set llm: anthropic/claude-haiku-4-5 (for example) on each agent in agents.yaml, run uv add "crewai[anthropic]", and put ANTHROPIC_API_KEY=<your-key> in .env - crewai run read the key from .env with nothing exported in the shell.
Rules the scaffold implies:
- Keep
[tool.crewai] type = "flow". The CLI uses it to decide thatcrewai runmeansuv run kickoff. - The template's
plan_content()overwritesself.state.topicwith"AI Agents"unless a trigger payload is present, sokickoff(inputs={"topic": ...})(and a deployed kickoff'sinputs) is ignored. Delete that assignment before relying on inputs. - The template's
plot()callsplot()with the defaultshow=True, socrewai flow plotopens a browser. Change it toplot("<name>.html", show=False)for headless use. - Import with the absolute package path (
from lead_router.crews.content_crew.content_crew import ContentCrew), as the template does. kickoff()inmain.pymust returnNone. The generated console script doessys.exit(kickoff()), so returning the flow result (a dict, say) makes the process exit with status 1 and prints the value to stderr, andcrewai runprints "An error occurred while running the flow" - yetcrewai runitself still exits 0, so a CI step that only checks its exit code passes.crewai run --inputs '{...}'is rejected for a Python flow:Error: --inputs requires a declarative flow definition ([tool.crewai].definition) or --definition. Pass inputs in code (flow.kickoff(inputs=...)), or read them fromsys.argvin yourkickoff()and calluv run kickoff '<json>'.crewai flow kickoffstill works but prints "deprecated. Use 'crewai run' instead."- A placeholder or invalid key makes the flow fail, yet
crewai runstill exits 0 (it printsAn error occurred while running the flow: Command '['uv', 'run', 'kickoff']' returned non-zero exit status 1.). Check for that line, not the exit code.
2. State: structured or dict
| Structured (recommended) | Unstructured | |
|---|---|---|
| Declare | class MyFlow(Flow[MyState]) with MyState(BaseModel) |
class MyFlow(Flow) |
| Access | self.state.topic |
self.state["topic"] |
id |
Added for you (self.state.id, a UUID string) |
self.state["id"] |
| Validation | kickoff(inputs=...) values are type-checked |
none |
from pydantic import BaseModel
from crewai.flow import Flow, listen, start
class ReportState(BaseModel):
topic: str = "" # give every field a default
draft: str = ""
notes: list[str] = []
class ReportFlow(Flow[ReportState]):
@start()
def plan(self):
self.state.notes.append(f"planning {self.state.topic}")
return self.state.topic.upper()
@listen(plan)
def write(self, plan_output): # receives plan()'s return value
self.state.draft = f"Draft about {plan_output}"
return self.state.draft
flow = ReportFlow()
result = flow.kickoff(inputs={"topic": "bees"}) # inputs set state BEFORE @start runs
print(result) # "Draft about BEES" - kickoff returns the last method's ou
Установить build-flow в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл build-flow?
Building CrewAI Flows on crewai 1.15.x: structured (Pydantic) vs dict state and state.id, @start/@listen/@router wiring, or_/and_ semantics, router labels vs method names, @persist (correct import, where it stores state, restore_from_state_id), checkpointing with CheckpointConfig, @human_feedback and HumanFeedbackResult.feedback, plot(), calling crews and agents from flow methods, kickoff inputs, and the `crewai create flow` scaffold. Use when writing or debugging a Flow subclass or main.py with `from crewai.flow import ...`, when a listener never fires or fires twice, or when you see errors like "listen condition 'x' references the handler name 'x'", "cannot import name 'persist'", "'StateWithId' object is not subscriptable", "Flow state model must have an 'id' field", "--inputs requires a declarative flow definition", "invoked synchronously from within a running event loop", or HumanFeedbackCollapseError.
Как установить скилл build-flow?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл build-flow запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic