AS AgentScopeAPI 手册 / API Reference

AgentBase

@SuppressWarnings("deprecation") public abstract class AgentBase implements Agent
源码Source io/agentscope/core/agent/AgentBase.java:90–1027

AgentBase 实现所有智能体共享的生命周期:运行互斥、拦截器、状态恢复、结构化输出分派与协作式中断。自定义智能体通常继承它并实现 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_KEY
staticfinal
String
调用范围键字段。
Reactor Context key carrying the per-call scope object returned by `#beforeAgentExecution(List, RuntimeContext, RunControl)`.
RUNTIME_CONTEXT_KEY
staticfinal
String
运行时上下文键字段。
Reactor Context key carrying the caller-supplied per-call `RuntimeContext`.
SHUTDOWN_REQUEST_ID_KEY
staticfinal
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
staticfinal

调用范围键字段。声明为 public static final String CALL_SCOPE_KEY。

Reactor Context key carrying the per-call scope object returned by #beforeAgentExecution(List, RuntimeContext, RunControl).

源码Source io/agentscope/core/agent/AgentBase.java:228

RUNTIME_CONTEXT_KEY

public static final String RUNTIME_CONTEXT_KEY
staticfinal

运行时上下文键字段。声明为 public static final String RUNTIME_CONTEXT_KEY。

Reactor Context key carrying the caller-supplied per-call RuntimeContext.

源码Source io/agentscope/core/agent/AgentBase.java:236–237

SHUTDOWN_REQUEST_ID_KEY

public static final String SHUTDOWN_REQUEST_ID_KEY
staticfinal

SHUTDOWN 请求标识键字段。声明为 public static final String SHUTDOWN_REQUEST_ID_KEY。

Reactor Context key carrying this call's graceful-shutdown requestId (issued by GracefulShutdownManager#registerRequest).

源码Source io/agentscope/core/agent/AgentBase.java:246–247

构造器详情Constructor Detail

AgentBase

public AgentBase(String name)

初始化 AgentBase 实例。

Constructor for AgentBase.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。Agent name
源码Source io/agentscope/core/agent/AgentBase.java:115–117

AgentBase

public AgentBase(String name, String description)

初始化 AgentBase 实例。

Constructor for AgentBase.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。Agent name
descriptionString描述(类型 `String`)。Agent description
源码Source io/agentscope/core/agent/AgentBase.java:125–127

AgentBase

public AgentBase(String name, String description, boolean checkRunning, List<Hook> hooks)
deprecated

初始化 AgentBase 实例。

Creates a new instance.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `#AgentBase(String, String, List)` instead.
参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。The name.
descriptionString描述(类型 `String`)。The description.
checkRunningboolean检查运行中(类型 `boolean`)。The check running.
hooksList<Hook>hooks(类型 `List`)。The hooks.
源码Source io/agentscope/core/agent/AgentBase.java:132–135

AgentBase

public AgentBase(String name, String description, List<Hook> hooks)

初始化 AgentBase 实例。

Constructor for AgentBase with hooks.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。Agent name
descriptionString描述(类型 `String`)。Agent description
hooksList<Hook>hooks(类型 `List`)。List of hooks for monitoring/intercepting execution
源码Source io/agentscope/core/agent/AgentBase.java:144–151

方法详情Method Detail

getAgentId

public final String getAgentId()
final

获取智能体标识。

Returns the agent id.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/agent/AgentBase.java:153–156

getName

public final String getName()
final

获取名称。

Returns the name.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/agent/AgentBase.java:158–161

getDescription

public final String getDescription()
final

获取 getDescription。

Returns the description.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/agent/AgentBase.java:163–166

isCheckRunning

public final boolean isCheckRunning()
finaldeprecated

判断是否检查运行中。

Returns whether the check running.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。No longer enforced; per-session serialization handles concurrency.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/agent/AgentBase.java:169–172

call

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

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

Process a list of input messages and generate a response with hook execution.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
返回Returns Mono<Msg>
返回Mono。Response message
源码Source io/agentscope/core/agent/AgentBase.java:182–185

callInternal

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.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。input messages
contextRuntimeContext上下文(类型 `RuntimeContext`)。caller-supplied per-call `RuntimeContext`, or `null`
doCallFnFunction<List<Msg>, Mono<Msg>>执行调用 Fn(类型 `Function , Mono >`)。the concrete call implementation (`#doCall` or a structured-output variant)
返回Returns Mono<Msg>
返回Mono。response message
源码Source io/agentscope/core/agent/AgentBase.java:203–209

