> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# SkillBase

> Abstract base class for creating reusable, pluggable agent skills.

[agentbase]: /docs/server-sdks/reference/typescript/agents/agent-base

[skills]: /docs/server-sdks/reference/typescript/agents/skills

[skillregistry]: /docs/server-sdks/reference/typescript/agents/skill-registry

[cleanup]: /docs/server-sdks/reference/typescript/agents/skill-base/cleanup

[getglobaldata]: /docs/server-sdks/reference/typescript/agents/skill-base/get-global-data

[gethints]: /docs/server-sdks/reference/typescript/agents/skill-base/get-hints

[getinstancekey]: /docs/server-sdks/reference/typescript/agents/skill-base/get-instance-key

[getparameterschema]: /docs/server-sdks/reference/typescript/agents/skill-base/get-parameter-schema

[getpromptsections]: /docs/server-sdks/reference/typescript/agents/skill-base/get-prompt-sections

[getskilldata]: /docs/server-sdks/reference/typescript/agents/skill-base/get-skill-data

[getskillnamespace]: /docs/server-sdks/reference/typescript/agents/skill-base/get-skill-namespace

[isinitialized]: /docs/server-sdks/reference/typescript/agents/skill-base/is-initialized

[markinitialized]: /docs/server-sdks/reference/typescript/agents/skill-base/mark-initialized

[setup]: /docs/server-sdks/reference/typescript/agents/skill-base/setup

[updateskilldata]: /docs/server-sdks/reference/typescript/agents/skill-base/update-skill-data

[validateenvvars]: /docs/server-sdks/reference/typescript/agents/skill-base/validate-env-vars

SkillBase is the abstract base class for all agent skills. Skills are modular,
reusable capabilities -- such as weather lookup, web search, or calendar access --
that can be added to any [`AgentBase`][agentbase] agent with a single call to
`agent.addSkill()`.

Extend SkillBase to create custom skills. Metadata (name, description, version,
required packages, required environment variables, multi-instance support) is
declared as **static class constants** on the subclass — the [`SkillRegistry`][skillregistry]
and `SkillManager` read these constants directly. You override `getTools()` to
expose SWAIG tools and optionally override lifecycle and prompt methods.

> **Info**
>
> For the catalog of built-in skills and their configuration parameters, see
> the [Skills][skills] page.

## **Static Class Constants**

Subclasses declare their identity and requirements by overriding these static
members. The [`SkillRegistry`][skillregistry] reads them directly — no manifest
object is exchanged.

**`SKILL_NAME`** `string` — required

Unique skill name used for registration. Subclasses **must** override with a
non-empty string; the constructor throws otherwise.

---

**`SKILL_DESCRIPTION`** `string` — required

Human-readable description. Subclasses **must** override with a non-empty
string; the constructor throws otherwise.

---

**`SKILL_VERSION`** `string` — default: 1.0.0

Semantic version string.

---

**`REQUIRED_PACKAGES`** `readonly string[]` — default: \[]

NPM packages the skill depends on. Checked at load time by `validatePackages()`.

---

**`REQUIRED_ENV_VARS`** `readonly string[]` — default: \[]

Environment variables the skill requires. Checked at load time by `validateEnvVars()`.

---

**`SUPPORTS_MULTIPLE_INSTANCES`** `boolean` — default: false

When `true`, the same skill can be added to an agent multiple times with
different configurations (distinguished by `tool_name`).

---

**`getParameterSchema()`** `static method`

Returns metadata about all parameters the skill accepts.
See [`getParameterSchema`][getparameterschema].

---

## **Constructor**

```typescript {1}
constructor(config?: SkillConfig)
```

The skill name, description, and version come from the subclass's static
constants — not from constructor arguments.

**`config`** `SkillConfig`

Optional configuration key-value pairs for the skill instance. Any
`swaig_fields` entry is extracted and automatically merged into tool
definitions.

---

## **Instance Properties**

**`skillName`** `string`

The registered name for this skill instance, copied from `SKILL_NAME` (readonly).

---

**`instanceId`** `string`

Unique identifier for this skill instance (readonly).

---

**`config`** `SkillConfig`

Configuration parameters passed to the constructor (protected).

---

**`swaigFields`** `Record<string, unknown>`

SWAIG metadata extracted from config, automatically merged into tool
definitions (readonly).

---

## **Methods**

#### [setup](/docs/server-sdks/reference/typescript/agents/skill-base/setup)

Initialize the skill. Return `false` to fail-closed on missing config.

#### [cleanup](/docs/server-sdks/reference/typescript/agents/skill-base/cleanup)

Release resources when the skill is removed or the agent shuts down.

#### [getTools](/docs/server-sdks/reference/typescript/agents/skill-base/get-tools)

Return SWAIG tool definitions this skill exposes.

