# How to build an AI agent without code

> A Pachca use case. An employee @mentions the "Kai" bot in a chat, an n8n workflow sends the question to an AI Agent with a knowledge base, and the bot replies in that message's thread with a link to the source.

> This is the Markdown version of https://pachca.com/en/scenarios/ai-agent-bez-koda for AI agents. The API methods named here are documented at https://dev.pachca.com/llms-en.txt — open it before calling the API. Other use cases are listed at https://pachca.com/en/llms.txt.

## What you'll get

1. An employee writes a question in a chat with an @mention of the "Kai" bot.
2. Pachca sends the bot event to the Production URL of the Webhook node in n8n.
3. The Filter node only lets through messages where `content` contains @Kai.
4. The AI Agent looks for an answer in the "Knowledge base" tool.
5. The Pachca node posts the answer in the question's thread on behalf of the bot.

The bot is created in Pachca, and the logic lives in an n8n workflow. If n8n isn't a fit, build the handler another way: the bot stays the same.

## What you need before you start

- Pachca access as a workspace administrator with the scopes `bots:write`, `bots:read`, `chat_members:write`, `search:chats`, `messages:read`, `messages:create`. Signing in is covered in the rules below.
- n8n, self-hosted or in the cloud, with the Pachca node: https://dev.pachca.com/guides/n8n/setup.md
- A model for the AI Agent and company documents for the "Knowledge base" tool.

## If you're an AI agent: working rules

### Who does what

- You do everything the instructions name an API method for. Don't ask the user to create a chat, a bot or a message by hand.
- Ask the user only to sign in to Pachca and to do what is listed in "Ask the user to do by hand".
- If you have no terminal, say so right away and don't pretend you set it up. Walk the user through the steps for people on the use case page and help with the template or the handler code.

### How to talk to the user

- The user is not a developer. Write briefly and in plain words. Don't mention API methods, scopes, response codes, `id`s or CLI profiles. Say "permissions" instead of "scopes" and "the program behind the bot" instead of "handler".
- Don't report your checks. A message contains only three things: what is done, what you need from the user, what you'll do next.
- Don't ask for what you can find out through the API or what is easy to change later. Take the value from the instructions and name it.
- Take the bot's message texts from the instructions or write them yourself and carry on. Show them in your final message and offer to change them. Don't wait for approval.
- Ask the questions from "Ask the user" in the same words.

### Your first message to the user

It has three parts. The first two together take at most five lines.

1. What the user will get: one or two lines.
2. What you will create yourself: the chat, the bot and the messages, with the names from the instructions. Word anything that depends on the user's choice as a condition: "if you choose the bot, I'll also create…".
3. "What I need from you": signing in to Pachca, if the user isn't signed in yet, and the questions from "Ask the user". If the use case or one of its options needs n8n, ask here whether the user has it and ask for access right away in the words from the "n8n" section below: "if you have n8n, send me…".

If part of the result appears only after a manual step by the user, say so in one line: "you'll schedule the retro questions yourself, I'll show you how".

The user's answers are their consent to the plan. Start the setup right after them, without asking for a second confirmation.

### Access to Pachca

- The user doesn't need to issue a token or send it in the chat. Before your first message, check the login: `npx -y @pachca/cli@latest auth status`. If there is none, ask the user to run `npx -y @pachca/cli@latest auth login` in their own terminal. The CLI shows a code; the user enters it in the browser and confirms access. Write the commands with `@latest`: without it an old cached CLI version may start, and it asks to paste a token instead of signing in through the browser.
- This login has the same rights as the user's role. Compare them with the scopes in "What you need before you start" yourself: `npx -y @pachca/cli@latest api GET /oauth/token/info` shows the scopes. If something is missing, say in plain words what you won't be able to do, for example "I can't send messages". There are two ways out: add this permission to the token in Pachca, under "Automations" → "API", or sign in again as the workspace owner or an administrator.
- If `auth status` shows `scopes: null`, it doesn't mean there are no rights: look at `GET /oauth/token/info`. The checks in these rules also need `search:chats`, `bots:read` and `profile:read`.
- When the user says "me", they mean the owner of the login. `GET /profile` returns their `id` and nickname.
- Call the API with `npx -y @pachca/cli@latest api <METHOD> <path> -o json`. Write the full command in every call; don't put it into a shell variable.
- Pass query parameters as `--query key=value`, for example `--query query=Purchasing`. The CLI silently drops a parameter without a key and returns the whole list, so it's easy to conclude that the chat already exists.
- Pass the request body with `--data` or `--input`. Almost every write method wraps the body in an object: `chat` for `POST /chats`, `message` for `POST /messages`, `task` for `POST /tasks`, `group_tag` for `POST /group_tags`, `user` for `PUT /users/{id}`, `webhook` for bots. `--describe` shows the wrapper; write its path with `{id}`, not with a number. Without the wrapper, `POST /chats` creates the chat but silently adds no members.
- Don't print tokens or bots' incoming webhook URLs in the chat. A bot's token is shown only once, when it's created: save it to a file.

