AgentScope SDK
AgentScope is a flexible and easy-to-use multi-agent framework for building LLM-based applications with support for various AI providers. It enables creation of intelligent agents, tool integration, memory management, and multi-agent orchestration through a unified Python interface.
Core Functionality
AgentScope provides a comprehensive platform for building AI-powered multi-agent applications. It supports agent creation with pre-built ReAct agents or custom agent classes, automatic tool schema generation, flexible memory management systems, and multi-provider model integration. The framework includes retrieval-augmented generation capabilities, sophisticated workflow orchestration patterns, evaluation frameworks, and development tools for monitoring and debugging.
When to Use
This skill should be used when users need to work with AgentScope, a multi-agent platform for building AI-powered applications. It provides comprehensive guidance on agents, tools, memory management, models, RAG, workflows, evaluation, and development operations.
Getting Started
Begin with the quickstart tutorials to understand core concepts:
- Key Concepts: Refer to
references/quickstart_key_concept.py for foundational architecture including state management, message handling, tools, agents, and formatters
- Message System: Refer to
references/quickstart_message.py for creating messages with multimodal content support, tool use handling, and serialization
- Agent Basics: Refer to
references/quickstart_agent.py for ReAct agent features including realtime steering, parallel tool calls, and structured output
Module Overview
Agents Module
Create and customize agents using ReActAgent or build custom agents from AgentBase. Register agent skills for specialized capabilities.
- Key APIs: ReActAgent, AgentBase, UserAgent, PlanNotebook
- Detailed documentation:
references/task_agent.py, references/task_agent_skill.py, references/example_react_agent.py
Tools Module
Implement tool functions with automatic JSON schema generation, integrate MCP servers, and customize behavior using hooks.
- Key APIs: Toolkit, ToolResponse, HttpStatefulClient, StdIOStatefulClient, register_instance_hook
- Detailed documentation:
references/task_tool.py, references/task_hook.py, references/task_mcp.py, references/example_mcp.py
Memory Module
Manage conversation context with short-term and long-term memory systems, including compression strategies for token optimization.
- Key APIs: InMemoryMemory, MemoryBase, Mem0LongTermMemory, ReMePersonalLongTermMemory, MemoryWithCompress
- Detailed documentation:
references/task_memory.py, references/task_long_term_memory.py, references/example_memory_compress.py
Models Module
Integrate multiple LLM providers including OpenAI, DashScope, Anthropic, Gemini, and Ollama with unified interfaces for chat, embeddings, and text-to-speech.
- Key APIs: DashScopeChatModel, OpenAIChatModel, AnthropicChatModel, GeminiChatModel, DashScopeTextEmbedding, DashScopeRealtimeTTSModel, OpenAITokenCounter
- Detailed documentation:
references/task_model.py, references/task_embedding.py, references/task_token.py, references/task_tts.py
RAG Module
Build retrieval-augmented generation systems with document readers, vector embeddings, and knowledge base storage.
- Key APIs: TextReader, PDFReader, ImageReader, SimpleKnowledge, QdrantStore, DashScopeTextEmbedding, retrieve_knowledge
- Detailed documentation:
references/task_rag.py, references/example_rag_basic.py
Planning Module
Enable agents to break down complex tasks into subtasks with manual or agent-managed plan specification and execution tracking.
- Key APIs: PlanNotebook, Plan, SubTask
- Detailed documentation:
references/task_plan.py, references/example_plan_agent.py, references/example_plan_manual.py
State Management Module
Manage agent states with automatic variable registration and session-level persistence.
- Key APIs: StateModule, register_state, JSONSession, state_dict, load_state_dict
- Detailed documentation:
references/task_state.py, references/task_prompt.py, references/task_tracing.py
Pipelines Module
Orchestrate multi-agent workflows with sequential and fanout execution patterns using message broadcasting.
- Key APIs: MsgHub, sequential_pipeline, fanout_pipeline, SequentialPipeline, FanoutPipeline
- Detailed documentation:
references/task_pipeline.py
Workflows Module
Implement common multi-agent patterns including concurrent execution, conversations, handoffs, debates, and routing.
- Key APIs: ReActAgent, MsgHub, RoutingChoice, ToolResponse
- Detailed documentation:
references/workflow_concurrent_agents.py, references/workflow_conversation.py, references/workflow_handoffs.py, references/workflow_multiagent_debate.py, references/workflow_routing.py
Evaluation Module
Assess agent performance with custom metrics, benchmarks, and evaluators supporting sequential and parallel execution.
- Key APIs: BenchmarkBase, MetricBase, GeneralEvaluator, RayEvaluator, ToyBenchmark, CheckEqual
- Detailed documentation:
references/task_eval.py
Studio Module
Monitor and debug agent applications with AgentScope Studio's web interface for visualization and tracing.
- Key APIs: agentscope.init, as_studio
- Detailed documentation:
references/task_studio.py
Browser Automation Module
Automate web browsing tasks using Playwright MCP integration with specialized BrowserAgent capabilities.
- Key APIs: BrowserAgent, StdIOStatefulClient, ReActAgent
- Detailed documentation:
references/example_browser_agent.py, references/example_browser_agent_impl.py
Key APIs
Agent Creation
ReActAgent: Pre-built reasoning and acting agent with tool support
AgentBase: Base class for custom agent implementation
UserAgent: Specialized agent for user interactions
Message Management
Msg: Message objects with multimodal content support
MsgHub: Broadcast messages to multiple agents
TextBlock, ToolUseBlock, ToolResultBlock: Content block types
Tool Integration
Toolkit: Manage tool functions with automatic schema generation
register_tool_function: Register Python functions as tools
register_mcp_client: Integrate MCP servers for external tools
Memory Systems
InMemoryMemory: Short-term conversation memory
Mem0LongTermMemory: Persistent memory using mem0
MemoryWithCompress: Automatic memory compression
Model Integration
DashScopeChatModel: Alibaba DashScope LLM integration
OpenAIChatModel: OpenAI API integration
DashScopeTextEmbedding: Text embedding generation
OpenAITokenCounter: Token counting for API usage estimation
Workflow Orchestration
sequential_pipeline: Execute agents in sequence
fanout_pipeline: Execute agents in parallel
PlanNotebook: Task planning and subtask management
State Management
StateModule: Base class for stateful agents
JSONSession: Session persistence with JSON storage
register_state: Decorator for automatic state registration
Common Patterns
Agent Initialization Pattern
agent = ReActAgent(
name="assistant",
model_config=DashScopeChatModel(),
memory=InMemoryMemory(),
tools=[...]
)
Message Exchange Pattern
msg = Msg(name="user", content="Hello world")
response = await agent(msg)
Tool Registration Pattern
toolkit = Toolkit()
toolkit.register_tool_function(execute_python_code)
agent = ReActAgent(tools=toolkit.get_json_schemas())
Pipeline Execution Pattern
async with MsgHub("hub") as hub:
await sequential_pipeline([agent1, agent2], hub)
State Management Pattern
class MyStatefulAgent(StateModule):
def __init__(self):
super().__init__()
self.register_state("counter", 0)
MCP Integration Pattern
client = HttpStatefulClient("http://localhost:8000/sse")
toolkit.register_mcp_client(client)
Workflow
- Initialize AgentScope with model configuration and API keys
- Create agents using ReActAgent or custom AgentBase subclasses
- Register tools via Toolkit or integrate MCP servers for external capabilities
- Configure memory with InMemoryMemory for short-term or long-term memory classes
- Orchestrate workflows using pipelines, MsgHub, or custom coordination logic
- Monitor execution through AgentScope Studio for debugging and visualization
Refer to detailed documentation in references/ directory for specific implementation patterns and advanced configurations.
Resource References
Quick Start
references/quickstart_agent.py - Agent basics with ReActAgent
references/quickstart_key_concept.py - Core architecture concepts
references/quickstart_message.py - Message system overview
Agent Development
references/task_agent.py - Agent initialization and planning
references/task_agent_skill.py - Agent skill registration
references/example_react_agent.py - Custom agent examples
Tool Integration
references/task_tool.py - Tool function implementation
references/task_mcp.py - MCP server integration
references/task_hook.py - Lifecycle hooks for customization
Memory Management
references/task_memory.py - Short-term memory usage
references/task_long_term_memory.py - Persistent memory systems
references/example_memory_compress.py - Memory compression strategies
Model Integration
references/task_model.py - Multi-provider LLM integration
references/task_embedding.py - Text and multimodal embeddings
references/task_token.py - Token counting for cost estimation
references/task_tts.py - Text-to-speech capabilities
RAG Implementation
references/task_rag.py - Comprehensive RAG guide
references/example_rag_basic.py - Basic RAG example
Workflow Patterns
references/workflow_conversation.py - User-agent and multi-agent conversations
references/workflow_routing.py - Query routing to specialized agents
references/workflow_handoffs.py - Orchestrator-worker delegation
references/workflow_concurrent_agents.py - Parallel agent execution
references/workflow_multiagent_debate.py - Consensus through debate
State Management
references/task_state.py - State module usage
references/task_prompt.py - Message formatting for LLM providers
references/task_tracing.py - OpenTelemetry tracing setup
Evaluation and Monitoring
references/task_eval.py - Agent evaluation framework
references/task_studio.py - Studio deployment and usage
Advanced Examples
references/example_browser_agent.py - Browser automation with Playwright
references/example_plan_agent.py - Planning with ReActAgent
references/example_plan_manual.py - Manual plan specification
1---2name: agentscope-sdk3description: This skill should be used when users need to work with AgentScope, a multi-agent platform for building AI-powered applications. It provides comprehensive guidance on agents, tools, memory management, models, RAG, workflows, evaluation, and development operations.4---56# AgentScope SDK78AgentScope is a flexible and easy-to-use multi-agent framework for building LLM-based applications with support for various AI providers. It enables creation of intelligent agents, tool integration, memory management, and multi-agent orchestration through a unified Python interface.910## Core Functionality1112AgentScope provides a comprehensive platform for building AI-powered multi-agent applications. It supports agent creation with pre-built ReAct agents or custom agent classes, automatic tool schema generation, flexible memory management systems, and multi-provider model integration. The framework includes retrieval-augmented generation capabilities, sophisticated workflow orchestration patterns, evaluation frameworks, and development tools for monitoring and debugging.1314## When to Use1516This skill should be used when users need to work with AgentScope, a multi-agent platform for building AI-powered applications. It provides comprehensive guidance on agents, tools, memory management, models, RAG, workflows, evaluation, and development operations.1718## Getting Started1920Begin with the quickstart tutorials to understand core concepts:2122- **Key Concepts**: Refer to `references/quickstart_key_concept.py` for foundational architecture including state management, message handling, tools, agents, and formatters23- **Message System**: Refer to `references/quickstart_message.py` for creating messages with multimodal content support, tool use handling, and serialization24- **Agent Basics**: Refer to `references/quickstart_agent.py` for ReAct agent features including realtime steering, parallel tool calls, and structured output2526## Module Overview2728### Agents Module29Create and customize agents using ReActAgent or build custom agents from AgentBase. Register agent skills for specialized capabilities.3031- **Key APIs**: ReActAgent, AgentBase, UserAgent, PlanNotebook32- **Detailed documentation**: `references/task_agent.py`, `references/task_agent_skill.py`, `references/example_react_agent.py`3334### Tools Module35Implement tool functions with automatic JSON schema generation, integrate MCP servers, and customize behavior using hooks.3637- **Key APIs**: Toolkit, ToolResponse, HttpStatefulClient, StdIOStatefulClient, register_instance_hook38- **Detailed documentation**: `references/task_tool.py`, `references/task_hook.py`, `references/task_mcp.py`, `references/example_mcp.py`3940### Memory Module41Manage conversation context with short-term and long-term memory systems, including compression strategies for token optimization.4243- **Key APIs**: InMemoryMemory, MemoryBase, Mem0LongTermMemory, ReMePersonalLongTermMemory, MemoryWithCompress44- **Detailed documentation**: `references/task_memory.py`, `references/task_long_term_memory.py`, `references/example_memory_compress.py`4546### Models Module47Integrate multiple LLM providers including OpenAI, DashScope, Anthropic, Gemini, and Ollama with unified interfaces for chat, embeddings, and text-to-speech.4849- **Key APIs**: DashScopeChatModel, OpenAIChatModel, AnthropicChatModel, GeminiChatModel, DashScopeTextEmbedding, DashScopeRealtimeTTSModel, OpenAITokenCounter50- **Detailed documentation**: `references/task_model.py`, `references/task_embedding.py`, `references/task_token.py`, `references/task_tts.py`5152### RAG Module53Build retrieval-augmented generation systems with document readers, vector embeddings, and knowledge base storage.5455- **Key APIs**: TextReader, PDFReader, ImageReader, SimpleKnowledge, QdrantStore, DashScopeTextEmbedding, retrieve_knowledge56- **Detailed documentation**: `references/task_rag.py`, `references/example_rag_basic.py`5758### Planning Module59Enable agents to break down complex tasks into subtasks with manual or agent-managed plan specification and execution tracking.6061- **Key APIs**: PlanNotebook, Plan, SubTask62- **Detailed documentation**: `references/task_plan.py`, `references/example_plan_agent.py`, `references/example_plan_manual.py`6364### State Management Module65Manage agent states with automatic variable registration and session-level persistence.6667- **Key APIs**: StateModule, register_state, JSONSession, state_dict, load_state_dict68- **Detailed documentation**: `references/task_state.py`, `references/task_prompt.py`, `references/task_tracing.py`6970### Pipelines Module71Orchestrate multi-agent workflows with sequential and fanout execution patterns using message broadcasting.7273- **Key APIs**: MsgHub, sequential_pipeline, fanout_pipeline, SequentialPipeline, FanoutPipeline74- **Detailed documentation**: `references/task_pipeline.py`7576### Workflows Module77Implement common multi-agent patterns including concurrent execution, conversations, handoffs, debates, and routing.7879- **Key APIs**: ReActAgent, MsgHub, RoutingChoice, ToolResponse80- **Detailed documentation**: `references/workflow_concurrent_agents.py`, `references/workflow_conversation.py`, `references/workflow_handoffs.py`, `references/workflow_multiagent_debate.py`, `references/workflow_routing.py`8182### Evaluation Module83Assess agent performance with custom metrics, benchmarks, and evaluators supporting sequential and parallel execution.8485- **Key APIs**: BenchmarkBase, MetricBase, GeneralEvaluator, RayEvaluator, ToyBenchmark, CheckEqual86- **Detailed documentation**: `references/task_eval.py`8788### Studio Module89Monitor and debug agent applications with AgentScope Studio's web interface for visualization and tracing.9091- **Key APIs**: agentscope.init, as_studio92- **Detailed documentation**: `references/task_studio.py`9394### Browser Automation Module95Automate web browsing tasks using Playwright MCP integration with specialized BrowserAgent capabilities.9697- **Key APIs**: BrowserAgent, StdIOStatefulClient, ReActAgent98- **Detailed documentation**: `references/example_browser_agent.py`, `references/example_browser_agent_impl.py`99100## Key APIs101102**Agent Creation**103- `ReActAgent`: Pre-built reasoning and acting agent with tool support104- `AgentBase`: Base class for custom agent implementation105- `UserAgent`: Specialized agent for user interactions106107**Message Management**108- `Msg`: Message objects with multimodal content support109- `MsgHub`: Broadcast messages to multiple agents110- `TextBlock`, `ToolUseBlock`, `ToolResultBlock`: Content block types111112**Tool Integration**113- `Toolkit`: Manage tool functions with automatic schema generation114- `register_tool_function`: Register Python functions as tools115- `register_mcp_client`: Integrate MCP servers for external tools116117**Memory Systems**118- `InMemoryMemory`: Short-term conversation memory119- `Mem0LongTermMemory`: Persistent memory using mem0120- `MemoryWithCompress`: Automatic memory compression121122**Model Integration**123- `DashScopeChatModel`: Alibaba DashScope LLM integration124- `OpenAIChatModel`: OpenAI API integration125- `DashScopeTextEmbedding`: Text embedding generation126- `OpenAITokenCounter`: Token counting for API usage estimation127128**Workflow Orchestration**129- `sequential_pipeline`: Execute agents in sequence130- `fanout_pipeline`: Execute agents in parallel131- `PlanNotebook`: Task planning and subtask management132133**State Management**134- `StateModule`: Base class for stateful agents135- `JSONSession`: Session persistence with JSON storage136- `register_state`: Decorator for automatic state registration137138## Common Patterns139140**Agent Initialization Pattern**141```python142agent = ReActAgent(143 name="assistant",144 model_config=DashScopeChatModel(),145 memory=InMemoryMemory(),146 tools=[...]147)148```149150**Message Exchange Pattern**151```python152msg = Msg(name="user", content="Hello world")153response = await agent(msg)154```155156**Tool Registration Pattern**157```python158toolkit = Toolkit()159toolkit.register_tool_function(execute_python_code)160agent = ReActAgent(tools=toolkit.get_json_schemas())161```162163**Pipeline Execution Pattern**164```python165async with MsgHub("hub") as hub:166 await sequential_pipeline([agent1, agent2], hub)167```168169**State Management Pattern**170```python171class MyStatefulAgent(StateModule):172 def __init__(self):173 super().__init__()174 self.register_state("counter", 0)175```176177**MCP Integration Pattern**178```python179client = HttpStatefulClient("http://localhost:8000/sse")180toolkit.register_mcp_client(client)181```182183## Workflow1841851. **Initialize AgentScope** with model configuration and API keys1862. **Create agents** using ReActAgent or custom AgentBase subclasses1873. **Register tools** via Toolkit or integrate MCP servers for external capabilities1884. **Configure memory** with InMemoryMemory for short-term or long-term memory classes1895. **Orchestrate workflows** using pipelines, MsgHub, or custom coordination logic1906. **Monitor execution** through AgentScope Studio for debugging and visualization191192Refer to detailed documentation in `references/` directory for specific implementation patterns and advanced configurations.193194## Resource References195196**Quick Start**197- `references/quickstart_agent.py` - Agent basics with ReActAgent198- `references/quickstart_key_concept.py` - Core architecture concepts199- `references/quickstart_message.py` - Message system overview200201**Agent Development**202- `references/task_agent.py` - Agent initialization and planning203- `references/task_agent_skill.py` - Agent skill registration204- `references/example_react_agent.py` - Custom agent examples205206**Tool Integration**207- `references/task_tool.py` - Tool function implementation208- `references/task_mcp.py` - MCP server integration209- `references/task_hook.py` - Lifecycle hooks for customization210211**Memory Management**212- `references/task_memory.py` - Short-term memory usage213- `references/task_long_term_memory.py` - Persistent memory systems214- `references/example_memory_compress.py` - Memory compression strategies215216**Model Integration**217- `references/task_model.py` - Multi-provider LLM integration218- `references/task_embedding.py` - Text and multimodal embeddings219- `references/task_token.py` - Token counting for cost estimation220- `references/task_tts.py` - Text-to-speech capabilities221222**RAG Implementation**223- `references/task_rag.py` - Comprehensive RAG guide224- `references/example_rag_basic.py` - Basic RAG example225226**Workflow Patterns**227- `references/workflow_conversation.py` - User-agent and multi-agent conversations228- `references/workflow_routing.py` - Query routing to specialized agents229- `references/workflow_handoffs.py` - Orchestrator-worker delegation230- `references/workflow_concurrent_agents.py` - Parallel agent execution231- `references/workflow_multiagent_debate.py` - Consensus through debate232233**State Management**234- `references/task_state.py` - State module usage235- `references/task_prompt.py` - Message formatting for LLM providers236- `references/task_tracing.py` - OpenTelemetry tracing setup237238**Evaluation and Monitoring**239- `references/task_eval.py` - Agent evaluation framework240- `references/task_studio.py` - Studio deployment and usage241242**Advanced Examples**243- `references/example_browser_agent.py` - Browser automation with Playwright244- `references/example_plan_agent.py` - Planning with ReActAgent245- `references/example_plan_manual.py` - Manual plan specification