AS AgentScopeAPI 手册 / API Reference

HarnessAgent

public class HarnessAgent implements Agent, AutoCloseable
源码Source io/agentscope/harness/agent/HarnessAgent.java:169–2971

Harness 智能体,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent 包,实现 Agent、AutoCloseable。核心成员包括 getWorkspaceManager、workspaceFor、getCompactionHook、getSkillRepositories、getSkillUsageStore、queryAudit。

HarnessAgent is the user-facing harness API that wraps a ReActAgent with workspace / filesystem / sandbox / subagent / skill / plan-mode / MCP orchestration.

Use #builder() to configure. For plain ReAct usage without any of the above, use ReActAgent#builder() directly.

Capabilities added on top of the inner ReActAgent:

  • Workspace-based context loading (AGENTS.md, MEMORY.md, KNOWLEDGE.md)

  • Pluggable file-system backend (local, sandbox, remote/composite)

  • Subagent orchestration via task / task_output tools (sync + background)

  • Skill loading via AgentSkillRepository, including the self-learning loop

  • Memory flush + message offload before context compression

  • Workspace-managed tools.json (MCP servers + allow/deny filter)

  • Plan mode (read-only design phase) with plan_enter/plan_write/plan_exit tools

  • Context-overflow emergency compaction via CompactionMiddleware

Thread Safety: HarnessAgent is stateless between calls and safe to use as a singleton serving multiple users/sessions concurrently. Each call() uses the io.agentscope.core.agent.RuntimeContext's (userId, sessionId) to isolate state. Calls targeting the same session are serialized automatically; different sessions run in parallel.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
`HarnessAgent`的构建器。
Builder for `HarnessAgent`.

方法摘要Method Summary

