Note: The goal of this document is to clarify the problems AgentScope solves in engineering practice and the help it provides to developers, rather than providing rigorous academic definitions.
Core Flow
Before diving into each concept, let’s understand how an agent works. The core of AgentScope is the ReAct Loop (Reasoning + Acting):Message
Problem solved: Agents need a unified data structure to carry various types of information—text, images, tool calls, etc. Message is the most fundamental data structure in AgentScope, used for:- Exchanging information between agents
- Storing conversation history in memory
- Serving as a unified medium for LLM API interactions
Content types:
TextBlock- Plain textImageBlock/AudioBlock/VideoBlock- Multimodal contentThinkingBlock- Reasoning traces (for reasoning models)ToolUseBlock- Tool invocation initiated by LLMToolResultBlock- Tool execution result
GenerateReason Values:
Example:
Agent
Problem solved: Need a unified abstraction to encapsulate the logic of “receive message → process → return response”. The Agent interface defines the core contract:Stateful Design
Agents in AgentScope are stateful objects. Each Agent instance holds its own:- Memory: Conversation history
- Toolkit: Tool collection and their state
- Configuration: System prompt, model settings, etc.
Important: Since both Agent and Toolkit are stateful, the same instance cannot be called concurrently. If you need to handle multiple concurrent requests, create independent Agent instances for each request or use an object pool.
ReActAgent
ReActAgent is the main implementation provided by the framework, using the ReAct algorithm (Reasoning + Acting loop):
For detailed configuration, see Creating a ReAct Agent.
Tool
Problem solved: LLMs can only generate text and cannot perform actual operations. Tools enable agents to query databases, call APIs, perform calculations, etc. In AgentScope, a “tool” is a Java method annotated with@Tool, supporting:
- Instance methods, static methods, class methods
- Synchronous or asynchronous calls
- Streaming or non-streaming returns
Important:@ToolParammust explicitly specify thenameattribute because Java does not preserve method parameter names at runtime.
Memory
Problem solved: Agents need to remember conversation history to have contextual conversations. Memory manages conversation history.ReActAgent automatically:
- Adds user messages to memory
- Adds tool calls and results to memory
- Adds agent responses to memory
- Reads memory as context during reasoning
InMemoryMemory (in-memory storage) by default. For cross-session persistence, see State Management.
Formatter
Problem solved: Different LLM providers have different API formats, requiring an adapter layer to abstract away differences. Formatter is responsible for converting AgentScope messages to the format required by specific LLM APIs, including:- Prompt engineering (adding system prompts, formatting multi-turn conversations)
- Message validation
- Identity handling in multi-agent scenarios
DashScopeChatFormatter- Alibaba Cloud DashScope (Qwen series)OpenAIChatFormatter- OpenAI and compatible APIsAnthropicChatFormatter- Anthropic (Claude series)GeminiChatFormatter- Google GeminiOllamaChatFormatter- Ollama local modelsDeepSeekFormatter- DeepSeekGLMFormatter- GLM (Zhipu)
Formatter is automatically selected based on Model type; manual configuration is usually not needed.
Hook
Problem solved: Need to insert custom logic at various stages of agent execution, such as logging, monitoring, message modification, etc. Hook provides extension points at key nodes of the ReAct loop through an event mechanism:
Hook Priority: Hooks execute in priority order (lower value = higher priority), default is 100.
Example:
For detailed usage, see Hook System.
State Management and Session
Problem solved: Agent state such as conversation history and configuration needs to be saved and restored to support session persistence. AgentScope separates “initialization” from “state” through theStateModule interface:
saveTo(Session, SessionKey)- Save current state to SessionloadFrom(Session, SessionKey)- Restore state from SessionloadIfExists(Session, SessionKey)- Restore state from Session if it exists
Reactive Programming
Problem solved: LLM calls and tool execution typically involve I/O operations; synchronous blocking wastes resources. AgentScope is built on Project Reactor, using:Mono<T>- Returns 0 or 1 resultFlux<T>- Returns 0 to N results (for streaming)
Next Steps
- Creating a ReAct Agent - Complete agent creation tutorial
- Tool System - Learn advanced tool usage
- Hook System - Customize agent behavior
- Model Integration - Integrate different LLM providers