AS AgentScopeAPI 手册 / API Reference

AgentProtocolTaskClient

public final class AgentProtocolTaskClient
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:53–408

智能体协议任务客户端,封装与远端服务的连接和调用。位于 io.agentscope.harness.agent.subagent.task 包。核心成员包括 submitTask、getStatus、waitForResult、cancelTask、resumeTask、openEventStream。

Minimal HTTP client for the internal AgentScope task protocol (POST/GET /tasks/...).

The client-supplied taskId is used as the remote task identifier (no separate run id).

构造器摘要Constructor Summary

构造器Constructor说明Description
public AgentProtocolTaskClient()
初始化 `AgentProtocolTaskClient` 实例。
Creates a new instance.
public AgentProtocolTaskClient(HttpClient http)
初始化 `AgentProtocolTaskClient` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public void submitTask(String baseUrl, Map<String, String> headers, String taskId, String agentId, String input) throws IOException, InterruptedException
执行提交任务相关操作。
`POST /tasks` with body `{task_id, agent_id, input}` (+ optional context).
public void submitTask(String baseUrl, Map<String, String> headers, String taskId, String agentId, String input, RemoteSubmitContext context) throws IOException, InterruptedException
执行提交任务相关操作。
`POST /tasks` with body `{task_id, agent_id, input, context?}`.
public RemoteTaskStatus getStatus(String baseUrl, Map<String, String> headers, String taskId) throws IOException, InterruptedException
获取状态。
`GET /tasks/{taskId}`.
public String waitForResult(String baseUrl, Map<String, String> headers, String taskId, long timeoutSeconds) throws IOException, InterruptedException
等待用于结果。
`GET /tasks/{taskId}/wait?timeout_seconds=<n>` — blocks until the server completes the task.
public void cancelTask(String baseUrl, Map<String, String> headers, String taskId) throws IOException, InterruptedException
执行取消任务相关操作。
`POST /tasks/{taskId}/cancel`.
public void resumeTask(String baseUrl, Map<String, String> headers, String taskId, List<RemoteConfirmDecision> decisions) throws IOException, InterruptedException
执行恢复任务相关操作。
`POST /tasks/{taskId}/resume` with body `{decisions: [...]}`.
public Closeable openEventStream(String baseUrl, Map<String, String> headers, String taskId, long fromSeq, Consumer<RemoteAgentEvent> consumer) throws IOException, InterruptedException
打开事件流。
Opens `GET /tasks/{taskId}/events` as an SSE stream and delivers parsed events to ` consumer`.

构造器详情Constructor Detail

AgentProtocolTaskClient

public AgentProtocolTaskClient()

初始化 AgentProtocolTaskClient 实例。

Creates a new instance.

源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:68–74

AgentProtocolTaskClient

public AgentProtocolTaskClient(HttpClient http)

初始化 AgentProtocolTaskClient 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
httpHttpClientHTTP(类型 `HttpClient`)。The http.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:76–78

方法详情Method Detail

submitTask

public void submitTask(String baseUrl, Map<String, String> headers, String taskId, String agentId, String input) throws IOException, InterruptedException

执行提交任务相关操作。

POST /tasks with body {task_id, agent_id, input} (+ optional context).

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
headersMap<String, String>请求头(类型 `Map`)。The headers.
taskIdString任务标识(类型 `String`)。The task id.
agentIdString智能体标识(类型 `String`)。The agent id.
inputString输入消息(类型 `String`)。The input.
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:81–89

submitTask

public void submitTask(String baseUrl, Map<String, String> headers, String taskId, String agentId, String input, RemoteSubmitContext context) throws IOException, InterruptedException

执行提交任务相关操作。

POST /tasks with body {task_id, agent_id, input, context?}.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
headersMap<String, String>请求头(类型 `Map`)。The headers.
taskIdString任务标识(类型 `String`)。The task id.
agentIdString智能体标识(类型 `String`)。The agent id.
inputString输入消息(类型 `String`)。The input.
contextRemoteSubmitContext上下文(类型 `RemoteSubmitContext`)。The context.
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:96–124

getStatus

public RemoteTaskStatus getStatus(String baseUrl, Map<String, String> headers, String taskId) throws IOException, InterruptedException

获取状态。

GET /tasks/{taskId}.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
headersMap<String, String>请求头(类型 `Map`)。The headers.
taskIdString任务标识(类型 `String`)。The task id.
返回Returns RemoteTaskStatus
返回RemoteTaskStatus。Returns remote task status.
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:127–147

waitForResult

public String waitForResult(String baseUrl, Map<String, String> headers, String taskId, long timeoutSeconds) throws IOException, InterruptedException

等待用于结果。

GET /tasks/{taskId}/wait?timeout_seconds= — blocks until the server completes the task.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
headersMap<String, String>请求头(类型 `Map`)。The headers.
taskIdString任务标识(类型 `String`)。The task id.
timeoutSecondslong超时秒(类型 `long`)。The timeout seconds.
返回Returns String
返回字符串结果。Returns a string.
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:154–175

cancelTask

public void cancelTask(String baseUrl, Map<String, String> headers, String taskId) throws IOException, InterruptedException

执行取消任务相关操作。

POST /tasks/{taskId}/cancel.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
headersMap<String, String>请求头(类型 `Map`)。The headers.
taskIdString任务标识(类型 `String`)。The task id.
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:178–191

resumeTask

public void resumeTask(String baseUrl, Map<String, String> headers, String taskId, List<RemoteConfirmDecision> decisions) throws IOException, InterruptedException

执行恢复任务相关操作。

POST /tasks/{taskId}/resume with body {decisions: [...]}.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
headersMap<String, String>请求头(类型 `Map`)。The headers.
taskIdString任务标识(类型 `String`)。The task id.
decisionsList<RemoteConfirmDecision>decisions(类型 `List`)。The decisions.
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:198–226

openEventStream

public Closeable openEventStream(String baseUrl, Map<String, String> headers, String taskId, long fromSeq, Consumer<RemoteAgentEvent> consumer) throws IOException, InterruptedException

打开事件流。

Opens GET /tasks/{taskId}/events as an SSE stream and delivers parsed events to consumer.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。The base url.
headersMap<String, String>请求头(类型 `Map`)。The headers.
taskIdString任务标识(类型 `String`)。The task id.
fromSeqlong来自 Seq(类型 `long`)。The from seq.
consumerConsumer<RemoteAgentEvent>消费者(类型 `Consumer`)。The consumer.
返回Returns Closeable
返回Closeable。Returns closeable.
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/subagent/task/AgentProtocolTaskClient.java:232–298
基于官方固定版本源码静态生成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.