Repository navigation
Description
The workflow
I am building a server plugin that needs one small structured model response. The plugin searches project files for a favicon and reads the README when it needs to generate a simple SVG icon.
First, the plugin gathers the relevant text through bb.sdk.projects. Second, it needs to send a short prompt with a JSON output schema through the user's configured BB_INFERENCE service. Third, it validates and stores the result.
BB already uses this pattern for thread titles and commit messages, but a server plugin cannot call the same inference path.
What happens today
The Plugin SDK lets a plugin register an inference service through bb.experimental_aiServices.register(). It does not provide an API that lets a plugin consume the user's configured inference service.
The current workaround is bb.sdk.threads.spawn(). That creates a full agent thread and may provision a worktree, load project instructions, expose tools, and leave thread records. It also requires an available coding agent provider. Those costs are unnecessary for a short prompt that only needs structured JSON.
Core already has the needed path. Thread title generation calls inferenceCompleteWithFallback() with a prompt and schema:
bb/apps/server/src/services/threads/title-generation.ts
Lines 145 to 161 in 327a210
| const prompt = renderTemplate("generateThreadMetadata", { | |
| cleanedPrompt: fallback, | |
| }); | |
| const maxAttempts = Math.max(1, args.timeoutMaxAttempts ?? 1); | |
| try { | |
| const inference = await inferenceCompleteWithFallback(deps, { | |
| label: "Thread metadata inference", | |
| logContext: { threadId: args.threadId }, | |
| maxAttempts, | |
| prompt, | |
| retryDelayMs: INFERENCE_POLICY.threadMetadata.retryDelayMs, | |
| schema: threadMetadataSchema, | |
| timeoutMs: args.timeoutMs ?? INFERENCE_POLICY.threadMetadata.timeoutMs, | |
| }); | |
| const metadata = normalizeGeneratedThreadMetadata(inference); | |
| return complete(metadata, metadata ? undefined : "inference-unavailable"); |
The inference service resolves BB_INFERENCE, calls the selected service, and validates structured output:
bb/apps/server/src/services/ai/inference.ts
Lines 286 to 358 in 327a210
| export async function inferenceComplete<T extends TSchema>( | |
| deps: LoggedWorkSessionDeps, | |
| args: InferenceCompleteArgs<T>, | |
| ): Promise<Static<T> | null> { | |
| const configuredModel = args.model ?? deps.config.inferenceModel; | |
| const modelInfo = parseProviderModelConfig({ | |
| name: | |
| args.model === undefined ? "BB_INFERENCE" : "inference model override", | |
| value: configuredModel, | |
| }); | |
| if ( | |
| !isServerDirectAiServiceId(modelInfo.provider) && | |
| deps.aiServices.get(modelInfo.provider) !== null | |
| ) { | |
| return completeWithAiService(deps, modelInfo, args); | |
| } | |
| const model = getInferenceModel(deps, modelInfo); | |
| if (!model) { | |
| return null; | |
| } | |
| const tools: Tool<T>[] = [ | |
| { | |
| name: RESULT_TOOL_NAME, | |
| description: "Return the result as structured JSON.", | |
| parameters: args.schema, | |
| }, | |
| ]; | |
| const timeoutMs = args.timeoutMs; | |
| const abortController = timeoutMs ? new AbortController() : null; | |
| const completionPromise = getInferenceModels().complete( | |
| model, | |
| { | |
| messages: [ | |
| { | |
| role: "user", | |
| content: args.prompt, | |
| timestamp: Date.now(), | |
| }, | |
| ], | |
| tools, | |
| }, | |
| abortController ? { signal: abortController.signal } : undefined, | |
| ); | |
| let timer: ReturnType<typeof setTimeout> | null = null; | |
| const response = timeoutMs | |
| ? await Promise.race([ | |
| completionPromise, | |
| new Promise<never>((_, reject) => { | |
| timer = setTimeout(() => { | |
| reject(new InferenceTimeoutError({ timeoutMs })); | |
| abortController?.abort(); | |
| }, timeoutMs); | |
| timer.unref(); | |
| }), | |
| ]).finally(() => { | |
| if (timer) { | |
| clearTimeout(timer); | |
| } | |
| }) | |
| : await completionPromise; | |
| const toolCall = response.content.find( | |
| (item) => item.type === "toolCall" && item.name === RESULT_TOOL_NAME, | |
| ); | |
| if (!toolCall || toolCall.type !== "toolCall") { | |
| return null; | |
| } | |
| return validateToolCall(tools, toolCall) as Static<T>; |
The public Plugin SDK contract only exposes service registration:
bb/packages/plugin-sdk/src/backend-contract.ts
Lines 1448 to 1485 in 327a210
| // --------------------------------------------------------------------------- | |
| // AI services. | |
| // --------------------------------------------------------------------------- | |
| /** | |
| * What a plugin's AI service does. `inference` answers bb's server-side helper | |
| * completions (thread titles, commit messages: a prompt and a JSON Schema in, | |
| * a structured value out); `voice` transcribes recorded speech. | |
| */ | |
| export type PluginAiServiceKind = "inference" | "voice"; | |
| /** | |
| * An AI service a plugin offers from its `bb.host` entry, which implements | |
| * `experimental_aiServicesHostContract` (`@get-bb/plugin-sdk/ai-services`). | |
| * The user selects it with `BB_INFERENCE` / `BB_TRANSCRIPTION` set to | |
| * `<id>/<model>`; core calls the plugin's host entry on the primary host with | |
| * the `id` on every request, so one entry can serve several services. | |
| */ | |
| export interface PluginAiServiceDeclaration { | |
| /** The `<serviceId>` segment of the user's setting; stable, lowercase. */ | |
| readonly id: string; | |
| /** Shown beside the id wherever the setting's options are listed. */ | |
| readonly displayName: string; | |
| /** Which kinds this service answers; a kind it lacks is not offered. */ | |
| readonly kinds: readonly PluginAiServiceKind[]; | |
| } | |
| export interface PluginAiServices { | |
| /** | |
| * Register an AI service. Call during the factory; the registration lands | |
| * when the plugin load commits and is removed on reload or disable. The | |
| * plugin must declare a `bb.host` entry; registering without one fails the | |
| * load. A declared entry that fails to build fails the load on the build | |
| * error after the factory, with any provider the factory declared listed | |
| * as unavailable. Throws on an id another live plugin already serves. | |
| */ | |
| register(declaration: PluginAiServiceDeclaration): { dispose(): void }; | |
| } |
What you would expect
Expose a server plugin API for structured helper inference. The exact name is open, but the call could look like this:
const result = await bb.experimental_inference.complete({
prompt,
schema,
timeoutMs: 15_000,
signal,
});The API should use the effective BB_INFERENCE and BB_INFERENCE_FALLBACK settings. It should route through the registered inference service without exposing credentials to the plugin.
The API should also validate structured output, honor cancellation and timeouts, enforce input and output limits, and include the calling plugin ID in logs or usage records. A capability declaration or user permission would be reasonable if inference use needs explicit consent.
Context and alternatives
The current prototype uses a hidden agent thread to generate a project icon from a README. The workflow works, but it is slower and creates more resources than BB's existing helper inference path.
A plugin could call a model vendor directly, but that would require separate credentials and would ignore the user's BB inference settings. A plugin could also spawn the codex agent with the same model, but that still creates a full agent session.
I tested the SDK surface on BB 0.41.0 at commit 327a210506d24a6b487ac4ba1ffc711e89922b76, on macOS 27.0 with Node.js 24.15.0. The investigation used BB thread thr_esk5wmdpyi. I searched open and closed issues for plugin inference, BB_INFERENCE plugin, and related terms, and I did not find the same request.
- I searched open and closed issues for the same request.
- If an agent wrote this, the body ends with
> AGENT GENERATED.
AGENT GENERATED
Activity
bb-slop-cop commentedon Sep 4, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotClassified #3058:
pluginsNo reproduction report or pull request was created because the final Type is not Bug.
smsunarto commentedon Sep 10, 2026
I'd like this exposed through the shared BB SDK, so plugins and other SDK callers can request a completion without creating a thread.
A proposed initial surface, following the SDK's experimental naming convention:
Outside a plugin, the same method would be available on the SDK client. The eventual stable name could be
sdk.inference.complete().The implementation should wrap the existing
inferenceComplete()/inferenceCompleteWithFallback()service inapps/server/src/services/ai/inference.ts, keeping provider routing, credentials, structured-output validation, and retry/fallback policy in one place.Expected behavior:
BB_INFERENCEandBB_INFERENCE_FALLBACKdefaults, with an optional per-call model override.bb.sdk, with a documented example and tests for successful completion and failures.This is the consumer API requested here. #3323 complements it by letting additional coding providers serve helper inference. A provider should not need to support full agent-thread execution just to answer this call.
SawyerHood commentedon Oct 19, 2026
Duplicate helper-inference API request
Consolidating #5414 into this canonical tracker at the maintainer's request following the open-issue duplicate sweep.
Both requests ask for server plugins to consume core-selected BB_INFERENCE / BB_INFERENCE_FALLBACK for short structured completions, without spawning a thread or configuring separate provider credentials. This issue is the canonical implementation tracker.
Preserve the source's plugin-use context alongside the existing schema validation, timeout/cancellation, model-selection and shared API requirements. The original report and discussion remain available in #5414.