AS AgentScopeAPI 手册 / API Reference

SessionTurnRunner

@Service public class SessionTurnRunner
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:70–940

会话轮次运行器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.builder.web.managed 包。核心成员包括 runTurnAsync、resumeWithToolResults、abortManagedAttempt、interrupt、interruptRun、releaseSession。

Executes a managed session turn against the harness agent and records session events.

构造器摘要Constructor Summary

构造器Constructor说明Description
public SessionTurnRunner(HarnessAgentBuildService agentBuildService, DataSessionService sessionService, SessionEventLog eventLog, SessionEventMapper eventMapper, SessionEventPreviewBus previewBus, DataEnvironmentService environmentService, HandsLeaseService handsLeaseService, TurnLeaseService turnLeaseService, CoordinationStore coordinationStore, DeletedSessionRegistry deletedSessions, ControlPlaneClient controlPlaneClient, ToolConfirmationCoordinator confirmationCoordinator, AgentRunRegistry runRegistry)
初始化 `SessionTurnRunner` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public void runTurnAsync(ManagedSessionDto session, String userMessage)
运行轮次异步。
Runs a turn asynchronously so inbound HTTP handlers can return quickly.
public void runTurnAsync(ManagedSessionDto session, String userMessage, Runnable onAdmitted)
运行轮次异步。
Runs a turn asynchronously, invoking `onAdmitted` once the turn is certain to run — the lease is held by then, so a caller can record the message that triggered it only if it will actually be processed.
public void resumeWithToolResults(ManagedSessionDto session, List<ToolResultBlock> toolResults)
执行恢复使用工具结果相关操作。
Resumes a suspended turn with external tool results (self-hosted worker / `user.tool_result`).
public void abortManagedAttempt(String sessionId, String agentTaskId, String attemptId, long dispatchGeneration, String turnId, String reason)
执行中止托管尝试相关操作。
Handles a fenced abort locally or queues it for the replica holding the matching turn lease.
public void interrupt(String sessionId)
请求中断当前执行。
Cancels an in-flight turn.
public void interruptRun(String ownerId, String sessionId, String runId)
执行中断运行相关操作。
Cancels an exact run after the caller has authorized access to the session.
public void releaseSession(String sessionId, String ownerId)
执行 `releaseSession` 方法。
Drops the footprint of a session the control plane has deleted: an in-flight turn is cancelled first, then the team wakeup bindings, the cached instance with its persisted agent state, and the per-session preview bookkeeping.
public static ToolResultBlock toolResultFromPayload(Map<String, Object> payload)
static
构建`ToolResultBlock`来自工作进程/用户工具_结果负载。
Builds a `ToolResultBlock` from a worker/user tool_result payload.

构造器详情Constructor Detail

SessionTurnRunner

public SessionTurnRunner(HarnessAgentBuildService agentBuildService, DataSessionService sessionService, SessionEventLog eventLog, SessionEventMapper eventMapper, SessionEventPreviewBus previewBus, DataEnvironmentService environmentService, HandsLeaseService handsLeaseService, TurnLeaseService turnLeaseService, CoordinationStore coordinationStore, DeletedSessionRegistry deletedSessions, ControlPlaneClient controlPlaneClient, ToolConfirmationCoordinator confirmationCoordinator, AgentRunRegistry runRegistry)

初始化 SessionTurnRunner 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
agentBuildServiceHarnessAgentBuildService智能体构建服务(类型 `HarnessAgentBuildService`)。The agent build service.
sessionServiceDataSessionService会话服务(类型 `DataSessionService`)。The session service.
eventLogSessionEventLog事件日志(类型 `SessionEventLog`)。The event log.
eventMapperSessionEventMapper事件 Mapper(类型 `SessionEventMapper`)。The event mapper.
previewBusSessionEventPreviewBus预览总线(类型 `SessionEventPreviewBus`)。The preview bus.
environmentServiceDataEnvironmentService环境服务(类型 `DataEnvironmentService`)。The environment service.
handsLeaseServiceHandsLeaseServicehands Lease 服务(类型 `HandsLeaseService`)。The hands lease service.
turnLeaseServiceTurnLeaseService轮次 Lease 服务(类型 `TurnLeaseService`)。The turn lease service.
coordinationStoreCoordinationStorecoordination 存储(类型 `CoordinationStore`)。The coordination store.
deletedSessionsDeletedSessionRegistry已删除会话(类型 `DeletedSessionRegistry`)。The deleted sessions.
controlPlaneClientControlPlaneClient控制面客户端(类型 `ControlPlaneClient`)。The control plane client.
confirmationCoordinatorToolConfirmationCoordinator确认 Coordinator(类型 `ToolConfirmationCoordinator`)。The confirmation coordinator.
runRegistryAgentRunRegistry运行注册表(类型 `AgentRunRegistry`)。The run registry.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:102–129

