Skip to main content
This chapter introduces the core concepts in AgentScope from an engineering perspective to help you understand the framework’s design philosophy.
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):
Now let’s explore each concept in detail.

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
Core fields: Content types:
  • TextBlock - Plain text
  • ImageBlock / AudioBlock / VideoBlock - Multimodal content
  • ThinkingBlock - Reasoning traces (for reasoning models)
  • ToolUseBlock - Tool invocation initiated by LLM
  • ToolResultBlock - Tool execution result
Response Metadata: Messages returned by Agent contain additional metadata to help understand execution state: 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
Example:
Important: @ToolParam must explicitly specify the name attribute 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
Uses 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
Built-in implementations:
  • DashScopeChatFormatter - Alibaba Cloud DashScope (Qwen series)
  • OpenAIChatFormatter - OpenAI and compatible APIs
  • AnthropicChatFormatter - Anthropic (Claude series)
  • GeminiChatFormatter - Google Gemini
  • OllamaChatFormatter - Ollama local models
  • DeepSeekFormatter - DeepSeek
  • GLMFormatter - 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 the StateModule interface:
  • saveTo(Session, SessionKey) - Save current state to Session
  • loadFrom(Session, SessionKey) - Restore state from Session
  • loadIfExists(Session, SessionKey) - Restore state from Session if it exists
Session provides persistent storage across runs:

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 result
  • Flux<T> - Returns 0 to N results (for streaming)

Next Steps