main.py, a Crew, a Flow, or a factory function.
Create a project
Terminal
OPENAI_API_KEY in .env for the default openai/gpt-6-luna model, then install and run:
The scaffold selects the Responses API (api: responses) for tool calling with this model. In YAML/JSON projects, edit llm.model and llm.api in the definition; the Python template reads MODEL from .env and selects the Responses API.
Terminal
crewai install creates uv.lock. Commit it with the project. Keep .env local and use the deployment’s environment settings for provider credentials.
Local conversations
The scaffold setsconversational: true, or Agent(conversational=True) in Python. In a terminal, crewai run opens the existing conversational chat interface. Each submitted message uses the configured Agent and tools with the session history. Set the flag to false to use independent kickoffs only.
Terminal
agent.handle_turn(...) and agent.as_flow(). History stays in memory by default; configure Flow persistence explicitly for recovery across processes. Use a separate Agent instance for each independent conversation. The session_id option identifies/restores a Flow session; it does not turn one Agent into a concurrent multi-session server.
Project structure
pyproject.toml selects the Agent definition and packages the configuration and any local tools:
Define the Agent
The default identity is a general-purpose CrewAI Agent. Editrole, goal, and backstory to specialize it. The included support tools are examples used only when relevant; replace or remove them for other use cases. No skills are installed by default.
Edit agent.json:
messages at runtime; do not add a fixed input field to the definition.
Choose YAML or Python
Terminal
agent.yaml with the same fields:
agent = Agent(...) from src/python_support/agent.py. Use it when defining the Agent requires Python logic.
Both .yml and .yaml are supported. When renaming or moving a configuration, update definition and the wheel’s only-include list together. Definition paths must stay inside the project root.
Without an explicit definition, discovery accepts a single root agent.py, agent.json, agent.yml, or agent.yaml, or the conventional src/<package>/agent.py. Multiple discovered files produce an error; set definition to choose one.
Add tools from the CLI
In a terminal,crewai create agent for a JSON or YAML project opens the same tool picker as crewai create crew, including CrewAI Platform applications. Run crewai tool add in the project to add more tools later, either from the picker or by name:
Terminal
tools list and changes the crewai dependency to crewai[tools] when a tool needs it; run crewai install afterwards. CrewAI Platform applications are validated on AMP before they are added, and the Enterprise Action Auth Token is saved to .env. Run crewai tool setup to validate the platform applications already in the definition, for example after cloning the project. Python agents are edited in agent.py instead.
Add a custom tool
Use the includedtools/support_hours.py as a starting point for another tool:
custom:support_hours loads a BaseTool subclass from tools/support_hours.py. Add any tool dependencies to pyproject.toml and refresh the lockfile with crewai install. Only load trusted project code: custom tools and Python references execute Python during loading.
Reference tools and skills
The generated examples use local, fictional data. They do not inspect accounts, reset passwords, issue refunds, or create tickets.
The
skills/ directory starts empty, with only .gitkeep to preserve it in Git and packaged builds. Add skills/<name>/SKILL.md with name and description frontmatter to create a skill. Added skills are discovered as metadata; the Agent can use load_skill to load relevant instructions on demand.
Local skill paths in YAML/JSON resolve against the project root, including when load_agent_project(path) is called from another directory. The Python scaffold keeps both tools/ and skills/ inside src/<package>/ and anchors skills to agent.py. The wheel and deployment archive include these files.
Try a request that combines the example capabilities:
Terminal
Pass a message history
messages also accepts a non-empty list of role/content messages:
Terminal
Validate and deploy the preview
Terminal
.env and .venv.
For a deployment with a compatible preview Enterprise runtime, use the existing deployment workflow described in the CLI reference. The managed API accepts the same input:
Conversational managed deployments
With the compatible experimental Enterprise runtime, the internal Agent adapter setsconversational = True. Chat uses the configured Agent and its tools for every turn. Start a session, then reuse its session_id for subsequent messages:
kickoff_id; poll /status/<kickoff_id> until the turn completes before sending another message. The session retains user/assistant history and passes it to a fresh Agent each turn. Its transcript contains the public answer, while execution results retain structured Agent output and usage. Session lifetime and persistence depend on the deployed runtime’s storage configuration. Separate sessions have separate histories.
POST /kickoff remains available for independent executions. Local crewai run opens chat, while crewai run --inputs remains a single kickoff. The scaffold enables the conversational flag in the Agent definition; you do not need to write a Flow or main.py.
This preview has been exercised with a native API and Celery worker. Token streaming, restore/checkpoint support, first-class Agent provisioning, and production container/release compatibility remain outside its verified scope.
Agent state
Experimental. A conversational Agent can keep a typed state: givestate= a Pydantic model. The state is saved between turns. Each turn the agent gets it as data, one line per path, in a delimited <application_data> message placed just before the user’s newest message; that message is rebuilt every turn and never saved to the conversation. The agent also gets two tools to change the state:
update_statereplaces whole fields. It has one optional argument per field the agent may change.patch_stateadds, replaces or removes single items at a path the agent was shown, such as/todos/0/done, or/todos/-to append. Values are JSON text. Every path in one call means what it meant when the agent saw the state: replacements are applied first, then adds and removals from the end backwards.
Each list must name fields of the state, and the state can’t declare the conversation’s own fields (
messages, id and the rest of ConversationState); the Agent raises ValueError when it is declared. The state is saved with Flow persistence, as @persist does: by default a SQLite file. Saving is keyed by the session id and includes the conversation’s messages, so two stateful Agents that use the same session id with the same store share one conversation: give each conversation its own session id. An Agent without state saves nothing between processes, gets no state tools, no extra instructions and no data message. One-shot kickoff() and Agents inside a Crew don’t use the state.
Read the state from your tools
A tool callscurrent_state() to get a copy of the state of the conversation it runs in. The copy is read when it is called, so it includes changes the agent made earlier in the turn, and it includes hidden fields. Changing the copy changes nothing. Outside a turn it raises RuntimeError.
JSON and YAML agents
Givestate as a JSON Schema. The three lists take the same field names.
agent.json
Tool approval
Experimental. List the tools that may run only after the person in the conversation approves the call intools_requiring_approval. A name matches a tool with or without its MCP server prefix, so crm_log_meeting matches mcp_example_com_hubspot_crm_log_meeting, the name crewAI gives that tool from the server below.
agent.json
{"tool": "mcp_example_com_hubspot_crm_log_meeting", "arguments": {"account": "Acme", "notes": "Renewal in May"}}, with the options approve and reject, and answer in the chat. Outside AMP, the turn returns a HumanFeedbackPending and your app passes the person’s answer to resume(), as for any paused flow.
A tool confirmation is not a human-in-the-loop review: only the person in the conversation answers it. It never goes to a
@human_feedback provider, so on CrewAI AMP it creates no review in the review queue, sends no email, and no approver rules apply. On AMP it works for managed agents only.
The agent gets the outcome as data, in a delimited
<application_data> message after the user’s message: the call, then its result or that the user declined it. Words the user answered with follow as the user’s own message. Until the turn ends, every later run of the agent gets these messages for each call answered in the turn. They are not saved to the conversation.
What runs is the call saved with the pause, never one sent with a message. A listed tool’s results are never cached. While a call waits for an answer, a new message in the same conversation raises an error: answer the call first.
A waiting call is saved with the paused turn in the flow’s storage, so the person can answer it later, with no time limit, but only while that storage keeps it. On CrewAI AMP, the deployment’s workers need persistent flow storage that survives restarts and redeploys, shared by all of them when there is more than one. Without it, a waiting call is lost when the worker restarts, and the person has to ask again.
Limits:
- When the model asks for several tools at once, the calls before the first listed tool run and the rest don’t. Calls that ran before the pause, in that batch or earlier in the run, reach the agent’s next run as data, so it doesn’t make them again. Nobody confirms them and a reject doesn’t undo them, so list every tool that changes something.
- A call longer than 16,000 characters as JSON is never put up for confirmation: the agent is told to shorten it, so the person always sees the whole call. Such a call doesn’t stop the batch: the model’s other calls after it in the same response run.
- Two listed tools mean two approvals, one after the other.
- An approved call’s result reaches the agent whole, even one so large that the agent would otherwise read it in parts from a file.
- Outside a conversation turn, as in one-shot
kickoff(), an agent step in a regular Flow, a Crew, or an agent that one of the agent’s tools runs, a listed tool never runs: the agent is told it needs approval.
