Skip to content

examples: add Tuning Engines OpenAI-compatible endpoint#1333

Open
cerebrixos wants to merge 2 commits into
VoltAgent:mainfrom
cerebrixos:tuning-engines-example
Open

examples: add Tuning Engines OpenAI-compatible endpoint#1333
cerebrixos wants to merge 2 commits into
VoltAgent:mainfrom
cerebrixos:tuning-engines-example

Conversation

@cerebrixos
Copy link
Copy Markdown

@cerebrixos cerebrixos commented May 30, 2026

Summary

  • add a runnable with-tuning-engines example alongside the existing provider examples
  • configure @ai-sdk/openai with a custom baseURL and TUNING_ENGINES_API_KEY
  • update the examples index to include the new example

Why

We are an AI infrastructure team using VoltAgent with Tuning Engines. VoltAgent remains the agent runtime for tools, memory, and server behavior; Tuning Engines provides a governed OpenAI-compatible endpoint for model access, policy checks, audit logs, traces, and usage/cost reporting. Since the examples already include provider/gateway setups such as OpenRouter, this gives teams using Tuning Engines a starter that matches the existing examples structure. It would mean a lot to us if this is useful, and I am happy to adjust the example to fit your conventions.

Validation

  • git diff --check
  • attempted dependency install for the example; the repo-wide pnpm workspace install failed locally because the machine ran out of disk while fetching workspace dependencies, so I did not complete a TypeScript build in this environment

Summary by cubic

Adds a runnable with-tuning-engines example that routes VoltAgent model calls through a governed OpenAI-compatible endpoint, with startup validation and logging. This enables policy checks, traces, and usage/cost reporting without changing agent code.

  • New Features
    • New example at examples/with-tuning-engines using @ai-sdk/openai with custom baseURL and TUNING_ENGINES_API_KEY; optional TUNING_ENGINES_MODEL (default gpt-4o); .env.example added; linked in the examples index.
    • Runs a VoltAgent server via @voltagent/server-hono with LibSQL memory (@voltagent/libsql) and structured logging via @voltagent/logger.
    • Startup hardening: throws if TUNING_ENGINES_API_KEY is missing; dev script uses tsx with .env.
    • Demo performs one text generation on boot and logs response text and usage.

Written for commit 38f7fff. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added a new "Tuning Engines" example showing VoltAgent integration with a governed OpenAI-compatible endpoint, selectable model, local memory, logging, and a runnable dev/start workflow.
  • Documentation

    • Included full example docs, environment variable placeholders, installation and dev/start instructions, usage notes, and project structure guidance.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 30, 2026

⚠️ No Changeset found

Latest commit: 38f7fff

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 37892fd6-b8f1-43fc-8be5-bf70111d9099

📥 Commits

Reviewing files that changed from the base of the PR and between 67305f3 and 38f7fff.

📒 Files selected for processing (2)
  • examples/with-tuning-engines/package.json
  • examples/with-tuning-engines/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/with-tuning-engines/package.json
  • examples/with-tuning-engines/src/index.ts

📝 Walkthrough

Walkthrough

Adds a new example project showing VoltAgent routed through Tuning Engines (OpenAI-compatible) with docs, env template, package/tsconfig, and a runnable TypeScript entrypoint that starts a Hono server, configures LibSQL memory, and performs a sample generateText call.

Changes

Tuning Engines Example

Layer / File(s) Summary
Example announcement and docs
examples/README.md, examples/with-tuning-engines/README.md
Adds the example to the main index and a full README describing prerequisites, env vars (TUNING_ENGINES_API_KEY, optional TUNING_ENGINES_MODEL), install/dev/run steps, features, and project layout.
Project configuration and dependencies
examples/with-tuning-engines/package.json, examples/with-tuning-engines/tsconfig.json
Introduces package.json with dependencies and scripts and a tsconfig.json targeting ES2022/NodeNext with strict settings.
Environment template and example implementation
examples/with-tuning-engines/.env.example, examples/with-tuning-engines/src/index.ts
Adds env template for Tuning Engines credentials and an example entrypoint that validates env, constructs an OpenAI-compatible Tuning Engines client, sets up LibSQL-backed Memory, starts a Hono server, and issues a sample generateText() request with logging.

Sequence Diagram

