You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/agents/tutorials/slackbot-knowledgebase/index.mdx
+20-16Lines changed: 20 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,9 @@ import {
22
22
23
23
In this tutorial, you will create an AI-powered Slackbot. The bot will answer user's questions, using the content embeded with [AutoRAG](/autorag). You will use the Agents SDK to create the agent.
24
24
25
-
For each new thread, you will have a new instance of the agent. You will also store the messages of each thread in the state of the agent. This will allow you to maintain the conversation context.
25
+
For each new thread, you will have a new instance of the agent. You will also store the messages of each thread in the state of the agent. This will allow you to maintain the conversation context. If a user asks a follow-up question, the agent will have access to the previous messages and can provide a more accurate response.
26
+
27
+
Using the Agents SDK, you don't need to implement the state management logic. The SDK provide you with the necessary tools to manage the state seamlessly. You also don't need an external database to store the messages, as they are stored in the persistent storage of the agent.
26
28
27
29
While this tutorial focuses on building a Slackbot, the same principles can be applied to any use-case that requires an AI-powered agent. You can even extend this tutorial to build agents for incident response, customer support, or any other use-case that requires an AI-powered agent.
28
30
@@ -50,20 +52,22 @@ Create a new Workers project by running the following command:
50
52
}}
51
53
/>
52
54
53
-
You will need to install the [Cloudflare Agents SDK](), [AI SDK](), OpenAI provider for AI SDK, [zod](), the [Slack Web API package]().
55
+
You will need to install the [Cloudflare Agents SDK](https://developers.cloudflare.com/agents/), [AI SDK](https://www.npmjs.com/package/ai), OpenAI provider for AI SDK, [zod](https://www.npmjs.com/package/zod), the [Slack Web API package](https://www.npmjs.com/package/@slack/web-api).
54
56
55
57
<PackageManagerspkg="agents ai @ai-sdk/openai zod @slack/web-api" />
56
58
57
59
Your project is now set up. You can start building your agent!
58
60
59
61
## Step 2: Handle Slack events
60
62
61
-
The worker will receive events from Slack. You will need to handle these events and process them accordingly. Slack sends two types of events:
63
+
Based on the Slack events you subscribe to, the Worker will receive events from Slack. You will need to handle these events and process them accordingly. Slack sends two types of events:
62
64
63
65
-`url_verification`: To verify the request is from Slack.
64
66
-`event_callback`: Event callback for the events you subscribe to.
65
67
66
-
You will need to handle both of the events. The `url_verification` event can be handled by our worker and doesn't need to be processed by the agent. The `event_callback` event will be processed by the agent.
68
+
You will need to handle both of these events. The `url_verification` event can be handled by our Worker. This event is used to verify the request is from Slack and doesn't need AI capabilities to be processed by the agent.
69
+
70
+
The `event_callback` event will be processed by the agent. This event contains the actual events you subscribed to. It will provide the event data that will be used by the agent to generate responses.
67
71
68
72
To handle the `url_verification` event, you will need to:
You will also need to add the OpenAI API key to the `.dev.vars` file. You can get the API key from [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys).
283
+
284
+
```text title=".dev.vars"
285
+
OPENAI_API_KEY=sk-1234567890
286
+
```
287
+
278
288
You now have a Slackbot that can answer user's questions. To make sure it uses the knowledge base, you will need to add the knowledge base tool to the AI model.
279
289
280
290
## Step 4: Create the knowledge base tool
@@ -346,7 +356,7 @@ To create a Slack app, follow these steps:
346
356
347
357
:::note
348
358
349
-
You will need to add a URL in the `Request URL` field in the `Event Subscriptions` page. This URL will be used to receive events from Slack. You will add this URL after deploying the worker.
359
+
You will need to add a URL in the `Request URL` field in the `Event Subscriptions` page. This URL will be used to receive events from Slack. You will add this URL after deploying the Worker.
350
360
351
361
:::
352
362
@@ -356,19 +366,13 @@ You will need to add a URL in the `Request URL` field in the `Event Subscription
You will also need to add the OpenAI API key to the `.dev.vars` file. You can get the API key from [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys).
360
-
361
-
```text title=".dev.vars"
362
-
OPENAI_API_KEY=sk-1234567890
363
-
```
364
-
365
-
## Step 6: Deploy the worker
369
+
## Step 6: Deploy the Worker
366
370
367
-
Your Slack app is now ready to receive events from Slack. You will need to deploy the agent to Cloudflare Workers. Slack will send events to the worker, and the worker will process the events and send responses to Slack.
371
+
Your Slack app is now ready to receive events from Slack. You will need to deploy the agent to Cloudflare Workers. Slack will send events to the Worker, and the Worker will process the events and send responses to Slack.
368
372
369
373
:::note
370
374
371
-
Application running on `localhost` will not receive events from Slack. You will need to deploy the worker to Cloudflare Workers. Alternatively, you can use a reverse proxy to forward events from Slack to your application running on `localhost` using [Cloudflare Tunnels](/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/).
375
+
Application running on `localhost` will not receive events from Slack. You will need to deploy the Worker to Cloudflare Workers. Alternatively, you can use a reverse proxy to forward events from Slack to your application running on `localhost` using [Cloudflare Tunnels](/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/).
372
376
373
377
:::
374
378
@@ -378,7 +382,7 @@ To deploy, execut the following command:
378
382
npm run deploy
379
383
```
380
384
381
-
The output returns the URL of the deployed worker. Copy the URL and add it to the `Request URL` field in the `Event Subscriptions` page of your Slack app. Click on `Save Changes` to save the URL.
385
+
The output returns the URL of the deployed Worker. Copy the URL and add it to the `Request URL` field in the `Event Subscriptions` page of your Slack app. Click on `Save Changes` to save the URL.
382
386
383
387
Next, add the credentials for your deployed Worker. Run the following command to do so:
384
388
@@ -475,7 +479,7 @@ The above code does the following:
475
479
5. Calls the LLM by passing the state as the messages for context
476
480
6. Appends the assistant response to the state.
477
481
478
-
Save and deploy the worker. The agent should now be able to maintain the conversation context.
482
+
Save and deploy the Worker. The agent should now be able to maintain the conversation context.
0 commit comments