agentscope.agents.dict_dialog_agent module
An agent that replies in a dictionary format.
- class agentscope.agents.dict_dialog_agent.DictDialogAgent(*args: tuple, **kwargs: dict)[源代码]
基类:
AgentBase
An agent that generates response in a dict format, where user can specify the required fields in the response via specifying the parser
About parser, please refer to our [tutorial](https://modelscope.github.io/agentscope/en/tutorial/203-parser.html)
For usage example, please refer to the example of werewolf in examples/game_werewolf
- __init__(name: str, sys_prompt: str, model_config_name: str, use_memory: bool = True, max_retries: int | None = 3) None [源代码]
Initialize the dict dialog agent.
- 参数:
name (str) – The name of the agent.
sys_prompt (Optional[str], defaults to None) – The system prompt of the agent, which can be passed by args or hard-coded in the agent.
model_config_name (str, defaults to None) – The name of the model config, which is used to load model from configuration.
use_memory (bool, defaults to True) – Whether the agent has memory.
max_retries (Optional[int], defaults to None) – The maximum number of retries when failed to parse the model output.
- set_parser(parser: ParserBase) None [源代码]
Set response parser, which will provide 1) format instruction; 2) response parsing; 3) filtering fields when returning message, storing message in memory. So developers only need to change the parser, and the agent will work as expected.
- reply(x: Sequence[Msg] | Msg | None = None) Msg [源代码]
Reply function of the agent. Processes the input data, generates a prompt using the current dialogue memory and system prompt, and invokes the language model to produce a response. The response is then formatted and added to the dialogue 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.
- 返回:
The output message generated by the agent.
- 返回类型:
Msg
- 抛出:
json.decoder.JSONDecodeError – If the response from the language model is not valid JSON, it defaults to treating the response as plain text.
- 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