sequenceDiagram
  participant Env as Environment
  participant App as VoltAgent Example
  participant OpenAI as TuningEngines OpenAI Client
  participant Mem as LibSQL Memory
  participant Server as Hono Server

  Env->>App: TUNING_ENGINES_API_KEY / TUNING_ENGINES_MODEL (validation)
  App->>OpenAI: instantiate client (baseURL=Tuning Engines)
  App->>Mem: initialize LibSQLMemoryAdapter
  App->>Server: start honoServer() with VoltAgent
  App->>OpenAI: generateText() sample request
  OpenAI->>App: response (text + usage)
  App->>App: log results / handle error (set exit code)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • omeraplak

Poem

🐰 A small example hops to the light,
Tuning Engines guiding requests just right,
Hono listens, LibSQL keeps track,
VoltAgent nudges models on the right track,
Logs a hello, then smiles—goodnight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new Tuning Engines example as an OpenAI-compatible endpoint.
Description check ✅ Passed The description includes a clear summary, rationale for the change, validation steps, and technical details, though some template sections are not explicitly addressed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
examples/with-tuning-engines/package.json (1)

1-39: ⚡ Quick win

Add a Node engine constraint to match the documented prerequisite.

Line 11 in the README requires Node.js v20+, but this package doesn’t enforce it. Adding engines prevents accidental installs/runs on unsupported Node versions.

Suggested patch
 {
   "name": "voltagent-example-with-tuning-engines",
   "author": "",
+  "engines": {
+    "node": ">=20"
+  },
   "dependencies": {
     "`@ai-sdk/openai`": "^3.0.0",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/with-tuning-engines/package.json` around lines 1 - 39, Add an
"engines" field to package.json to enforce the documented Node.js prerequisite
(v20+); update the root JSON object (the same level as "type", "scripts",
"dependencies") to include "engines": { "node": ">=20.0.0" } so installs on
older Node versions fail with a clear constraint message and prevent accidental
runs on unsupported Node versions.
examples/with-tuning-engines/src/index.ts (1)

39-48: ⚡ Quick win

Handle request failures in the demo IIFE.

Line 39 starts an async IIFE with no error handling; transient API/network errors can fail noisily and obscure what happened. Wrap it in try/catch and log the error.

Suggested patch
 (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,
-  });
+  try {
+    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,
+    });
+  } catch (error) {
+    logger.error("Tuning Engines example request failed", { error });
+    process.exitCode = 1;
+  }
 })();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/with-tuning-engines/src/index.ts` around lines 39 - 48, The async
IIFE that calls agent.generateText and then logger.info should be wrapped in a
try/catch to handle transient API/network failures: surround the await
agent.generateText(...) and subsequent logger.info(...) with try { ... } catch
(err) { logger.error("Tuning Engines example request failed", { error: err }) }
so failures are logged instead of crashing; reference the existing async IIFE,
agent.generateText, and logger.info to find where to add the try/catch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@examples/with-tuning-engines/package.json`:
- Around line 1-39: Add an "engines" field to package.json to enforce the
documented Node.js prerequisite (v20+); update the root JSON object (the same
level as "type", "scripts", "dependencies") to include "engines": { "node":
">=20.0.0" } so installs on older Node versions fail with a clear constraint
message and prevent accidental runs on unsupported Node versions.

In `@examples/with-tuning-engines/src/index.ts`:
- Around line 39-48: The async IIFE that calls agent.generateText and then
logger.info should be wrapped in a try/catch to handle transient API/network
failures: surround the await agent.generateText(...) and subsequent
logger.info(...) with try { ... } catch (err) { logger.error("Tuning Engines
example request failed", { error: err }) } so failures are logged instead of
crashing; reference the existing async IIFE, agent.generateText, and logger.info
to find where to add the try/catch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8fe86834-8fd0-49a3-81a5-25dd41677456

📥 Commits

Reviewing files that changed from the base of the PR and between 41cad53 and 67305f3.

📒 Files selected for processing (6)
  • examples/README.md
  • examples/with-tuning-engines/.env.example
  • examples/with-tuning-engines/README.md
  • examples/with-tuning-engines/package.json
  • examples/with-tuning-engines/src/index.ts
  • examples/with-tuning-engines/tsconfig.json

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Re-trigger cubic

@cerebrixos
Copy link
Copy Markdown
Author

Thanks for the review notes. I pushed 38f7ffff with both hardening tweaks:

  • added engines.node >=20.0.0 to the example package
  • wrapped the sample agent.generateText(...) call in try/catch and log failures cleanly

Validation:

  • git diff --check
  • npx --yes --package @biomejs/biome@1.9.4 biome check examples/with-tuning-engines/package.json examples/with-tuning-engines/src/index.ts

Both passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants