From 67305f35a2eebf9a8ea4902c484bb56342e1c574 Mon Sep 17 00:00:00 2001 From: cerebrixos <248534569+cerebrixos@users.noreply.github.com> Date: Sat, 30 May 2026 14:59:11 -0400 Subject: [PATCH] Add Tuning Engines example --- examples/README.md | 1 + examples/with-tuning-engines/.env.example | 2 + examples/with-tuning-engines/README.md | 75 ++++++++++++++++++++++ examples/with-tuning-engines/package.json | 39 +++++++++++ examples/with-tuning-engines/src/index.ts | 48 ++++++++++++++ examples/with-tuning-engines/tsconfig.json | 13 ++++ 6 files changed, 178 insertions(+) create mode 100644 examples/with-tuning-engines/.env.example create mode 100644 examples/with-tuning-engines/README.md create mode 100644 examples/with-tuning-engines/package.json create mode 100644 examples/with-tuning-engines/src/index.ts create mode 100644 examples/with-tuning-engines/tsconfig.json diff --git a/examples/README.md b/examples/README.md index a69801d31..c0909fa07 100644 --- a/examples/README.md +++ b/examples/README.md @@ -98,6 +98,7 @@ Create a multi-agent research workflow where different AI agents collaborate to - [Amazon Bedrock](./with-amazon-bedrock) — Run AWS Bedrock models by configuring credentials and model IDs in VoltAgent. - [Anthropic](./with-anthropic) — Use Claude models as your agent’s LLM via the AI SDK. - [OpenRouter](./with-openrouter) — Use OpenRouter through VoltAgent's built-in `openrouter/` routing. +- [Tuning Engines](./with-tuning-engines) — Route VoltAgent model calls through a governed OpenAI-compatible endpoint for policy, traces, and usage/cost reporting. - [Chroma](./with-chroma) — RAG with Chroma vectors showing automatic vs tool‑driven retrieval patterns. - [Client‑side Tools](./with-client-side-tools) — Next.js UI triggers typed client‑side tools safely, VoltAgent on the server. - [Cloudflare Workers](./with-cloudflare-workers) — Deploy your agent on Workers using the Hono server adapter. diff --git a/examples/with-tuning-engines/.env.example b/examples/with-tuning-engines/.env.example new file mode 100644 index 000000000..56434538c --- /dev/null +++ b/examples/with-tuning-engines/.env.example @@ -0,0 +1,2 @@ +TUNING_ENGINES_API_KEY=sk-te-your-inference-key +TUNING_ENGINES_MODEL=gpt-4o diff --git a/examples/with-tuning-engines/README.md b/examples/with-tuning-engines/README.md new file mode 100644 index 000000000..a2c85e0cb --- /dev/null +++ b/examples/with-tuning-engines/README.md @@ -0,0 +1,75 @@ +# with-tuning-engines + +A [VoltAgent](https://github.com/VoltAgent/voltagent) application using Tuning Engines as a governed OpenAI-compatible endpoint. + +Tuning Engines can sit between VoltAgent and the underlying model providers so that VoltAgent owns the agent runtime, tools, and memory, while Tuning Engines centralizes model access, policy checks, audit logs, traces, and usage/cost reporting. + +## Getting Started + +### Prerequisites + +- Node.js (v20 or newer) +- npm, yarn, or pnpm +- A Tuning Engines inference key with access to the model alias you want to use + +### Installation + +1. Clone this repository +2. Install dependencies +3. Copy `.env.example` to `.env` +4. Set `TUNING_ENGINES_API_KEY` +5. Optionally set `TUNING_ENGINES_MODEL` + +```bash +npm install +# or +yarn +# or +pnpm install +``` + +### Development + +Run the development server: + +```bash +npm run dev +# or +yarn dev +# or +pnpm dev +``` + +The example starts a VoltAgent server on port `3141`. + +The dev script uses `tsx watch --env-file=.env ./src`, matching the example's `package.json` setup. + +## What This Example Shows + +- `Agent` configured with `@ai-sdk/openai` and a custom `baseURL` +- Tuning Engines inference key usage via `TUNING_ENGINES_API_KEY` +- Optional model alias selection via `TUNING_ENGINES_MODEL` +- Local memory storage with LibSQL +- Hono server integration through `@voltagent/server-hono` + +## Notes + +Use `pnpm build && pnpm start` for the compiled output, or `pnpm dev` during development. + +## Project Structure + +```text +. +├── src/ +│ └── index.ts +├── .env.example +├── package.json +├── tsconfig.json +└── README.md +``` + +## Try Example + +```bash +npm create voltagent-app@latest -- --example with-tuning-engines +``` diff --git a/examples/with-tuning-engines/package.json b/examples/with-tuning-engines/package.json new file mode 100644 index 000000000..e1f184b5c --- /dev/null +++ b/examples/with-tuning-engines/package.json @@ -0,0 +1,39 @@ +{ + "name": "voltagent-example-with-tuning-engines", + "author": "", + "dependencies": { + "@ai-sdk/openai": "^3.0.0", + "@voltagent/cli": "^0.1.21", + "@voltagent/core": "^2.7.5", + "@voltagent/libsql": "^2.1.2", + "@voltagent/logger": "^2.0.2", + "@voltagent/server-hono": "^2.0.13", + "ai": "^6.0.0" + }, + "devDependencies": { + "@types/node": "^24.2.1", + "tsx": "^4.21.0", + "typescript": "^5.8.2" + }, + "keywords": [ + "agent", + "ai", + "openai-compatible", + "tuning-engines", + "voltagent" + ], + "license": "MIT", + "private": true, + "repository": { + "type": "git", + "url": "https://github.com/VoltAgent/voltagent.git", + "directory": "examples/with-tuning-engines" + }, + "scripts": { + "build": "tsc", + "dev": "tsx watch --env-file=.env ./src", + "start": "node dist/index.js", + "volt": "volt" + }, + "type": "module" +} diff --git a/examples/with-tuning-engines/src/index.ts b/examples/with-tuning-engines/src/index.ts new file mode 100644 index 000000000..d79c65df0 --- /dev/null +++ b/examples/with-tuning-engines/src/index.ts @@ -0,0 +1,48 @@ +import { createOpenAI } from "@ai-sdk/openai"; +import { Agent, Memory, VoltAgent } from "@voltagent/core"; +import { LibSQLMemoryAdapter } from "@voltagent/libsql"; +import { createPinoLogger } from "@voltagent/logger"; +import { honoServer } from "@voltagent/server-hono"; + +if (!process.env.TUNING_ENGINES_API_KEY) { + throw new Error("TUNING_ENGINES_API_KEY is required"); +} + +const tuningEngines = createOpenAI({ + apiKey: process.env.TUNING_ENGINES_API_KEY, + baseURL: "https://api.tuningengines.com/v1", +}); + +const logger = createPinoLogger({ + name: "with-tuning-engines", + level: "info", +}); + +const agent = new Agent({ + name: "Tuning Engines Assistant", + instructions: + "You are a helpful assistant running through a governed OpenAI-compatible endpoint.", + model: tuningEngines(process.env.TUNING_ENGINES_MODEL ?? "gpt-4o"), + memory: new Memory({ + storage: new LibSQLMemoryAdapter(), + }), +}); + +new VoltAgent({ + agents: { + agent, + }, + logger, + server: honoServer(), +}); + +(async () => { + const result = await agent.generateText( + "Explain how policy, traces, and usage reporting help production AI agents.", + ); + + logger.info("Tuning Engines example request completed", { + text: result.text, + usage: result.usage, + }); +})(); diff --git a/examples/with-tuning-engines/tsconfig.json b/examples/with-tuning-engines/tsconfig.json new file mode 100644 index 000000000..d37040df9 --- /dev/null +++ b/examples/with-tuning-engines/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "outDir": "dist" + }, + "include": ["src/**/*.ts"] +}