#### [getDataMapTools](/docs/server-sdks/reference/typescript/agents/skill-base/get-data-map-tools)

Return fully-built SWAIG function dicts (DataMap style).

#### [getParameterSchema](/docs/server-sdks/reference/typescript/agents/skill-base/get-parameter-schema)

Return metadata about all parameters the skill accepts.

#### [getGlobalData](/docs/server-sdks/reference/typescript/agents/skill-base/get-global-data)

Return data to merge into the agent's global data.

#### [getHints](/docs/server-sdks/reference/typescript/agents/skill-base/get-hints)

Return speech recognition hints for this skill.

#### [getInstanceKey](/docs/server-sdks/reference/typescript/agents/skill-base/get-instance-key)

Get the unique key used to track this skill instance.

#### [getPromptSections](/docs/server-sdks/reference/typescript/agents/skill-base/get-prompt-sections)

Return prompt sections for the agent.

#### [getSkillData](/docs/server-sdks/reference/typescript/agents/skill-base/get-skill-data)

Extract this skill's namespaced data from raw request data.

#### [getSkillNamespace](/docs/server-sdks/reference/typescript/agents/skill-base/get-skill-namespace)

Get the namespace key used to store this skill's data.

#### [updateSkillData](/docs/server-sdks/reference/typescript/agents/skill-base/update-skill-data)

Write data under this skill's namespace into a FunctionResult.

#### [isInitialized](/docs/server-sdks/reference/typescript/agents/skill-base/is-initialized)

Check whether the skill has been initialized.

#### [markInitialized](/docs/server-sdks/reference/typescript/agents/skill-base/mark-initialized)

Mark the skill as initialized.

#### [validateEnvVars](/docs/server-sdks/reference/typescript/agents/skill-base/validate-env-vars)

Validate that required environment variables are set.

#### [hasAllEnvVars](/docs/server-sdks/reference/typescript/agents/skill-base/has-all-env-vars)

Check whether all required env vars are present.

#### [validatePackages](/docs/server-sdks/reference/typescript/agents/skill-base/validate-packages)

Validate that required packages can be imported.

#### [hasAllPackages](/docs/server-sdks/reference/typescript/agents/skill-base/has-all-packages)

Check whether all required packages are importable.

#### [getConfig](/docs/server-sdks/reference/typescript/agents/skill-base/get-config)

Look up a configuration value by key.

#### [getAgent](/docs/server-sdks/reference/typescript/agents/skill-base/get-agent)

Get the agent this skill is attached to.

#### [setAgent](/docs/server-sdks/reference/typescript/agents/skill-base/set-agent)

Attach the skill to an agent.

#### [defineTool](/docs/server-sdks/reference/typescript/agents/skill-base/define-tool)

Imperatively register a tool with this skill.

### defineTool (protected)

```typescript {1}
protected defineTool(toolDef: SkillToolDefinition): void
```

Imperatively register a tool. Use from `setup()` when the tool shape depends on
config evaluated at runtime. The method merges `this.swaigFields` into the
definition and pushes it onto the internal dynamic-tools list; the default
`getTools()` returns that list. Skills with a static tool list should override
`getTools()` directly instead.

### getConfig

```typescript {1}
getConfig<T = unknown>(key: string, defaultValue?: T): T
```

Read a configuration value by key, with an optional fallback default.

**`key`** `string` — required

The configuration key to look up.

---

**`defaultValue`** `T`

Value to return if the key is not present in the config.

---

### hasAllEnvVars / hasAllPackages

```typescript {1-2}
hasAllEnvVars(): boolean
async hasAllPackages(): Promise<boolean>
```

Boolean wrappers around `validateEnvVars()` and `validatePackages()`.

## **Examples**

### Custom skill

```typescript {4-6}
import { SkillBase, type SkillToolDefinition } from '@signalwire/sdk';

class MyWeatherSkill extends SkillBase {
  static override SKILL_NAME = 'my_weather';
  static override SKILL_DESCRIPTION = 'Look up weather';
  static override SKILL_VERSION = '1.0.0';

  override getTools(): SkillToolDefinition[] {
    return [{
      name: 'get_weather',
      description: 'Get current weather for a city',
      parameters: { city: { type: 'string', description: 'City name' } },
      handler: async (args) => ({ response: 'Sunny, 72F' }),
    }];
  }
}
```

### Using a skill

```typescript {6-9}
import { AgentBase } from '@signalwire/sdk';

const agent = new AgentBase({ name: 'weather-agent' });
agent.setPromptText("You are a helpful assistant.");
await agent.addSkillByName('weather_api', {
  api_key: 'YOUR_API_KEY', // or set WEATHER_API_KEY; setup fails without a key
  units: 'metric',
});

agent.run();
```