agentscope.agents.user_agent module

User Agent class

class agentscope.agents.user_agent.UserAgent(*args: tuple, **kwargs: dict)[源代码]

基类:AgentBase

User agent class

__init__(name: str = 'User', input_hint: str = 'User Input: ', require_url: bool = False) None[源代码]

Initialize a UserAgent object.

参数:
  • name (str, defaults to “User”) – The name of the agent. Defaults to “User”.

  • (str (input_hint) – “`): The hint of the input. Defaults to “User Input: “.

  • Input (defaults to `"User) –

    `): The hint of the input. Defaults to “User Input: “.

  • require_url (bool, defaults to False) – Whether the agent requires user to input a URL. Defaults to False. The URL can lead to a website, a file, or a directory. It will be added into the generated message in field url.

reply(x: Sequence[Msg] | Msg | None = None, required_keys: list[str] | str | None = None, timeout: int | None = None) Msg[源代码]

Processes the input provided by the user and stores it in memory, potentially formatting it with additional provided details.

The method prompts the user for input, then optionally prompts for additional specifics based on the provided format keys. All information is encapsulated in a message object, which is then added to the object’s memory.

参数:
  • x (Optional[Union[Msg, Sequence[Msg]]], defaults to None) – The input message(s) to the agent, which also can be omitted if the agent doesn’t need any input.

  • required_keys (Optional[Union[list[str], str]], defaults to None) – Strings that requires user to input, which will be used as the key of the returned dict. Defaults to None.

  • timeout (Optional[int], defaults to None) – Raise TimeoutError if user exceed input time, set to None for no limit.

返回:

The output message generated by the agent.

返回类型:

Msg

speak(content: str | Msg) None[源代码]

Speak out the message generated by the agent. If a string is given, a Msg object will be created with the string as the content.

参数:

content (Union[str, Msg]) – The content of the message to be spoken out. If a string is given, a Msg object will be created with the agent’s name, role as “user”, and the given string as the content.