LogiAgent: Automated Logical Testing for REST Systems with LLM-Based Multi-Agents

Ke Zhang, Chenxi Zhang, Chong Wang, Chi Zhang, YaChen Wu, Zhenchang Xing, Yang Liu, Qingshan Li, Xin PengarXiv 2025 · DOI

TL;DR

This paper introduces LogiAgent, a novel multi-agent system powered by Large Language Models (LLMs) for automated logical testing of REST APIs. Unlike traditional tools that focus on crashes, LogiAgent uses LLMs to generate complex test scenarios and validate responses against business logic, uncovering subtle functional bugs. It demonstrates significant improvements in detecting logical issues and achieving test coverage compared to existing methods.

What Problem Does This Paper Address?

Modern web services rely heavily on REST APIs, making their correctness and reliability crucial. While automated testing tools exist, they often fall short by primarily focusing on detecting server crashes (e.g., 5xx errors) or generating random inputs. This leaves a significant gap in identifying "logical issues" – subtle bugs that arise from incorrect business logic, inconsistent data flow, or violations of domain-specific rules, even when API calls return successful status codes (e.g., 200 OK). These logical flaws can lead to unexpected behavior and vulnerabilities that traditional testing misses. The paper aims to bridge this gap by introducing a more sophisticated approach to logical testing for REST APIs.

Methods

LogiAgent employs a multi-agent system architecture, with each agent leveraging LLMs to perform specific tasks:

  • Test Scenario Generator: This agent uses LLMs to create comprehensive and diverse test scenarios that mimic real-world business logic. It leverages an "API Relationship Graph" (ARG) to understand semantic connections between APIs and uses historical test data to ensure novelty.
  • API Request Executor: This agent is responsible for generating valid API request parameters and executing the API calls. It uses LLMs, informed by previous API interactions and historical execution data (from the Execution Memory), to construct contextually consistent requests.
  • API Response Validator: This agent uses LLMs to assess API responses against "logical oracles." These oracles go beyond simple status code checks and incorporate business logic, domain knowledge, and expected outcomes derived from API documentation and the scenario context.

A Scenario Scheduler manages the execution flow, while a long-term Execution Memory stores historical API execution data (parameter values and failure reflections) to maintain context and improve future test generation. This memory component is crucial for enabling the agents to learn from past executions and avoid repeating errors or generating invalid inputs.

Datasets

The evaluation was conducted on 12 real-world REST systems. These systems vary in size and complexity, ranging from small services with a few operations to larger ones with thousands of lines of code and dozens of APIs. The paper includes a table listing these systems, their lines of code, and the number of operations. Some systems were deployed locally, while others were publicly accessible online APIs.

Key Insights and Ideas

  • LLMs are powerful for logical testing: The paper demonstrates that LLMs can be effectively used not just for generating API calls but also for understanding complex business logic and defining sophisticated test oracles, which is key to uncovering logical bugs.
  • Context is king for API testing: The "Execution Memory" component is vital. By storing and retrieving historical execution data, LogiAgent can maintain contextual consistency across API calls, leading to more realistic and effective test scenarios.
  • Logical oracles are more than status codes: The success of LogiAgent hinges on its ability to define and use logical oracles that go beyond simple HTTP status codes, assessing the actual content and business implications of API responses.
  • Domain-specific challenges remain: While LogiAgent performs well, it faces challenges with highly complex, domain-specific systems where LLMs might struggle to fully grasp intricate business rules, leading to higher false-positive rates.

Key Results

  • Logical Issue Detection: LogiAgent identified 234 potential logical issues across 12 systems, with 66.19% confirmed as true bugs or enhancements after manual verification. This included 139 bugs and 95 enhancements.
  • Server Crash Detection: LogiAgent also performed well in detecting server crashes (500 errors), achieving comparable results to state-of-the-art tools.
  • Test Coverage: LogiAgent significantly outperformed four state-of-the-art REST API testing tools in terms of operation coverage and code coverage (branch, line, and method).
  • Ablation Study: An ablation study confirmed the significant contribution of the Execution Memory component, showing that removing parameter retrieval or failure reflection retrieval negatively impacted code coverage.

Limitations and Future Work

  • False Positives: The paper acknowledges that LLMs can still produce false positives due to hallucinations or misinterpretations of domain knowledge and API specifications. This is particularly noticeable in complex, domain-specific systems.
  • Domain-Specific Knowledge: Future work aims to enhance LogiAgent's capabilities by incorporating domain-specific knowledge bases and potentially analyzing system code when available to improve accuracy and reduce false positives.
  • Scalability and Efficiency: While not explicitly detailed as a limitation, the computational cost of LLM inference and the complexity of managing multi-agent systems are implicit areas for future optimization.

Summary updated

BibTeX
@misc{zhang2025logiagent,
  author = {Ke Zhang and Chenxi Zhang and Chong Wang and Chi Zhang and YaChen Wu and Zhenchang Xing and Yang Liu and Qingshan Li and Xin Peng},
  title = {{LogiAgent: Automated Logical Testing for REST Systems with LLM-Based Multi-Agents}},
  year = {2025},
  eprint = {2503.15079},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.15079},
}
Figure