UserAgent
@Deprecated(forRemoval = true, since = "2.0.0") public class UserAgent extends AgentBase
io/agentscope/core/agent/user/UserAgent.java:68–356用户智能体,驱动智能体的推理、工具调用与会话执行。位于 io.agentscope.core.agent.user 包,继承自 AgentBase。核心成员包括 builder、doCall、getUserInput、overrideInstanceInputMethod、overrideClassInputMethod、getInputMethod。
UserAgent class for handling user interaction within the agent framework.
Acts as a bridge between various user input sources (streams, web UI, etc.) and the message system. Supports pluggable input methods through the UserInputBase interface, allowing customization of how user input is collected and converted into framework messages.
Design Philosophy:
-
UserAgent does NOT manage memory - it only captures user input
-
Input is obtained via pluggable UserInputBase implementations
-
Supports both simple text input and structured input with validation
-
Can participate in MsgHub for multi-agent conversations
Usage Examples:
`// Simple console input (default)
UserAgent user = UserAgent.builder()
.name("User")
.build();
Msg input = user.call().block();
// With custom input method
UserAgent user = UserAgent.builder()
.name("User")
.inputMethod(myCustomInput)
.build();
// With hooks
UserAgent user = UserAgent.builder()
.name("User")
.hooks(List.of(myHook))
.build();
`
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | UserAgent的构建器。 Builder for UserAgent. |
方法摘要Method Summary
方法详情Method Detail
builder
public static Builder builder()
创建用于UserAgent的构建器。
Create a new builder for UserAgent.
Builderio/agentscope/core/agent/user/UserAgent.java:89–91doCall
protected Mono<Msg> doCall(List<Msg> msgs)
执行调用操作。
Process multiple input messages and generate user input response.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages to display |
Mono<Msg>io/agentscope/core/agent/user/UserAgent.java:101–104doCall
public Mono<Msg> doCall(List<Msg> msgs, Class<?> structuredModel)
执行调用操作。
Process multiple input messages with structured model and generate user input response.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。Input messages to display |
structuredModel | Class<?> | 结构化模型(类型 `Class`)。Optional class defining the structure of expected input |
Mono<Msg>io/agentscope/core/agent/user/UserAgent.java:115–118getUserInput
public Mono<Msg> getUserInput(List<Msg> contextMessages, Class<?> structuredModel)
获取用户输入使用可选上下文消息和结构化模型。
Get user input with optional context messages and structured model.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
contextMessages | List<Msg> | 上下文消息(类型 `List`)。Optional messages to display before prompting |
structuredModel | Class<?> | 结构化模型(类型 `Class`)。Optional class defining the structure of expected input |
Mono<Msg>io/agentscope/core/agent/user/UserAgent.java:129–134overrideInstanceInputMethod
protected void overrideInstanceInputMethod(UserInputBase inputMethod)
设置该参数。
Override the input method for this UserAgent instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
inputMethod | UserInputBase | 新的输入方法到使用。The new input method to use |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if inputMethod is null
io/agentscope/core/agent/user/UserAgent.java:206–211overrideClassInputMethod
protected static void overrideClassInputMethod(UserInputBase inputMethod)
设置该参数。
Override the default input method for all new UserAgent instances.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
inputMethod | UserInputBase | 新的默认输入方法。The new default input method |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if inputMethod is null
io/agentscope/core/agent/user/UserAgent.java:221–226getInputMethod
protected UserInputBase getInputMethod()
获取当前输入方法用于此实例。
Get the current input method for this instance.
UserInputBaseio/agentscope/core/agent/user/UserAgent.java:234–236doObserve
protected Mono<Void> doObserve(Msg msg)
执行观察操作。
Observe messages without generating a reply.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息(类型 `Msg`)。Message to observe |
Mono<Void>io/agentscope/core/agent/user/UserAgent.java:246–250handleInterrupt
protected Mono<Msg> handleInterrupt(InterruptContext context, Msg... originalArgs)
处理中断。
Handle interrupt scenarios.
| 名称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 |
Mono<Msg>io/agentscope/core/agent/user/UserAgent.java:260–270嵌套类详情Nested Class Detail
Builder
public static class BuilderUserAgent的构建器。位于 io.agentscope.core.agent.user 包。核心成员包括 name、description、checkRunning、inputMethod、hooks、build。
Builder for UserAgent.
Provides fluent API for configuring agent name, input method, and hooks. The name is required; other properties have sensible defaults.
继承成员Inherited Members
AgentBasegetAgentId, getName, getDescription, isCheckRunning, call, callInternal, interruptRunning, runLifecycle, callSerializationKey, call, call, doCall, addSystemHook, removeSystemHook, interrupt, interrupt, interrupt, checkInterruptedAsync, resetInterruptFlag, getInterruptFlag, getInterruptSource, getAgentState, beforeAgentExecution, afterAgentExecution, getHooks, addHook, removeHook, getSortedHooks, seedSystemMsg, stateForCall, consumeSystemMsgAfterPreCall, removeSubscribers, resetSubscribers, hasSubscribers, getSubscriberCount, observe, observe, stream, stream, stream, toString, CALL_SCOPE_KEY, RUNTIME_CONTEXT_KEY, SHUTDOWN_REQUEST_ID_KEY