方法Method说明Description
public WorkspaceManager getWorkspaceManager()
获取工作区管理器。
Returns the workspace manager bound to this agent, or `null` if not configured.
public WorkspaceManager workspaceFor(String userId, String sessionId)
执行工作区用于相关操作。
Returns a `WorkspaceManager` view whose filesystem and namespace are bound to the given `(userId, sessionId)` for the duration of the returned view's IO.
public CompactionMiddleware getCompactionHook()
获取压缩钩子。
Returns the `CompactionMiddleware` instance if compaction was configured, or `null`.
public List<AgentSkillRepository> getSkillRepositories()
获取 `getSkillRepositories`。
Returns the ordered list of `AgentSkillRepository` instances bound to this agent (low to high priority).
public SkillUsageStore getSkillUsageStore()
获取技能用量存储。
Access to the sidecar telemetry store.
public List<SkillAuditLog.Entry> queryAudit(String dayUtc, java.util.function.Predicate<SkillAuditLog.Entry> filter)
查询 `queryAudit`。
Query the audit log for a given UTC day.
public Mono<SkillCurator.CuratorRunReport> runCuratorOnce()
运行 `runCuratorOnce`。
Force-run the skill curator immediately, bypassing the idle-and-interval gate.
public Mono<SkillPromoter.PromotionResult> promoteSkill(String name, String reviewerId, RuntimeContext ctx)
执行 `promoteSkill` 方法。
Promote a draft skill for the explicitly supplied request context.
public void enterPlanMode(RuntimeContext ctx)
设置该参数。
Enters plan mode for the session identified by the given `RuntimeContext`.
public void exitPlanMode(RuntimeContext ctx)
设置该参数。
Exits plan mode for the session identified by the given `RuntimeContext`.
public boolean isPlanModeActive(RuntimeContext ctx)
判断是否 `isPlanModeActive`。
Returns whether the plan mode active.
public void clearContext(RuntimeContext ctx)
清空上下文。
Clears the model-visible conversation context for the session identified by `ctx`.
public void clearContext(String userId, String sessionId)
清空上下文。
Clears the model-visible conversation context for one `(userId, sessionId)` session.
public void clearStateCache()
清空状态缓存。
Clears all locally cached per-session state and permission engines held by the wrapped `ReActAgent`.
public void clearStateCache(RuntimeContext ctx)
清空状态缓存。
Clears the locally cached state and permission engine for the session identified by `ctx`.
public void clearStateCache(String userId, String sessionId)
清空状态缓存。
Clears the locally cached state and permission engine for one `(userId, sessionId)` slot.
public void enterPlanMode(String userId, String sessionId)
执行 `enterPlanMode` 方法。
Enters plan mode for the given `(userId, sessionId)` session, independent of which slot is currently active.
public void exitPlanMode(String userId, String sessionId)
执行 `exitPlanMode` 方法。
Exits plan mode for the given `(userId, sessionId)` session and persists the change.
public boolean isPlanModeActive(String userId, String sessionId)
判断是否 `isPlanModeActive`。
Returns whether the plan mode active.
public void setPermissionMode(RuntimeContext ctx, io.agentscope.core.permission.PermissionMode mode)
设置权限模式。
Switches the `io.agentscope.core.permission.PermissionMode` for the session identified by the given `RuntimeContext` at runtime.
public void setPermissionMode(String userId, String sessionId, io.agentscope.core.permission.PermissionMode mode)
设置权限模式。
Switches the `io.agentscope.core.permission.PermissionMode` for the given `(userId, sessionId)` session at runtime, preserving configured rules and rebuilding the cached permission engine.
public io.agentscope.core.permission.PermissionMode getPermissionMode(String userId, String sessionId)
获取权限模式。
Returns the permission mode.
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
public ReActAgent getDelegate()
获取委托。
Returns the wrapped `ReActAgent`.
public Model getModel()
获取模型。
Returns the model.
public int getMaxIters()
获取最大迭代次数。
Returns the max iters.
public AgentStateStore getStateStore()
获取状态存储。
Returns the state store.
public DistributedStore getDistributedStore()
获取分布式存储。
The distributed store configured on this agent, or `null` for local deployments.
public io.agentscope.harness.agent.subagent.DefaultAgentManager getSubagentAgentManager()
获取子智能体智能体管理器。
The internal `io.agentscope.harness.agent.subagent.DefaultAgentManager` able to re-materialize this agent's subagents, or `null` when none is owned (e.g.
public TaskRepository getTaskRepository()
获取任务仓库。
Background subagent `TaskRepository` owned by the subagent middleware, or `null` when subagents are not configured.
public String getDefaultSessionId()
获取默认会话标识。
Returns the default session id.
public AgentState getAgentState()
deprecated
获取智能体状态。
Returns the agent state.
public String getName()
获取名称。
Returns the name.
public String getAgentId()
获取智能体标识。
Returns the agent id.
public String getDescription()
获取 `getDescription`。
Returns the description.
public void interrupt()
请求中断当前执行。
Returns the interrupt.
public void interrupt(Msg msg)
请求中断当前执行。
Performs the interrupt operation.
public void interrupt(RuntimeContext ctx)
请求中断当前执行。
Interrupts the in-flight call for the session identified by `ctx`.
public void interrupt(RuntimeContext ctx, Msg msg)
请求中断当前执行。
Interrupts the in-flight call for the session identified by `ctx` with an associated user message.
public void interrupt(String userId, String sessionId)
请求中断当前执行。
Interrupts the in-flight call for a specific `(userId, sessionId)` session.
public void interrupt(String userId, String sessionId, Msg msg)
请求中断当前执行。
Interrupts the in-flight call for a specific `(userId, sessionId)` session with an associated user message.
public T extends Channel T channel(T channel)
设置渠道。
Returns a channel bound to this agent's internal gateway.
public HarnessGateway gateway()
返回网关。
Returns the internal gateway backing `#channel`.
public Mono<Msg> call(List<Msg> msgs)
deprecated
向智能体发送输入并返回最终回复。
Performs the call operation.
public Mono<Msg> call(List<Msg> msgs, Class<?> structuredModel)
deprecated
向智能体发送输入并返回最终回复。
Performs the call operation.
public Mono<Msg> call(List<Msg> msgs, JsonNode schema)
deprecated
向智能体发送输入并返回最终回复。
Performs the call operation.
public Mono<Msg> call(Msg msg, RuntimeContext ctx)
向智能体发送输入并返回最终回复。
Performs the call operation.
public Mono<Msg> call(String text, RuntimeContext ctx)
向智能体发送输入并返回最终回复。
Calls the agent with a plain text input and per-call `RuntimeContext`.
public Mono<Msg> call(List<Msg> msgs, RuntimeContext ctx)
向智能体发送输入并返回最终回复。
Performs the call operation.
public Mono<Msg> call(List<Msg> msgs, Class<?> structuredModel, RuntimeContext ctx)
向智能体发送输入并返回最终回复。
Performs the call operation.
public Mono<Msg> call(List<Msg> msgs, JsonNode schema, RuntimeContext ctx)
向智能体发送输入并返回最终回复。
Performs the call operation.
public Flux<Event> stream(List<Msg> msgs, StreamOptions options)
deprecated
执行流相关操作。
Performs the stream operation.
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, Class<?> structuredModel)
deprecated
执行流相关操作。
Performs the stream operation.
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, JsonNode schema)
deprecated
执行流相关操作。
Performs the stream operation.
public Flux<Event> stream(Msg msg, RuntimeContext ctx)
deprecated
执行流相关操作。
Performs the stream operation.
public Flux<Event> stream(List<Msg> msgs, RuntimeContext ctx)
deprecated
执行流相关操作。
Performs the stream operation.
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, RuntimeContext ctx)
deprecated
执行流相关操作。
Performs the stream operation.
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, Class<?> structuredModel, RuntimeContext ctx)
deprecated
执行流相关操作。
Performs the stream operation.
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, JsonNode schema, RuntimeContext ctx)
deprecated
执行流相关操作。
Performs the stream operation.
public AgentRun<AgentEvent> prepareRun(List<Msg> msgs, RuntimeContext ctx)
执行 `prepareRun` 方法。
Prepare a cancellable execution covering the complete harness/sandbox lifecycle.
public AgentRun<Msg> prepareCall(List<Msg> msgs, RuntimeContext ctx)
执行 `prepareCall` 方法。
Prepare a cancellable reply execution covering the complete harness/sandbox lifecycle.
public Flux<AgentEvent> streamEvents(Msg msg)
deprecated
执行事件。
Streams the events.
public Flux<AgentEvent> streamEvents(List<Msg> msgs)
deprecated
执行事件。
Streams the events.
public Flux<AgentEvent> streamEvents(Msg msg, RuntimeContext ctx)
执行事件。
Stream fine-grained `AgentEvent`s for a single message with a caller-supplied `RuntimeContext`.
public Flux<AgentEvent> streamEvents(String text)
deprecated
执行事件。
Streams the events.
public Flux<AgentEvent> streamEvents(String text, RuntimeContext ctx)
执行事件。
Stream fine-grained `AgentEvent`s for a plain text input with a caller-supplied `RuntimeContext`.
public Flux<AgentEvent> streamEvents(List<Msg> msgs, RuntimeContext ctx)
执行事件。
Stream fine-grained `AgentEvent`s for a list of messages with a caller-supplied `RuntimeContext`.
public Mono<Void> observe(Msg msg)
接收外部观察消息并写入上下文。
Performs the observe operation.
public Mono<Void> observe(List<Msg> msgs)
接收外部观察消息并写入上下文。
Performs the observe operation.
public Toolkit getToolkit()
获取工具包。
Returns the toolkit.
public static Builder builder()
static
返回构建器实例。
Returns the builder.

