类 UserAgent

java.lang.Object
io.agentscope.core.agent.AgentBase
io.agentscope.core.agent.user.UserAgent
所有已实现的接口:
Agent, CallableAgent, ObservableAgent, StreamableAgent, StateModule

public class UserAgent extends AgentBase
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();
 
  • 方法详细资料

    • builder

      public static UserAgent.Builder builder()
      Create a new builder for UserAgent.
      返回:
      A new builder instance
    • handleInterrupt

      protected reactor.core.publisher.Mono<Msg> handleInterrupt(InterruptContext context, Msg... originalArgs)
      Handle interrupt scenarios. For UserAgent, interrupts simply return an interrupted message.
      指定者:
      handleInterrupt 在类中 AgentBase
      参数:
      context - The interrupt context containing metadata about the interruption
      originalArgs - The original arguments passed to the call() method
      返回:
      Mono containing an interrupt message