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. Callagent.interrupt() to cancel the current task. The agent then runs handle_interrupt() for post-processing.
Memory Compression
As conversations grow, token counts can exceed model limits. Enable automatic compression by passing aCompressionConfig when creating the agent:
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.
summary_schema, summary_template, and compression_prompt:
Structured Output
Pass a PydanticBaseModel 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 enablesReActAgent 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.
- 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.
Core attributes and methods:
Manual Plan Specification
Create a plan upfront, then pass thePlanNotebook to ReActAgent:
Agent-Managed Plan Execution
Pass a freshPlanNotebook 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
Hook Signatures
All pre-hooks share the same signature: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
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):
Session Management
A session is a collection ofStateModule 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:
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.A2A Agent
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 manuallyNacosAgentCardResolver 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 anA2AAgent and use it like any other agent:
Chatbot scenario:
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):Multi-Agent with ChatRoom
ChatRoom manages multiple RealtimeAgent instances in a shared conversation space, with automatic message broadcasting and unified lifecycle management.
Event Reference
ModelEvents (Realtime Model → Agent)
ModelEvents (Realtime Model → Agent)
ServerEvents (Backend → Frontend)
ServerEvents (Backend → Frontend)
ClientEvents (Frontend → Backend)
ClientEvents (Frontend → Backend)