interruptRunning

protected final void interruptRunning(Object key, InterruptSource source, Msg message)
final

执行中断运行中相关操作。

Session-level interruption targets only the execution currently admitted for this key.

参数Parameters
名称Name类型Type说明Description
keyObject键(类型 `Object`)。The key.
sourceInterruptSource来源(类型 `InterruptSource`)。The source.
messageMsg消息(类型 `Msg`)。The message.
源码Source io/agentscope/core/agent/AgentBase.java:215–220

runLifecycle

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…

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
doCallFnFunction<List<Msg>, Mono<Msg>>执行调用 Fn(类型 `Function , Mono >`)。The do call fn.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/core/agent/AgentBase.java:256–262

callSerializationKey

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.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。the caller-supplied per-call `RuntimeContext` (may be `null`)
返回Returns Object
序列化密钥,或`null`到运行不使用序列化。the serialization key, or `null` to run without serialization
源码Source io/agentscope/core/agent/AgentBase.java:364–366

call

public final Mono<Msg> call(List<Msg> msgs, Class<?> structuredOutputClass)
final

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

Process multiple input messages and generate structured output with hook execution.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
structuredOutputClassClass<?>结构化输出类(类型 `Class`)。Class defining the structure of the output
返回Returns Mono<Msg>
返回Mono。Response message with structured data in metadata
源码Source io/agentscope/core/agent/AgentBase.java:408–411

call

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

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

Process multiple input messages and generate structured output with hook execution.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
schemaJsonNode模式定义(类型 `JsonNode`)。com.fasterxml.jackson.databind.JsonNode instance defining the structure of the output
返回Returns Mono<Msg>
返回Mono。Response message with structured data in metadata
源码Source io/agentscope/core/agent/AgentBase.java:422–425

doCall

protected abstract Mono<Msg> doCall(List<Msg> msgs)
abstract

执行调用操作。

Internal implementation for processing multiple input messages.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
返回Returns Mono<Msg>
返回Mono。Response message
源码Source io/agentscope/core/agent/AgentBase.java:434

doCall

protected Mono<Msg> doCall(List<Msg> msgs, Class<?> structuredOutputClass)

执行调用操作。

Internal implementation for processing multiple messages with structured output.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
structuredOutputClassClass<?>结构化输出类(类型 `Class`)。Class defining the structure
返回Returns Mono<Msg>
返回Mono。Response message with structured data in metadata
源码Source io/agentscope/core/agent/AgentBase.java:445–449

doCall

protected Mono<Msg> doCall(List<Msg> msgs, JsonNode outputSchema)

执行调用操作。

Internal implementation for processing multiple messages with structured output.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
outputSchemaJsonNode输出模式(类型 `JsonNode`)。com.fasterxml.jackson.databind.JsonNode instance defining the structure
返回Returns Mono<Msg>
返回Mono。Response message with structured data in metadata
源码Source io/agentscope/core/agent/AgentBase.java:460–464

addSystemHook

public static void addSystemHook(Hook hook)
static

添加系统钩子。

Adds the system hook.

参数Parameters
名称Name类型Type说明Description
hookHook钩子(类型 `Hook`)。The hook.
源码Source io/agentscope/core/agent/AgentBase.java:466–468

removeSystemHook

public static void removeSystemHook(Hook hook)
static

移除系统钩子。

Removes the system hook.

参数Parameters
名称Name类型Type说明Description
hookHook钩子(类型 `Hook`)。The hook.
源码Source io/agentscope/core/agent/AgentBase.java:470–472

interrupt

public void interrupt()
deprecated

请求中断当前执行。

Returns the interrupt.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Subclasses should implement per-session interrupt via RuntimeContext.
源码Source io/agentscope/core/agent/AgentBase.java:475–477

interrupt

public void interrupt(Msg msg)
deprecated

请求中断当前执行。

Performs the interrupt operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Subclasses should implement per-session interrupt via RuntimeContext.
参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。The msg.
源码Source io/agentscope/core/agent/AgentBase.java:480–482

interrupt

public void interrupt(InterruptSource source)
deprecated

请求中断当前执行。

Performs the interrupt operation.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Subclasses should implement per-session interrupt via RuntimeContext.
参数Parameters
名称Name类型Type说明Description
sourceInterruptSource来源(类型 `InterruptSource`)。The source.
源码Source io/agentscope/core/agent/AgentBase.java:485–486

checkInterruptedAsync

protected Mono<Void> checkInterruptedAsync()
deprecated

检查 checkInterruptedAsync 条件。

