AgentBase
@SuppressWarnings("deprecation") public abstract class AgentBase implements Agent
io/agentscope/core/agent/AgentBase.java:90–1027AgentBase 实现所有智能体共享的生命周期:运行互斥、拦截器、状态恢复、结构化输出分派与协作式中断。自定义智能体通常继承它并实现 doCall。位于 io.agentscope.core.agent 包,实现 Agent。核心成员包括 getAgentId、getName、getDescription、isCheckRunning、call、callInternal。
Abstract base class for all agents in the AgentScope framework.
This class provides common functionality for agents including basic hook integration, MsgHub subscriber management, interrupt handling, tracing, and state management through StateModule. It does NOT manage memory - that is the responsibility of specific agent implementations like ReActAgent.
Design Philosophy:
-
AgentBase provides infrastructure (hooks, subscriptions, interrupt, state) but not domain logic
-
Memory management is delegated to concrete agents that need it (e.g., ReActAgent)
-
State management implements StateModule interface
-
Interrupt mechanism uses reactive patterns: subclasses call checkInterruptedAsync() at appropriate checkpoints, which propagates InterruptedException through Mono chain
-
Observe pattern: agents can receive messages without generating a reply
Thread Safety: The base lifecycle keeps execution state per subscription. Subclasses define serialization through callSerializationKey; ReActAgent serializes calls within each session. Configure hooks before invoking the agent rather than mutating configuration while calls are running.
Interrupt Mechanism:
`// External call to interrupt
agent.interrupt(userMsg);
// Inside agent's Mono chain, at checkpoints:
return checkInterruptedAsync()
.then(doWork())
.flatMap(result -> checkInterruptedAsync().thenReturn(result));
// AgentBase.call() catches the exception:
.onErrorResume(error -> {
if (error instanceof InterruptedException) {
return handleInterrupt(context, msg);
}
...
});
`
核心精讲Deep dive
AgentBase:智能体生命周期AgentBase: the agent lifecycle
AgentBase 实现所有智能体共享的生命周期:运行互斥、拦截器、状态恢复、结构化输出分派与协作式中断。自定义智能体通常继承它并实现 doCall。
AgentBase implements the lifecycle shared by all agents: run mutual exclusion, hooks, state restoration, structured output dispatch and cooperative interruption. Custom agents typically extend it and implement doCall.
- call 负责生命周期,doCall 是子类实现的单次推理入口。call owns the lifecycle, while doCall is the subclass hook for one reasoning pass.
- checkRunning 防止同一智能体并发执行,interrupt 触发协作式取消。checkRunning prevents concurrent execution on one agent, and interrupt triggers cooperative cancellation.
- 结构化输出重载会把结果写入 Msg 的 structured data。Structured-output overloads store the result in the Msg structured data.
自定义智能体的最小骨架Minimal custom agent skeleton
import io.agentscope.core.agent.AgentBase;
import io.agentscope.core.message.Msg;
import io.agentscope.core.message.MsgRole;
import java.util.List;
import reactor.core.publisher.Mono;
public final class EchoAgent extends AgentBase {
public EchoAgent() {
super("echo");
}
@Override
protected Mono<Msg> doCall(List<Msg> msgs) {
Msg last = msgs.get(msgs.size() - 1);
return Mono.just(Msg.builderForRole(last.getRole())
.name("echo")
.textContent(last.getTextContent())
.build());
}
public static void main(String[] args) {
Msg reply = new EchoAgent().call(List.of(
Msg.builderForRole(MsgRole.USER)
.name("user")
.textContent("Hello")
.build()
)).block();
System.out.println(reply.getTextContent());
}
}字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
CALL_SCOPE_KEYstaticfinal | String | 调用范围键字段。 Reactor Context key carrying the per-call scope object returned by `#beforeAgentExecution(List, RuntimeContext, RunControl)`. |
RUNTIME_CONTEXT_KEYstaticfinal | String | 运行时上下文键字段。 Reactor Context key carrying the caller-supplied per-call `RuntimeContext`. |
SHUTDOWN_REQUEST_ID_KEYstaticfinal | String | SHUTDOWN 请求标识键字段。 Reactor Context key carrying this call's graceful-shutdown `requestId` (issued by `GracefulShutdownManager#registerRequest`). |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public AgentBase(String name) | 创建智能体基类实例。 Constructor for AgentBase. |
public AgentBase(String name, String description) | 创建智能体基类实例。 Constructor for AgentBase. |
public AgentBase(String name, String description, boolean checkRunning, List<Hook> hooks)deprecated | 创建智能体基类实例。 Creates a new instance. |
public AgentBase(String name, String description, List<Hook> hooks) | 创建智能体基类实例。 Constructor for AgentBase with hooks. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public final String getAgentId()final | 返回智能体 ID。 Returns the agent id. |
public final String getName()final | 返回智能体名称。 Returns the name. |
public final String getDescription()final | 返回智能体描述。 Returns the description. |
public final boolean isCheckRunning()finaldeprecated | 判断是否检查运行中。 Returns whether the check running. |
public final Mono<Msg> call(List<Msg> msgs)final | 执行一次调用并管理生命周期。 Process a list of input messages and generate a response with hook execution. |
protected Mono<Msg> callInternal(List<Msg> msgs, RuntimeContext context, Function<List<Msg>, Mono<Msg>> doCallFn) | 调用内部。 Extension point called by every `call()` overload, allowing subclasses to wrap the
entire invocation in additional middleware (e.g. |
protected final void interruptRunning(Object key, InterruptSource source, Msg message)final | 中断指定键上正在运行的调用。 Session-level interruption targets only the execution currently admitted for this key. |
protected Mono<Msg> runLifecycle(List<Msg> msgs, Function<List<Msg>, Mono<Msg>> doCallFn) | 运行生命周期。 Shared `call()` lifecycle: acquire execution, then (inside `deferContextual` so
the caller-supplied `RuntimeContext` is read per-subscription) run `#beforeAgentExecution(List, RuntimeContext, RunControl)` (which returns this call's per-call scope), carry
that scope on the Reactor Context, and run the preCall → doCall → postCall chain with error
handling, releasing execution on terminate. |
protected Object callSerializationKey(RuntimeContext rc) | 调用序列化键。 Returns a key that serializes concurrent calls sharing it: calls with an equal, non-null key
run one-at-a-time in FIFO order, while calls with different keys (or a `null` key) run
concurrently. |
public final Mono<Msg> call(List<Msg> msgs, Class<?> structuredOutputClass)final | 执行一次调用并管理生命周期。 Process multiple input messages and generate structured output with hook execution. |
public final Mono<Msg> call(List<Msg> msgs, JsonNode schema)final | 执行一次调用并管理生命周期。 Process multiple input messages and generate structured output with hook execution. |
protected abstract Mono<Msg> doCall(List<Msg> msgs)abstract | 子类实现的单次推理入口。 Internal implementation for processing multiple input messages. |
protected Mono<Msg> doCall(List<Msg> msgs, Class<?> structuredOutputClass) | 子类实现的单次推理入口。 Internal implementation for processing multiple messages with structured output. |
protected Mono<Msg> doCall(List<Msg> msgs, JsonNode outputSchema) | 子类实现的单次推理入口。 Internal implementation for processing multiple messages with structured output. |
public static void addSystemHook(Hook hook)static | 添加系统钩子。 Adds the system hook. |
public static void removeSystemHook(Hook hook)static | 移除系统钩子。 Removes the system hook. |
public void interrupt()deprecated | 请求中断当前执行。 Returns the interrupt. |
public void interrupt(Msg msg)deprecated | 请求中断当前执行。 Performs the interrupt operation. |
public void interrupt(InterruptSource source)deprecated | 请求中断当前执行。 Performs the interrupt operation. |
protected Mono<Void> checkInterruptedAsync()deprecated | 检查 `checkInterruptedAsync` 条件。 Returns the check interrupted async. |
protected void resetInterruptFlag()deprecated | 重置中断开关。 Resets the interrupt flag. |
protected AtomicBoolean getInterruptFlag()deprecated | 获取中断开关。 Returns the interrupt flag. |
protected InterruptSource getInterruptSource()deprecated | 获取中断来源。 Returns the interrupt source. |
protected Mono<Void> doObserve(Msg msg) | 执行观察操作。 Observe a message without generating a reply. |
protected abstract Mono<Msg> handleInterrupt(InterruptContext context, Msg... originalArgs)abstract | 处理中断。 Handle an interruption that occurred during execution. |
public AgentState getAgentState() | 获取智能体状态。 Returns the agent's mutable runtime state, or `null` if this agent type does not
maintain an `AgentState`. |
protected Object beforeAgentExecution(List<Msg> msgs, RuntimeContext rc, RunControl control) | 在智能体执行前调用。 Invoked at the start of a `call` / stream-backed call, after `#acquireExecution` and before any hooks. |
protected void afterAgentExecution() | 在智能体执行后调用。 Invoked in `Mono.using` cleanup, before clearing the running state. |
public List<Hook> getHooks() | 获取 `getHooks`。 Get the list of hooks for this agent. |
protected void addHook(Hook hook) | 添加钩子。 Add a hook to this agent dynamically. |
protected void removeHook(Hook hook) | 移除钩子。 Remove a hook from this agent dynamically. |
public List<Hook> getSortedHooks() | 获取 `getSortedHooks`。 Get hooks sorted by priority (lower value = higher priority). |
protected Mono<Msg> seedSystemMsg(Object callScope) | 设置预置系统消息。 Returns the initial system message to seed into `PreCallEvent` before hooks run. |
protected AgentState stateForCall(Object callScope) | 设置调用时使用的状态。 Returns the `AgentState` whose conversation buffer should seed the pre-call memory
snapshot for this invocation. |
protected void consumeSystemMsgAfterPreCall(Msg systemMsg, Object callScope) | 执行消费系统消息之后前置调用相关操作。 Called after `PreCallEvent` hooks have run, with the final system message value. |
public void removeSubscribers(String hubId) | 移除 `removeSubscribers`。 Remove all subscribers for a specific MsgHub. |
public void resetSubscribers(String hubId, List<AgentBase> subscribers) | 重置 `resetSubscribers`。 Reset the subscriber list for a specific MsgHub. |
public boolean hasSubscribers() | 判断是否具有 `hasSubscribers`。 Check if this agent has any subscribers. |
public int getSubscriberCount() | 获取 `getSubscriberCount`。 Get the total number of subscribers across all MsgHubs. |
public final Mono<Void> observe(Msg msg)final | 接收外部观察消息并写入上下文。 Observe a single message without generating a reply. |
public final Mono<Void> observe(List<Msg> msgs)final | 接收外部观察消息并写入上下文。 Observe multiple messages without generating a reply. |
public Flux<Event> stream(List<Msg> msgs, StreamOptions options)deprecated | 执行流相关操作。 Stream with multiple input messages. |
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, Class<?> structuredModel)deprecated | 执行流相关操作。 Stream with multiple input messages. |
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, JsonNode schema)deprecated | 执行流相关操作。 Stream with multiple input messages using a JSON schema. |
public String toString() | 返回 `toString` 结果。 Returns the to string. |
字段详情Field Detail
CALL_SCOPE_KEY
public static final String CALL_SCOPE_KEY
调用范围键字段。声明为 public static final String CALL_SCOPE_KEY。
Reactor Context key carrying the per-call scope object returned by #beforeAgentExecution(List, RuntimeContext, RunControl).
io/agentscope/core/agent/AgentBase.java:228RUNTIME_CONTEXT_KEY
public static final String RUNTIME_CONTEXT_KEY
运行时上下文键字段。声明为 public static final String RUNTIME_CONTEXT_KEY。
Reactor Context key carrying the caller-supplied per-call RuntimeContext.
io/agentscope/core/agent/AgentBase.java:236–237SHUTDOWN_REQUEST_ID_KEY
public static final String SHUTDOWN_REQUEST_ID_KEY
SHUTDOWN 请求标识键字段。声明为 public static final String SHUTDOWN_REQUEST_ID_KEY。
Reactor Context key carrying this call's graceful-shutdown requestId (issued by GracefulShutdownManager#registerRequest).
io/agentscope/core/agent/AgentBase.java:246–247构造器详情Constructor Detail
AgentBase
public AgentBase(String name)
初始化 AgentBase 实例。
Constructor for AgentBase.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。Agent name |
io/agentscope/core/agent/AgentBase.java:115–117AgentBase
public AgentBase(String name, String description)
初始化 AgentBase 实例。
Constructor for AgentBase.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。Agent name |
description | String | 描述(类型 `String`)。Agent description |
io/agentscope/core/agent/AgentBase.java:125–127AgentBase
public AgentBase(String name, String description, boolean checkRunning, List<Hook> hooks)
初始化 AgentBase 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。The name. |
description | String | 描述(类型 `String`)。The description. |
checkRunning | boolean | 检查运行中(类型 `boolean`)。The check running. |
hooks | List<Hook> | hooks(类型 `List`)。The hooks. |
io/agentscope/core/agent/AgentBase.java:132–135AgentBase
public AgentBase(String name, String description, List<Hook> hooks)
初始化 AgentBase 实例。
Constructor for AgentBase with hooks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。Agent name |
description | String | 描述(类型 `String`)。Agent description |
hooks | List<Hook> | hooks(类型 `List`)。List of hooks for monitoring/intercepting execution |
io/agentscope/core/agent/AgentBase.java:144–151方法详情Method Detail
getAgentId
public final String getAgentId()
获取智能体标识。
Returns the agent id.
Stringio/agentscope/core/agent/AgentBase.java:153–156getName
public final String getName()
获取名称。
Returns the name.
Stringio/agentscope/core/agent/AgentBase.java:158–161getDescription
public final String getDescription()
获取 getDescription。
Returns the description.
Stringio/agentscope/core/agent/AgentBase.java:163–166isCheckRunning
public final boolean isCheckRunning()
判断是否检查运行中。
Returns whether the check running.
booleanio/agentscope/core/agent/AgentBase.java:169–172call
public final Mono<Msg> call(List<Msg> msgs)
向智能体发送输入并返回最终回复。
Process a list of input messages and generate a response with hook execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:182–185callInternal
protected Mono<Msg> callInternal(List<Msg> msgs, RuntimeContext context, Function<List<Msg>, Mono<Msg>> doCallFn)
调用内部。
Extension point called by every call() overload, allowing subclasses to wrap the entire invocation in additional middleware (e.g.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。input messages |
context | RuntimeContext | 上下文(类型 `RuntimeContext`)。caller-supplied per-call `RuntimeContext`, or `null` |
doCallFn | Function<List<Msg>, Mono<Msg>> | 执行调用 Fn(类型 `Function , Mono >`)。the concrete call implementation (`#doCall` or a structured-output variant) |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:203–209interruptRunning
protected final void interruptRunning(Object key, InterruptSource source, Msg message)
执行中断运行中相关操作。
Session-level interruption targets only the execution currently admitted for this key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | Object | 键(类型 `Object`)。The key. |
source | InterruptSource | 来源(类型 `InterruptSource`)。The source. |
message | Msg | 消息(类型 `Msg`)。The message. |
io/agentscope/core/agent/AgentBase.java:215–220runLifecycle
protected Mono<Msg> runLifecycle(List<Msg> msgs, Function<List<Msg>, Mono<Msg>> doCallFn)
运行生命周期。
Shared call() lifecycle: acquire execution, then (inside deferContextual so the caller-supplied RuntimeContext is read per-subscription) run #beforeAgentExecution(List, RuntimeContext, RunControl) (which returns this call's per-call scope), carry that scope on the Reacto…
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
doCallFn | Function<List<Msg>, Mono<Msg>> | 执行调用 Fn(类型 `Function , Mono >`)。The do call fn. |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:256–262callSerializationKey
protected Object callSerializationKey(RuntimeContext rc)
调用序列化键。
Returns a key that serializes concurrent calls sharing it: calls with an equal, non-null key run one-at-a-time in FIFO order, while calls with different keys (or a null key) run concurrently.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。the caller-supplied per-call `RuntimeContext` (may be `null`) |
Objectio/agentscope/core/agent/AgentBase.java:364–366call
public final Mono<Msg> call(List<Msg> msgs, Class<?> structuredOutputClass)
向智能体发送输入并返回最终回复。
Process multiple input messages and generate structured output with hook execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
structuredOutputClass | Class<?> | 结构化输出类(类型 `Class`)。Class defining the structure of the output |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:408–411call
public final Mono<Msg> call(List<Msg> msgs, JsonNode schema)
向智能体发送输入并返回最终回复。
Process multiple input messages and generate structured output with hook execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
schema | JsonNode | 模式定义(类型 `JsonNode`)。com.fasterxml.jackson.databind.JsonNode instance defining the structure of the output |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:422–425doCall
protected abstract Mono<Msg> doCall(List<Msg> msgs)
执行调用操作。
Internal implementation for processing multiple input messages.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:434doCall
protected Mono<Msg> doCall(List<Msg> msgs, Class<?> structuredOutputClass)
执行调用操作。
Internal implementation for processing multiple messages with structured output.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
structuredOutputClass | Class<?> | 结构化输出类(类型 `Class`)。Class defining the structure |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:445–449doCall
protected Mono<Msg> doCall(List<Msg> msgs, JsonNode outputSchema)
执行调用操作。
Internal implementation for processing multiple messages with structured output.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
outputSchema | JsonNode | 输出模式(类型 `JsonNode`)。com.fasterxml.jackson.databind.JsonNode instance defining the structure |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:460–464addSystemHook
public static void addSystemHook(Hook hook)
添加系统钩子。
Adds the system hook.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hook | Hook | 钩子(类型 `Hook`)。The hook. |
io/agentscope/core/agent/AgentBase.java:466–468removeSystemHook
public static void removeSystemHook(Hook hook)
移除系统钩子。
Removes the system hook.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hook | Hook | 钩子(类型 `Hook`)。The hook. |
io/agentscope/core/agent/AgentBase.java:470–472interrupt
public void interrupt()
请求中断当前执行。
Returns the interrupt.
io/agentscope/core/agent/AgentBase.java:475–477interrupt
public void interrupt(Msg msg)
请求中断当前执行。
Performs the interrupt operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息(类型 `Msg`)。The msg. |
io/agentscope/core/agent/AgentBase.java:480–482interrupt
public void interrupt(InterruptSource source)
请求中断当前执行。
Performs the interrupt operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
source | InterruptSource | 来源(类型 `InterruptSource`)。The source. |
io/agentscope/core/agent/AgentBase.java:485–486checkInterruptedAsync
protected Mono<Void> checkInterruptedAsync()
检查 checkInterruptedAsync 条件。
Returns the check interrupted async.
Mono<Void>io/agentscope/core/agent/AgentBase.java:489–492resetInterruptFlag
protected void resetInterruptFlag()
重置中断开关。
Resets the interrupt flag.
io/agentscope/core/agent/AgentBase.java:495–496getInterruptFlag
protected AtomicBoolean getInterruptFlag()
获取中断开关。
Returns the interrupt flag.
AtomicBooleanio/agentscope/core/agent/AgentBase.java:534–537getInterruptSource
protected InterruptSource getInterruptSource()
获取中断来源。
Returns the interrupt source.
InterruptSourceio/agentscope/core/agent/AgentBase.java:540–543doObserve
protected Mono<Void> doObserve(Msg msg)
执行观察操作。
Observe a message without generating a reply.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息到观察。The message to observe |
Mono<Void>io/agentscope/core/agent/AgentBase.java:560–562handleInterrupt
protected abstract Mono<Msg> handleInterrupt(InterruptContext context, Msg... originalArgs)
处理中断。
Handle an interruption that occurred during execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | InterruptContext | 上下文(类型 `InterruptContext`)。The interrupt context containing metadata about the interruption |
originalArgs varargs | Msg... | original 参数(类型 `Msg...`)。The original arguments passed to the call() method (empty, single Msg, or List) |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:580getAgentState
public AgentState getAgentState()
获取智能体状态。
Returns the agent's mutable runtime state, or null if this agent type does not maintain an AgentState.
AgentStateio/agentscope/core/agent/AgentBase.java:586–588beforeAgentExecution
protected Object beforeAgentExecution(List<Msg> msgs, RuntimeContext rc, RunControl control)
在智能体执行前调用。
Invoked at the start of a call / stream-backed call, after #acquireExecution and before any hooks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。the messages passed by the caller to `call()` |
rc | RuntimeContext | rc(类型 `RuntimeContext`)。the caller-supplied per-call `RuntimeContext`, or `null` when none was provided (read from the Reactor Context, so concurrency-safe) |
control | RunControl | control(类型 `RunControl`)。this execution's independent interruption and cancellation control |
Objectio/agentscope/core/agent/AgentBase.java:605–607afterAgentExecution
protected void afterAgentExecution()
在智能体执行后调用。
Invoked in Mono.using cleanup, before clearing the running state.
io/agentscope/core/agent/AgentBase.java:613getHooks
public List<Hook> getHooks()
获取 getHooks。
Get the list of hooks for this agent.
List<Hook>io/agentscope/core/agent/AgentBase.java:621–623addHook
protected void addHook(Hook hook)
添加钩子。
Add a hook to this agent dynamically.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hook | Hook | 钩子到添加。The hook to add |
io/agentscope/core/agent/AgentBase.java:633–638removeHook
protected void removeHook(Hook hook)
移除钩子。
Remove a hook from this agent dynamically.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hook | Hook | 钩子到移除。The hook to remove |
io/agentscope/core/agent/AgentBase.java:652–656getSortedHooks
public List<Hook> getSortedHooks()
获取 getSortedHooks。
Get hooks sorted by priority (lower value = higher priority).
List<Hook>io/agentscope/core/agent/AgentBase.java:664–666seedSystemMsg
protected Mono<Msg> seedSystemMsg(Object callScope)
设置预置系统消息。
Returns the initial system message to seed into PreCallEvent before hooks run.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
callScope | Object | 调用范围(类型 `Object`)。the per-call scope captured at call entry (may be `null`); lets subclasses resolve the call's `RuntimeContext` for system-prompt middlewares without reading a shared instance field |
Mono<Msg>io/agentscope/core/agent/AgentBase.java:679–681stateForCall
protected AgentState stateForCall(Object callScope)
设置调用时使用的状态。
Returns the AgentState whose conversation buffer should seed the pre-call memory snapshot for this invocation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
callScope | Object | 调用范围(类型 `Object`)。the per-call scope captured at call entry (may be `null`) |
AgentStateio/agentscope/core/agent/AgentBase.java:692–694consumeSystemMsgAfterPreCall
protected void consumeSystemMsgAfterPreCall(Msg systemMsg, Object callScope)
执行消费系统消息之后前置调用相关操作。
Called after PreCallEvent hooks have run, with the final system message value.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
systemMsg | Msg | 系统消息(类型 `Msg`)。the system message produced by all PreCall hooks (may be null) |
callScope | Object | 调用范围(类型 `Object`)。the per-call scope captured at call entry (see `#beforeAgentExecution(List, RuntimeContext, RunControl)`); may be `null` |
io/agentscope/core/agent/AgentBase.java:707removeSubscribers
public void removeSubscribers(String hubId)
移除 removeSubscribers。
Remove all subscribers for a specific MsgHub.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hubId | String | 中心标识(类型 `String`)。MsgHub identifier |
io/agentscope/core/agent/AgentBase.java:824–826resetSubscribers
public void resetSubscribers(String hubId, List<AgentBase> subscribers)
重置 resetSubscribers。
Reset the subscriber list for a specific MsgHub.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
hubId | String | 中心标识(类型 `String`)。MsgHub identifier |
subscribers | List<AgentBase> | subscribers(类型 `List`)。New list of subscribers (will be copied) |
io/agentscope/core/agent/AgentBase.java:836–838hasSubscribers
public boolean hasSubscribers()
判断是否具有 hasSubscribers。
Check if this agent has any subscribers.
booleanio/agentscope/core/agent/AgentBase.java:846–849getSubscriberCount
public int getSubscriberCount()
获取 getSubscriberCount。
Get the total number of subscribers across all MsgHubs.
intio/agentscope/core/agent/AgentBase.java:857–859observe
public final Mono<Void> observe(Msg msg)
接收外部观察消息并写入上下文。
Observe a single message without generating a reply.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息(类型 `Msg`)。Message to observe |
Mono<Void>io/agentscope/core/agent/AgentBase.java:886–889observe
public final Mono<Void> observe(List<Msg> msgs)
接收外部观察消息并写入上下文。
Observe multiple messages without generating a reply.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Messages to observe |
Mono<Void>io/agentscope/core/agent/AgentBase.java:898–904stream
public Flux<Event> stream(List<Msg> msgs, StreamOptions options)
执行流相关操作。
Stream with multiple input messages.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
options | StreamOptions | 选项(类型 `StreamOptions`)。Stream configuration options |
Flux<Event>io/agentscope/core/agent/AgentBase.java:915–919stream
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, Class<?> structuredModel)
执行流相关操作。
Stream with multiple input messages.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
options | StreamOptions | 选项(类型 `StreamOptions`)。Stream configuration options |
structuredModel | Class<?> | 结构化模型(类型 `Class`)。Optional class defining the structure |
Flux<Event>io/agentscope/core/agent/AgentBase.java:931–935stream
public Flux<Event> stream(List<Msg> msgs, StreamOptions options, JsonNode schema)
执行流相关操作。
Stream with multiple input messages using a JSON schema.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages |
options | StreamOptions | 选项(类型 `StreamOptions`)。Stream configuration options |
schema | JsonNode | 模式定义(类型 `JsonNode`)。JSON schema defining the structure of the response |
Flux<Event>io/agentscope/core/agent/AgentBase.java:947–951toString
public String toString()
返回 toString 结果。
Returns the to string.
Stringio/agentscope/core/agent/AgentBase.java:1023–1026