Extensions API, require programmatic Agent invocation with prompt text support in Build mode

I need a supported way to start Agent from a JavaScript Replit Extension, pass a prompt string, and execute it in Build mode, with an explicit success or failure result.

Requirement: agent.invoke(prompt, opts)

Problem
Extensions can orchestrate workflows in the workspace, they can run commands, edit files, and notify users, however there is no supported way to invoke Replit Agent programmatically with a prompt and respect Build semantics.

Behavior

  • mode: "build" returns an edit request; extension may call applyEdit, or set autoApply: true.

  • Promise shape mirrors existing SDK patterns that return structured { ok | error }.

  • Respect user tier and credit limits; return an error if Build is unavailable.

Security and permissions

  • New manifest scope, for example "agent:invoke".

  • All actions occur in the current workspace context; no implicit elevation.

Why this matters
Enables safe automation and integrations that already exist at the workflow level, for example, synthesize a targeted prompt, invoke Agent to execute and optionally auto-apply. Keeps AI usage inside Replit, preserves workspace context, aligns with Plan and Build semantics.

Proposed API

import { agent } from "@replit/extensions";

type Mode = "plan" | "build";

interface InvokeOptions {
  mode: Mode;                 // plan = no edits, build = produce edit request
  autoApply?: boolean;        // build only, apply the generated edit request
  timeoutMs?: number;
  onUpdate?: (e: AgentEvent) => void; // optional progress events
  context?: { paths?: string[] };     // optional file scope hints
}

type InvokeResult =
  | { ok: true; mode: "plan"; replyText: string }
  | { ok: true; mode: "build"; runId: string; editId?: string; applied?: boolean }
  | { ok: false; error: string; code?: string };

declare function invoke(prompt: string, opts: InvokeOptions): Promise<InvokeResult>;
declare function applyEdit(editId: string): Promise<{ ok: boolean; error?: string }>;
 

Minimal usage

const r = await agent.invoke(
  "Fix SQL injection in routes/login, parameterize query, update tests",
  { mode: "build", autoApply: true, timeoutMs: 180000 }
);
if (!r.ok) console.error(r.error);

VS Code extensions support a similar flow: select a chat model with vscode.lm.selectChatModels, then invoke it using model.sendRequest(messages, options, token).

4 Likes

A lovely ask which I +1. But the day headless API access to platforms like Replit become available, all hell will break loose. Overnight we will have 10,000 different Replits. Bring it on I say :blush:

1 Like

thanks for the +1 @Gipity-Steve :+1: . VS Code Extensions have similar functionality, no reason why we should not have it in Replit as well :victory_hand: . I have updated this with details in the description has well :innocent:

+1 This would be a great API to have.