Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-tzafon-model-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inngest/agent-kit": minor
---

Re-export `tzafon` model creator from `@inngest/ai`
24 changes: 23 additions & 1 deletion docs/concepts/models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Within AgentKit, models are adapters that wrap a given provider (ex. OpenAI, Ant
Each [Agent](/concepts/agents) can each select their own model to use and a [Network](/concepts/networks) can select a default model.

```ts
import { openai, anthropic, gemini } from "@inngest/agent-kit";
import { openai, anthropic, gemini, tzafon } from "@inngest/agent-kit";
```

## How to use a model
Expand Down Expand Up @@ -59,6 +59,13 @@ import { gemini, createAgent } from "@inngest/agent-kit";
const model = gemini({ model: "gemini-1.5-flash" });
```

```ts Tzafon
import { tzafon, createAgent } from "@inngest/agent-kit";

const model = tzafon({ model: "tzafon.sm-1" });
const modelWithApiKey = tzafon({ model: "tzafon.sm-1", apiKey: "sk_..." });
```

</CodeGroup>

### Configure model hyper parameters (temperature, etc.)
Expand Down Expand Up @@ -96,6 +103,15 @@ const model = gemini({
});
```

```ts Tzafon
import { tzafon, createAgent } from "@inngest/agent-kit";

const model = tzafon({
model: "tzafon.sm-1",
defaultParameters: { temperature: 0.7, max_tokens: 2048 },
});
```

</CodeGroup>

<Info>
Expand Down Expand Up @@ -189,6 +205,11 @@ For a full list of supported models, you can always check [the models directory
"grok-4-latest"
```

```plaintext Tzafon
"tzafon.sm-1"
"tzafon.northstar-cua-fast"
```

</CodeGroup>

### Environment variable used for each model provider
Expand All @@ -197,6 +218,7 @@ For a full list of supported models, you can always check [the models directory
- Anthropic: `ANTHROPIC_API_KEY`
- Gemini: `GEMINI_API_KEY`
- Grok: `XAI_API_KEY`
- Tzafon: `TZAFON_API_KEY`

## Contribution

Expand Down
3 changes: 2 additions & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"reference/model-openai",
"reference/model-anthropic",
"reference/model-gemini",
"reference/model-grok"
"reference/model-grok",
"reference/model-tzafon"
]
},
{
Expand Down
71 changes: 71 additions & 0 deletions docs/reference/model-tzafon.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: Tzafon Model
description: "Configure Tzafon as your model provider"
---

The `tzafon` function configures Tzafon as your model provider.

```ts
import { createAgent, tzafon } from "@inngest/agent-kit";

const agent = createAgent({
name: "Code writer",
system: "You are an expert TypeScript programmer.",
model: tzafon({ model: "tzafon.sm-1" }),
});
```


## Configuration

The `tzafon` function accepts a configuration object:

```ts
const agent = createAgent({
model: tzafon({
model: "tzafon.sm-1",
apiKey: process.env.TZAFON_API_KEY,
baseUrl: "https://api.tzafon.ai/v1/",
defaultParameters: { temperature: 0.7, max_tokens: 2048 },
}),
});
```

### Options

<ParamField path="model" type="string" required>
ID of the model to use.

See the [Tzafon models list](https://docs.tzafon.ai/api-reference/completions/models).
</ParamField>

<ParamField path="apiKey" type="string">
The Tzafon API key to use for authenticating your request. By default we'll
search for and use the `TZAFON_API_KEY` environment variable.
</ParamField>

<ParamField
path="baseUrl"
type="string"
default="https://api.tzafon.ai/v1/"
>
The base URL for the Tzafon API.
</ParamField>

<ParamField path="defaultParameters" type="object">
The default parameters to use for the model (ex: `temperature`, `max_tokens`,
etc).
</ParamField>

### Available Models

```plaintext Tzafon
"tzafon.sm-1"
"tzafon.northstar-cua-fast"
```

For the latest list of available models, see the [Tzafon API reference](https://docs.tzafon.ai/api-reference/completions/models).

## Limitations

Tzafon models do not currently support tool or function calling. Agents using Tzafon will produce text-only responses and cannot invoke AgentKit tools. The adapter automatically strips `tools` and `tool_choice` from requests to avoid API errors.
5 changes: 5 additions & 0 deletions packages/agent-kit/src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as openai from "./openai";
import * as azureOpenai from "./azure-openai";
import * as gemini from "./gemini";
import * as grok from "./grok";
import * as tzafon from "./tzafon";

export type Adapters = {
[Format in AiAdapter.Format]: {
Expand Down Expand Up @@ -34,4 +35,8 @@ export const adapters: Adapters = {
request: grok.requestParser,
response: grok.responseParser,
},
tzafon: {
request: tzafon.requestParser,
response: tzafon.responseParser,
},
};
44 changes: 44 additions & 0 deletions packages/agent-kit/src/adapters/tzafon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Adapters for Tzafon I/O to transform to/from internal network messages.
* Tzafon is an OpenAI-compatible API, but does not support tool/function
* calling. Requests containing `tools` or `tool_choice` are rejected with
* a 400 error, so this adapter strips them from the request body.
*
* @module
*/

import type { AiAdapter, OpenAi, Tzafon } from "@inngest/ai";
import type { AgenticModel } from "../model";
import {
requestParser as openaiRequestParser,
responseParser as openaiResponseParser,
} from "./openai";

/**
* Parse a request from internal network messages to an OpenAI input,
* stripping `tools` and `tool_choice` since Tzafon does not support them.
*/
export const requestParser: AgenticModel.RequestParser<Tzafon.AiModel> = (
model,
messages,
tools,
tool_choice = "auto"
) => {
const request: AiAdapter.Input<Tzafon.AiModel> = openaiRequestParser(
model as unknown as OpenAi.AiModel,
messages,
tools,
tool_choice
);

delete request.tools;
delete request.tool_choice;

return request;
};

/**
* Parse a response from Tzafon output to internal network messages.
*/
export const responseParser: AgenticModel.ResponseParser<Tzafon.AiModel> =
openaiResponseParser as unknown as AgenticModel.ResponseParser<Tzafon.AiModel>;
3 changes: 3 additions & 0 deletions packages/agent-kit/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class AgenticModel<TAiAdapter extends AiAdapter.Any> {
},
gemini: () => {},
grok: () => {},
tzafon: () => {
headers["Authorization"] = `Bearer ${modelCopy.authKey}`;
},
};

formatHandlers[modelCopy.format as AiAdapter.Format]();
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-kit/src/models.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { anthropic, gemini, openai, grok } from "@inngest/ai";
export { anthropic, gemini, openai, grok, tzafon } from "@inngest/ai";