Skip to content

Agent Configuration

The agent is configured through a sweny.config.ts file in your project root and environment variables. The config file defines plugins, storage, auth, and model settings. Environment variables provide secrets and runtime overrides.

import { defineConfig } from "@swenyai/agent";
import { noAuth } from "@swenyai/providers/auth";
import { fsStorage } from "@swenyai/providers/storage";
import { allowAllGuard } from "@swenyai/providers/access";
import { memoryPlugin, workspacePlugin } from "@swenyai/agent";
export default defineConfig({
name: "my-agent",
auth: noAuth(),
storage: fsStorage({ baseDir: "./.sweny-data" }),
accessGuard: allowAllGuard(),
plugins: [memoryPlugin(), workspacePlugin()],
model: {
maxTurns: 25,
disallowedTools: [],
},
rateLimit: {
maxPerMinute: 10,
maxPerHour: 100,
},
logLevel: "info",
});
FieldTypeDefaultDescription
namestring"sweny-agent"Agent display name, used in system prompt
authAuthProvidernoAuth()Authentication provider (docs)
storageStorageProvider(required)Session, memory, and workspace backend (docs)
accessGuardAccessGuardallowAllGuard()Access control policy (docs)
pluginsToolPlugin[][]Tool plugins to register (docs)
systemPromptstring(built-in default)Custom base system prompt
model.maxTurnsnumber20Max agent turns per user message
model.disallowedToolsstring[][]Additional tools to deny beyond the default guard
slack.appTokenstringfrom envSlack app-level token (xapp-...)
slack.botTokenstringfrom envSlack bot token (xoxb-...)
slack.signingSecretstringfrom envSlack signing secret
rateLimit.maxPerMinutenumber(unlimited)Per-user rate limit per minute
rateLimit.maxPerHournumber(unlimited)Per-user rate limit per hour
auditAuditLoggerconsole loggerAudit log backend
healthPortnumber3000Health check HTTP port
logLevel"debug" | "info" | "warn" | "error""info"Log verbosity
allowedUsersstring[][] (all allowed)Slack user IDs allowed to interact

A type-only helper that returns its argument unchanged. It provides TypeScript autocomplete in your config file:

import { defineConfig } from "@swenyai/agent";
export default defineConfig({
// IDE autocomplete works here
});
VariableDescriptionRequired
ANTHROPIC_API_KEYClaude API keyOne of these two
CLAUDE_CODE_OAUTH_TOKENClaude OAuth tokenmust be set
SLACK_APP_TOKENSlack app-level token (xapp-...)Yes (Slack mode)
SLACK_BOT_TOKENSlack bot token (xoxb-...)Yes (Slack mode)
SLACK_SIGNING_SECRETSlack signing secretYes (Slack mode)
LOG_LEVELLog verbosity (debug, info, warn, error)No (defaults to info)

Environment variables are validated with Zod on startup. At least one of ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN must be set, or the agent will fail to start. Slack tokens are validated for their expected prefixes (xapp-, xoxb-).

Create a .env file in your project root:

Terminal window
ANTHROPIC_API_KEY=sk-ant-...
SLACK_APP_TOKEN=xapp-...
SLACK_BOT_TOKEN=xoxb-...
SLACK_SIGNING_SECRET=...

The config loader merges file and environment settings:

  1. loadConfig() looks for sweny.config.ts in the current directory (or a custom path)
  2. If the file is missing or fails to import, a default config is used
  3. Environment variables fill in Slack tokens and log level only when not set in the config file (config file takes priority)
  4. Zod schema validation runs and fails fast with clear error messages if required values are missing

The CLI uses the same config file. Slack tokens are not required when running in CLI mode:

Terminal window
npx tsx --env-file=.env src/cli.ts

Available commands in the REPL:

CommandDescription
/quit, /exitExit the CLI
/resetClear the current session
/memoryShow saved memories
/memory clearClear all memories
/workspaceShow workspace files
/workspace resetClear the workspace
/helpList commands