OpenProgram Docs

Python SDK

Your script OpenProgram() Worker the App's, port 18100 Conversation in every sidebar sends: messages, answers, stops streams: text, tool calls, approvals, result Same models, permissions and memory as the App; continue the conversation there.
  1. Your scriptOpenProgram() sends messages, answers and stops
  2. Workerthe App's, port 18100; streams text, tool calls, approvals and the result
  3. Conversationstored; shows in every sidebar

The SDK ships with OpenProgram; nothing else to install. It finds this profile's Worker and starts one if none runs.

from openprogram.interfaces.sdk import OpenProgram

with OpenProgram() as op:
    result = op.session().run("Summarise README.md")
    print(result.text, result.usage)

With no approval handler, run() is unattended: a step that would ask for approval is refused at once, as with openprogram --print.

Stream a reply

import asyncio
from openprogram.interfaces.sdk import AsyncOpenProgram, TextDelta, ToolCall

async def main():
    async with AsyncOpenProgram() as op:
        turn = await op.session().send("List the open TODOs")
        async for event in turn:
            if isinstance(event, TextDelta):
                print(event.text, end="", flush=True)
            elif isinstance(event, ToolCall):
                print(f"\n[{event.name}] {event.arguments}")
        result = await turn.result()

asyncio.run(main())
EventWhen
TurnStartedThe Worker took the message; names the execution
StatusChangedrunning, paused (waiting for an answer), cancelling, …
TextDelta, ThinkingDeltaA piece of the reply, or of visible reasoning
ToolCall, ToolResultA tool call and its output, matched by id
ApprovalRequest, QuestionThe turn waits for you; see below
UsageUpdateThe turn's tokens, as it ends; also result.usage

The blocking client is the same: for event in session.send(...), then turn.result().

Answer approvals

def decide(request):
    print(request.tool, request.arguments, request.risk_level)
    return input("Allow? [y/N] ") == "y"      # or a scope: "session", "always"

with OpenProgram() as op:
    op.session().run("Deploy the docs", permission_mode="ask", on_approval=decide)
MethodEffect
request.approve(scope="once")The call runs; request.scopes lists the wider grants the Worker offers
request.deny(reason)The call is refused; the reason reaches the model
question.answer(value), question.decline()A question from the Agent; on_question= in run()

An approval answered here is answered in the App too, and the other way round. The first answer counts; a later one raises CommandRejected.

Stop a turn

turn = session.send("Rewrite every test")
...
turn.cancel()
assert turn.result().status == "cancelled"   # result.text: what was written before the stop

Conversations, Agents, models

CallReturns
op.session()A new conversation, created by its first message; agent="reviewer" binds a saved Agent, project= a project
op.session(id)An existing one, to continue; .messages() reads it
op.sessions()Every conversation, newest first
op.agents(), op.models()Saved Agents; models enabled in Settings, as provider/model
send(text, model=, effort=, permission_mode=)Overrides for one turn; session.set_model() keeps a model for the conversation
send(text, response_format=)A JSON schema; the value is result.structured_output

Run a Program

with OpenProgram() as op:
    run = op.run_program("research", {"topic": "agent sandboxes"})
    print(run.result().output)

It runs as the Programs page runs it: a code node in a conversation, in its own process on the Worker.

Errors

ErrorWhen
WorkerNotFoundNo Worker, and start=False or it did not start
AuthenticationErrorThe token was refused: a token from an earlier Worker, or a wrong one
TurnRefusedThe message was not taken, for example the conversation is busy; code says why
TurnFailedThe turn ran and failed, usually the model; retryable and kind
ProgramNotFound, ProgramFailedNo such Program entry; the run ended in error
ConnectionLostThe Worker went away; the turn goes on there, read it with messages()

All of them are OpenProgramError with a code.

Another computer's Worker

OpenProgram(url="https://studio.example.net:18100", token=token)

The token is one that Worker accepts: its owner token, or the credential of a paired device. On this computer the owner token is read for you. Whoever holds a token acts as you.

Voice input

Last updated · 2026-11-30