# Write an AI Agent extension in TypeScript with Shiitake

> Write an AI agent extension in TypeScript with Shiitake. Add a prompt section and test it without a model API key before adding tools or stored state.

To write an AI agent extension in TypeScript, start with Shiitake's
`defineExtension`. This example adds a named section to the system prompt before
each model request. Test that contribution without a model API key before adding
tools, stored state, commands or a client panel.

## Run a prompt extension without an API key

Use Node.js 24 or newer. In a new project folder, install Shiitake and a
TypeScript runner. These commands download packages from npm and write the
project's manifest and lockfile:

```sh
npm init -y
npm pkg set type=module
npm install @fungi.computer/shiitake
npm install --save-dev tsx@4.23.12
```

Save this as `main.ts`:

```ts
import { defineExtension } from "@fungi.computer/shiitake/extensions";
import { echoSystemPrompt, memoryHost } from "@fungi.computer/shiitake/testing";

const houseStyle = defineExtension("house-style").define({
  prompt: () => [{ name: "voice", text: "Answer in one short sentence." }],
});

const host = await memoryHost({
  extensions: [houseStyle],
  script: [echoSystemPrompt()],
});
try {
  await host.agent.session("style").send("Hi", { requestId: "hi" });
  const snapshot = await host.settle("style");
  const reply = snapshot.messages.at(-1)?.value;
  if (reply?.role === "assistant")
    for (const part of reply.content)
      if (part.type === "text") console.log(part.text);
} finally {
  await host.close();
}
```

Run it from that folder:

```sh
node --import tsx main.ts
```

The reply includes your section:

```text
[extension:house-style.voice]
Answer in one short sentence.
```

`memoryHost` runs a real Shiitake Agent with an in-memory database.
`echoSystemPrompt()` is a stand-in model that replies with the prompt it
received. It makes the result inspectable without a provider account, an API key
or a network model request. It is a test of the extension's prompt contribution,
not a test of how a real model follows that instruction.

The test host admits the extensions you list. A production host separately
chooses its extension roster and grants; defining an extension does not grant it
access to files, tools or commands. Run your extensions on a host you control.
Fungi-hosted Agents load Fungi's own extensions, not arbitrary packages from a
conversation.

## Add one capability at a time

The
[Shiitake extension guide](https://docs.fungi.computer/shiitake/extensions/first-extension/)
builds this example into a Bookmarks extension:

- [Give the model a tool](https://docs.fungi.computer/shiitake/extensions/model-tool/):
  declare a Mycelium operation's input and output with Effect schemas.
- [Remember things](https://docs.fungi.computer/shiitake/extensions/stored-state/):
  give the extension stored state.
- [Add commands](https://docs.fungi.computer/shiitake/extensions/commands/) and
  [a client entry](https://docs.fungi.computer/shiitake/extensions/client-entry/)
  when people need to use it outside a model turn.
- [Test it](https://docs.fungi.computer/shiitake/extensions/test-it/) with
  scripted model calls before trying a live provider.

Keep the
[Extension reference](https://docs.fungi.computer/shiitake/extensions/reference/)
and [Grants guide](https://docs.fungi.computer/shiitake/extensions/grants/)
beside the code. They explain all extension features and the permissions each
one needs.