方法详情Method Detail

getWorkspaceManager

public WorkspaceManager getWorkspaceManager()

获取工作区管理器。

Returns the workspace manager bound to this agent, or null if not configured.

返回Returns WorkspaceManager
返回WorkspaceManager。Returns workspace manager.
源码Source io/agentscope/harness/agent/HarnessAgent.java:246–248

workspaceFor

public WorkspaceManager workspaceFor(String userId, String sessionId)

执行工作区用于相关操作。

Returns a WorkspaceManager view whose filesystem and namespace are bound to the given (userId, sessionId) for the duration of the returned view's IO.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
返回Returns WorkspaceManager
返回WorkspaceManager。Returns workspace manager.
源码Source io/agentscope/harness/agent/HarnessAgent.java:256–261

getCompactionHook

public CompactionMiddleware getCompactionHook()

获取压缩钩子。

Returns the CompactionMiddleware instance if compaction was configured, or null.

返回Returns CompactionMiddleware
返回CompactionMiddleware。Returns compaction middleware.
源码Source io/agentscope/harness/agent/HarnessAgent.java:264–266

getSkillRepositories

public List<AgentSkillRepository> getSkillRepositories()

获取 getSkillRepositories。

Returns the ordered list of AgentSkillRepository instances bound to this agent (low to high priority).

