Skip to main content
This tutorial guides you from a basic conversational agent, progressively adding tools, memory, and a knowledge base, to build a fully functional personal research assistant. Imagine you are a computer science engineer with a keen interest in the development of artificial intelligence — especially large language models and the Transformer architecture. You want your assistant to:
  • Search for the latest academic papers and technical news
  • Perform Q&A based on downloaded paper PDFs
  • Remember your research interests and preferences, and proactively leverage this information in future conversations
You will learn the following core features step by step:

Environment Setup

The mock sections in Part 1 and Part 2 only require DASHSCOPE_API_KEY to run.

Part 1: Get Started in 5 Minutes — Your First Agent

In AgentScope, building an agent requires understanding just three core components:
  • Model — The large language model, the agent’s “brain”
  • Agent — The intelligent entity with a name, persona, memory, and tools
  • Message (Msg) — A conversation message containing content and metadata
Their relationship is: User sends Msg → Agent thinks with Model → Returns Msg.

1.1 Creating a Chat Model and Agent

Let’s start by creating a basic research assistant. Note that the sys_prompt includes a user profile.

1.2 Basic Conversation

Send a message and get the agent’s reply.

1.3 Multi-Turn Conversation

The agent comes with short-term memory (InMemoryMemory), which retains conversation history within the current session.

Part 2: Giving the Assistant “Hands” — Tool Calling

Large language models can only “talk” but cannot “act”. Through tools, the agent can search the internet, execute code, call external APIs, and more.

2.1 Local Mock Tools

Tools are just ordinary Python functions that return a ToolResponse object. AgentScope automatically extracts the JSON Schema from the function signature and docstring.

Register Tools and Create a Tool-Equipped Agent

In addition to custom tools, AgentScope provides built-in tool functions such as execute_python_code that can be registered directly.
Create a tool-equipped agent and test it.

2.2 Connecting to Real Search — Tavily MCP (Optional)

MCP (Model Context Protocol) is a standardized tool protocol. AgentScope natively supports MCP, enabling plug-and-play integration with various external services. Tavily is a search API designed for AI agents, providing an MCP Server. Once connected, the agent gains real internet search capabilities.
Note: This code requires setting the TAVILY_API_KEY environment variable and installing Node.js (for npx to launch the Tavily MCP Server). If you don’t have these set up yet, you can skip this section and continue using the mock tools from Part 2.1.

Part 3: Giving the Assistant “Memory”

Memory enables the agent to not only remember “what was just said” (short-term memory), but also to remember “who you are” across sessions (long-term memory).

3.1 Short-Term Memory

InMemoryMemory is the most basic memory component.

Memory Marks

Use marks to categorize messages for easy filtering later.

Memory Compression

Automatically compress old messages when conversation exceeds the model’s context window.

Memory Persistence

Export and restore memory state for cross-process session recovery.

3.2 Long-Term Memory — Remembering “Who You Are”

Short-term memory only persists within a single session. ReMePersonalLongTermMemory, based on the ReMe framework, can store and retrieve user profile information across sessions.
Note: Using long-term memory requires an additional installation: pip install 'agentscope[reme]'.
The code below demonstrates the workflow of recording and retrieving user profiles. We write user background information (computer engineer, interested in AI) into long-term memory, which the agent can retrieve at any time.
When integrating with an agent, the recommended approach is to use agent_control mode, allowing the agent to manage memory autonomously:

Part 4: Giving the Assistant “Knowledge” — RAG Integration

Retrieval-Augmented Generation (RAG) enables the agent to retrieve information from documents you provide, rather than relying solely on knowledge from its training data.

4.1 Paper PDF

We use the classic Attention Is All You Need paper as an example. The paper has been pre-downloaded to paper_path at script startup.

4.2 Building the Knowledge Base

Use PDFReader to parse the paper, and SimpleKnowledge + QdrantStore to build a vector knowledge base.
Note: Requires pip install 'agentscope[rag]' for qdrant dependencies.

4.3 Agentic RAG

Register knowledge retrieval as a tool, letting the agent autonomously decide when to query the knowledge base.
Tip: An alternative approach is Generic RAG — pass knowledge directly to ReActAgent’s knowledge parameter for automatic retrieval each turn. Agentic RAG offers more flexibility, while Generic RAG is simpler.

Part 5: The Complete Research Assistant

Integrate tools + memory + knowledge base to build the final version.

ResearchAssistant

Model

qwen-max

Short-term Memory

InMemoryMemory

Long-term Memory

LongTermMemory

Toolkit

search_papers · execute_python_code · take_notes · retrieve_knowledge · record_to_memory · retrieve_from_memory

Next Steps

Congratulations on completing this tutorial! You have mastered the core capabilities of an AgentScope single agent. Next, you can explore: