diff --git a/.changeset/add-tzafon-model-provider.md b/.changeset/add-tzafon-model-provider.md new file mode 100644 index 00000000..9625c051 --- /dev/null +++ b/.changeset/add-tzafon-model-provider.md @@ -0,0 +1,5 @@ +--- +"@inngest/agent-kit": minor +--- + +Re-export `tzafon` model creator from `@inngest/ai` diff --git a/docs/concepts/models.mdx b/docs/concepts/models.mdx index fd655f7d..f19a5e69 100644 --- a/docs/concepts/models.mdx +++ b/docs/concepts/models.mdx @@ -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 @@ -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_..." }); +``` + ### Configure model hyper parameters (temperature, etc.) @@ -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 }, +}); +``` + @@ -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" +``` + ### Environment variable used for each model provider @@ -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 diff --git a/docs/docs.json b/docs/docs.json index d0d78f04..3b9d5abd 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -119,7 +119,8 @@ "reference/model-openai", "reference/model-anthropic", "reference/model-gemini", - "reference/model-grok" + "reference/model-grok", + "reference/model-tzafon" ] }, { diff --git a/docs/reference/model-tzafon.mdx b/docs/reference/model-tzafon.mdx new file mode 100644 index 00000000..ab93c303 --- /dev/null +++ b/docs/reference/model-tzafon.mdx @@ -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 + + + ID of the model to use. + + See the [Tzafon models list](https://docs.tzafon.ai/api-reference/completions/models). + + + + The Tzafon API key to use for authenticating your request. By default we'll + search for and use the `TZAFON_API_KEY` environment variable. + + + + The base URL for the Tzafon API. + + + + The default parameters to use for the model (ex: `temperature`, `max_tokens`, + etc). + + +### 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. diff --git a/packages/agent-kit/src/adapters/index.ts b/packages/agent-kit/src/adapters/index.ts index 07ea9b77..c486ac06 100644 --- a/packages/agent-kit/src/adapters/index.ts +++ b/packages/agent-kit/src/adapters/index.ts @@ -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]: { @@ -34,4 +35,8 @@ export const adapters: Adapters = { request: grok.requestParser, response: grok.responseParser, }, + tzafon: { + request: tzafon.requestParser, + response: tzafon.responseParser, + }, }; diff --git a/packages/agent-kit/src/adapters/tzafon.ts b/packages/agent-kit/src/adapters/tzafon.ts new file mode 100644 index 00000000..295b2603 --- /dev/null +++ b/packages/agent-kit/src/adapters/tzafon.ts @@ -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 = ( + model, + messages, + tools, + tool_choice = "auto" +) => { + const request: AiAdapter.Input = 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 = + openaiResponseParser as unknown as AgenticModel.ResponseParser; diff --git a/packages/agent-kit/src/model.ts b/packages/agent-kit/src/model.ts index 2cf2d97e..b55a50a4 100644 --- a/packages/agent-kit/src/model.ts +++ b/packages/agent-kit/src/model.ts @@ -79,6 +79,9 @@ export class AgenticModel { }, gemini: () => {}, grok: () => {}, + tzafon: () => { + headers["Authorization"] = `Bearer ${modelCopy.authKey}`; + }, }; formatHandlers[modelCopy.format as AiAdapter.Format](); diff --git a/packages/agent-kit/src/models.ts b/packages/agent-kit/src/models.ts index f874f229..d0c4a580 100644 --- a/packages/agent-kit/src/models.ts +++ b/packages/agent-kit/src/models.ts @@ -1 +1 @@ -export { anthropic, gemini, openai, grok } from "@inngest/ai"; +export { anthropic, gemini, openai, grok, tzafon } from "@inngest/ai";