返回Returns List<AgentSkillRepository>
返回列出。Returns list.
源码Source io/agentscope/harness/agent/HarnessAgent.java:272–274

getSkillUsageStore

public SkillUsageStore getSkillUsageStore()

获取技能用量存储。

Access to the sidecar telemetry store.

返回Returns SkillUsageStore
返回SkillUsageStore。Returns skill usage store.
源码Source io/agentscope/harness/agent/HarnessAgent.java:278–280

queryAudit

public List<SkillAuditLog.Entry> queryAudit(String dayUtc, java.util.function.Predicate<SkillAuditLog.Entry> filter)

查询 queryAudit。

Query the audit log for a given UTC day.

参数Parameters
名称Name类型Type说明Description
dayUtcStringday Utc(类型 `String`)。The day utc.
filterjava.util.function.Predicate<SkillAuditLog.Entry>过滤条件(类型 `java.util.function.Predicate`)。The filter.
返回Returns List<SkillAuditLog.Entry>
返回列出。Returns list.
源码Source io/agentscope/harness/agent/HarnessAgent.java:286–292

runCuratorOnce

public Mono<SkillCurator.CuratorRunReport> runCuratorOnce()

运行 runCuratorOnce。

Force-run the skill curator immediately, bypassing the idle-and-interval gate.

返回Returns Mono<SkillCurator.CuratorRunReport>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:298–303

promoteSkill

public Mono<SkillPromoter.PromotionResult> promoteSkill(String name, String reviewerId, RuntimeContext ctx)

执行 promoteSkill 方法。

Promote a draft skill for the explicitly supplied request context.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。The name.
reviewerIdStringreviewer 标识(类型 `String`)。The reviewer id.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Mono<SkillPromoter.PromotionResult>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:312–321

enterPlanMode

public void enterPlanMode(RuntimeContext ctx)

设置该参数。

Enters plan mode for the session identified by the given RuntimeContext.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
源码Source io/agentscope/harness/agent/HarnessAgent.java:327–329

exitPlanMode

public void exitPlanMode(RuntimeContext ctx)

设置该参数。

Exits plan mode for the session identified by the given RuntimeContext.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
源码Source io/agentscope/harness/agent/HarnessAgent.java:332–334

isPlanModeActive

public boolean isPlanModeActive(RuntimeContext ctx)

判断是否 isPlanModeActive。

Returns whether the plan mode active.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns boolean
返回布尔值,表示判断结果。whether plan mode is active for the session identified by the given `RuntimeContext`.
源码Source io/agentscope/harness/agent/HarnessAgent.java:337–339

clearContext

public void clearContext(RuntimeContext ctx)

清空上下文。

Clears the model-visible conversation context for the session identified by ctx.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。runtime context identifying the session
源码Source io/agentscope/harness/agent/HarnessAgent.java:349–351

clearContext

public void clearContext(String userId, String sessionId)

清空上下文。

Clears the model-visible conversation context for one (userId, sessionId) session.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。user identity for the slot (`null` = anonymous / single-tenant)
sessionIdString会话标识(类型 `String`)。session identity; `null` or blank uses the default session id
源码Source io/agentscope/harness/agent/HarnessAgent.java:362–364

clearStateCache

public void clearStateCache()

清空状态缓存。

Clears all locally cached per-session state and permission engines held by the wrapped ReActAgent.

源码Source io/agentscope/harness/agent/HarnessAgent.java:370–372

clearStateCache

public void clearStateCache(RuntimeContext ctx)

清空状态缓存。

Clears the locally cached state and permission engine for the session identified by ctx.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。runtime context identifying the session
源码Source io/agentscope/harness/agent/HarnessAgent.java:380–382

clearStateCache

public void clearStateCache(String userId, String sessionId)

清空状态缓存。

