agentscope package

Subpackages

Submodules

Module contents

Import all modules in the package.

agentscope.init(model_configs: dict | str | list | None = None, project: str | None = None, name: str | None = None, disable_saving: bool = False, save_dir: str = './runs', save_log: bool = True, save_code: bool = True, save_api_invoke: bool = False, cache_dir: str = '/home/runner/.cache/agentscope', 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, studio_url: str | None = None) Sequence[AgentBase][source]

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

Parameters:
  • 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.

  • disable_saving (bool, defaults to False) – Whether to disable saving files. If True, this will override the save_log, save_code, and save_api_invoke parameters.

  • 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.

  • cache_dir (str) – The directory to cache files. In Linux/Mac, the dir defaults to

  • Windows ( In)

  • to (the dir defaults)

  • `C

    users<username>.cacheagentscope`.

  • 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.

  • studio_url (Optional[str], defaults to None) – The url of the agentscope studio.

agentscope.state_dict() dict[source]

Get the status of agentscope.

agentscope.print_llm_usage() dict[source]

Print the usage of LLM.

agentscope.msghub(participants: Sequence[AgentBase], announcement: Sequence[Msg] | Msg | None = None) MsgHubManager[source]

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

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

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

Example

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)