Runtime 与运行结果¶
Runtime 组合模型、工具、Skills 与会话。使用 async with 初始化并释放资源,复用同一 Runtime 可以发起多次运行。
常用接口¶
| 接口 | 用途 |
|---|---|
from_config |
从配置对象、字典或 JSON 路径创建 Runtime。 |
BumblehiveRuntime |
run() 获取结果;stream() 消费事件;run_console() 在终端展示过程。history 与 session_id 不能同时使用,approval_handler 仅影响当前调用。 |
AgentRunResult |
final_content 是最终回答,usage 是模型用量,stop_reason 说明结束原因。首先检查 error;tools_used 只记录成功执行的工具。 |
创建与运行¶
从配置对象、字典或 JSON 路径创建 Runtime。
from_config
¶
from_config(config: ConfigInput = None) -> BumblehiveRuntime
Create a runtime from a JSON file, mapping, or config object.
run() 获取结果;stream() 消费事件;run_console() 在终端展示过程。history 与 session_id 不能同时使用,approval_handler 仅影响当前调用。
BumblehiveRuntime
¶
High-level agent runtime built from BumblehiveConfig.
from_config
classmethod
¶
from_config(config: ConfigInput = None) -> BumblehiveRuntime
Create a runtime from a JSON file, mapping, config object, or defaults.
initialize_tools
async
¶
initialize_tools() -> None
Register built-ins and connect the runtime-scoped MCP servers once.
run
async
¶
run(message: UserMessage, *, config: Mapping[str, Any] | None = None, hooks: HookInput = None, history: MessageHistory | None = None, session_id: str | None = None, approval_handler: ToolApprovalHandler | None = None) -> AgentRunResult
Run one conversation turn.
With neither history nor session_id, the turn is stateless.
Passing history reads caller-owned in-memory history without
updating it. Use history.replace_run_messages(result.messages) to
carry a completed run into the next turn.
Passing session_id loads, recovers, and persists a managed session.
Passing both raises ValueError.
Do not share one MessageHistory across concurrent runs: await turns
sequentially, or use separate histories for parallel conversations.
stream
¶
stream(message: UserMessage, *, config: Mapping[str, Any] | None = None, hooks: HookInput = None, history: MessageHistory | None = None, session_id: str | None = None, approval_handler: ToolApprovalHandler | None = None, max_queue_size: int = DEFAULT_STREAM_QUEUE_SIZE) -> AsyncEventStream[AgentRunResult]
Stream one turn with stateless, in-memory, or persisted history.
run_console
async
¶
run_console(message: UserMessage, *, config: Mapping[str, Any] | None = None, hooks: HookInput = None, history: MessageHistory | None = None, session_id: str | None = None, approval_handler: ToolApprovalHandler | None = None, renderer: Any | None = None, max_queue_size: int = DEFAULT_STREAM_QUEUE_SIZE) -> AgentRunResult
Run and render one turn with optional conversation history.
delete_session
async
¶
delete_session(session_id: str) -> bool
Delete a persisted session and evict its cached state.
读取结果¶
final_content 是最终回答,usage 是模型用量,stop_reason 说明结束原因。首先检查 error;tools_used 只记录成功执行的工具。
AgentRunResult
dataclass
¶
Outcome of one tool-capable model run.