Loading...
Loading...
This 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).
npx skill4agent add agentscope-ai/agentscope-skills agentscope-skillpip install agentscope
# or
uv pip install agentscopefrom 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"
)MsgMsgfrom 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())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)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)# 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 pullagentscope/
├── 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 filesexamples/agent/examples/workflows/examples/functionality/examples/deployment/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 needsexamplesdocs/tutorial/src/agentscope/src/agentscope/examples/docs/tutorial/scripts/view_pypi_latest_version.shcd /path/to/this/skill/directory/scripts/
bash view_pypi_latest_version.shview_module_signature.pyagentscopeagentscope.agentagentscope.agent.ReActAgentcd /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.ReActAgentreferences/multi_agent_orchestration.mddeployment_guide.md