Skip to content

Commit 60a3bb0

Browse files
docs: updates quickstart on crew flow (CopilotKit#1928)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 6b8ce25 commit 60a3bb0

5 files changed

Lines changed: 206 additions & 197 deletions

File tree

docs/content/docs/crewai-flows/quickstart.mdx

Lines changed: 86 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ import CopilotUI from "@/snippets/copilot-ui.mdx";
4545

4646
## Prerequisites
4747

48-
Before you begin, you'll need the following:
49-
50-
- [**OpenAI API key**](https://platform.openai.com/api-keys)
48+
Before you begin, you must have a [CrewAI Flow](https://docs.crewai.com/guides/flows/first-flow) deployed on [CrewAI Enterprise](https://docs.crewai.com/enterprise/introduction). If you're looking for a sample flows, check out this [example agentic chat implementation](https://github.com/suhasdeshpande/agentic_chat).
5149

5250
## Getting started
5351

@@ -112,218 +110,109 @@ Before you begin, you'll need the following:
112110
description="I want to deeply understand what's happening under the hood or don't have a Next.js application."
113111
icon={<SquareChartGantt />}
114112
>
113+
<Step>
114+
### Connect to Copilot Cloud
115+
1. Go to [Copilot Cloud](https://cloud.copilotkit.ai), sign in and click Get Started
116+
2. Click "Add Remote Endpoint" and fill in the details of your CrewAI Flow. Note: If your Agent Name contains multiple words, use underscores (`_`) as separators.
117+
3. Click "Save Endpoint"
118+
4. Copy the Copilot Cloud Public API Key
119+
120+
<img src="/images/copilot-cloud/crewai-flow-cpk-setup.gif" alt="CrewAI Flow Copilot Setup" className="rounded-lg shadow-xl mt-4" />
121+
</Step>
122+
115123
<Step>
116124
### Install CopilotKit
117125
First, install the latest packages for CopilotKit into your frontend.
118126
```package-install
119127
npm install @copilotkit/react-ui @copilotkit/react-core
120128
```
121129
</Step>
122-
<TailoredContent
123-
className="step"
124-
id="agent"
125-
header={
126-
<div>
127-
<p className="text-xl font-semibold">Do you already have a CrewAI Flow agent?</p>
128-
<p className="text-base">
129-
You will need a CrewAI Flow agent to get started!
130-
</p>
131-
<p className="text-base">
132-
Either bring your own or feel free to use our starter repo.
133-
</p>
134-
</div>
135-
}
136-
>
137-
<TailoredContentOption
138-
id="bring-your-own"
139-
title="Bring your own CrewAI Flow agent"
140-
description="I already have a CrewAI Flow agent and want to use it with CopilotKit."
141-
icon={<SiCrewai />}
142-
/>
143-
<TailoredContentOption
144-
id="coagents-starter"
145-
title="Use the CoAgents Starter repo"
146-
description="I don't have a CrewAI Flow agent yet, but want to get started quickly."
147-
icon={<img src="/images/copilotkit-logo.svg" alt="CopilotKit Logo" width={20} height={20} />}
148-
>
149-
<Step>
150-
### Clone the `coagents-starter` repo
151-
152-
<Tabs groupId="language" items={["Python"]}>
153-
<Tab value="Python">
154-
```bash
155-
git clone https://github.com/CopilotKit/CopilotKit
156-
cd CopilotKit/examples/coagents-starter-crewai-flows/agent-py
157-
```
158-
</Tab>
159-
</Tabs>
160-
</Step>
161-
<Step>
162-
### Create a `.env` file
163-
164-
```bash
165-
touch .env
166-
```
167-
</Step>
168-
<Step>
169-
### Add your API keys
170130

171-
Then add your **OpenAI API key** to the `.env` file.
172-
173-
```plaintext title=".env"
174-
OPENAI_API_KEY=your_openai_api_key
175-
```
176-
</Step>
177-
</TailoredContentOption>
178-
</TailoredContent>
179131
<Step>
180-
### Launch your local agent
132+
### Setup the CopilotKit Provider
133+
The [`<CopilotKit>`](/reference/components/CopilotKit) component must wrap the Copilot-aware parts of your application. For most use-cases,
134+
it's appropriate to wrap the CopilotKit provider around the entire app, e.g. in your layout.tsx.
181135

182-
Start your local CrewAI Flow agent:
136+
<CloudCopilotKitProvider components={props.components} />
183137

184-
```bash
185-
# Install dependencies
186-
poetry lock
187-
poetry install
188-
# Start the server
189-
poetry run demo
190-
```
191-
This will start a local agent server that you can connect to.
138+
<Callout type="info">
139+
Looking for a way to run multiple CrewAI Flows? Check out our [Multi-Agent](/crewai-flows/multi-agent-flows) guide.
140+
</Callout>
141+
</Step>
142+
<Step>
143+
### Choose a Copilot UI
144+
You are almost there! Now it's time to setup your Copilot UI.
145+
<CopilotUI components={props.components} />
192146
</Step>
193-
194-
<TailoredContent
195-
className="step"
196-
id="copilot-hosting"
197-
header={
198-
<div>
199-
<p className="text-xl font-semibold">Choose your connection method</p>
200-
<p className="text-base">
201-
Now you need to connect your CrewAI Flow to CopilotKit.
202-
</p>
203-
</div>
204-
}
205-
>
206-
<TailoredContentOption
207-
id="copilot-cloud"
208-
title="Copilot Cloud (Recommended)"
209-
description="I want to host my Copilot on Copilot Cloud"
210-
icon={<FaCloud />}
211-
>
212-
<Step>
213-
### Add a remote endpoint for your CrewAI Flow
214-
Using Copilot Cloud, you need to connect a remote endpoint that will connect to your CrewAI Flow.
215-
<Tabs groupId="lg-deployment-type" items={['Self hosted (FastAPI)', 'CrewAI Enterprise']}>
216-
<Tab value="Self hosted (FastAPI)">
217-
**Running your FastAPI server in production**
218-
219-
Head over to [Copilot Cloud](https://cloud.copilotkit.ai) sign up and setup a remote endpoint with the following information:
220-
- OpenAI API key
221-
- Your FastAPI server URL
222-
223-
**Running your FastAPI server locally**
224-
225-
If you're running your FastAPI server locally, you can open a tunnel to it so Copilot Cloud can connect to it.
226-
227-
```bash
228-
npx copilotkit@latest dev --port 8000
229-
```
230-
</Tab>
231-
<Tab value="CrewAI Enterprise">
232-
Coming soon!
233-
</Tab>
234-
</Tabs>
235-
</Step>
236-
<Step>
237-
### Setup your CopilotKit provider
238-
The [`<CopilotKit>`](/reference/components/CopilotKit) component must wrap the Copilot-aware parts of your application. For most use-cases,
239-
it's appropriate to wrap the CopilotKit provider around the entire app, e.g. in your layout.tsx.
240-
241-
<CloudCopilotKitProvider components={props.components} />
242-
243-
<Callout type="info">
244-
Looking for a way to run multiple CrewAI Flows? Check out our [Multi-Agent](/crewai-flows/multi-agent-flows) guide.
245-
</Callout>
246-
</Step>
247-
</TailoredContentOption>
248-
<TailoredContentOption
249-
id="self-hosted"
250-
title="Self-Hosted Copilot Runtime"
251-
description="I want to self-host the Copilot Runtime"
252-
icon={<ServerIcon />}
253-
>
254-
<Step>
255-
### Install Copilot Runtime
256-
Copilot Runtime is a production-ready proxy for your CrewAI Flows. In your frontend, go ahead and install it.
257-
258-
```package-install
259-
@copilotkit/runtime
260-
```
261-
</Step>
262-
<Step>
263-
### Setup a Copilot Runtime Endpoint
264-
Now we need to setup a Copilot Runtime endpoint and point your frontend to it.
265-
<SelfHostingCopilotRuntimeStarter components={props.components}/>
266-
</Step>
267-
<Step>
268-
### Add your CrewAI Flow deployment to Copilot Runtime
269-
Now we need to add your CrewAI Flow deployment to Copilot Runtime. This will make it
270-
so your frontend can find your CrewAI Flows correctly.
271-
```ts
272-
import {
273-
CopilotRuntime,
274-
// ...
275-
} from "@copilotkit/runtime";
276-
// ...
277-
const runtime = new CopilotRuntime({
278-
remoteEndpoints: [
279-
// [!code highlight:3]
280-
// Our FastAPI endpoint URL
281-
{ url: "http://localhost:8000/copilotkit" },
282-
],
283-
});
284-
// ...
285-
```
286-
</Step>
287-
<Step>
288-
### Configure the CopilotKit Provider
289-
The [`<CopilotKit>`](/reference/components/CopilotKit) component must wrap the Copilot-aware parts of your application. For most use-cases,
290-
it's appropriate to wrap the CopilotKit provider around the entire app, e.g. in your layout.tsx.
291-
<SelfHostingCopilotRuntimeConfigureCopilotKitProvider components={props.components}/>
292-
<Callout type="info">
293-
Looking for a way to run multiple CrewAI Flows? Check out our [Multi-Agent](/crewai-flows/multi-agent-flows) guide.
294-
</Callout>
295-
</Step>
296-
</TailoredContentOption>
297-
</TailoredContent>
298147
<Step>
299-
### Setup the Copilot UI
300-
The last step is to use CopilotKit's UI components to render the chat interaction with your agent. In most situations,
301-
this is done alongside your core page components, e.g. in your `page.tsx` file.
148+
### Create a CrewAI Flow component
149+
Place the following snippet in your **main page** (e.g. `page.tsx` in Next.js) or wherever you want to use CopilotKit.
302150

303151
```tsx title="page.tsx"
304-
// [!code highlight:3]
152+
"use client";
305153
import "@copilotkit/react-ui/styles.css";
306-
import { CopilotPopup } from "@copilotkit/react-ui";
307-
308-
export function YourApp() {
309-
return (
310-
<main>
311-
<h1>Your main content</h1>
312-
// [!code highlight:7]
313-
<CopilotPopup
314-
labels={{
315-
title: "Popup Assistant",
316-
initial: "Hi! I'm connected to an agent. How can I help?",
317-
}}
318-
/>
319-
</main>
154+
import { CopilotKit, useCopilotAction } from "@copilotkit/react-core";
155+
import { CopilotChat } from "@copilotkit/react-ui";
156+
import React, { useState } from "react";
157+
158+
const publicApiKey = process.env.NEXT_PUBLIC_COPILOT_API_KEY || "";
159+
/**
160+
* AgentName refers to the Crew Flow Agent you have saved via CLI during setup.
161+
* It is used to identify the agent you want to use for the chat.
162+
*/
163+
const agentName =
164+
process.env.NEXT_PUBLIC_COPILOTKIT_AGENT_NAME || "DefaultAgent";
165+
166+
// Main Chat Component: Handles chat interface and background customization
167+
const Chat = () => {
168+
const [background, setBackground] = useState(
169+
"linear-gradient(135deg, #667eea 0%, #764ba2 100%)"
170+
);
171+
172+
// Action: Allow AI to change background color dynamically
173+
useCopilotAction({
174+
name: "change_background",
175+
description:
176+
"Change the background color of the chat. Can be anything that the CSS background attribute accepts. Regular colors, linear of radial gradients etc.",
177+
parameters: [
178+
{
179+
name: "background",
180+
type: "string",
181+
description: "The background. Prefer gradients.",
182+
},
183+
],
184+
handler: ({ background }) => setBackground(background),
185+
followUp: false,
186+
});
187+
188+
return (
189+
<div
190+
className="h-screen w-full flex items-center justify-center"
191+
style={{ background }}
192+
>
193+
<div className="w-full max-w-3xl h-[80vh] px-4">
194+
<div className="h-full bg-white/10 backdrop-blur-lg rounded-2xl shadow-2xl overflow-hidden">
195+
<CopilotChat
196+
className="h-full"
197+
labels={{
198+
initial: "Hi, I'm an agent. Want to chat?",
199+
placeholder: "Type a message...",
200+
}}
201+
/>
202+
</div>
203+
</div>
204+
</div>
205+
);
206+
207+
// App Component: Main wrapper that provides CopilotKit context
208+
const CrewAIFlow: React.FC = () => (
209+
<CopilotKit publicApiKey={publicApiKey} agent={agentName}>
210+
<Chat />
211+
</CopilotKit>
320212
);
321-
}
322-
```
323213

324-
<Callout type="info">
325-
Looking for other chat component options? Check out our [Agentic Chat UI](/crewai-flows/agentic-chat-ui) guide.
326-
</Callout>
214+
export default CrewAIFlow;
215+
```
327216
</Step>
328217
<Step>
329218
### 🎉 Talk to your agent!
44.5 MB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
3+
"name": "coagents-starter-crewai-flows",
4+
"type": "registry:page",
5+
"title": "Coagents Starter CrewAI Flows",
6+
"description": "Quickstart for CopilotKit and CrewAI Flows on CrewAI Enterprise.",
7+
"dependencies": [
8+
"@copilotkit/react-core",
9+
"@copilotkit/react-ui"
10+
],
11+
"files": [
12+
{
13+
"path": "registry/quickstarts/coagents-starter-crewai-flows/page.tsx",
14+
"content": "\"use client\";\nimport \"@copilotkit/react-ui/styles.css\";\nimport { CopilotKit, useCopilotAction } from \"@copilotkit/react-core\";\nimport { CopilotChat } from \"@copilotkit/react-ui\";\nimport React, { useState } from \"react\";\n\nconst publicApiKey = process.env.NEXT_PUBLIC_COPILOT_API_KEY;\nconst agentName = process.env.NEXT_PUBLIC_COPILOTKIT_AGENT_NAME;\n\nif (!publicApiKey || !agentName) {\n throw new Error(\"Missing environment variables\");\n}\n\n// Main Chat Component: Handles chat interface and background customization\nconst Chat = () => {\n const [background, setBackground] = useState(\n \"linear-gradient(135deg, #667eea 0%, #764ba2 100%)\"\n );\n\n // Action: Allow AI to change background color dynamically\n useCopilotAction({\n name: \"change_background\",\n description:\n \"Change the background color of the chat. Can be anything that the CSS background attribute accepts. Regular colors, linear of radial gradients etc.\",\n parameters: [\n {\n name: \"background\",\n type: \"string\",\n description: \"The background. Prefer gradients.\",\n },\n ],\n handler: ({ background }) => setBackground(background),\n followUp: false,\n });\n\n return (\n <div\n className=\"h-screen w-full flex items-center justify-center\"\n style={{ background }}\n >\n <div className=\"w-full max-w-3xl h-[80vh] px-4\">\n <div className=\"h-full bg-white/10 backdrop-blur-lg rounded-2xl shadow-2xl overflow-hidden\">\n <CopilotChat\n className=\"h-full\"\n labels={{\n initial: \"Hi, I'm an agent. Want to chat?\",\n placeholder: \"Type a message...\",\n }}\n />\n </div>\n </div>\n </div>\n );\n};\n\n// App Component: Main wrapper that provides CopilotKit context\nconst CrewAIFlow: React.FC = () => (\n <CopilotKit publicApiKey={publicApiKey} agent={agentName}>\n <Chat />\n </CopilotKit>\n);\n\nexport default CrewAIFlow;\n",
15+
"type": "registry:page",
16+
"target": "app/copilotkit/page.tsx"
17+
}
18+
]
19+
}

registry/registry.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@
295295
"target": "app/copilotkit/page.tsx"
296296
}
297297
]
298+
},
299+
{
300+
"name": "coagents-starter-crewai-flows",
301+
"type": "registry:page",
302+
"title": "Coagents Starter CrewAI Flows",
303+
"description": "Quickstart for CopilotKit and CrewAI Flows on CrewAI Enterprise.",
304+
"dependencies": ["@copilotkit/react-core", "@copilotkit/react-ui"],
305+
"files": [
306+
{
307+
"path": "registry/quickstarts/coagents-starter-crewai-flows/page.tsx",
308+
"type": "registry:page",
309+
"target": "app/copilotkit/page.tsx"
310+
}
311+
]
298312
}
299313
]
300314
}

0 commit comments

Comments
 (0)