OpenProgram Docs

Agent calls and methods

from openprogram import Agent

class ReviewAgent(Agent):
    tools = []
    instructions = "Preserve facts. Return concise text."

    def classify(self, review: str) -> str:
        """Classify review sentiment."""
        return self(f"Classify as positive, negative, or neutral:\n{review}")

    def summarize(self, review: str) -> str:
        """Summarize a review with its sentiment."""
        sentiment = self.classify(review)
        return self(f"Summarize this {sentiment} review in one sentence:\n{review}")

reviewer = ReviewAgent(model="configured-model")
summary = reviewer.summarize("The service was fast.")

self(...) makes a model request through the existing Runtime. The docstring describes the function; the prompt carries instruction and data.

ThingBehaviour
Agent instanceStores configuration; keeps no conversation between independent top-level calls
Nested call, same AgentUses the active execution; no DAG node of its own
Another AgentIts own DAG; the parent stores the result and a child_session_id reference
DAG contentsUser messages, model requests and directly dispatched tools
Permission, cancellation, file checkpointsStay with the originating execution
ContextSelects permitted history and resolves configured content per request

Direct and asynchronous calls

from openprogram import agent, agent_async

answer = agent("Summarize this text", tools=[])
# In an async function:
# answer = await agent_async("Summarize this text", tools=[])
# answer = await reviewer.arun("Summarize this text")

tools=[]: no model tools. tools=None: the runtime resolves available tools under current authorization.

Method metadata and tools

class TextAgent(Agent):
    tools = []
    method_options = {
        "summarize": {
            "tool": True,
            "name": "summarize_notes",
            "input": {"text": {"description": "Text to summarize"}},
            "expose": "io",
        },
    }

    def summarize(self, text: str) -> str:
        """Summarize text."""
        return self(f"Summarize:\n{text}")

method_options declares input form metadata, visibility, durable steps, authorization and tool registration; fields are in Function metadata. Only tool=True makes a tool; recording does not. Name and signature supply the schema. Visibility controls history rendering, not permission.

Ordinary Program functions

The managed loader captures source-defined functions in authorized Program packages, not arbitrary host files or dependencies. List public entries in PROGRAM_ENTRIES; private helpers keep runtime access without DAG nodes or tool status. Compose deterministically in Python, or supply registered tools for model-selected calls.

Persistent conversations

from openprogram import Agent, Context, TurnRequest
from openprogram.runtime.context.session_db import default_db

context = Context.for_session(default_db(), "example-conversation",
                              blocks={"reference": "User-supplied reference material"})
worker = Agent(context=context)
result = worker.run_turn(
    TurnRequest(session_id="example-conversation", user_text="Summarize the reference",
                agent_id="main", source="python"),
    on_event=lambda event: print(event["type"]),
)
print(result.final_text)

ChatAgent is the conversation subtype behind the App, Web, TUI and channel adapters. It and Agent.run_turn() share one turn runtime for history, permissions, tools, streaming, compression and final persistence.

ItemRule
Next turnReuse the session ID
Context.for_sessionSelects the store; creates no provider. Optional head_id selects the predecessor branch.
Context(history=None)Excludes past graph content, keeps the current prompt
Named content and providersRendered as user content; cannot alter system instructions or tool permissions
arun_turn(), aresume_turn()Async versions. Callbacks run on the execution thread, so hand off thread-safely to asyncio. Cancelling the awaiting task signals the turn and waits for its cooperative cleanup.
cancel_eventA threading.Event, for synchronous callers
resume_turn(continuation)Consumes an existing continuation and its frozen request; adds no user message and reapplies no changed instance settings
Pause, steering, continuation admissionThe production driver's execution-control service; the Agent API adds no second job registry
Tool deadlineDoes not cancel the parent conversation

API reference · Function metadata

Last updated · 2026-11-25