Non-TypeScript backends
Non-TypeScript backends can use the same Document Authoring AI tool contract as TypeScript apps. Export the tool and prompt definitions as JSON, load that file in your backend, and keep document execution in the browser session that owns the live editor.
Export the definitions
Run the export command from your project:
npx @nutrient-sdk/document-authoring-ai export-tools > document-authoring-ai-tools.jsonThe export contains the prompt guide, each tool name and description, each inputSchema, each outputSchema, and tool metadata such as metadata.capability.
Use promptGuide as your model’s system prompt. Use each inputSchema to bind tools in your agent framework. Use each outputSchema if your backend validates results from the browser before sending them back to the model.
Backend loop
The backend owns model orchestration. It loads the JSON export, binds tools to the model, receives tool calls, forwards those calls to the browser/editor session, and returns browser execution results as tool results.
This Python LangChain-style loop shows the shape. The same boundary applies if you use LangGraph, Go, Ruby, or a custom agent runtime. See LangChain’s message docs(opens in a new tab) for the HumanMessage, SystemMessage, and ToolMessage classes used below.
import jsonfrom langchain.messages import HumanMessage, SystemMessage, ToolMessage
with open("document-authoring-ai-tools.json") as file: document_authoring_ai = json.load(file)
messages = [ SystemMessage(document_authoring_ai["promptGuide"]), HumanMessage("Find the renewal paragraph and make it clearer."),]
# Convert document_authoring_ai["tools"] into the tool format expected by# your model provider or agent framework, then bind those tools to the model.model_with_tools = model.bind_tools(tools)
for _ in range(10): ai_message = model_with_tools.invoke(messages) messages.append(ai_message)
if not ai_message.tool_calls: break
for tool_call in ai_message.tool_calls: result = send_tool_call_to_browser_editor({ "id": tool_call["id"], "name": tool_call["name"], "args": tool_call["args"], })
messages.append( ToolMessage( content=json.dumps(result), tool_call_id=tool_call["id"], ) )The backend doesn’t execute Document Authoring edits itself; it gives the model the tool definitions, receives tool calls, and sends those calls to the browser session that owns the live DocAuthEditor. For the full tool-call flow, see agentic tools.
Browser-side execution
The browser owns document access and validation. Create the toolkit from the live editor, apply your Edit/Review/View policy, and execute tool calls with toolkit.executeTool:
import { isAiWriteToolName,} from "@nutrient-sdk/document-authoring-ai";import { getAiToolkit } from "@nutrient-sdk/document-authoring-ai/editor";
const toolkit = getAiToolkit(editor);
async function runDocumentToolCall(rawCall) { const editorMode = editor.getEditorMode(); const isWriteTool = isAiWriteToolName(rawCall.name);
if (isWriteTool && editorMode === "view") { throw new Error("Switch to Edit or Review mode before editing."); }
return toolkit.executeTool(rawCall, { writeMode: isWriteTool && editorMode === "review" ? "track_changes" : "apply", });}Send the executed result back to the backend and attach it to the model’s tool-call message. Document access, validation, editor mode policy, and document mutation stay with the editor-bound runtime. For Edit, Review, and View mode handling, see review and approval.
The JSON export is metadata only. It contains tool schemas and prompts that your backend uses to bind tools to the model. Document changes still happen in the browser session that owns the live editor; there’s no MCP server or REST execution endpoint, and the backend never edits the document directly.