Clears the locally cached state and permission engine for one (userId, sessionId) slot.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。user identity for the slot (`null` = anonymous / single-tenant)
sessionIdString会话标识(类型 `String`)。session identity; `null` or blank uses the default session id
源码Source io/agentscope/harness/agent/HarnessAgent.java:391–393

enterPlanMode

public void enterPlanMode(String userId, String sessionId)

执行 enterPlanMode 方法。

Enters plan mode for the given (userId, sessionId) session, independent of which slot is currently active.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
源码Source io/agentscope/harness/agent/HarnessAgent.java:400–408

exitPlanMode

public void exitPlanMode(String userId, String sessionId)

执行 exitPlanMode 方法。

Exits plan mode for the given (userId, sessionId) session and persists the change.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
源码Source io/agentscope/harness/agent/HarnessAgent.java:411–419

isPlanModeActive

public boolean isPlanModeActive(String userId, String sessionId)

判断是否 isPlanModeActive。

Returns whether the plan mode active.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
返回Returns boolean
返回布尔值,表示判断结果。whether plan mode is active for the given `(userId, sessionId)` session.
源码Source io/agentscope/harness/agent/HarnessAgent.java:422–425

setPermissionMode

public void setPermissionMode(RuntimeContext ctx, io.agentscope.core.permission.PermissionMode mode)

设置权限模式。

Switches the io.agentscope.core.permission.PermissionMode for the session identified by the given RuntimeContext at runtime.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
modeio.agentscope.core.permission.PermissionMode模式(类型 `io.agentscope.core.permission.PermissionMode`)。The mode.
源码Source io/agentscope/harness/agent/HarnessAgent.java:432–435

setPermissionMode

public void setPermissionMode(String userId, String sessionId, io.agentscope.core.permission.PermissionMode mode)

设置权限模式。

Switches the io.agentscope.core.permission.PermissionMode for the given (userId, sessionId) session at runtime, preserving configured rules and rebuilding the cached permission engine.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
modeio.agentscope.core.permission.PermissionMode模式(类型 `io.agentscope.core.permission.PermissionMode`)。The mode.
源码Source io/agentscope/harness/agent/HarnessAgent.java:442–445

getPermissionMode

public io.agentscope.core.permission.PermissionMode getPermissionMode(String userId, String sessionId)

获取权限模式。

Returns the permission mode.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
返回Returns io.agentscope.core.permission.PermissionMode
返回io.agentscope.核心.权限.PermissionMode。the current permission mode for the given `(userId, sessionId)` session.
源码Source io/agentscope/harness/agent/HarnessAgent.java:448–451

close

public void close()

关闭连接并释放相关资源。

Releases resources and connections.

源码Source io/agentscope/harness/agent/HarnessAgent.java:453–475

getDelegate

public ReActAgent getDelegate()

获取委托。

Returns the wrapped ReActAgent.

返回Returns ReActAgent
返回ReActAgent。Returns ReAct agent.
源码Source io/agentscope/harness/agent/HarnessAgent.java:492–494

getModel

public Model getModel()

获取模型。

Returns the model.

返回Returns Model
返回模型。Returns model.
源码Source io/agentscope/harness/agent/HarnessAgent.java:496–498

getMaxIters

public int getMaxIters()

获取最大迭代次数。

Returns the max iters.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/HarnessAgent.java:500–502

getStateStore

public AgentStateStore getStateStore()

获取状态存储。

Returns the state store.

返回Returns AgentStateStore
返回AgentStateStore。Returns agent state store.
源码Source io/agentscope/harness/agent/HarnessAgent.java:504–506

getDistributedStore

public DistributedStore getDistributedStore()

获取分布式存储。

The distributed store configured on this agent, or null for local deployments.

返回Returns DistributedStore
返回DistributedStore。Returns distributed store.
源码Source io/agentscope/harness/agent/HarnessAgent.java:514–516

getSubagentAgentManager

public io.agentscope.harness.agent.subagent.DefaultAgentManager getSubagentAgentManager()

获取子智能体智能体管理器。

The internal io.agentscope.harness.agent.subagent.DefaultAgentManager able to re-materialize this agent's subagents, or null when none is owned (e.g.

