From a42f39fe1f923d06c96564ee2b53e1735e543c85 Mon Sep 17 00:00:00 2001 From: VC Date: Fri, 22 May 2026 16:41:30 -0400 Subject: [PATCH] Add Tuning Engines Dapr AI integration docs Signed-off-by: VC --- .../tuning-engines/_index.md | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 daprdocs/content/en/developing-ai/agent-integrations/tuning-engines/_index.md diff --git a/daprdocs/content/en/developing-ai/agent-integrations/tuning-engines/_index.md b/daprdocs/content/en/developing-ai/agent-integrations/tuning-engines/_index.md new file mode 100644 index 00000000000..8d7440cbd78 --- /dev/null +++ b/daprdocs/content/en/developing-ai/agent-integrations/tuning-engines/_index.md @@ -0,0 +1,78 @@ +--- +type: docs +title: "Tuning Engines" +linkTitle: "Tuning Engines" +weight: 45 +description: "Use Dapr Workflow with Tuning Engines as a governed AI endpoint" +--- + +### What is the Dapr Tuning Engines integration pattern? + +Dapr Workflow owns durable execution, retries, service invocation, pub/sub, and +sidecar-based application integration. Tuning Engines can sit behind workflow +activities as an OpenAI-compatible AI endpoint that provides model routing, +policy checks, approvals, usage attribution, and runtime traces. + +Use this pattern when a Dapr application needs governed model calls without +embedding provider-specific credentials or policy logic in every workflow. + +### Configuration + +Set a Tuning Engines inference key and choose the model or routing alias your +tenant has enabled: + +```bash +export TE_INFERENCE_KEY=sk-te-your-inference-key +export TE_MODEL=auto +``` + +### Activity example + +```ts +import { WorkflowRuntime } from "@dapr/dapr"; + +type Input = { + prompt: string; + run_id: string; +}; + +function newId(prefix: string): string { + return `${prefix}_${crypto.randomUUID().replaceAll("-", "")}`; +} + +async function governedModelActivity(_ctx: unknown, input: Input) { + const request_id = newId("req"); + const response = await fetch("https://api.tuningengines.com/v1/chat/completions", { + method: "POST", + headers: { + Authorization: `Bearer ${process.env.TE_INFERENCE_KEY}`, + "Content-Type": "application/json", + "X-TE-Run-ID": input.run_id, + "X-TE-Request-ID": request_id, + }, + body: JSON.stringify({ + model: process.env.TE_MODEL || "auto", + messages: [{ role: "user", content: input.prompt }], + metadata: { + run_id: input.run_id, + request_id, + runtime: "dapr", + event_type: "model.call", + }, + }), + }); + + if (!response.ok) { + throw new Error(`Tuning Engines request failed: ${response.status} ${await response.text()}`); + } + + return response.json(); +} + +const runtime = new WorkflowRuntime(); +runtime.registerActivityWithName("governedModelActivity", governedModelActivity); +``` + +The `run_id` and `request_id` metadata let Tuning Engines correlate the model +call with policy decisions, approval requests, usage/cost logs, and trace +events. Dapr continues to own the workflow state and the activity lifecycle.