Install
openclaw skills install agentscope-skillThis guide covers the design philosophy, core concepts, and practical usage of the AgentScope framework. Use this skill whenever the user wants to do anything with the AgentScope (Python) library. This includes building agent applications using AgentScope, answering questions about AgentScope, looking for guidance on how to use AgentScope, searching for examples or specific information (functions/classes/modules).
openclaw skills install agentscope-skillAgentScope is a production-ready, enterprise-grade open-source framework for building multi-agent applications with large language models. Its functionalities cover:
pip install agentscope
# or
uv pip install agentscope
from agentscope.message import Msg, TextBlock, ImageBlock, URLSource
msg = Msg(
name="user",
content=[TextBlock("Hello world"), ImageBlock(type="image", source=URLSource(type="url", url="..."))],
role="user"
)
Msg objects as conversation history/context with a marking mechanism for advanced memory management (compression, retrieval).Msg objects to LLM API-specific formats. Must be used with the corresponding ChatModel. Supports multi-agent conversations with different agent identifiers.from agentscope.agent import ReActAgent, UserAgent
from agentscope.model import DashScopeChatModel
from agentscope.formatter import DashScopeChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.tool import Toolkit, execute_python_code, execute_shell_command
import os, asyncio
async def main():
# Initialize toolkit with tools
toolkit = Toolkit()
toolkit.register_tool_function(execute_python_code)
toolkit.register_tool_function(execute_shell_command)
# Create ReActAgent with model, memory, formatter, and toolkit
agent = ReActAgent(
name="Friday",
sys_prompt="You're a helpful assistant named Friday.",
model=DashScopeChatModel(
model_name="qwen-max",
api_key=os.getenv("DASHSCOPE_API_KEY"),
stream=True,
),
memory=InMemoryMemory(),
formatter=DashScopeChatFormatter(),
toolkit=toolkit,
)
# Create user agent for terminal input
user = UserAgent(name="user")
# Conversation loop
msg = None
while True:
msg = await agent(msg) # Agent processes and replies
msg = await user(msg) # User inputs next message
if msg.get_text_content() == "exit":
break
asyncio.run(main())
AgentScope adopts explicit message passing for multi-agent conversations (PyTorch-like dynamic graph), allowing flexible information flow control.
alice, bob, carol, david = ReActAgent(...), ReActAgent(...), ReActAgent(...), ReActAgent(...)
msg_alice = await alice()
msg_bob = await bob(msg_alice) # Bob receives Alice's message and generate a reply. Alice doesn't receive Bob's message unless explicitly passed back.
msg_carol = await carol(msg_alice) # Similarly, the agent cannot receive messages from other agents unless explicitly passed.
# Broadcasting with MsgHub, a syntactic sugar for message broadcasting within a group of agents
from agentscope.pipeline import MsgHub
async with MsgHub(
participants=[alice, bob, carol],
announcement=Msg("Host", "Let's discuss", "user")
) as hub:
await alice() # Bob and Carol receive this
await bob() # Alice and Carol receive this
# Manual broadcast
await hub.broadcast(Msg("Host", "New topic", "user"))
# Dynamic participant management
hub.add(david)
hub.delete(bob)
Wrap worker agents as tools for the master agent.
from agentscope.tool import ToolResponse, Toolkit
async def create_worker(task: str) -> ToolResponse:
"""Create a worker agent for the given task.
Args:
task (`str`): The given task, which should be specific and concise.
"""
task_msg = Msg(name="master", content=task, role="user") # Use the input task or wrap it into a more complex prompt
worker = ReActAgent(...)
res = await worker(task_msg)
return ToolResponse(content=res.content) # Return the worker's response as the tool response
toolkit = Toolkit()
toolkit.register_tool_function(create_worker)
This section provides guidance on how to effectively answer questions about AgentScope or coding with the framework.
CRITICAL: Before doing anything else, clone or update the AgentScope repository. The repository contains essential examples and references.
# Clone into this skill directory so that you can refer to it across different sessions
cd /path/to/this/skill/directory
git clone -b main https://github.com/agentscope-ai/agentscope.git
# Or update if already cloned
cd /path/to/this/skill/directory/agentscope
git pull
Why this matters: The repository contains working examples, complete API documentation in source code, and implementation patterns that are more reliable than guessing.
The cloned repository is organized as follows. Note this may be outdated as the project evolves, you should always check the actual structure after cloning.
agentscope/
├── src/agentscope/ # Main library source code
│ ├── agent/ # Agent implementations (ReActAgent, etc.)
│ ├── model/ # LLM API wrappers (OpenAI, Anthropic, DashScope, etc.)
│ ├── formatter/ # Message formatters for different models
│ ├── memory/ # Memory implementations
│ ├── tool/ # Tool management and built-in tools
│ ├── message/ # Msg class and content blocks
│ ├── pipeline/ # Multi-agent orchestration (MsgHub, etc.)
│ ├── session/ # Session/state management
│ ├── mcp/ # MCP integration
│ ├── rag/ # RAG functionality
│ ├── realtime/ # Realtime voice interaction
│ ├── tts/ # Text-to-speech
│ ├── evaluate/ # Evaluation tools
│ └── ... # Other modules
│
├── examples/ # Working examples organized by category
│ ├── agent/ # Different agent types
│ │ └── ...
│ ├── workflows/ # Multi-agent workflows
│ │ └── ...
│ ├── functionality/ # Specific features
│ │ └── ...
│ ├── deployment/ # Deployment patterns
│ ├── integration/ # Third-party integrations
│ ├── evaluation/ # Evaluation examples
│ └── game/ # Game examples (e.g., werewolves)
│
├── docs/ # Documentation
│ ├── tutorial/ # Tutorial markdown files
│ ├── changelog.md # Version history
│ └── roadmap.md # Development roadmap
│
└── tests/ # Test files
When looking for similar implementations, browse the examples directory by category rather than searching by keywords alone:
examples/agent/examples/workflows/examples/functionality/examples/deployment/Example workflow:
User asks: "Build a FastAPI app with AgentScope"
→ Browse: List files in examples/deployment/
→ Check: Are there any web service examples?
→ Search: Look for "fastapi", "flask", "api", "server" in examples/
→ Read: Found examples and adapt to user's needs
Before implementing custom solutions, verify if AgentScope already provides the functionality:
examples for examplesdocs/tutorial/src/agentscope/ for implementation detailsAlways create a plan before coding:
When writing code:
This section lists all available resources for working with AgentScope.
When the repository is cloned locally, the following structure is available for reference:
src/agentscope/: Main library source code
examples/: Working examples demonstrating features
docs/tutorial/: Tutorial documentation source files
Located in scripts/ directory of this skill.
view_pypi_latest_version.sh: View the latest version of AgentScope on PyPI.cd /path/to/this/skill/directory/scripts/
bash view_pypi_latest_version.sh
view_module_signature.py: Explore the structure of AgentScope modules, classes, and methods.
Search strategy: Use deep-first search - start broad, then narrow down:agentscope → see all submodulesagentscope.agent → see agent-related classesagentscope.agent.ReActAgent → see specific class methodscd /path/to/this/skill/directory/scripts/
# View top-level module
python view_module_signature.py --module agentscope
# View specific submodule
python view_module_signature.py --module agentscope.agent
# View specific class
python view_module_signature.py --module agentscope.agent.ReActAgent
Located in references/ directory of this skill.
multi_agent_orchestration.md: Multi-agent orchestration concepts and implementationdeployment_guide.md: Deployment patterns and best practices