Skip to main content
AgentScope provides several built-in agent types to cover different use cases. Use the cards below to jump to the section you need.

ReAct Agent

The primary agent for tool-using, reasoning, and structured output tasks.

Customizing Agents

Build your own agent by extending AgentBase or ReActAgentBase.

Agent Hooks

Inject custom logic before or after agent core functions.

State and Session Management

Save and restore agent state across sessions.

A2A Agent

Connect to remote agents using the Agent-to-Agent protocol.

Realtime Agent

Handle voice and live interactions with realtime model APIs.

ReAct Agent

ReActAgent is the primary built-in agent in AgentScope. It supports:

Realtime Steering

Realtime steering lets you interrupt an agent mid-reply. Call agent.interrupt() to cancel the current task. The agent then runs handle_interrupt() for post-processing.
You can override handle_interrupt in a subclass to customize the response when an interruption occurs — for example, calling the LLM to generate a context-aware acknowledgment.

Memory Compression

As conversations grow, token counts can exceed model limits. Enable automatic compression by passing a CompressionConfig when creating the agent:
When the token count exceeds trigger_threshold, the agent compresses older messages into a structured summary with these default fields:
Compression uses a marking mechanism — old messages are marked as compressed and excluded from future retrievals, while the summary is stored separately. Original messages are preserved.
Customizing compression You can control the compression behavior with summary_schema, summary_template, and compression_prompt:
Use a smaller, faster model for compression by specifying compression_model and compression_formatter to reduce cost and latency.

Structured Output

Pass a Pydantic BaseModel subclass as structured_model when calling the agent. The structured result is available in response.metadata.
response.get_text_content() still returns the text content. The structured data is in response.metadata.

Planning

The Plan Module enables ReActAgent to formally break down complex tasks into manageable sub-tasks and execute them systematically. Pass a PlanNotebook instance via the plan_notebook parameter to activate it. Once provided, the agent:
  • Is automatically equipped with plan management tool functions
  • Receives a hint message at the beginning of each reasoning step guiding it through the current plan
The current plan module requires subtasks to be executed sequentially. Parallel subtask execution is on the roadmap.
Key capabilities:
  • Creating, modifying, abandoning, and restoring plans
  • Switching between multiple plans
  • Gracefully handling interruptions by temporarily suspending the current plan
  • Real-time visualization and monitoring via plan change hooks

PlanNotebook

PlanNotebook is the core class. It manages plan state, provides tool functions, and generates hint messages.
The plan_to_hint callable is the primary interface for prompt engineering. Provide your own implementation for better performance.
PlanStorageBase inherits from StateModule, so plan storage is automatically saved and loaded by session management.
Core attributes and methods:

Manual Plan Specification

Create a plan upfront, then pass the PlanNotebook to ReActAgent:

Agent-Managed Plan Execution

Pass a fresh PlanNotebook and let the agent decide when and how to plan. For complex tasks, the agent will create a plan autonomously and execute it step by step:

Plan Visualization and Monitoring

Register a hook to react whenever the plan changes — useful for forwarding plan state to a frontend or logging system:

Customizing Agents

AgentScope provides two base classes for building custom agents: Inherit from AgentBase for simple agents, or ReActAgentBase if you want the reasoning/acting separation with corresponding hooks.

Agent Hooks

Hooks let you inject custom logic at specific points in an agent’s execution without modifying its core code.

Supported Hook Types

Hooks are implemented via metaclass and support inheritance — subclasses automatically inherit hook support from their parent classes.

Hook Signatures

All pre-hooks share the same signature:
Post-hooks receive an additional output argument:
All positional and keyword arguments of the core function are passed as a single kwargs dict. When a hook returns None, the next hook receives the most recent non-None return value (or the original arguments if all previous hooks returned None).

Hook Management

AgentScope provides the following methods to manage instance-level hooks: Example: modifying message content before reply
Never call the core function (reply, observe, print, _reasoning, _acting) inside a hook — this will cause an infinite loop.

State and Session Management

StateModule

StateModule is the foundation for state management. Any class that inherits from it can register attributes as part of its state, enabling serialization and restoration. AgentBase, MemoryBase, LongTermMemoryBase, and Toolkit all inherit from StateModule. Attributes that themselves inherit from StateModule are automatically included in the parent’s state (nested serialization):
Saving and restoring agent state:

Session Management

A session is a collection of StateModule objects (e.g., multiple agents) whose state you want to persist together. AgentScope provides JSONSession, which saves and loads session state as a JSON file named by session ID:
Saving a session:
Loading a session:
You can pass multiple agents to save_session_state and load_session_state as keyword arguments. The keyword names must be consistent between save and load calls.
JSONSession is a concrete implementation of SessionBase. You can implement your own session class with a custom storage backend (e.g., Redis, a database) by subclassing SessionBase and implementing save_session_state and load_session_state.

A2A Agent

A2A support is an experimental feature and may change in future versions. Current limitations include:
  • Only supports chatbot scenarios (one user, one agent)
  • Does not support real-time interruption
  • Does not support structured output
  • Messages received via observe are sent to the remote agent only when reply is called
A2AAgent lets you communicate with any remote agent that implements the A2A protocol. The related classes are:

Obtaining an Agent Card

An Agent Card describes the remote agent’s name, capabilities, and connection details. There are four ways to obtain one. 1. Create manually
2. Fetch from a well-known URL
3. Load from a local JSON file
The JSON file should follow this format:
4. Fetch from Nacos registry
NacosAgentCardResolver requires a Nacos server version 3.1.0 or higher with the Agent Registry feature enabled.

Using A2AAgent

Once you have an Agent Card, create an A2AAgent and use it like any other agent: Chatbot scenario:
As a tool function (handoff/router pattern):

Realtime Agent

The realtime agent is currently under active development. Contributions, discussions, and feedback are welcome.
RealtimeAgent is designed for real-time interactions such as voice conversations. It bridges realtime model APIs with your application via a unified event interface.

Supported Providers

Initializing a realtime model:

Creating a RealtimeAgent

Starting a Realtime Conversation

A typical setup uses a WebSocket server (e.g., FastAPI) as the backend and a browser client as the frontend. Backend (FastAPI):
Frontend (JavaScript):

Multi-Agent with ChatRoom

ChatRoom manages multiple RealtimeAgent instances in a shared conversation space, with automatic message broadcasting and unified lifecycle management.

Event Reference