Returns the check interrupted async.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。No longer needed; ReActAgent uses per-execution InterruptControl.
返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/core/agent/AgentBase.java:489–492

resetInterruptFlag

protected void resetInterruptFlag()
deprecated

重置中断开关。

Resets the interrupt flag.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。No-op; interrupt state is owned by the execution.
源码Source io/agentscope/core/agent/AgentBase.java:495–496

getInterruptFlag

protected AtomicBoolean getInterruptFlag()
deprecated

获取中断开关。

Returns the interrupt flag.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。No-op stub.
返回Returns AtomicBoolean
返回AtomicBoolean。Returns atomic boolean.
源码Source io/agentscope/core/agent/AgentBase.java:534–537

getInterruptSource

protected InterruptSource getInterruptSource()
deprecated

获取中断来源。

Returns the interrupt source.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Returns USER. Interrupt source is owned by the execution.
返回Returns InterruptSource
返回InterruptSource。Returns interrupt source.
源码Source io/agentscope/core/agent/AgentBase.java:540–543

doObserve

protected Mono<Void> doObserve(Msg msg)

执行观察操作。

Observe a message without generating a reply.

参数Parameters
名称Name类型Type说明Description
msgMsg消息到观察。The message to observe
返回Returns Mono<Void>
返回Mono。Mono that completes when observation is done
源码Source io/agentscope/core/agent/AgentBase.java:560–562

handleInterrupt

protected abstract Mono<Msg> handleInterrupt(InterruptContext context, Msg... originalArgs)
abstract

处理中断。

Handle an interruption that occurred during execution.

参数Parameters
名称Name类型Type说明Description
contextInterruptContext上下文(类型 `InterruptContext`)。The interrupt context containing metadata about the interruption
originalArgs varargsMsg...original 参数(类型 `Msg...`)。The original arguments passed to the call() method (empty, single Msg, or List)
返回Returns Mono<Msg>
返回Mono。Recovery message to return to the user
源码Source io/agentscope/core/agent/AgentBase.java:580

getAgentState

public AgentState getAgentState()

获取智能体状态。

Returns the agent's mutable runtime state, or null if this agent type does not maintain an AgentState.

返回Returns AgentState
返回AgentState。Returns agent state.
源码Source io/agentscope/core/agent/AgentBase.java:586–588

beforeAgentExecution

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.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。the messages passed by the caller to `call()`
rcRuntimeContextrc(类型 `RuntimeContext`)。the caller-supplied per-call `RuntimeContext`, or `null` when none was provided (read from the Reactor Context, so concurrency-safe)
controlRunControlcontrol(类型 `RunControl`)。this execution's independent interruption and cancellation control
返回Returns Object
返回对象。this call's per-call scope object, or `null` if this agent type keeps none
源码Source io/agentscope/core/agent/AgentBase.java:605–607

afterAgentExecution

protected void afterAgentExecution()

在智能体执行后调用。

Invoked in Mono.using cleanup, before clearing the running state.

源码Source io/agentscope/core/agent/AgentBase.java:613

getHooks

public List<Hook> getHooks()

获取 getHooks。

Get the list of hooks for this agent.

返回Returns List<Hook>
返回列出。List of hooks
源码Source io/agentscope/core/agent/AgentBase.java:621–623

addHook

protected void addHook(Hook hook)

添加钩子。

Add a hook to this agent dynamically.

参数Parameters
名称Name类型Type说明Description
hookHook钩子到添加。The hook to add
源码Source io/agentscope/core/agent/AgentBase.java:633–638

removeHook

protected void removeHook(Hook hook)

移除钩子。

Remove a hook from this agent dynamically.

参数Parameters
名称Name类型Type说明Description
hookHook钩子到移除。The hook to remove
源码Source io/agentscope/core/agent/AgentBase.java:652–656

getSortedHooks

public List<Hook> getSortedHooks()

获取 getSortedHooks。

Get hooks sorted by priority (lower value = higher priority).

返回Returns List<Hook>
返回列出。Sorted list of hooks
源码Source io/agentscope/core/agent/AgentBase.java:664–666

seedSystemMsg

protected Mono<Msg> seedSystemMsg(Object callScope)

设置预置系统消息。

Returns the initial system message to seed into PreCallEvent before hooks run.

