jianmu.engine¶
适用对象:运行时扩展开发者 / 核心维护者 / 高阶使用者
是否必读:按需
相关模块:jianmu.node, jianmu.message, jianmu.memory
1. 模块职责¶
jianmu.engine 是运行时核心层,负责行为树异步执行、状态管理和运行上下文注入。
大多数普通用户会通过 jianmu 根入口或 jianmu.node 间接使用这里的能力;只有在你需要定制运行时行为时,才需要直接进入这个模块。
2. 适合查什么¶
AsyncBehaviourStateManagerReactiveRunnerRunContext
3. 使用建议¶
- 自定义节点时,通常依赖这里提供的运行时注入语义
- 自定义调度或执行模型时,再直接使用
ReactiveRunner LoopUntilSuccess这类 Jianmu 自定义组合节点优先从jianmu.node查看
4. 最小示例¶
from jianmu.engine import ReactiveRunner, RunContext, StateManager
state_manager = StateManager(MyState)
state_manager.initialize()
runner = ReactiveRunner(
root=my_tree,
state_manager=state_manager,
ctx=RunContext(),
)
5. 常见入口¶
- 想管理 durable state:看
StateManager - 想驱动树运行:看
ReactiveRunner - 想传运行时依赖:看
RunContext - 想用 Jianmu 自定义组合节点:看
jianmu.node.LoopUntilSuccess
6. 注意事项¶
- 普通应用通常会从
jianmu根入口或jianmu.node间接使用这一层 - 只有在你要自定义运行时行为时,才需要直接长期依赖
jianmu.engine AsyncBehaviour更偏运行时基类;面向用户的同步/异步节点概念仍优先看jianmu.Node/jianmu.AsyncNode
7. API 参考¶
Agent¶
Agent
¶
Agent(
root: Behaviour,
*,
state_schema: type[BaseModel] | None = None,
state_manager: StateManager | None = None,
context: RunContext | None = None,
setup_timeout: float = 15.0,
checkpointer: CheckpointerProtocol | None = None,
thread_id: str | None = None,
checkpoint_interval: int | None = None,
max_fps: float | None = None,
)
User-facing single-agent facade that wraps ReactiveRunner.
Agent is a lightweight shell around a prepared behaviour tree, its
state manager, runtime context, and one configured ReactiveRunner.
It does not replace the runner; it centralizes high-level construction,
default runtime configuration, and checkpoint wiring.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
root |
Root behaviour tree bound to the facade. |
|
state_manager |
Backing state manager used for all agent execution. |
|
context |
Runtime dependency context shared with the wrapped runner. |
|
runner |
ReactiveRunner
|
Wrapped low-level |
Create an Agent facade from a prepared behaviour tree.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
root
|
Behaviour
|
Root behaviour tree node. |
必需 |
state_schema
|
type[BaseModel] | None
|
Optional state schema used when creating a state manager implicitly. |
None
|
state_manager
|
StateManager | None
|
Optional prebuilt state manager. |
None
|
context
|
RunContext | None
|
Optional runtime dependency context. |
None
|
setup_timeout
|
float
|
Maximum setup time passed to the wrapped runner. |
15.0
|
checkpointer
|
CheckpointerProtocol | None
|
Optional explicit default checkpointer. |
None
|
thread_id
|
str | None
|
Optional default checkpoint thread identifier. |
None
|
checkpoint_interval
|
int | None
|
Optional default checkpoint save interval. |
None
|
max_fps
|
float | None
|
Optional default runner maximum FPS. |
None
|
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If neither |
源代码位于: jianmu/engine/agent.py
runner
property
¶
Return the wrapped low-level reactive runner.
返回:
| 类型 | 描述 |
|---|---|
ReactiveRunner
|
The resulting |
state
property
¶
Return the current state snapshot from the state manager.
返回:
| 类型 | 描述 |
|---|---|
Any
|
The resulting |
run
async
¶
run(
input_data: dict[str, Any] | None = None,
*,
reset_tree: bool = True,
reset_data: bool = False,
max_ticks: int | None = None,
timeout_s: float | None = None,
checkpointer: CheckpointerProtocol | None = None,
checkpoint_interval: int | None = None,
event_driven_checkpoint: bool = False,
thread_id: str | None = None,
max_fps: float | None = None,
) -> Any
Run the wrapped agent to completion.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input_data
|
dict[str, Any] | None
|
Optional initial input state merged before the run. |
None
|
reset_tree
|
bool
|
Whether to reset the tree before execution. |
True
|
reset_data
|
bool
|
Whether to reset the backing state manager first. |
False
|
max_ticks
|
int | None
|
Optional hard tick limit. |
None
|
timeout_s
|
float | None
|
Optional wall-clock timeout for the full run. |
None
|
checkpointer
|
CheckpointerProtocol | None
|
Optional explicit run-time checkpointer override. |
None
|
checkpoint_interval
|
int | None
|
Optional explicit checkpoint interval override. |
None
|
event_driven_checkpoint
|
bool
|
Whether to save checkpoints only when checkpointable state/tree status changes. |
False
|
thread_id
|
str | None
|
Optional explicit checkpoint thread identifier override. |
None
|
max_fps
|
float | None
|
Optional explicit runner FPS cap override. |
None
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
Final root-node status from the wrapped runner. |
源代码位于: jianmu/engine/agent.py
step
async
¶
Execute one runner step in step mode.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
obs
|
dict[str, Any] | None
|
Optional observation payload merged before the step. |
None
|
yield_to_async
|
bool
|
Whether to yield once after the tick. |
False
|
返回:
| 类型 | 描述 |
|---|---|
dict[str, Any]
|
Step-scoped state fields returned by the wrapped runner. |
源代码位于: jianmu/engine/agent.py
run_until_suspend
async
¶
run_until_suspend(
input_data: dict[str, Any] | None = None,
*,
resume_data: dict[str, Any] | None = None,
resume_request_id: str | None = None,
restore: str | RestorePolicy = RestorePolicy.NEVER,
suspension_mode: str
| SuspensionMode = SuspensionMode.YIELD,
reset_tree: bool = True,
reset_data: bool = False,
max_ticks: int | None = None,
timeout_s: float | None = None,
checkpointer: CheckpointerProtocol | None = None,
checkpoint_interval: int | None = None,
event_driven_checkpoint: bool = False,
thread_id: str | None = None,
max_fps: float | None = None,
) -> RunResult
Run until terminal completion or a publishable suspension point.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input_data
|
dict[str, Any] | None
|
The |
None
|
resume_data
|
dict[str, Any] | None
|
The |
None
|
resume_request_id
|
str | None
|
Active suspension id required when resume_data is provided. |
None
|
restore
|
str | RestorePolicy
|
The |
NEVER
|
suspension_mode
|
str | SuspensionMode
|
The |
YIELD
|
reset_tree
|
bool
|
The |
True
|
reset_data
|
bool
|
The |
False
|
max_ticks
|
int | None
|
Collection of max tick values. |
None
|
timeout_s
|
float | None
|
Collection of timeout values. |
None
|
checkpointer
|
CheckpointerProtocol | None
|
The |
None
|
checkpoint_interval
|
int | None
|
The |
None
|
event_driven_checkpoint
|
bool
|
Whether to save checkpoints only when checkpointable state/tree status changes. |
False
|
thread_id
|
str | None
|
Identifier for thread. |
None
|
max_fps
|
float | None
|
Collection of max fp values. |
None
|
返回:
| 类型 | 描述 |
|---|---|
RunResult
|
The resulting |
源代码位于: jianmu/engine/agent.py
resume_interaction
async
¶
resume_interaction(
*,
thread_id: str | None = None,
request_id: str,
payload: dict[str, Any],
checkpointer: CheckpointerProtocol | None = None,
suspension_mode: str
| SuspensionMode = SuspensionMode.YIELD,
reset_tree: bool = True,
reset_data: bool = False,
max_ticks: int | None = None,
timeout_s: float | None = None,
checkpoint_interval: int | None = None,
event_driven_checkpoint: bool = False,
max_fps: float | None = None,
) -> ResumeInteractionResult
Resume a suspended interaction and return a facade-friendly result.
This facade wraps ReactiveRunner.resume_and_continue and preserves
its strict request_id semantics. Approval suspensions resume
through the shared RunContext.approval_manager bridge; when the
bridge prerequisites are missing, the method returns a structured
recoverable resume result instead of raising to the caller.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
thread_id
|
str | None
|
Optional checkpoint thread identifier override. |
None
|
request_id
|
str
|
Active suspension request identifier to resume. |
必需 |
payload
|
dict[str, Any]
|
Host-provided resume payload. |
必需 |
checkpointer
|
CheckpointerProtocol | None
|
Optional explicit run-time checkpointer override. |
None
|
suspension_mode
|
str | SuspensionMode
|
Host-facing handling mode for any subsequent suspension. |
YIELD
|
reset_tree
|
bool
|
Whether to reset tree execution before resuming. |
True
|
reset_data
|
bool
|
Whether to reset the backing state manager first. |
False
|
max_ticks
|
int | None
|
Optional hard tick limit. |
None
|
timeout_s
|
float | None
|
Optional wall-clock timeout for the resumed run. |
None
|
checkpoint_interval
|
int | None
|
Optional checkpoint interval override. |
None
|
event_driven_checkpoint
|
bool
|
Whether to save checkpoints only when checkpointable state/tree status changes. |
False
|
max_fps
|
float | None
|
Optional runner FPS cap override. |
None
|
返回:
| 类型 | 描述 |
|---|---|
ResumeInteractionResult
|
Structured resume status plus the run result when execution starts. |
源代码位于: jianmu/engine/agent.py
resume
async
¶
Continue agent execution without resetting tree or state.
This is a convenience alias for continuing the current in-memory runner state. It is not a durable checkpoint restore API.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
Final root-node status from the wrapped runner. |
源代码位于: jianmu/engine/agent.py
reset
¶
Reset the wrapped runner.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
reset_data
|
bool
|
Whether to reinitialize the state manager. |
True
|
AsyncBehaviour¶
AsyncBehaviour
¶
Bases: Behaviour
Base class for asynchronous Jianmu nodes.
Initialize an asynchronous Jianmu behaviour node.
源代码位于: jianmu/engine/behaviour.py
initialise
¶
Start a fresh async task whenever the node re-enters execution.
源代码位于: jianmu/engine/behaviour.py
tick
¶
Restart completed RUNNING tasks so async nodes can make forward progress across ticks.
源代码位于: jianmu/engine/behaviour.py
update
¶
Map async task state back into py_trees status values.
返回:
| 类型 | 描述 |
|---|---|
Status
|
|
Status
|
task is missing or returned an invalid type, |
Status
|
cancelled, or the |
源代码位于: jianmu/engine/behaviour.py
terminate
¶
Cancel the in-flight task when the node is interrupted.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
new_status
|
Status
|
The status py_trees is transitioning this node to. |
必需 |
源代码位于: jianmu/engine/behaviour.py
update_async
async
¶
Run one asynchronous node update.
返回:
| 类型 | 描述 |
|---|---|
Status
|
py_trees status value produced by the async node logic. |
引发:
| 类型 | 描述 |
|---|---|
NotImplementedError
|
Always raised in the base class; subclasses must override this method. |
源代码位于: jianmu/engine/behaviour.py
StateManager¶
StateManager
¶
Thread-safe state container with validation, reducers, and change notifications.
StateManager is the durable state surface for a Jianmu workflow. It
owns one Pydantic schema instance, validates all writes, supports
reducer-style merges, and notifies listeners such as ReactiveRunner
when state changes should wake the tree.
Typical usage looks like::
from typing import Annotated
from pydantic import BaseModel
class AgentState(BaseModel):
task: str = ""
messages: list = []
scratchpad: Annotated[list[str], Ephemeral("step")] = []
sm = StateManager(AgentState)
sm.initialize({"task": "summarize this repository"})
sm.update({"messages": ["hello"]})
current = sm.get()
Use the root schema for durable state, and namespace=... only for
runtime-scoped extra fields when the schema allows extra='allow'.
Create a state manager for a Pydantic schema.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
schema
|
Type[T]
|
Pydantic model type that defines the durable state surface. |
必需 |
源代码位于: jianmu/engine/state.py
revision
property
¶
Return a monotonic durable-state revision for checkpoint cursors.
This is runner bookkeeping, not a business-level data version.
subscribe
¶
Register a state-change listener.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
callback
|
Callable[[], None]
|
Zero-argument callable invoked after successful writes or explicit signal notifications. |
必需 |
源代码位于: jianmu/engine/state.py
unsubscribe
¶
Remove a previously registered listener.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
callback
|
Callable[[], None]
|
Listener previously passed to :meth: |
必需 |
源代码位于: jianmu/engine/state.py
signal
¶
initialize
¶
Initialize and validate the state model.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
initial_state
|
Optional[Dict[str, Any]]
|
Optional initial values used to build the backing schema instance. |
None
|
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the supplied state does not satisfy the schema. |
源代码位于: jianmu/engine/state.py
get
¶
Return the whole state model or a single field lookup.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
key
|
str | None
|
Optional field name to read. When omitted, returns a validated copy of the full state model. |
None
|
namespace
|
str | None
|
Optional runtime namespace prefix for extra fields. |
None
|
default
|
Any
|
Fallback value used when the requested field is missing. |
None
|
返回:
| 类型 | 描述 |
|---|---|
T | Any
|
The full state model copy or the resolved field value. |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the full model is requested before initialization and the schema cannot be constructed from defaults alone. |
源代码位于: jianmu/engine/state.py
update
¶
Apply validated updates, then notify listeners if requested.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
updates
|
Dict[str, Any]
|
Field values to merge into the current state. |
必需 |
signal
|
bool
|
Whether to notify listeners after the write succeeds. |
True
|
namespace
|
str | None
|
Optional runtime namespace for extra fields. |
None
|
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the write targets invalid schema fields or fails validation. |
RuntimeError
|
If a registered reducer raises during the merge. |
源代码位于: jianmu/engine/state.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
clear
¶
Delete runtime-only fields under a namespace prefix.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
namespace
|
str
|
Namespace whose extra fields should be removed. |
必需 |
signal
|
bool
|
Whether to notify listeners after clearing data. |
True
|
源代码位于: jianmu/engine/state.py
snapshot_namespace
¶
Return a deep-copied snapshot of runtime namespace data.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
namespace
|
str
|
Namespace to snapshot. |
必需 |
strip_prefix
|
bool
|
Whether returned keys should omit the namespace prefix. |
True
|
返回:
| 类型 | 描述 |
|---|---|
Dict[str, Any]
|
A deep-copied mapping of namespace-local state values. |
源代码位于: jianmu/engine/state.py
merge_dict
¶
Atomically merge a dictionary field.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
field
|
str
|
Dictionary-typed schema field to merge into. |
必需 |
updates
|
Dict[str, Any]
|
Partial mapping applied with last-write-wins semantics. |
必需 |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the merged dictionary fails schema validation. |
源代码位于: jianmu/engine/state.py
transform_field
¶
transform_field(
key: str,
transform: Callable[[Any], Any],
*,
namespace: str | None = None,
signal: bool = True,
) -> Any
Atomically transform one field and persist the validated result.
This is the safest way to perform read-modify-write updates for mutable fields such as message histories or counters::
sm.transform_field("messages", lambda current: list(current or []) + [msg])
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
key
|
str
|
Logical field name to transform. |
必需 |
transform
|
Callable[[Any], Any]
|
Pure function receiving the current field value. |
必需 |
namespace
|
str | None
|
Optional runtime namespace prefix. |
None
|
signal
|
bool
|
Whether to notify listeners after a successful write. |
True
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
The transformed field value returned by |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If namespace writes target schema fields, if extra='allow' is not set, or if validation fails. |
源代码位于: jianmu/engine/state.py
dump_checkpoint
¶
Export the full state payload for checkpoint persistence.
返回:
| 类型 | 描述 |
|---|---|
Dict[str, Any]
|
Serializable checkpoint payload containing the current state. |
源代码位于: jianmu/engine/state.py
set_runtime_metadata
¶
Persist runner-internal metadata outside the user state schema.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
key
|
str
|
The |
必需 |
value
|
Any
|
Value to apply. |
必需 |
源代码位于: jianmu/engine/state.py
get_runtime_metadata
¶
Return one runner-internal metadata value.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
key
|
str
|
The |
必需 |
default
|
Any
|
Default value to use when no explicit value is available. |
None
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
The resulting |
源代码位于: jianmu/engine/state.py
clear_runtime_metadata
¶
Clear one runtime metadata key or the whole runtime metadata store.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
key
|
str | None
|
The |
None
|
源代码位于: jianmu/engine/state.py
restore_runtime_metadata
¶
Replace runtime metadata from checkpoint payload.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
Dict[str, Any] | None
|
The |
必需 |
源代码位于: jianmu/engine/state.py
reset_step_fields
¶
reset_run_fields
¶
reset_call_fields
¶
Reset all scope='call' fields.
ReactiveRunner invokes this before one model/tool call cycle so
temporary call-scoped state does not leak across turns.
get_step_fields
¶
Return the current values of all scope='step' fields.
返回:
| 类型 | 描述 |
|---|---|
Dict[str, Any]
|
Mapping of step-scoped field names to their current values. |
源代码位于: jianmu/engine/state.py
ReactiveRunner¶
ReactiveRunner
¶
ReactiveRunner(
root: Behaviour,
state_manager: StateManager,
ctx: Optional[RunContext] = None,
*,
setup_timeout: float = 15.0,
max_pending_wakeups: int | None = None,
hot_loop_warn_factor: float | None = None,
)
Event-driven runner that drives a Jianmu behaviour tree to completion.
The runner binds a root behaviour tree to a StateManager and optional
RunContext. It injects runtime dependencies into Jianmu nodes, reacts
to state changes, supports step mode for interactive apps, and can restore
checkpoints for resumable execution.
The three most important execution entrypoints are:
tick_once(): perform a single synchronous tree tickstep(): one async tick plus step-scoped state handlingrun(): drive the tree until it reachesSUCCESSorFAILURE
Minimal usage::
runner = ReactiveRunner(root=my_tree, state_manager=sm, ctx=ctx)
status = await runner.run({"task": "solve this problem"})
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
root |
Root behaviour bound to the runner. |
|
state_manager |
Shared runtime state store used by all injected nodes. |
|
ctx |
Active runtime dependency context. |
|
tree |
Wrapped |
Create a runner for a behaviour tree and state manager.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
root
|
Behaviour
|
Root behaviour node of the tree. |
必需 |
state_manager
|
StateManager
|
Durable state store shared across all nodes. |
必需 |
ctx
|
Optional[RunContext]
|
Optional runtime dependency context injected into Jianmu nodes. |
None
|
setup_timeout
|
float
|
Maximum setup time passed to |
15.0
|
max_pending_wakeups
|
int | None
|
Maximum buffered wakeups retained before coalescing repeated notifications. |
None
|
hot_loop_warn_factor
|
float | None
|
Warning threshold multiplier relative to
|
None
|
源代码位于: jianmu/engine/runtime.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
tick_once
¶
Execute one synchronous tree tick without entering the run loop.
This is the lowest-level execution API. Prefer step() for
interactive stepping and run() for normal agent execution.
返回:
| 类型 | 描述 |
|---|---|
Status
|
The Status of the root node after the tick. |
源代码位于: jianmu/engine/runtime.py
step
async
¶
Run exactly one tree tick in step mode.
step() is designed for UIs or orchestrators that want explicit
turn-by-turn control. It resets Ephemeral("step") fields, merges an
optional observation payload, performs one tick, and returns the
current step-scoped action fields.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
obs
|
Optional[Dict[str, Any]]
|
Optional observation data merged into state before ticking. |
None
|
yield_to_async
|
bool
|
Whether to yield once to the event loop after the tick. |
False
|
返回:
| 类型 | 描述 |
|---|---|
Dict[str, Any]
|
Current step-scoped action payload from the state manager. |
引发:
| 类型 | 描述 |
|---|---|
RuntimeError
|
If run() is currently active. |
源代码位于: jianmu/engine/runtime.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 | |
run
async
¶
run(
input_data: Optional[Dict[str, Any]] = None,
reset_tree: bool = True,
reset_data: bool = False,
max_ticks: int = None,
timeout_s: float | None = None,
checkpointer: Any = None,
checkpoint_interval: int | None = 1,
thread_id: str = "default_thread",
max_fps: float = 60.0,
) -> Status
Drive the behaviour tree until it finishes or hits a guardrail.
run() is the normal end-to-end execution mode. It can optionally
reset the tree, reset or reuse state, seed initial input data, restore
from a checkpoint backend, and then keep ticking until the root reaches
a terminal status.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input_data
|
Optional[Dict[str, Any]]
|
Optional initial input state applied before the run. |
None
|
reset_tree
|
bool
|
Whether to interrupt and reset tree execution first. |
True
|
reset_data
|
bool
|
Whether to fully reinitialize state before the run. |
False
|
max_ticks
|
int
|
Optional hard tick limit. |
None
|
timeout_s
|
float | None
|
Optional wall-clock timeout for the full run. |
None
|
checkpointer
|
Any
|
Optional checkpoint backend implementing Jianmu's checkpointer protocol. |
None
|
checkpoint_interval
|
int | None
|
Tick interval between checkpoint saves, or
|
1
|
thread_id
|
str
|
Logical thread/session identifier for checkpoints. |
'default_thread'
|
max_fps
|
float
|
Maximum runner tick frequency. |
60.0
|
返回:
| 类型 | 描述 |
|---|---|
Status
|
Final root node status. |
引发:
| 类型 | 描述 |
|---|---|
RuntimeError
|
If step() is currently active. |
源代码位于: jianmu/engine/runtime.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 | |
run_until_suspend
async
¶
run_until_suspend(
input_data: Optional[Dict[str, Any]] = None,
*,
resume_data: Optional[Dict[str, Any]] = None,
resume_request_id: str | None = None,
restore: str | RestorePolicy = RestorePolicy.NEVER,
suspension_mode: str
| SuspensionMode = SuspensionMode.YIELD,
reset_tree: bool = True,
reset_data: bool = False,
max_ticks: int = None,
timeout_s: float | None = None,
checkpointer: Any = None,
checkpoint_interval: int | None = 1,
thread_id: str = "default_thread",
max_fps: float = 60.0,
) -> RunResult
Run until terminal completion or a publishable suspension point.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input_data
|
Optional[Dict[str, Any]]
|
The |
None
|
resume_data
|
Optional[Dict[str, Any]]
|
The |
None
|
resume_request_id
|
str | None
|
Active suspension id required when resume_data is provided. |
None
|
restore
|
str | RestorePolicy
|
The |
NEVER
|
suspension_mode
|
str | SuspensionMode
|
The |
YIELD
|
reset_tree
|
bool
|
The |
True
|
reset_data
|
bool
|
The |
False
|
max_ticks
|
int
|
Collection of max tick values. |
None
|
timeout_s
|
float | None
|
Collection of timeout values. |
None
|
checkpointer
|
Any
|
The |
None
|
checkpoint_interval
|
int | None
|
Tick interval between checkpoint saves, or
|
1
|
thread_id
|
str
|
Identifier for thread. |
'default_thread'
|
max_fps
|
float
|
Collection of max fp values. |
60.0
|
返回:
| 类型 | 描述 |
|---|---|
RunResult
|
The resulting |
引发:
| 类型 | 描述 |
|---|---|
RuntimeError
|
If the operation cannot be completed at runtime. |
ValueError
|
If input validation fails. |
源代码位于: jianmu/engine/runtime.py
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 | |
resume_and_continue
async
¶
resume_and_continue(
*,
thread_id: str,
request_id: str,
payload: dict[str, Any],
checkpointer: Any = None,
suspension_mode: str
| SuspensionMode = SuspensionMode.YIELD,
reset_tree: bool = True,
reset_data: bool = False,
max_ticks: int = None,
timeout_s: float | None = None,
checkpoint_interval: int | None = 1,
max_fps: float = 60.0,
**kwargs: Any,
) -> RunResult
Resume a checkpointed suspension and continue execution.
This convenience entrypoint resumes a checkpointed suspension and then
continues execution through run_until_suspend(). User-input,
external-execution, and approval suspensions all flow through the same
strict request_id validation path, while approval resumes bridge
through the shared RunContext.approval_manager before tree re-entry.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
thread_id
|
str
|
Logical checkpoint thread identifier. |
必需 |
request_id
|
str
|
Active suspension request identifier to resume. |
必需 |
payload
|
dict[str, Any]
|
Host-provided resume payload. |
必需 |
checkpointer
|
Any
|
Optional checkpoint backend implementing Jianmu's protocol. |
None
|
suspension_mode
|
str | SuspensionMode
|
Host-facing handling mode for any subsequent suspension. |
YIELD
|
reset_tree
|
bool
|
Whether to interrupt and reset tree execution first. |
True
|
reset_data
|
bool
|
Whether to fully reinitialize state before the run. |
False
|
max_ticks
|
int
|
Optional hard tick limit. |
None
|
timeout_s
|
float | None
|
Optional wall-clock timeout for the resumed run. |
None
|
checkpoint_interval
|
int | None
|
Tick interval between checkpoint saves, or
|
1
|
max_fps
|
float
|
Maximum runner tick frequency. |
60.0
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
返回:
| 类型 | 描述 |
|---|---|
RunResult
|
The resumed run result. |
源代码位于: jianmu/engine/runtime.py
reset
¶
Interrupt the tree and reset runner-local execution state.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
reset_data
|
bool
|
Whether to reinitialize the backing state manager. |
True
|
源代码位于: jianmu/engine/runtime.py
RunContext¶
RunContext
dataclass
¶
RunContext(
model_client: Any = None,
approval_manager: Optional["ApprovalManager"] = None,
sandbox: Optional[Any] = None,
constraints: Optional[Constraints] = None,
runtime: Optional[Any] = None,
prompt_runtime: Optional[PromptRuntimeContext] = None,
runtime_event_bus: Optional["RuntimeEventBus"] = None,
effect_manager: Optional["EffectCommitManager"] = None,
hooks: Optional["HookManager"] = None,
)
Runtime-only dependency container injected into executing nodes.
RunContext carries resources that should not live in serializable
agent state, such as model clients, approval managers, or
sandbox handles. ReactiveRunner injects the same context into every
Jianmu-aware node before execution.
Typical usage keeps durable data in StateManager and places shared
service objects here::
ctx = RunContext(
model_client=my_model_client,
constraints=my_constraints,
approval_manager=my_approval_manager,
)
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
model_client |
Any
|
Default model client used by nodes that resolve model execution capability from runtime context. |
approval_manager |
Optional['ApprovalManager']
|
Optional approval workflow manager used by guarded tool execution. |
sandbox |
Optional[Any]
|
Optional sandbox/runtime handle shared by execution nodes. |
constraints |
Optional[Constraints]
|
Optional global constraints applied by guard/execution components. |
runtime |
Optional[Any]
|
Optional opaque runtime extension slot for app-specific data. |
prompt_runtime |
Optional[PromptRuntimeContext]
|
Optional prompt-construction overrides for the current run, such as bootstrap files or skill-aware prompt assembly. |
runtime_event_bus |
Optional['RuntimeEventBus']
|
Optional runtime-semantic event bus consumed by nodes, guards, and runtimes to publish execution facts. |
effect_manager |
Optional['EffectCommitManager']
|
Optional governed side-effect commit manager used by nodes/adapters that opt into prepare/commit/receipt execution. |
hooks |
Optional['HookManager']
|
Optional hook manager for execution-scoped extension points. |