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.
- to_dist(host: str = 'localhost', port: int | None = None, max_pool_size: int = 8192, max_expire_time: int = 7200, max_timeout_seconds: int = 5, local_mode: bool = True, retry_strategy: ~agentscope.rpc.retry_strategy.RetryBase = <agentscope.rpc.retry_strategy.RetryFixedTimes object>) Any
Convert current object into its distributed version.
- 参数:
host (str, defaults to “localhost”) – Hostname of the rpc agent server.
port (int, defaults to None) – Port of the rpc agent server.
max_pool_size (int, defaults to 8192) – Only takes effect when host and port are not filled in. The max number of agent reply messages that the started agent server can accommodate. Note that the oldest message will be deleted after exceeding the pool size.
max_expire_time (int, defaults to 7200) – Only takes effect when host and port are not filled in. Maximum time for reply messages to be cached in the launched agent server. Note that expired messages will be deleted.
max_timeout_seconds (int, defaults to 5) – Max timeout seconds for the rpc call.
local_mode (bool, defaults to True) – Only takes effect when host and port are not filled in. Whether the started agent server only listens to local requests.
retry_strategy (RetryBase, defaults to _DEAFULT_RETRY_STRATEGY) – The retry strategy for the async rpc call.
- 返回:
the wrapped agent instance with distributed functionality
- 返回类型:
RpcObject