examples: add Tuning Engines OpenAI-compatible endpoint#1333
Conversation
|
📝 WalkthroughWalkthroughThis PR adds a new example project demonstrating VoltAgent integration with Tuning Engines as a governed OpenAI-compatible endpoint. The example includes documentation, project configuration, environment setup, and a working implementation that initializes a VoltAgent with OpenAI client routing, LibSQL memory persistence, and Hono server. ChangesTuning Engines Example
Sequence DiagramsequenceDiagram
participant Env as Environment
participant App as VoltAgent Example
participant OpenAI as OpenAI Client<br/>(Tuning Engines)
participant Mem as LibSQL Memory
participant Server as Hono Server
Env->>App: TUNING_ENGINES_API_KEY<br/>(validation)
App->>OpenAI: new OpenAI client<br/>(baseURL=tuning-engines)
App->>Mem: new Memory<br/>(LibSQL adapter)
App->>Server: new honoServer()<br/>with VoltAgent
Server->>App: server listening:3141
App->>OpenAI: generateText()<br/>sample request
OpenAI->>App: text + usage
App->>App: log results
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
examples/with-tuning-engines/package.json (1)
1-39: ⚡ Quick winAdd 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
enginesprevents 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 winHandle 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/catchand 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
📒 Files selected for processing (6)
examples/README.mdexamples/with-tuning-engines/.env.exampleexamples/with-tuning-engines/README.mdexamples/with-tuning-engines/package.jsonexamples/with-tuning-engines/src/index.tsexamples/with-tuning-engines/tsconfig.json
Summary
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
Summary by cubic
Adds a runnable
with-tuning-enginesexample that routes VoltAgent model calls through a governed OpenAI-compatible endpoint. This enables policy checks, traces, and usage/cost reporting without changing agent code.examples/with-tuning-enginesusing@ai-sdk/openaiwith a custombaseURLandTUNING_ENGINES_API_KEY.TUNING_ENGINES_MODELenv var (defaults togpt-4o);.env.exampleincluded.@voltagent/server-honoand local memory with@voltagent/libsql.Written for commit 67305f3. Summary will update on new commits.
Summary by CodeRabbit
New Features
Documentation