返回Returns io.agentscope.harness.agent.subagent.DefaultAgentManager
返回io.agentscope.Harness.智能体.子智能体.DefaultAgentManager。Returns io agentscope harness agent subagent default agent manager.
源码Source io/agentscope/harness/agent/HarnessAgent.java:523–531

getTaskRepository

public TaskRepository getTaskRepository()

获取任务仓库。

Background subagent TaskRepository owned by the subagent middleware, or null when subagents are not configured.

返回Returns TaskRepository
返回TaskRepository。Returns task repository.
源码Source io/agentscope/harness/agent/HarnessAgent.java:537–545

getDefaultSessionId

public String getDefaultSessionId()

获取默认会话标识。

Returns the default session id.

另见See also @see ReActAgent#getDefaultSessionId()
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/HarnessAgent.java:548–550

getAgentState

public AgentState getAgentState()
deprecated

获取智能体状态。

Returns the agent state.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#getDelegate()`.getAgentState(RuntimeContext)` or `.getAgentState(String, String)` with explicit session identity.
返回Returns AgentState
返回AgentState。Returns agent state.
源码Source io/agentscope/harness/agent/HarnessAgent.java:556–560

getName

public String getName()

获取名称。

Returns the name.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/HarnessAgent.java:562–565

getAgentId

public String getAgentId()

获取智能体标识。

Returns the agent id.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/HarnessAgent.java:567–570

getDescription

public String getDescription()

获取 getDescription。

Returns the description.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/HarnessAgent.java:572–575

interrupt

public void interrupt()

请求中断当前执行。

Returns the interrupt.

源码Source io/agentscope/harness/agent/HarnessAgent.java:577–580

interrupt

public void interrupt(Msg msg)

请求中断当前执行。

Performs the interrupt operation.

参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。The msg.
源码Source io/agentscope/harness/agent/HarnessAgent.java:582–585

interrupt

public void interrupt(RuntimeContext ctx)

请求中断当前执行。

Interrupts the in-flight call for the session identified by ctx.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。runtime context identifying the session to interrupt
源码Source io/agentscope/harness/agent/HarnessAgent.java:592–594

interrupt

public void interrupt(RuntimeContext ctx, Msg msg)

请求中断当前执行。

Interrupts the in-flight call for the session identified by ctx with an associated user message.

参数Parameters
名称Name类型Type说明Description
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。runtime context identifying the session to interrupt
msgMsg消息(类型 `Msg`)。optional user message to attach to the interrupt signal
源码Source io/agentscope/harness/agent/HarnessAgent.java:603–605

interrupt

public void interrupt(String userId, String sessionId)

请求中断当前执行。

Interrupts the in-flight call for a specific (userId, sessionId) session.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。user identity for the slot (`null` = anonymous / single-tenant)
sessionIdString会话标识(类型 `String`)。session identity; `null` or blank uses the default session id
源码Source io/agentscope/harness/agent/HarnessAgent.java:613–615

interrupt

public void interrupt(String userId, String sessionId, Msg msg)

请求中断当前执行。

Interrupts the in-flight call for a specific (userId, sessionId) session with an associated user message.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
msgMsg消息(类型 `Msg`)。The msg.
源码Source io/agentscope/harness/agent/HarnessAgent.java:621–623

channel

public T extends Channel T channel(T channel)

设置渠道。

Returns a channel bound to this agent's internal gateway.

参数Parameters
名称Name类型Type说明Description
channelT渠道(类型 `T`)。the channel instance to bind (e.g. `ChatUiChannel.perPeer()`)
返回Returns T
返回T。the same channel instance, now wired to this agent's gateway
源码Source io/agentscope/harness/agent/HarnessAgent.java:646–650

gateway

public HarnessGateway gateway()

返回网关。

Returns the internal gateway backing #channel.

返回Returns HarnessGateway
返回HarnessGateway。Returns harness gateway.
源码Source io/agentscope/harness/agent/HarnessAgent.java:656–659

call

public Mono<Msg> call(List<Msg> msgs)
deprecated

向智能体发送输入并返回最终回复。

Performs the call operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#call(List, RuntimeContext)` with explicit runtime context.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:707–711

call

public Mono<Msg> call(List<Msg> msgs, Class<?> structuredModel)
deprecated

