AgentScope: A Flexible yet Robust Multi-Agent Platform

1.0.18 · active · verified Wed Apr 15

AgentScope is an open-source Python framework for building and running large language model (LLM) based multi-agent systems. It emphasizes clear abstractions, modular design, and efficient communication between agents, enabling structured, scalable, and production-ready AI applications. The library is actively developed with frequent releases, currently at version 1.0.18, and supports Python 3.10 and higher.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates a basic conversation between a `UserAgent` and a `ReActAgent` using an OpenAI model. It showcases how to initialize a model with an API key (from an environment variable) and instantiate agents directly, then run an asynchronous conversation loop. The example assumes `OPENAI_API_KEY` is set.

import os
import asyncio
from agentscope.agent import ReActAgent, UserAgent
from agentscope.model import OpenAIChatModel
from agentscope.formatter import OpenAIChatFormatter
from agentscope.message import Msg

async def main():
    # Set your OpenAI API key as an environment variable
    # export OPENAI_API_KEY="your_api_key_here"
    if not os.environ.get("OPENAI_API_KEY"):
        print("Please set the OPENAI_API_KEY environment variable.")
        return

    # Initialize the model
    model = OpenAIChatModel(
        model_name="gpt-4o", # or "gpt-3.5-turbo"
        api_key=os.environ.get("OPENAI_API_KEY", ""),
        formatter=OpenAIChatFormatter()
    )

    # Create a ReAct agent and a User agent
    # Note: As of v1.0.0, agentscope.init(model_configs=...) is deprecated.
    # Instantiate models and pass them directly to agents.
    assistant = ReActAgent(
        name="Assistant",
        model=model,
        sys_prompt="You are a helpful AI assistant. Always be polite."
    )
    user = UserAgent(name="User")

    print("\n--- Start Conversation ---")
    x = None
    while True:
        x = await assistant.reply(x)
        x = await user.reply(x)
        if x.content.lower() == "exit":
            break
    print("--- End Conversation ---")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →