# agentscope **Repository Path**: github-fast/agentscope ## Basic Information - **Project Name**: agentscope - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-01-22 - **Last Updated**: 2025-06-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [**中文主页**](https://github.com/modelscope/agentscope/blob/main/README_ZH.md) | [**日本語のホームページ**](https://github.com/modelscope/agentscope/blob/main/README_JA.md) | [**Tutorial**](https://doc.agentscope.io/) | [**Roadmap**](https://github.com/modelscope/agentscope/blob/main/docs/ROADMAP.md) | [**FAQ**](https://doc.agentscope.io/tutorial/faq.html)
|
|
## 📑 Table of Contents
- [🚀 Quickstart](#-quickstart)
- [💻 Installation](#-installation)
- [🛠️ From source](#-from-source)
- [📦 From PyPi](#-from-pypi)
- [📝 Example](#-example)
- [👋 Hello AgentScope](#-hello-agentscope)
- [🧑🤝🧑 Multi-Agent Conversation](#-multi-agent-conversation)
- [💡 Reasoning with Tools & MCP](#-reasoning-with-tools--mcp)
- [🔠 Structured Output](#-structured-output)
- [✏️ Workflow Orchestration](#-workflow-orchestration)
- [⚡️ Distribution and Parallelization](#%EF%B8%8F-distribution-and-parallelization)
- [👀 Tracing & Monitoring](#-tracing--monitoring)
- [⚖️ License](#-license)
- [📚 Publications](#-publications)
- [✨ Contributors](#-contributors)
## 🚀 Quickstart
### 💻 Installation
> AgentScope requires **Python 3.9** or higher.
#### 🛠️ From source
```bash
# Pull the source code from GitHub
git clone https://github.com/modelscope/agentscope.git
# Install the package in editable mode
cd agentscope
pip install -e .
```
#### 📦 From PyPi
```bash
pip install agentscope
```
## 📝 Example
### 👋 Hello AgentScope


Creating a basic conversation **explicitly** between **a user** and **an assistant** with AgentScope:
```python
from agentscope.agents import DialogAgent, UserAgent
import agentscope
# Load model configs
agentscope.init(
model_configs=[
{
"config_name": "my_config",
"model_type": "dashscope_chat",
"model_name": "qwen-max",
}
]
)
# Create a dialog agent and a user agent
dialog_agent = DialogAgent(
name="Friday",
model_config_name="my_config",
sys_prompt="You're a helpful assistant named Friday"
)
user_agent = UserAgent(name="user")
# Build the workflow/conversation explicitly
x = None
while x is None or x.content != "exit":
x = dialog_agent(x)
x = user_agent(x)
```
### 🧑🤝🧑 Multi-Agent Conversation
AgentScope is designed for **multi-agent** applications, offering flexible control over information flow and communication between agents.


```python
from agentscope.agents import DialogAgent
from agentscope.message import Msg
from agentscope.pipelines import sequential_pipeline
from agentscope import msghub
import agentscope
# Load model configs
agentscope.init(
model_configs=[
{
"config_name": "my_config",
"model_type": "dashscope_chat",
"model_name": "qwen-max",
}
]
)
# Create three agents
friday = DialogAgent(
name="Friday",
model_config_name="my_config",
sys_prompt="You're a helpful assistant named Friday"
)
saturday = DialogAgent(
name="Saturday",
model_config_name="my_config",
sys_prompt="You're a helpful assistant named Saturday"
)
sunday = DialogAgent(
name="Sunday",
model_config_name="my_config",
sys_prompt="You're a helpful assistant named Sunday"
)
# Create a chatroom by msghub, where agents' messages are broadcast to all participants
with msghub(
participants=[friday, saturday, sunday],
announcement=Msg("user", "Counting from 1 and report one number each time without other things", "user"), # A greeting message
) as hub:
# Speak in sequence
sequential_pipeline([friday, saturday, sunday], x=None)
```
### 💡 Reasoning with Tools & MCP

Creating a reasoning agent with built-in tools and **MCP servers**!
```python
from agentscope.agents import ReActAgentV2, UserAgent
from agentscope.service import ServiceToolkit, execute_python_code
import agentscope
agentscope.init(
model_configs={
"config_name": "my_config",
"model_type": "dashscope_chat",
"model_name": "qwen-max",
}
)
# Add tools
toolkit = ServiceToolkit()
toolkit.add(execute_python_code)
# Connect to Gaode MCP server
toolkit.add_mcp_servers(
{
"mcpServers": {
"amap-amap-sse": {
"url": "https://mcp.amap.com/sse?key={YOUR_GAODE_API_KEY}"
}
}
}
)
# Create a reasoning-acting agent
agent = ReActAgentV2(
name="Friday",
model_config_name="my_config",
service_toolkit=toolkit,
sys_prompt="You're a helpful assistant named Friday."
)
user_agent = UserAgent(name="user")
# Build the workflow/conversation explicitly
x = None
while x is None or x.content != "exit":
x = agent(x)
x = user_agent(x)
```
### 🔠 Structured Output

Specifying structured output with a Pydantic base model.
```python
from agentscope.agents import ReActAgentV2
from agentscope.service import ServiceToolkit
from agentscope.message import Msg
from pydantic import BaseModel, Field
from typing import Literal
import agentscope
agentscope.init(
model_configs={
"config_name": "my_config",
"model_type": "dashscope_chat",
"model_name": "qwen-max",
}
)
# Create a reasoning-acting agent
agent = ReActAgentV2(
name="Friday",
model_config_name="my_config",
service_toolkit=ServiceToolkit(),
max_iters=20
)
class CvModel(BaseModel):
name: str = Field(max_length=50, description="The name")
description: str = Field(max_length=200, description="The brief description")
aget: int = Field(gt=0, le=120, description="The age of the person")
class ChoiceModel(BaseModel):
choice: Literal["apple", "banana"]
# Specify structured output using `structured_model`
res_msg = agent(
Msg("user", "Introduce Einstein", "user"),
structured_model=CvModel
)
print(res_msg.metadata)
# Switch to different structured model
res_msg = agent(
Msg("user", "Choice a fruit", "user"),
structured_model=ChoiceModel
)
print(res_msg.metadata)
```
### ✏️ Workflow Orchestration

[Routing](https://www.anthropic.com/engineering/building-effective-agents), [parallelization](https://www.anthropic.com/engineering/building-effective-agents), [orchestrator-workers](https://www.anthropic.com/engineering/building-effective-agents), or [evaluator-optimizer](https://www.anthropic.com/engineering/building-effective-agents).
Build your own workflow with AgentScope easily! Taking routing as an example:
```python
from agentscope.agents import ReActAgentV2
from agentscope.service import ServiceToolkit
from agentscope.message import Msg
from pydantic import BaseModel, Field
from typing import Literal, Union
import agentscope
agentscope.init(
model_configs={
"config_name": "my_config",
"model_type": "dashscope_chat",
"model_name": "qwen-max",
}
)
# Workflow: Routing
routing_agent = ReActAgentV2(
name="Routing",
model_config_name="my_config",
sys_prompt="You're a routing agent. Your target is to route the user query to the right follow-up task",
service_toolkit=ServiceToolkit()
)
# Use structured output to specify the routing task
class RoutingChoice(BaseModel):
your_choice: Literal[
'Content Generation',
'Programming',
'Information Retrieval',
None
] = Field(description="Choice the right follow-up task, and choice `None` if the task is too simple or no suitable task")
task_description: Union[str, None] = Field(description="The task description", default=None)
res_msg = routing_agent(
Msg("user", "Help me to write a poem", "user"),
structured_model=RoutingChoice
)
# Execute the follow-up task
if res_msg.metadata["your_choice"] == "Content Generation":
...
elif res_msg.metadata["your_choice"] == "Programming":
...
elif res_msg.metadata["your_choice"] == "Information Retrieval":
...
else:
...
```
### ⚡️ Distribution and Parallelization



Using `to_dist` function to run the agent in distributed mode!
```python
from agentscope.agents import DialogAgent
from agentscope.message import Msg
import agentscope
# Load model configs
agentscope.init(
model_configs=[
{
"config_name": "my_config",
"model_type": "dashscope_chat",
"model_name": "qwen-max",
}
]
)
# Using `to_dist()` to run the agent in distributed mode
agent1 = DialogAgent(
name="Saturday",
model_config_name="my_config"
).to_dist()
agent2 = DialogAgent(
name="Sunday",
model_config_name="my_config"
).to_dist()
# The two agent will run in parallel
agent1(Msg("user", "Execute task1 ...", "user"))
agent2(Msg("user", "Execute task2 ...", "user"))
```
### 👀 Tracing & Monitoring


AgentScope provides a local visualization and monitoring tool, **AgentScope Studio**.
```bash
# Install AgentScope Studio
npm install -g @agentscope/studio
# Run AgentScope Studio
as_studio
```
```python
import agentscope
# Connect application to AgentScope Studio
agentscope.init(
model_configs = {
"config_name": "my_config",
"model_type": "dashscope_chat",
"model_name": "qwen_max",
},
studio_url="http://localhost:3000", # The URL of AgentScope Studio
)
# ...
```