agentscope

Import all modules in the package.

agentscope.init(model_configs: dict | str | list | None = None, project: str | None = None, name: str | None = None, save_dir: str = './runs', save_log: bool = True, save_code: bool = True, save_api_invoke: bool = False, use_monitor: bool = True, logger_level: Literal['TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'] = 'INFO', runtime_id: str | None = None, agent_configs: dict | str | list | None = None) Sequence[AgentBase][源代码]

A unified entry to initialize the package, including model configs, runtime names, saving directories and logging settings.

参数:
  • model_configs (Optional[Union[dict, str, list]], defaults to None) – A dict, a list of dicts, or a path to a json file containing model configs.

  • project (Optional[str], defaults to None) – The project name, which is used to identify the project.

  • name (Optional[str], defaults to None) – The name for runtime, which is used to identify this runtime.

  • runtime_id (Optional[str], defaults to None) – The id for runtime, which is used to identify this runtime. Use None will generate a random id.

  • save_dir (str, defaults to ./runs) – The directory to save logs, files, codes, and api invocations. If dir is None, when saving logs, files, codes, and api invocations, the default directory ./runs will be created.

  • save_log (bool, defaults to False) – Whether to save logs locally.

  • save_code (bool, defaults to False) – Whether to save codes locally.

  • save_api_invoke (bool, defaults to False) – Whether to save api invocations locally, including model and web search invocation.

  • use_monitor (bool, defaults to True) – Whether to activate the monitor.

  • logger_level (LOG_LEVEL, defaults to “INFO”) – The logging level of logger.

  • agent_configs (Optional[Union[str, list, dict]], defaults to None) – The config dict(s) of agents or the path to the config file, which can be loaded by json.loads(). One agent config should cover the required arguments to initialize a specific agent object, otherwise the default values will be used.

agentscope.msghub(participants: Sequence[AgentBase], announcement: Sequence[dict] | dict | None = None) MsgHubManager[源代码]

msghub is used to share messages among a group of agents.

参数:
  • participants (Sequence[AgentBase]) – A Sequence of participated agents in the msghub.

  • announcement (Optional[Union[list[dict], dict]], defaults to None) – The message that will be broadcast to all participants at the very beginning without requiring response.

示例

In the following code, we create a msghub with three agents, and each message output by agent1, agent2, agent3 will be passed to all other agents, that’s what we mean msghub.

with msghub(participant=[agent1, agent2, agent3]):
    agent1()
    agent2()

Actually, it has the same effect as the following code, but much more easy and elegant!

x1 = agent1()
agent2.observe(x1)
agent3.observe(x1)

x2 = agent2()
agent1.observe(x2)
agent3.observe(x2)