向智能体发送输入并返回最终回复。

Performs the call operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#call(List, Class, RuntimeContext)` with explicit runtime context.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
structuredModelClass<?>结构化模型(类型 `Class`)。The structured model.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:716–721

call

public Mono<Msg> call(List<Msg> msgs, JsonNode schema)
deprecated

向智能体发送输入并返回最终回复。

Performs the call operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#call(List, JsonNode, RuntimeContext)` with explicit runtime context.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
schemaJsonNode模式定义(类型 `JsonNode`)。The schema.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:726–730

call

public Mono<Msg> call(Msg msg, RuntimeContext ctx)

向智能体发送输入并返回最终回复。

Performs the call operation.

参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。The msg.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:732–734

call

public Mono<Msg> call(String text, RuntimeContext ctx)

向智能体发送输入并返回最终回复。

Calls the agent with a plain text input and per-call RuntimeContext.

参数Parameters
名称Name类型Type说明Description
textString文本(类型 `String`)。input text (wrapped into a `UserMessage`)
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。per-call runtime context
返回Returns Mono<Msg>
返回Mono。response message
源码Source io/agentscope/harness/agent/HarnessAgent.java:743–745

call

public Mono<Msg> call(List<Msg> msgs, RuntimeContext ctx)

向智能体发送输入并返回最终回复。

Performs the call operation.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:747–751

call

public Mono<Msg> call(List<Msg> msgs, Class<?> structuredModel, RuntimeContext ctx)

向智能体发送输入并返回最终回复。

Performs the call operation.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
structuredModelClass<?>结构化模型(类型 `Class`)。The structured model.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:753–757

call

public Mono<Msg> call(List<Msg> msgs, JsonNode schema, RuntimeContext ctx)

向智能体发送输入并返回最终回复。

Performs the call operation.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
schemaJsonNode模式定义(类型 `JsonNode`)。The schema.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:759–763

stream

public Flux<Event> stream(List<Msg> msgs, StreamOptions options)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(List)` for the fine-grained `AgentEvent` stream that aligns with Python 2.0's `agent.reply_stream()`.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
optionsStreamOptions选项(类型 `StreamOptions`)。The options.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:769–773

stream

public Flux<Event> stream(List<Msg> msgs, StreamOptions options, Class<?> structuredModel)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(List)` for the fine-grained `AgentEvent` stream.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
optionsStreamOptions选项(类型 `StreamOptions`)。The options.
structuredModelClass<?>结构化模型(类型 `Class`)。The structured model.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:779–784

stream

public Flux<Event> stream(List<Msg> msgs, StreamOptions options, JsonNode schema)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(List)` for the fine-grained `AgentEvent` stream.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
optionsStreamOptions选项(类型 `StreamOptions`)。The options.
schemaJsonNode模式定义(类型 `JsonNode`)。The schema.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:790–794

stream

public Flux<Event> stream(Msg msg, RuntimeContext ctx)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(Msg, RuntimeContext)`.
参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。The msg.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:799–802

stream

public Flux<Event> stream(List<Msg> msgs, RuntimeContext ctx)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(List, RuntimeContext)`.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:807–810

stream

public Flux<Event> stream(List<Msg> msgs, StreamOptions options, RuntimeContext ctx)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(List, RuntimeContext)`.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
optionsStreamOptions选项(类型 `StreamOptions`)。The options.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:815–820

stream

public Flux<Event> stream(List<Msg> msgs, StreamOptions options, Class<?> structuredModel, RuntimeContext ctx)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(List, RuntimeContext)`.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
optionsStreamOptions选项(类型 `StreamOptions`)。The options.
structuredModelClass<?>结构化模型(类型 `Class`)。The structured model.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:825–832

stream

public Flux<Event> stream(List<Msg> msgs, StreamOptions options, JsonNode schema, RuntimeContext ctx)
deprecated

执行流相关操作。

Performs the stream operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `#streamEvents(List, RuntimeContext)`.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
optionsStreamOptions选项(类型 `StreamOptions`)。The options.
schemaJsonNode模式定义(类型 `JsonNode`)。The schema.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns Flux<Event>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:837–843

prepareRun

