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

# Run agents

> Interact with agents through Slack, the CLI, and your own code.

Agents can be used in a variety of ways:

| Surface               | Status      | Best for                                                                      |
| --------------------- | ----------- | ----------------------------------------------------------------------------- |
| **Slack**             | Available   | The primary way Keystroke users interact with agents today, directly in Slack |
| **CLI**               | Available   | Testing and debugging agents during development                               |
| **HTTP API**          | Available   | Use agents via API and integrate them into your own services                  |
| **Workflow steps**    | Available   | Use agents as steps in deterministic workflows                                |
| **Triggers**          | Available   | Run an agent automatically on a schedule, webhook, or poll                    |
| **External channels** | Coming soon | Use agents in tools like Microsoft Teams, Telegram, Linear, and more          |
| **In-app chat**       | Coming soon | An in-app chat interface for every agent, directly in the Keystroke web app   |
| **MCP server**        | Coming soon | Expose agents as tools to other MCP clients                                   |

## Use agents in Slack

Slack is how most teams use Keystroke agents today. You can connect Keystroke to Slack and bind Slack channels to your agent. Once bound, teammates can message the agent like any coworker, in a channel, a thread, or a DM, and the gateway turns each message into an agent session and posts the reply back to Slack.

See [external channels](/learn/agents/external-channels) for connecting Slack, binding channels, choosing listen modes, and inspecting channel sessions.

## Use agents from the CLI

The CLI is the most practical way to run an agent while you build and test it. Deploy your project, then prompt the agent against the deployed project:

```bash theme={null}
keystroke deploy --project <slug>   # or --filter agents/support
keystroke agents prompt support --message "What is Keystroke?"
```

The `support` value is the agent `slug` from `defineAgent()`. The response includes a `sessionId`, messages, and any error. When you call an agent from code and need a typed object back, pass an `outputSchema` and read `result.output` — see [structured output](/learn/agents/build-agents#structured-output).

Continue the same session by passing its ID:

```bash theme={null}
keystroke agents prompt support \
  --session-id <session-id> \
  --message "Now turn that into a Slack reply"
```

Most agent runtime commands follow the CLI's resolved target:

| Target    | Use when                                                                                  |
| --------- | ----------------------------------------------------------------------------------------- |
| **Cloud** | The default after deploy: invoke or inspect your deployed project                         |
| **Local** | You're running a local server (`keystroke dev` / `keystroke start`) for offline iteration |

```bash theme={null}
keystroke agents prompt support --message "Prompt the deployed agent"          # cloud (default after deploy)
keystroke --local agent prompt support --message "Prompt a local server"       # local server
```

See [targets: local vs cloud](/cli#targets-local-vs-cloud) for the full routing model.

<Note>
  `keystroke agents list` is platform/org-level and lists agents in the active organization or project. Prompt and session list/get commands run against the resolved project target. Session cancellation is platform-backed today.
</Note>

List recent sessions for one agent:

```bash theme={null}
keystroke agents sessions list support
```

Filter while debugging:

```bash theme={null}
keystroke agents sessions list support --status failed
keystroke agents sessions list support --source gateway
```

Get details:

```bash theme={null}
keystroke agents sessions get support <session-id> --include messages,trace
```

Use `--include gateway,messages,events,trace` when you need all available session detail. See the [CLI reference](/cli#agents) for the full command list.

Cancel a running cloud session by ID:

```bash theme={null}
keystroke agents sessions cancel <session-id>
```

Cancellation is useful when an agent is stuck in a long-running tool call or no longer needs to finish. This command uses the active platform context today, so use it for deployed/cloud sessions.

## Use agents in workflow steps

Agents can be called from workflows and actions with `.prompt()`:

```ts theme={null}
const result = await supportAgent.prompt({
  message: "Draft a reply for this customer thread.",
});
```

When called inside a workflow, the agent prompt is part of the workflow execution and also creates an agent session. Inspect both the workflow run and the agent run when debugging handoff behavior.

## Run agents from triggers

A [trigger](/learn/triggers/overview) attaches an event source (a schedule, a webhook, or a poll) to an agent, so the agent runs on its own when the source fires instead of waiting for someone to prompt it. Triggers live in `src/triggers/`; a source exposes `.attach()`, where you pass the agent and the `prompt` to run.

```ts src/triggers/morning-check.ts theme={null}
import { defineCronSource } from "@keystrokehq/keystroke/trigger";
import support from "../agents/support";

export default defineCronSource({ key: "morning-check", schedule: "0 9 * * *" }).attach({
  agent: support,
  prompt: () => "Summarize anything that needs attention this morning.",
});
```

Webhook and poll sources pass their payload to `prompt`, so the agent can act on the event that fired it:

```ts src/triggers/new-inbox.ts theme={null}
}).attach({
  agent: support,
  prompt: (payload) => `Summarize this new inbox item: ${JSON.stringify(payload)}`,
});
```

Each fire starts a new agent session, just like any other surface. Inspect them in **History** (filter **Type** to **Agent**) or from the CLI:

```bash theme={null}
keystroke triggers runs list morning-check --agent support
```

See [triggers](/learn/triggers/overview) for the full source-and-attach model, payload filters, and transforms.

Agents can also schedule their own runs at runtime instead of waiting for a code trigger. See [ephemeral triggers](/learn/agents/build-agents#ephemeral-triggers).

## Use agents via API

You can also prompt a deployed agent over HTTP. The route is asynchronous: it enqueues the prompt and returns `202` with a `sessionId` and `runId` to inspect later, rather than waiting for the agent to finish.

```bash theme={null}
curl -X POST https://<your-project>/api/projects/<project-id>/agents/support \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <org-api-key>" \
  -d '{ "message": "Summarize our refund policy" }'
```

Continue an existing session by including its `sessionId` in the body alongside the new `message`; send only the new message, not the prior turns. Inspect the result later in **History** or with `keystroke agents sessions get`.

This is mainly useful for wiring agents into your own services. For most internal tooling, Slack and the CLI cover what you need.

## Review agent runs

Every surface that runs an agent creates an agent session you can review later. Open **History** in the web app and filter **Type** to **Agent**. The detail panel shows messages, tool calls, metadata, trace data, timing, and errors.

From the CLI, use session commands when you want to inspect runs while debugging:

```bash theme={null}
keystroke agents sessions list support
keystroke agents sessions get support <session-id> --include messages,events,trace
```

See [agent runs](/learn/logs/agent-runs) for the full run history view.

## Next steps

<CardGroup cols={2}>
  <Card title="Triggers" href="/learn/triggers/overview">
    Run agents on a schedule, webhook, or poll.
  </Card>

  <Card title="External channels" href="/learn/agents/external-channels">
    Connect Slack and route channel messages to agents.
  </Card>

  <Card title="Agent runs" href="/learn/logs/agent-runs">
    Inspect messages, tool calls, errors, and traces.
  </Card>

  <Card title="Deploy a project" href="/learn/projects/deploy-a-project">
    Ship agent changes to the platform.
  </Card>
</CardGroup>
