Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

refine: chat/agent env + avatar wiring

nirholas50d67e9d7611
diff --git a/.env.example b/.env.example
index ef048797c..0ef8dd540 100644
--- a/.env.example
+++ b/.env.example
@@ -89,6 +89,16 @@ WATSONX_PROJECT_ID=
# WATSONX_MODEL_ID=ibm/granite-3-8b-instruct # default Granite chat model
# WATSONX_API_VERSION=2024-05-31
+# IBM watsonx Orchestrate — adds a "watsonx Orchestrate" brain to /api/chat so a
+# three.ws 3D avatar becomes the embodied front-end of an enterprise Orchestrate
+# agent. The URL is the agent's OpenAI-compatible chat-completions endpoint (the
+# Orchestrate instance "Test URL"; "/chat/completions" is appended if omitted).
+# The key is the bearer token from the agent's Agent Connect config. Both are
+# required for the provider to appear.
+WATSONX_ORCHESTRATE_URL=
+WATSONX_ORCHESTRATE_API_KEY=
+# WATSONX_ORCHESTRATE_AGENT=orchestrate-agent # agent id sent as the model field
+
# Privy wallet auth (client-side — get app ID from https://dashboard.privy.io)
VITE_PRIVY_APP_ID=
# Privy app ID (server-side — for verifying identity tokens in /api/auth/privy/verify)
diff --git a/api/_lib/env.js b/api/_lib/env.js
index 8a8f585d1..c8c46877e 100644
--- a/api/_lib/env.js
+++ b/api/_lib/env.js
@@ -113,6 +113,20 @@ export const env = {
return opt('WATSONX_API_VERSION');
},
+ // IBM watsonx Orchestrate agent (Agent Connect) — adds a "watsonx
+ // Orchestrate" brain to /api/chat so a 3D avatar fronts an enterprise
+ // Orchestrate agent. URL is the agent's chat-completions endpoint (instance
+ // Test URL); the key is the bearer token. Optional — unset = unavailable.
+ get WATSONX_ORCHESTRATE_URL() {
+ return opt('WATSONX_ORCHESTRATE_URL');
+ },
+ get WATSONX_ORCHESTRATE_API_KEY() {
+ return opt('WATSONX_ORCHESTRATE_API_KEY');
+ },
+ get WATSONX_ORCHESTRATE_AGENT() {
+ return opt('WATSONX_ORCHESTRATE_AGENT');
+ },
+
// Etherscan V2 — unified multichain explorer API (one key, all chains).
// Used by api/cron/erc8004-crawl.js to index ERC-8004 Registered events.
get ETHERSCAN_API_KEY() {
diff --git a/api/chat.js b/api/chat.js
index 050ccf782..23f317884 100644
--- a/api/chat.js
+++ b/api/chat.js
@@ -29,6 +29,7 @@ import { sql } from './_lib/db.js';
import { limits, clientIp } from './_lib/rate-limit.js';
import { loadUserProviderKeys } from './_lib/provider-keys.js';
import { watsonxConfig, watsonxAuthHeaders } from './_lib/watsonx.js';
+import { orchestrateConfig } from './_lib/orchestrate.js';
import { z } from 'zod';
// Providers anonymous (unauthenticated) callers may use. Groq and OpenRouter
@@ -79,6 +80,15 @@ const PROVIDERS = {
defaultModel: 'ibm/granite-3-8b-instruct',
style: 'watsonx',
},
+ // IBM watsonx Orchestrate agent (Agent Connect). OpenAI-compatible
+ // chat-completions endpoint, so it streams through the OpenAI reader; the
+ // endpoint URL + agent id are resolved in makeRoute. This makes a three.ws
+ // 3D avatar the embodied front-end of an enterprise Orchestrate agent.
+ orchestrate: {
+ envKey: 'WATSONX_ORCHESTRATE_API_KEY',
+ defaultModel: 'orchestrate-agent',
+ style: 'orchestrate',
+ },
};
const contextSchema = z
@@ -106,7 +116,7 @@ const chatBody = z.object({
context: contextSchema,
system_prompt: z.string().trim().min(1).max(2000).optional(),
agentId: z.string().uuid().optional(),
- provider: z.enum(['anthropic', 'openrouter', 'groq', 'openai', 'watsonx']).optional(),
+ provider: z.enum(['anthropic', 'openrouter', 'groq', 'openai', 'watsonx', 'orchestrate']).optional(),
model: z.string().min(1).max(120).optional(),
history: z
.array(
@@ -517,14 +527,18 @@ function pickProvider(requested, model, userKeys = {}) {
const cfg = PROVIDERS[name];
const apiKey = userKeys[name] || process.env[cfg.envKey];
if (!apiKey) continue;
- // watsonx needs both a key and a project/space scope to serve a model.
+ // watsonx needs both a key and a project/space scope to serve a model;
+ // Orchestrate needs both a key and its endpoint URL.
if (name === 'watsonx' && !watsonxConfig().configured) continue;
- // CHAT_MODEL is an Anthropic-style id; it must not leak into a watsonx
- // request (which expects an `ibm/…` model id). watsonx uses the
- // client-named model or its own Granite default.
+ if (name === 'orchestrate' && !orchestrateConfig().configured) continue;
+ // CHAT_MODEL is an Anthropic-style id; it must not leak into a watsonx or
+ // Orchestrate request (which expect their own model/agent ids). Those
+ // providers use the client-named value or their own default.
const chosenModel =
(requested === name && model) ||
- (name === 'watsonx' ? cfg.defaultModel : process.env.CHAT_MODEL || cfg.defaultModel);
+ (name === 'watsonx' || name === 'orchestrate'
+ ? cfg.defaultModel
+ : process.env.CHAT_MODEL || cfg.defaultModel);
return makeRoute(name, cfg, apiKey, chosenModel);
}
return null;
@@ -574,6 +588,7 @@ function buildFallbackChain(primary, userKeys = {}) {
const apiKey = userKeys[name] || process.env[cfg.envKey];
if (!apiKey) continue;
if (name === 'watsonx' && !watsonxConfig().configured) continue;
+ if (name === 'orchestrate' && !orchestrateConfig().configured) continue;
const key = `${name}:${cfg.defaultModel}`;
if (seen.has(key)) continue;
seen.add(key);
@@ -605,6 +620,28 @@ function makeRoute(name, cfg, apiKey, model) {
}),
};
}
+ if (cfg.style === 'orchestrate') {
+ const wxo = orchestrateConfig();
+ return {
+ name,
+ model: wxo.agent,
+ url: wxo.chatUrl,
+ style: 'orchestrate',
+ headers: {
+ Authorization: `Bearer ${wxo.apiKey}`,
+ 'Content-Type': 'application/json',
+ },
+ // The Orchestrate agent owns its own tools/skills, so the viewer's
+ // scene tools are not forwarded. System prompt is passed as the
+ // leading system message; OpenAI-shaped streaming handles the reply.
+ buildPayload: ({ systemPrompt, history, maxTokens }) => ({
+ model: wxo.agent,
+ messages: [{ role: 'system', content: systemPrompt }, ...history],
+ max_tokens: maxTokens,
+ stream: true,
+ }),
+ };
+ }
if (cfg.style === 'watsonx') {
const wx = watsonxConfig();
const scope = wx.projectId ? { project_id: wx.projectId } : { space_id: wx.spaceId };
diff --git a/src/avatar-page.js b/src/avatar-page.js
index f8cbdb4af..9dcad3937 100644
--- a/src/avatar-page.js
+++ b/src/avatar-page.js
@@ -79,6 +79,7 @@ const MODEL_OPTIONS = [
{ id: 'groq:llama-70b', label: 'Groq Llama 3.3 70B', provider: 'groq', model: 'llama-3.3-70b-versatile' },
{ id: 'openai:gpt-4o-mini', label: 'GPT-4o mini', provider: 'openai', model: 'gpt-4o-mini' },
{ id: 'watsonx:granite', label: 'IBM Granite 3 (watsonx)', provider: 'watsonx', model: 'ibm/granite-3-8b-instruct' },
+ { id: 'orchestrate:agent', label: 'watsonx Orchestrate', provider: 'orchestrate', model: 'orchestrate-agent' },
];
const MODEL_STORAGE_KEY = 'avatar_chat_model_v1';
diff --git a/src/nich-agent.js b/src/nich-agent.js
index 00897baa6..f41406103 100644
--- a/src/nich-agent.js
+++ b/src/nich-agent.js
@@ -838,4 +838,10 @@ const MODEL_OPTIONS = [
provider: 'watsonx',
model: 'ibm/granite-3-8b-instruct',
},
+ {
+ id: 'orchestrate:agent',
+ label: 'watsonx Orchestrate',
+ provider: 'orchestrate',
+ model: 'orchestrate-agent',
+ },
];