public AgentRun<AgentEvent> prepareRun(List<Msg> msgs, RuntimeContext ctx)

执行 prepareRun 方法。

Prepare a cancellable execution covering the complete harness/sandbox lifecycle.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns AgentRun<AgentEvent>
返回AgentRun。Returns agent run.
源码Source io/agentscope/harness/agent/HarnessAgent.java:846–848

prepareCall

public AgentRun<Msg> prepareCall(List<Msg> msgs, RuntimeContext ctx)

执行 prepareCall 方法。

Prepare a cancellable reply execution covering the complete harness/sandbox lifecycle.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
返回Returns AgentRun<Msg>
返回AgentRun。Returns agent run.
源码Source io/agentscope/harness/agent/HarnessAgent.java:851–853

streamEvents

public Flux<AgentEvent> streamEvents(Msg msg)
deprecated

执行事件。

Streams the events.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#streamEvents(Msg, RuntimeContext)` with explicit runtime context.
参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。The msg.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:860–863

streamEvents

public Flux<AgentEvent> streamEvents(List<Msg> msgs)
deprecated

执行事件。

Streams the events.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#streamEvents(List, RuntimeContext)` with explicit runtime context.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:868–871

streamEvents

public Flux<AgentEvent> streamEvents(Msg msg, RuntimeContext ctx)

执行事件。

Stream fine-grained AgentEvents for a single message with a caller-supplied RuntimeContext.

参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。input message
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。runtime context to propagate into the call
返回Returns Flux<AgentEvent>
返回Flux。event stream covering the full agent invocation lifecycle
源码Source io/agentscope/harness/agent/HarnessAgent.java:881–883

streamEvents

public Flux<AgentEvent> streamEvents(String text)
deprecated

执行事件。

Streams the events.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#streamEvents(String, RuntimeContext)` with explicit runtime context.
参数Parameters
名称Name类型Type说明Description
textString文本(类型 `String`)。The text.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/HarnessAgent.java:888–891

streamEvents

public Flux<AgentEvent> streamEvents(String text, RuntimeContext ctx)

执行事件。

Stream fine-grained AgentEvents for a plain text input with a caller-supplied RuntimeContext.

参数Parameters
名称Name类型Type说明Description
textString文本(类型 `String`)。input text (wrapped into a `UserMessage`)
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。runtime context to propagate into the call
返回Returns Flux<AgentEvent>
返回Flux。event stream covering the full agent invocation lifecycle
源码Source io/agentscope/harness/agent/HarnessAgent.java:901–903

streamEvents

public Flux<AgentEvent> streamEvents(List<Msg> msgs, RuntimeContext ctx)

执行事件。

Stream fine-grained AgentEvents for a list of messages with a caller-supplied RuntimeContext.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。input messages
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。runtime context to propagate into the call
返回Returns Flux<AgentEvent>
返回Flux。event stream covering the full agent invocation lifecycle
源码Source io/agentscope/harness/agent/HarnessAgent.java:920–924

observe

public Mono<Void> observe(Msg msg)

接收外部观察消息并写入上下文。

Performs the observe operation.

参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。The msg.
返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:926–929

observe

public Mono<Void> observe(List<Msg> msgs)

接收外部观察消息并写入上下文。

Performs the observe operation.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/HarnessAgent.java:931–934

getToolkit

public Toolkit getToolkit()

获取工具包。

Returns the toolkit.

返回Returns Toolkit
返回工具包。Returns toolkit.
源码Source io/agentscope/harness/agent/HarnessAgent.java:936–938

builder

public static Builder builder()
static

返回构建器实例。

Returns the builder.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/harness/agent/HarnessAgent.java:1118–1120

嵌套类详情Nested Class Detail

Builder

public static class Builder

HarnessAgent的构建器。位于 io.agentscope.harness.agent 包。核心成员包括 teamsMode、fromAgent、name、description、sysPrompt、checkRunning。

Builder for HarnessAgent. Owns the harness orchestration: workspace + filesystem + sandbox + hooks/middlewares + tools + skills + subagents + tools.json + plan-mode.

继承成员Inherited Members

继承自Methods inherited from CallableAgent
继承自Methods inherited from StreamableAgent
基于官方固定版本源码静态生成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.