方法详情Method Detail

runTurnAsync

public void runTurnAsync(ManagedSessionDto session, String userMessage)

运行轮次异步。

Runs a turn asynchronously so inbound HTTP handlers can return quickly.

参数Parameters
名称Name类型Type说明Description
sessionManagedSessionDto会话(类型 `ManagedSessionDto`)。The session.
userMessageString用户消息(类型 `String`)。The user message.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:132–134

runTurnAsync

public void runTurnAsync(ManagedSessionDto session, String userMessage, Runnable onAdmitted)

运行轮次异步。

Runs a turn asynchronously, invoking onAdmitted once the turn is certain to run — the lease is held by then, so a caller can record the message that triggered it only if it will actually be processed.

参数Parameters
名称Name类型Type说明Description
sessionManagedSessionDto会话(类型 `ManagedSessionDto`)。The session.
userMessageString用户消息(类型 `String`)。The user message.
onAdmittedRunnableon Admitted(类型 `Runnable`)。The on admitted.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:141–144

resumeWithToolResults

public void resumeWithToolResults(ManagedSessionDto session, List<ToolResultBlock> toolResults)

执行恢复使用工具结果相关操作。

Resumes a suspended turn with external tool results (self-hosted worker / user.tool_result).

参数Parameters
名称Name类型Type说明Description
sessionManagedSessionDto会话(类型 `ManagedSessionDto`)。The session.
toolResultsList<ToolResultBlock>工具结果(类型 `List`)。The tool results.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:150–161

abortManagedAttempt

public void abortManagedAttempt(String sessionId, String agentTaskId, String attemptId, long dispatchGeneration, String turnId, String reason)

执行中止托管尝试相关操作。

Handles a fenced abort locally or queues it for the replica holding the matching turn lease.

参数Parameters
名称Name类型Type说明Description
sessionIdString会话标识(类型 `String`)。The session id.
agentTaskIdString智能体任务标识(类型 `String`)。The agent task id.
attemptIdString尝试标识(类型 `String`)。The attempt id.
dispatchGenerationlongdispatch Generation(类型 `long`)。The dispatch generation.
turnIdString轮次标识(类型 `String`)。The turn id.
reasonString原因(类型 `String`)。The reason.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:347–370

interrupt

public void interrupt(String sessionId)

请求中断当前执行。

Cancels an in-flight turn.

参数Parameters
名称Name类型Type说明Description
sessionIdString会话标识(类型 `String`)。The session id.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:406–415

interruptRun

public void interruptRun(String ownerId, String sessionId, String runId)

执行中断运行相关操作。

Cancels an exact run after the caller has authorized access to the session.

参数Parameters
名称Name类型Type说明Description
ownerIdString所有者标识(类型 `String`)。The owner id.
sessionIdString会话标识(类型 `String`)。The session id.
runIdString运行标识(类型 `String`)。The run id.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:422–437

releaseSession

public void releaseSession(String sessionId, String ownerId)

执行 releaseSession 方法。

Drops the footprint of a session the control plane has deleted: an in-flight turn is cancelled first, then the team wakeup bindings, the cached instance with its persisted agent state, and the per-session preview bookkeeping.

参数Parameters
名称Name类型Type说明Description
sessionIdString会话标识(类型 `String`)。The session id.
ownerIdString所有者标识(类型 `String`)。The owner id.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:497–506

toolResultFromPayload

public static ToolResultBlock toolResultFromPayload(Map<String, Object> payload)
static

构建ToolResultBlock来自工作进程/用户工具_结果负载。

Builds a ToolResultBlock from a worker/user tool_result payload.

参数Parameters
名称Name类型Type说明Description
payloadMap<String, Object>负载(类型 `Map`)。The payload.
返回Returns ToolResultBlock
返回ToolResultBlock。Returns tool result block.
源码Source io/agentscope/builder/web/managed/SessionTurnRunner.java:858–891
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.