Skip to content

Commit 262c0ba

Browse files
committed
minor improvements
1 parent 19f5467 commit 262c0ba

File tree

1 file changed

+20
-16
lines changed
  • src/content/docs/agents/tutorials/slackbot-knowledgebase

1 file changed

+20
-16
lines changed

src/content/docs/agents/tutorials/slackbot-knowledgebase/index.mdx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import {
2222

2323
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.
2424

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.
2628

2729
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.
2830

@@ -50,20 +52,22 @@ Create a new Workers project by running the following command:
5052
}}
5153
/>
5254

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).
5456

5557
<PackageManagers pkg="agents ai @ai-sdk/openai zod @slack/web-api" />
5658

5759
Your project is now set up. You can start building your agent!
5860

5961
## Step 2: Handle Slack events
6062

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:
6264

6365
- `url_verification`: To verify the request is from Slack.
6466
- `event_callback`: Event callback for the events you subscribe to.
6567

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.
6771

6872
To handle the `url_verification` event, you will need to:
6973

@@ -275,6 +279,12 @@ new_sqlite_classes = ["KnowledgeBaseAgent"]
275279
```
276280
</WranglerConfig>
277281

282+
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+
278288
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.
279289

280290
## Step 4: Create the knowledge base tool
@@ -346,7 +356,7 @@ To create a Slack app, follow these steps:
346356

347357
:::note
348358

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.
350360

351361
:::
352362

@@ -356,19 +366,13 @@ You will need to add a URL in the `Request URL` field in the `Event Subscription
356366
SLACK_BOT_TOKEN=xoxb-1234567890-1234567890-1234567890
357367
```
358368

359-
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
366370

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.
368372

369373
:::note
370374

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/).
372376

373377
:::
374378

@@ -378,7 +382,7 @@ To deploy, execut the following command:
378382
npm run deploy
379383
```
380384

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.
382386

383387
Next, add the credentials for your deployed Worker. Run the following command to do so:
384388

@@ -475,7 +479,7 @@ The above code does the following:
475479
5. Calls the LLM by passing the state as the messages for context
476480
6. Appends the assistant response to the state.
477481

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.
479483

480484
## Summary
481485

0 commit comments

Comments
 (0)