参数Parameters
名称Name类型Type说明Description
callScopeObject调用范围(类型 `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
返回Returns Mono<Msg>
返回Mono。the seed system message; empty Mono if none
源码Source io/agentscope/core/agent/AgentBase.java:679–681

stateForCall

protected AgentState stateForCall(Object callScope)

设置调用时使用的状态。

Returns the AgentState whose conversation buffer should seed the pre-call memory snapshot for this invocation.

参数Parameters
名称Name类型Type说明Description
callScopeObject调用范围(类型 `Object`)。the per-call scope captured at call entry (may be `null`)
返回Returns AgentState
返回AgentState。the state to snapshot, or `null` if none
源码Source io/agentscope/core/agent/AgentBase.java:692–694

consumeSystemMsgAfterPreCall

protected void consumeSystemMsgAfterPreCall(Msg systemMsg, Object callScope)

执行消费系统消息之后前置调用相关操作。

Called after PreCallEvent hooks have run, with the final system message value.

参数Parameters
名称Name类型Type说明Description
systemMsgMsg系统消息(类型 `Msg`)。the system message produced by all PreCall hooks (may be null)
callScopeObject调用范围(类型 `Object`)。the per-call scope captured at call entry (see `#beforeAgentExecution(List, RuntimeContext, RunControl)`); may be `null`
源码Source io/agentscope/core/agent/AgentBase.java:707

removeSubscribers

public void removeSubscribers(String hubId)

移除 removeSubscribers。

Remove all subscribers for a specific MsgHub.

参数Parameters
名称Name类型Type说明Description
hubIdString中心标识(类型 `String`)。MsgHub identifier
源码Source io/agentscope/core/agent/AgentBase.java:824–826

resetSubscribers

public void resetSubscribers(String hubId, List<AgentBase> subscribers)

重置 resetSubscribers。

Reset the subscriber list for a specific MsgHub.

参数Parameters
名称Name类型Type说明Description
hubIdString中心标识(类型 `String`)。MsgHub identifier
subscribersList<AgentBase>subscribers(类型 `List`)。New list of subscribers (will be copied)
源码Source io/agentscope/core/agent/AgentBase.java:836–838

hasSubscribers

public boolean hasSubscribers()

判断是否具有 hasSubscribers。

Check if this agent has any subscribers.

返回Returns boolean
返回布尔值,表示判断结果。True if agent has one or more subscribers
源码Source io/agentscope/core/agent/AgentBase.java:846–849

getSubscriberCount

public int getSubscriberCount()

获取 getSubscriberCount。

Get the total number of subscribers across all MsgHubs.

返回Returns int
返回数值结果。Total count of subscribers
源码Source io/agentscope/core/agent/AgentBase.java:857–859

observe

public final Mono<Void> observe(Msg msg)
final

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

Observe a single message without generating a reply.

参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。Message to observe
返回Returns Mono<Void>
返回Mono。Mono that completes when observation is done
源码Source io/agentscope/core/agent/AgentBase.java:886–889

observe

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

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

Observe multiple messages without generating a reply.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Messages to observe
返回Returns Mono<Void>
返回Mono。Mono that completes when all observations are done
源码Source io/agentscope/core/agent/AgentBase.java:898–904

stream

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

执行流相关操作。

Stream with multiple input messages.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `ReActAgent#streamEvents(List)` for the fine-grained `AgentEvent` stream.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
optionsStreamOptions选项(类型 `StreamOptions`)。Stream configuration options
返回Returns Flux<Event>
返回Flux。Flux of events emitted during execution
源码Source io/agentscope/core/agent/AgentBase.java:915–919

stream

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

执行流相关操作。

Stream with multiple input messages.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `ReActAgent#streamEvents(...)` for the fine-grained `AgentEvent` stream.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
optionsStreamOptions选项(类型 `StreamOptions`)。Stream configuration options
structuredModelClass<?>结构化模型(类型 `Class`)。Optional class defining the structure
返回Returns Flux<Event>
返回Flux。Flux of events emitted during execution
源码Source io/agentscope/core/agent/AgentBase.java:931–935

stream

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

执行流相关操作。

Stream with multiple input messages using a JSON schema.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。since 2.0.0, for removal. Use `ReActAgent#streamEvents(...)` for the fine-grained `AgentEvent` stream.
参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages
optionsStreamOptions选项(类型 `StreamOptions`)。Stream configuration options
schemaJsonNode模式定义(类型 `JsonNode`)。JSON schema defining the structure of the response
返回Returns Flux<Event>
返回Flux。Flux of events emitted during execution
源码Source io/agentscope/core/agent/AgentBase.java:947–951

toString

public String toString()

返回 toString 结果。

Returns the to string.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/agent/AgentBase.java:1023–1026

继承成员Inherited Members

继承自Methods inherited from Agent
继承自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.