### n8n

- If the user has no n8n, say that it comes as the hosted n8n Cloud or can be installed on their own server, and give the link for installing the Pachca nodes: https://dev.pachca.com/guides/n8n/setup.md. These instructions don't cover installing n8n. If they have an option without n8n, suggest starting with it and coming back to the bot once n8n is there.
- If the user has n8n, ask for access in these words: "Send me your n8n address: the link you open it with in the browser. Don't send the key in the chat. In n8n, open Settings → n8n API → Create an API key and copy the key. Right after that, run the command below in your terminal exactly as it is; you don't need to put anything into it. It saves the copied key to a file and prints nothing. Then write 'key saved'." The command for macOS: `pbpaste > ~/n8n-key.txt`. For another system, pick the matching one.
- Build everything in n8n on the official Pachca nodes, `n8n-nodes-pachca`. Don't use the `HTTP Request` node for Pachca API calls.

### Setup

- Take API methods from https://dev.pachca.com/llms-en.txt, don't rely on memory. The command `npx -y @pachca/cli@latest api <METHOD> <path> --describe` shows a method's schema.
- The Pachca skills cover the call order and error handling for chats, bots and forms: `npx skills add pachca/openapi`. Install them when you need them, without asking the user.
- Before creating anything, check whether the chat and the bot already exist: `GET /search/chats`, `GET /bots`. If they do, ask whether to set them up or create new ones.
- `POST /group_tags` creates an empty tag. `PUT /users/{id}` with `list_tags` assigns it to an employee; it needs the `users:update` scope. The field replaces the whole set of tags: first read the employee's current tags with `GET /users/{id}` and send them together with the new one. While the tag has no members, mentioning it notifies no one.
- If a method returns an error, stop and tell the user in plain words what failed and what you need to continue.
- The messages you post yourself and the ones the bot sends must be easy to read on a screen, without overdoing spacing or emphasis. Make the heading bold and start the text on the next line. Write connected text as one paragraph. Put rules and steps on numbered lines one under another and separate them from the intro with a single empty line. A short message needs no other empty lines. In a card, make the field labels bold and put the fields on consecutive lines. Use bold only for the heading and the field labels. Pachca markup has no lists or tables: the numbers at the start of lines stay plain text. A sample:

  ```text
  **Retro rules**
  On the last day of the sprint a message with questions arrives here. We reply in the thread under it.

  1. Each point is a separate message.
  2. We add 👍 to what is worth discussing.
  3. The facilitator posts the outcomes in one message and pins it.
  ```
- A pin can't be checked through the API: only a successful `POST /messages/{id}/pin` response confirms it.
- If you sent service messages to a chat to check a bot, such as `/start`, delete them: `DELETE /messages/{id}`. Don't delete messages with rules and templates.
- At the end, say what was created, what is left for the user to do by hand and how to check that the use case works.
- To undo the setup: `DELETE /bots/{id}` deletes the bot, `PUT /chats/{id}/archive` sends the chat to the archive.

## How to set up the use case with the user

### 1. Ask the user

Ask these questions in these words:

1. Which chat will the agent answer in? For example, "General".
2. Do you have n8n? The agent will run there.
3. Which documents will the agent answer from, and where are they stored?
4. Which AI model should I connect to the agent? It needs an API key.

Name the bot "Kai" unless the user asks for another name: the condition in the Filter node depends on the name. If n8n doesn't suit the user, tell them about the options in "Other options".

