AS AgentScopeAPI 手册 / API Reference

UserAgent

@Deprecated(forRemoval = true, since = "2.0.0") public class UserAgent extends AgentBase
源码Source 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说明Description
public static Builder builder()
static
创建用于UserAgent的构建器。
Create a new builder for UserAgent.
protected Mono<Msg> doCall(List<Msg> msgs)
执行调用操作。
Process multiple input messages and generate user input response.
public Mono<Msg> doCall(List<Msg> msgs, Class<?> structuredModel)
执行调用操作。
Process multiple input messages with structured model and generate user input response.
public Mono<Msg> getUserInput(List<Msg> contextMessages, Class<?> structuredModel)
获取用户输入使用可选上下文消息和结构化模型。
Get user input with optional context messages and structured model.
protected void overrideInstanceInputMethod(UserInputBase inputMethod)
设置该参数。
Override the input method for this UserAgent instance.
protected static void overrideClassInputMethod(UserInputBase inputMethod)
static
设置该参数。
Override the default input method for all new UserAgent instances.
protected UserInputBase getInputMethod()
获取当前输入方法用于此实例。
Get the current input method for this instance.
protected Mono<Void> doObserve(Msg msg)
执行观察操作。
Observe messages without generating a reply.
protected Mono<Msg> handleInterrupt(InterruptContext context, Msg... originalArgs)
处理中断。
Handle interrupt scenarios.

方法详情Method Detail

builder

public static Builder builder()
static

创建用于UserAgent的构建器。

Create a new builder for UserAgent.

返回Returns Builder
一种新的构建器实例。A new builder instance
源码Source io/agentscope/core/agent/user/UserAgent.java:89–91

doCall

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

执行调用操作。

Process multiple input messages and generate user input response.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages to display
返回Returns Mono<Msg>
返回Mono。User input message
源码Source io/agentscope/core/agent/user/UserAgent.java:101–104

doCall

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

执行调用操作。

Process multiple input messages with structured model and generate user input response.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。Input messages to display
structuredModelClass<?>结构化模型(类型 `Class`)。Optional class defining the structure of expected input
返回Returns Mono<Msg>
返回Mono。User input message with structured data in metadata
源码Source io/agentscope/core/agent/user/UserAgent.java:115–118

getUserInput

public Mono<Msg> getUserInput(List<Msg> contextMessages, Class<?> structuredModel)

获取用户输入使用可选上下文消息和结构化模型。

Get user input with optional context messages and structured model.

参数Parameters
名称Name类型Type说明Description
contextMessagesList<Msg>上下文消息(类型 `List`)。Optional messages to display before prompting
structuredModelClass<?>结构化模型(类型 `Class`)。Optional class defining the structure of expected input
返回Returns Mono<Msg>
返回Mono。Mono containing the user input message
源码Source io/agentscope/core/agent/user/UserAgent.java:129–134

overrideInstanceInputMethod

protected void overrideInstanceInputMethod(UserInputBase inputMethod)

设置该参数。

Override the input method for this UserAgent instance.

参数Parameters
名称Name类型Type说明Description
inputMethodUserInputBase新的输入方法到使用。The new input method to use
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if inputMethod is null
源码Source io/agentscope/core/agent/user/UserAgent.java:206–211

overrideClassInputMethod

protected static void overrideClassInputMethod(UserInputBase inputMethod)
static

设置该参数。

Override the default input method for all new UserAgent instances.

参数Parameters
名称Name类型Type说明Description
inputMethodUserInputBase新的默认输入方法。The new default input method
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if inputMethod is null
源码Source io/agentscope/core/agent/user/UserAgent.java:221–226

getInputMethod

protected UserInputBase getInputMethod()

获取当前输入方法用于此实例。

Get the current input method for this instance.

返回Returns UserInputBase
当前输入方法。The current input method
源码Source io/agentscope/core/agent/user/UserAgent.java:234–236

doObserve

protected Mono<Void> doObserve(Msg msg)

执行观察操作。

Observe messages without generating a reply.

参数Parameters
名称Name类型Type说明Description
msgMsg消息(类型 `Msg`)。Message to observe
返回Returns Mono<Void>
返回Mono。Mono that completes immediately
源码Source io/agentscope/core/agent/user/UserAgent.java:246–250

handleInterrupt

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

处理中断。

Handle interrupt scenarios.

参数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
返回Returns Mono<Msg>
返回Mono。Mono containing an interrupt message
源码Source io/agentscope/core/agent/user/UserAgent.java:260–270

嵌套类详情Nested Class Detail

Builder

public static class Builder

UserAgent的构建器。位于 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

继承自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.