voltagent icon indicating copy to clipboard operation
voltagent copied to clipboard

examples: add Tuning Engines OpenAI-compatible endpoint

Open cerebrixos opened this issue 6 months ago • 5 comments

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 38f7ffffacfdd21cfe4ee9b11af9c8fcaca1a40e. 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.

cerebrixos avatar May 30 '26 18:05 cerebrixos

⚠️ No Changeset found

Latest commit: 38f7ffffacfdd21cfe4ee9b11af9c8fcaca1a40e

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

changeset-bot[bot] avatar May 30 '26 18:05 changeset-bot[bot]

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 67305f35a2eebf9a8ea4902c484bb56342e1c574 and 38f7ffffacfdd21cfe4ee9b11af9c8fcaca1a40e.

📒 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)

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.

coderabbitai[bot] avatar May 30 '26 18:05 coderabbitai[bot]

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/[email protected] biome check examples/with-tuning-engines/package.json examples/with-tuning-engines/src/index.ts

Both passed.

cerebrixos avatar Jun 04 '26 14:06 cerebrixos

Hello team @Theadd . Please do consider this PR for merge. So much appreciate in advance :)

cerebrixos avatar Jun 10 '26 03:06 cerebrixos

Thanks for adding this example. I tried the workspace install path and hit a reproducible lockfile issue:

pnpm install --frozen-lockfile --ignore-scripts

This exits with:

ERR_PNPM_OUTDATED_LOCKFILE Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with examples/with-tuning-engines/package.json

pnpm-workspace.yaml includes examples/*, and this PR adds examples/with-tuning-engines/package.json without updating pnpm-lock.yaml, so frozen installs/CI will reject the new workspace importer. Regenerating and committing the lockfile should clear this.

slegarraga avatar Jun 10 '26 15:06 slegarraga