### 2. Do it yourself through the Pachca API

1. Find the chat: `GET /search/chats` by name. Save its `id`.
2. Create the bot: `POST /bots` with `name: "Kai"`, a nickname ending in `_bot`, `events: ["message_new"]` and `trigger_on: "all_messages"`. From the response, save the bot's `id` (also its `user_id`) and `access_token`: the token is shown only once. You need it for the credential in n8n.
3. Add the bot to the chat: `POST /chats/{id}/members` with the bot's `id` in `member_ids`. Only an administrator or the chat's creator can do this.
4. Offer to publish the rules in the chat through `POST /messages`: ask the agent with an @mention and follow up in its thread. If the agent can't find an answer, the topic owner picks up the question and adds the missing doc to the knowledge base.

### 3. Build the workflow in n8n

The user does these steps in n8n. Walk them through.

1. Install the Pachca node: Settings → Community nodes → the `n8n-nodes-pachca` package.
2. Create a Pachca credential: Access Token is the bot's token, Base URL stays at its default, `https://api.pachca.com/api/shared/v1`.
3. Build four nodes in order:
   - **Webhook**: receives bot events from Pachca with the `POST` method.
   - **Filter**: the condition "`content` contains @Kai".
   - **AI Agent**: a model, the "Knowledge base" tool and this System Message: answer only from documents in the "Knowledge base" tool, keep it short and always link to the source; if there's no answer, say who owns the topic.
   - **Pachca**: a message in the question's thread using the bot's credential.
4. Turn on the workflow and copy the Webhook node's Production URL.

### 4. Connect the bot to the workflow

Set the Production URL as the bot's outgoing webhook: `PUT /bots/{id}` with `outgoing_url` using a personal token, or `PUT /bot/webhook` using the bot's token.

### 5. Ask the user to do by hand

- Turn on "Public bot" in the bot settings so employees can find it in search. You can't set this through the API.
- Add a logo to the bot.
- Open the "Outgoing webhook" tab and check that Webhook URL has the Production URL, and that "New messages" and "Any messages" are checked.

### 6. Check

1. Ask the user to ask a question in the chat with an @mention of the bot.
2. Find the question: `GET /messages` for the chat. The bot's answer is in that message's thread: read it with `GET /messages` using the `chat_id` of the thread.

## Other options

### A. Claude Code or Cursor with Pachca skills

The user gets a token in Automations → API and runs three commands:

```
npm install -g @pachca/cli
echo "YOUR_TOKEN" | pachca auth login --token -
npx skills add pachca/openapi
```

Then they describe the handler in plain words: the Kai agent answers from the knowledge base in the right chat, in a thread, with a link to the source. The assistant deploys the handler and gives the URL. Set that URL as the bot's `outgoing_url`, as in step 4.

### B. Your own service, built from the docs

A developer or their assistant writes the handler. They need to receive Pachca events with signature verification and reply in a thread: https://dev.pachca.com/guides/webhook/handler.md and https://dev.pachca.com/guides/ai-agents/interaction.md

## What the use case can't do

The "Create request" button and actions in other systems are built separately through the API. For manual setup, see the Help Center articles on buttons and outgoing webhooks, linked below.

## Troubleshooting

- The agent doesn't reply. The bot isn't added to the chat, "New messages" isn't checked in the outgoing webhook or the bot was addressed without an @mention.
- You can't create a token. API access is turned off in the workspace settings. Ask an administrator to turn it on or to issue a token from a service account.
- It worked, then stopped. The n8n workflow is turned off, or the outgoing webhook has the Test URL instead of the Production URL.

## Links

- The use case page with the demo and the instructions for a person: https://pachca.com/en/scenarios/ai-agent-bez-koda
- How the agent works under the hood: https://pachca.com/en/blog/ai-agent-v-korporativnom-messendzhere
- Buttons in chat bots: https://pachca.com/en/help-center/integrations/knopki-v-chat-botah
- Outgoing webhooks: https://pachca.com/en/help-center/integrations/ishodyashchie-webhook-kak-nastroit
- n8n and an AI agent: https://dev.pachca.com/guides/n8n/advanced.md
- Outgoing webhooks and event types: https://dev.pachca.com/guides/webhook/events.md
