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: docs/english/concepts/ai-apps.md
+180-9Lines changed: 180 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,21 @@
1
+
---
2
+
sidebar_label: Overview
3
+
---
1
4
2
-
# Using AI in Apps {#using-ai-in-apps}
5
+
# Creating agents with Bolt
3
6
4
-
The Slack platform offers features tailored for AI agents and assistants. Your apps can [utilize the `Assistant` class](#assistant) for a side-panel view designed with AI in mind, and they can utilize features applicable to messages throughout Slack, like [chat streaming](#text-streaming) and [feedback buttons](#adding-and-handling-feedback).
7
+
The Slack platform offers features tailored for AI agents. Your agent can utilize features applicable to messages throughout Slack, like [chat streaming](#text-streaming) and [feedback buttons](#adding-and-handling-feedback). They can also [utilize the `Assistant` class](/bolt-python/concepts/assistant-class) for a side-panel view designed with AI in mind,
5
8
6
9
If you're unfamiliar with using these feature within Slack, you may want to read the [API docs on the subject](/ai/). Then come back here to implement them with Bolt!
7
10
8
-
## Listening for events
11
+
---
9
12
10
-
Agents can be invoked throughout Slack, such as @mentions in channels.
13
+
## Listening for user invocation
11
14
12
-
:::tip[Using the Assistant side panel]
15
+
Agents can be invoked throughout Slack, such as @mentions in channels, messages to the app, and using the assistant side panel.
13
16
14
-
The Assistant side panel requires additional setup. See the [Assistant class guide](/concepts/assistant-class).
15
-
:::
17
+
<Tabs>
18
+
<TabItemvalue="appmention"label = "app_mention">
16
19
17
20
```python
18
21
import re
@@ -63,9 +66,172 @@ def handle_app_mentioned(
63
66
...
64
67
```
65
68
66
-
## Setting assistant status {#setting-assistant-status}
69
+
<TabItem>
70
+
<TabItemvalue="message"label = "Message">
71
+
72
+
```python
73
+
from logging import Logger
74
+
75
+
from slack_bolt.context.async_context import AsyncBoltContext
76
+
from slack_bolt.context.say.async_say import AsyncSay
77
+
from slack_bolt.context.say_stream.async_say_stream import AsyncSayStream
78
+
from slack_bolt.context.set_status.async_set_status import AsyncSetStatus
79
+
from slack_sdk.web.async_client import AsyncWebClient
80
+
81
+
from agent import CaseyDeps, run_casey_agent
82
+
from thread_context import session_store
83
+
from listeners.views.feedback_builder import build_feedback_blocks
84
+
85
+
86
+
asyncdefhandle_message(
87
+
client: AsyncWebClient,
88
+
context: AsyncBoltContext,
89
+
event: dict,
90
+
logger: Logger,
91
+
say: AsyncSay,
92
+
say_stream: AsyncSayStream,
93
+
set_status: AsyncSetStatus,
94
+
):
95
+
"""Handle messages sent to Casey via DM or in threads the bot is part of."""
96
+
# Issue submissions are posted by the bot with metadata so the message
97
+
# handler can run the agent on behalf of the original user.
"""Handle assistant thread started events by setting suggested prompts."""
218
+
try:
219
+
await set_suggested_prompts(
220
+
prompts=SUGGESTED_PROMPTS,
221
+
title="How can I help you today?",
222
+
)
223
+
exceptExceptionas e:
224
+
logger.exception(f"Failed to handle assistant thread started: {e}")
225
+
```
226
+
227
+
</TabItem>
228
+
</Tabs>
67
229
68
-
Your app can show users action is happening behind the scenes by setting the thread status.
230
+
---
231
+
232
+
## Setting status {#setting-assistant-status}
233
+
234
+
Your app can show its users action is happening behind the scenes by setting its thread status.
69
235
70
236
```python
71
237
defhandle_app_mentioned(
@@ -84,6 +250,8 @@ def handle_app_mentioned(
84
250
)
85
251
```
86
252
253
+
---
254
+
87
255
## Streaming messages {#text-streaming}
88
256
89
257
You can have your app's messages stream in to replicate conventional agent behavior. Bolt for Python provides a `say_stream` utility as a listener argument available for `app.event` and `app.message` listeners.
## Adding and handling feedback {#adding-and-handling-feedback}
116
286
117
287
You can use [feedback buttons block element](/reference/block-kit/block-elements/feedback-buttons-element/) to allow users to immediately provide feedback regarding the app's responses. Here's what the feedback buttons look like from the Support Agent sample app:
@@ -203,6 +373,7 @@ def handle_feedback_button(
203
373
logger.exception(f"Failed to handle feedback: {e}")
Copy file name to clipboardExpand all lines: docs/english/concepts/assistant-class.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
##The `Assistant` class instance {#assistant}
1
+
# The Assistant class
2
2
3
3
:::info[Some features within this guide require a paid plan]
4
4
If you don't have a paid workspace for development, you can join the [Developer Program](https://api.slack.com/developer-program) and provision a sandbox with access to all Slack features for free.
0 commit comments