> ## Documentation Index
> Fetch the complete documentation index at: https://docs.guild.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To act on a user's behalf in Guild, use the Guild REST API at https://api.guild.ai/v1.
> The OpenAPI spec is unauthenticated: https://docs.guild.ai/openapi.json (or openapi.yaml).
> Authenticate with an account API key, sent as HTTP Basic (key id as username, secret as password) or as `Authorization: Bearer <api_key_id>:<api_key_secret>`. See https://docs.guild.ai/api-reference/introduction#authentication.
> To run one agent on demand without account-wide access, use an API trigger instead: https://docs.guild.ai/platform/api-triggers.
> To search these docs from an MCP client, connect to https://docs.guild.ai/mcp. The full page index is https://docs.guild.ai/llms.txt.

# Answer questions when someone mentions your agent in Slack

> Build a Guild agent that replies in the thread when someone mentions it in Slack, using a Native agent, workspace context, and a Slack app_mention trigger.

This recipe builds an agent that answers when someone mentions it in a Slack channel. It replies in the message's thread, and reads the thread when it's mentioned again there. The agent answers from your [workspace context](/platform/context), so you control what it knows without changing the agent.

## Before you start

* The [Guild CLI](/cli/getting-started), logged in.
* Slack connected in your workspace. See [Slack setup](/integrations/slack#setup).
* The Slack agent invited to the channels where it should reply. It posts with the `chat:write` scope, which only reaches channels it belongs to.

## 1. Create the agent

```bash theme={null}
guild agent init --name slack-helper --agent-type GUILD_NATIVE
cd slack-helper
```

Replace `PROMPT.md`:

```markdown theme={null}
You answer questions people ask in Slack.

Your input is a Slack app_mention event. The question is in event.text,
the channel is event.channel, and the message timestamp is event.ts.

If event.thread_ts is set, read the thread first with
slack_conversations_replies, using channel event.channel and ts
event.thread_ts, so you know what was said before.

Answer from the workspace context. If it doesn't cover the question, say
you don't know and suggest who might.

Reply with slack_chat_post_message in the thread: set channel to
event.channel, and thread_ts to event.thread_ts if it is set, otherwise
event.ts. Keep replies under 150 words.
```

Replace `guild.yaml`:

```yaml theme={null}
integrations:
  - name: guildai~slack
    version: ^2.0.0
    tools:
      - slack_chat_post_message
      - slack_conversations_replies
```

## 2. Give it something to answer from

Add your team's facts to the workspace context: on-call rotation, where runbooks live, how to request access, release days. Open the workspace, click **Context**, write in Markdown, and publish. See [Workspace context](/platform/context).

## 3. Save it and install it in your workspace

```bash theme={null}
guild agent save --message "First version" --publish
guild workspace agent add <your-name>~slack-helper
```

## 4. Create the trigger

```bash theme={null}
guild trigger create \
  --type webhook \
  --integration slack \
  --event app_mention \
  --agent <your-name>~slack-helper \
  --service-config '{"channel_ids": ["<channel-id>"]}' \
  --name "Answer Slack mentions"
```

`channel_ids` limits the trigger to the channels you list. Find a channel's ID at the bottom of its details in Slack. Omit `--service-config` to answer in every channel.

Slack events have no actions, so there's no `--action`. The agent receives a prompt that names the event, followed by the Slack payload as JSON, trimmed to the fields an agent needs.

## 5. Try it

In the channel, mention the Slack agent with a question the context answers. The reply appears in the thread, with a link to the Guild session underneath. To ask a follow-up, mention it again in the same thread. Each mention is a new run in the thread's session; the agent reads the thread with `slack_conversations_replies` to see the earlier exchange. A reply in the thread that doesn't mention the agent doesn't trigger it.

## How the run is attributed

If the person who mentioned the agent has an [identity mapping](/platform/identity-mapping), the run acts as their Guild user. Otherwise it acts as the trigger's creator. Messages always post as the Slack agent.

## Variations

* **Answer direct messages too.** Create a second trigger on `message` with no `channel_ids`. It also fires on every message in channels the agent belongs to, so tell the agent to reply only when `event.channel_type` is `im`. See [Direct messages](/integrations/slack#direct-messages).
* **Look things up before answering.** Add another integration's read tools to `guild.yaml`, such as `jira_get_issue`, so the agent can answer "what's the status of ENG-123?".

## Related

* [Slack integration](/integrations/slack): events, scopes, and how sessions work
* [Event triggers](/platform/event-triggers): agent input and `service_config`
* [Native agents](/guide/native-agents): what a prompt-only agent can and can't do
