OpenProgram Docs

Agent call flow

User message dispatcher session, user node, model, tools Agent method body runtime.exec llm node, context, AgentSession agent_loop model, tools, repeat a tool body calls runtime.exec again: nesting
  1. User message → dispatcherDirectly to the loop
  2. Agent method body → runtime.execThrough AgentSession and LoopDriver
  3. agent_loopA tool body can call runtime.exec again: nesting

Entry points

A · dispatcherB · runtime.execagent_loop
JobTurn lifecycleOne LLM callCall model, run tools, feed back, until plain text
OrderCreate or load session · write user node · attach Runtime · resolve model (profile + override) · parse tools (channel, plan, approval) · loop · persist, title, auto-compactOpen llm node (timeout and retry outside) · select nodes with render_context · render messages and current turn · resolve toolset · assemble system and skills · create AgentSession · loop · close llm nodeBefore each round: convert_to_llm, memory prefetch, deferred-tool re-split
Recordinginsert_placeholder, then persist_assistant_message: one ROLE_LLM node_open_model_call_node, _close_model_call_node: one ROLE_LLM nodeTool code nodes' caller = the current llm node
Coderuntime/conversation/turn_runtime/runtime/agent/runtime/runtime/agent/loop/

One exec is one llm node: running on entry, reply and completed on exit. Tool rounds inside it are not extra nodes, so every two nested code nodes have an llm node between them. exec sits below the loop, which is what lets a function body call a model; that is also the source of self-recursion.

_call_id switches to the llm node once the prompt is built (test_tool_loop_subcall_attributes_to_llm_node). Sync and async paths match. agent_loop knows nothing about the DAG. tool.before fires only in _execute_tool_calls, so no path loses or doubles events.

Why two entries

Their surroundings do not overlap: session management, WebSocket broadcast, title and compaction against the llm node and AgentSession retry. Sending the dispatcher through exec fails for four reasons:

ConflictDetail
ModelThe dispatcher's _resolve_model(agent_profile, req.model_override) differs from the attached runtime's auto-detected api_model
ContextThe context engine's prep.agent_messages clashes with exec rendering from the DAG
Streamingexec's flat on_stream dict against the dispatcher's WebUI envelope
Duplicate nodeThe dispatcher's reply already is the record; another llm node gives [user, assistant, assistant] (test_dispatcher_integration.py::test_real_loop_text_only)

The loop driver LoopDriver sits below exec (exec → AgentSession → LoopDriver → agent_loop) and is built in one place; it is not a parallel path.

Callable path

Runtime(call=fn) wraps fn into a stand-in provider model (callable_model.py) and goes through _call_via_providers like any model: no legacy branch. The adapter converts messages back to content, calls fn with response_format, returns one assistant message, and has no tools or tool loop. stream_fn threads from exec by context variable to AgentSession (test_exec_stream_fn_injection).

Compared with other frameworks
OpenCodeOpenClawHermesOpenProgram
One LLM callStep, tool loop insiderunId pairingNo hierarchyOne llm node, tool loop inside
RecordingStep.Started → Step.Endedllm_input → llm_output hooksAppend-onlyWrite running, fill on close
Tool attributionToolPart in the StepNested under the runIdPeer messageCode node caller = llm node
Chat vs programmaticOne pathOne hook systemOne run_conversationTwo entries, one loop

Implementation status

Done: paired llm-node write, callable path, stream_fn, usage, blocks and status on close. The record is written by two pairs of the same shape; one primitive is designed, not adopted by the dispatcher.

Must surviveNeeded byRisk
extra.blocks (order of thinking, text, tool cards)Reply bubble, transcript/rows.pyHighest
Token columns, token_modelMetering UIHigh
predecessor = user messageBranch, fork, rewindHigh
cancelled / completedPartial output on stopMedium
  1. Give _open_model_call_node an optional role and predecessor; exec unchanged.
  2. Change insert_placeholder to call it.
  3. Change persist_assistant_message to close through it, keeping only field assembly.
  4. Delete the duplicate writes in turn_lifecycle.py (fold_error_into_placeholder).
  5. Verify chat end to end: bubbles, cards, tokens, stop, fork.

The front end is unaffected: _node_to_msg (state/store/session/_msg_adapter.py) still returns assistant; storage has only user, llm, code. Keep the prompt-cache prefix stable, and _run_loop_blocking as the test seam.

Session DAG design

Last updated · 2026-11-25