Skip to content

The Open Standard for Generative UI

Use explicit tool selection in compare (#830)

Zahle Khan078e6db11db0
diff --git a/docs/app/api/chat/route.ts b/docs/app/api/chat/route.ts
index 4ea8edbbb..e49212f6e 100644
--- a/docs/app/api/chat/route.ts
+++ b/docs/app/api/chat/route.ts
@@ -11,15 +11,19 @@ const openUiSystemPrompt = readFileSync(
const markdownSystemPrompt = `You are a helpful assistant. Respond using clear, well-structured GitHub-Flavored Markdown.
-Use headings, lists, tables, links, block quotes, and fenced code blocks when they make the response easier to understand. Use the available tools when they are relevant, and incorporate their results into the answer.
+Use headings, lists, tables, links, block quotes, and fenced code blocks when they make the response easier to understand.
Return only Markdown content. Do not emit OpenUI Lang, component syntax, JSON UI descriptions, or instructions for a renderer.`;
type ResponseMode = "markdown" | "openui";
+const TOOL_NAMES = ["get_weather", "get_stock_price", "search_web"] as const;
+type ToolName = (typeof TOOL_NAMES)[number];
+const TOOL_NAME_SET = new Set<string>(TOOL_NAMES);
interface ChatRequestBody {
messages: unknown[];
responseMode?: ResponseMode;
+ toolNames?: ToolName[];
}
function invalidRequest(message: string) {
@@ -31,7 +35,7 @@ function parseRequestBody(body: unknown): ChatRequestBody | Response {
return invalidRequest("Request body must be a JSON object");
}
- const { messages, responseMode } = body as Record<string, unknown>;
+ const { messages, responseMode, toolNames } = body as Record<string, unknown>;
if (!Array.isArray(messages)) {
return invalidRequest("messages must be an array");
@@ -41,9 +45,18 @@ function parseRequestBody(body: unknown): ChatRequestBody | Response {
return invalidRequest('responseMode must be either "markdown" or "openui"');
}
+ if (
+ toolNames !== undefined &&
+ (!Array.isArray(toolNames) ||
+ !toolNames.every((toolName) => typeof toolName === "string" && TOOL_NAME_SET.has(toolName)))
+ ) {
+ return invalidRequest(`toolNames must contain only: ${TOOL_NAMES.join(", ")}`);
+ }
+
return {
messages,
responseMode: responseMode as ResponseMode | undefined,
+ toolNames: toolNames as ToolName[] | undefined,
};
}
@@ -262,7 +275,11 @@ export async function POST(req: NextRequest) {
return parsedBody;
}
- const { messages, responseMode = "openui" } = parsedBody;
+ const { messages, responseMode = "openui", toolNames } = parsedBody;
+ const selectedTools =
+ toolNames === undefined
+ ? tools
+ : tools.filter((tool) => toolNames.includes(tool.function.name as ToolName));
const apiKey = process.env.OPENROUTER_API_KEY;
if (!apiKey) {
@@ -328,15 +345,24 @@ export async function POST(req: NextRequest) {
let callIdx = 0;
let resultIdx = 0;
- const runner = (client.chat.completions as any).runTools(
- {
- model: MODEL,
- messages: chatMessages,
- tools,
- stream: true,
- },
- { signal: req.signal },
- );
+ const runner: any =
+ selectedTools.length === 0
+ ? client.chat.completions.stream(
+ {
+ model: MODEL,
+ messages: chatMessages,
+ },
+ { signal: req.signal },
+ )
+ : (client.chat.completions as any).runTools(
+ {
+ model: MODEL,
+ messages: chatMessages,
+ tools: selectedTools,
+ stream: true,
+ },
+ { signal: req.signal },
+ );
activeRunner = runner;
const handleAbort = () => {
@@ -351,27 +377,29 @@ export async function POST(req: NextRequest) {
close();
};
- runner.on("functionToolCall", (fc: any) => {
- const id = `tc-${callIdx}`;
- pendingCalls.push({ id, name: fc.name, arguments: fc.arguments });
- enqueue(sseToolCallStart(encoder, { id, function: { name: fc.name } }, callIdx));
- callIdx++;
- });
-
- runner.on("functionToolCallResult", (result: string) => {
- const tc = pendingCalls[resultIdx];
- if (tc) {
- enqueue(
- sseToolCallArgs(
- encoder,
- { id: tc.id, function: { arguments: tc.arguments } },
- result,
- resultIdx,
- ),
- );
- }
- resultIdx++;
- });
+ if (selectedTools.length > 0) {
+ runner.on("functionToolCall", (fc: any) => {
+ const id = `tc-${callIdx}`;
+ pendingCalls.push({ id, name: fc.name, arguments: fc.arguments });
+ enqueue(sseToolCallStart(encoder, { id, function: { name: fc.name } }, callIdx));
+ callIdx++;
+ });
+
+ runner.on("functionToolCallResult", (result: string) => {
+ const tc = pendingCalls[resultIdx];
+ if (tc) {
+ enqueue(
+ sseToolCallArgs(
+ encoder,
+ { id: tc.id, function: { arguments: tc.arguments } },
+ result,
+ resultIdx,
+ ),
+ );
+ }
+ resultIdx++;
+ });
+ }
runner.on("chunk", (chunk: any) => {
// Keep credit handling to non-2xx responses. Provider-specific mid-stream
diff --git a/docs/app/chat/_components/agent-surfaces/oss-agent-surface.tsx b/docs/app/chat/_components/agent-surfaces/oss-agent-surface.tsx
index 79739b5cd..f10c34e41 100644
--- a/docs/app/chat/_components/agent-surfaces/oss-agent-surface.tsx
+++ b/docs/app/chat/_components/agent-surfaces/oss-agent-surface.tsx
@@ -47,6 +47,7 @@ export function OssAgentSurface({ themeMode, onCreditsExhausted }: OssAgentSurfa
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
messages: openAIMessageFormat.toApi(messages),
+ toolNames: [],
}),
signal,
});
diff --git a/docs/app/compare/_components/agent-surfaces/use-comparison-chat-llm.ts b/docs/app/compare/_components/agent-surfaces/use-comparison-chat-llm.ts
index ff9ed314c..0272e39bb 100644
--- a/docs/app/compare/_components/agent-surfaces/use-comparison-chat-llm.ts
+++ b/docs/app/compare/_components/agent-surfaces/use-comparison-chat-llm.ts
@@ -23,6 +23,7 @@ export function useComparisonChatLLM(
body: JSON.stringify({
messages: openAIMessageFormat.toApi(messages),
responseMode,
+ toolNames: [],
}),
signal,
});
diff --git a/docs/app/compare/_components/chat-page-header.tsx b/docs/app/compare/_components/chat-page-header.tsx
index fd5ab5926..46b4604e5 100644
--- a/docs/app/compare/_components/chat-page-header.tsx
+++ b/docs/app/compare/_components/chat-page-header.tsx
@@ -60,7 +60,6 @@ interface ComparisonPairMetadata {
const ALL_MODES_SUPPORTED: FeatureSupport = { markdown: true, oss: true, cloud: true };
const OSS_AND_CLOUD_SUPPORTED: FeatureSupport = { markdown: false, oss: true, cloud: true };
const CLOUD_ONLY_SUPPORTED: FeatureSupport = { markdown: false, oss: false, cloud: true };
-const MARKDOWN_AND_OSS_SUPPORTED: FeatureSupport = { markdown: true, oss: true, cloud: false };
function comparisonFeature(label: string, support: FeatureSupport): ComparisonFeature {
return { label, support };
@@ -101,7 +100,6 @@ const PAIR_METADATA: Record<ComparisonPair, ComparisonPairMetadata> = {
{ label: "Built-in tools", support: CLOUD_ONLY_SUPPORTED },
{ label: "Responsive output by default", support: CLOUD_ONLY_SUPPORTED },
{ label: "Automatic UI error correction", support: CLOUD_ONLY_SUPPORTED },
- { label: "Self-hostable and open source", support: MARKDOWN_AND_OSS_SUPPORTED },
],
},
"markdown-cloud": {
diff --git a/docs/app/compare/_components/comparison-controls.tsx b/docs/app/compare/_components/comparison-controls.tsx
index 503286369..6edd68063 100644
--- a/docs/app/compare/_components/comparison-controls.tsx
+++ b/docs/app/compare/_components/comparison-controls.tsx
@@ -4,7 +4,6 @@ import {
ArrowRight,
ArrowUp,
FileText,
- LayoutDashboard,
ListChecks,
Moon,
Plane,
@@ -27,6 +26,7 @@ const COMPARISON_SUGGESTIONS = [
"Show me a chart of the top 5 US stocks outperforming the market in 2025 with key trendlines.",
icon: TrendingUp,
color: "#067647",
+ hiddenForPair: "oss-cloud",
},
{
label: "Hidden travel gems to explore",
@@ -35,13 +35,6 @@ const COMPARISON_SUGGESTIONS = [
icon: Plane,
color: "#dd517b",
},
- {
- label: "Create an executive dashboard",
- prompt:
- "Visualize following SaaS metrics: MRR $1.28M, growth 8.4%, NRR 112%, churn 2.1%, CAC $740, and pipeline $3.6M. Highlight trends, risks, and the three actions leadership should take.",
- icon: LayoutDashboard,
- color: "#b54708",
- },
{
label: "Create an editable launch plan",
prompt:
@@ -148,7 +141,9 @@ export function ComparisonControls({
<div className={styles.suggestionScroller} aria-label="Try a comparison prompt">
<div className={styles.suggestionRow}>
{COMPARISON_SUGGESTIONS.filter(
- (suggestion) => !("pairOnly" in suggestion) || suggestion.pairOnly === comparisonPair,
+ (suggestion) =>
+ (!("pairOnly" in suggestion) || suggestion.pairOnly === comparisonPair) &&
+ (!("hiddenForPair" in suggestion) || suggestion.hiddenForPair !== comparisonPair),
).map((suggestion) => {
const SuggestionIcon = suggestion.icon;
const needsCloud = "cloudOnly" in suggestion && suggestion.cloudOnly;
diff --git a/docs/lib/openui-cloud/models.ts b/docs/lib/openui-cloud/models.ts
index 0be038ea7..9d61e44a4 100644
--- a/docs/lib/openui-cloud/models.ts
+++ b/docs/lib/openui-cloud/models.ts
@@ -1,4 +1,4 @@
-export const DEFAULT_MODEL = "anthropic/claude-sonnet-4.6";
+export const DEFAULT_MODEL = "openai/gpt-5.4";
export interface ModelOption {
id: string;