Choosing a Development Framework for Java AI Agent Applications

    Building a useful AI agent in Java requires more than a framework that can call an LLM. Based on a year-long agent project, this article compares four common implementation approaches in the Java ecosystem and evaluates them across five practical dimensions: memory management, task scheduling, hot-pluggable skill packages, tool-protocol integration, and sandboxed code execution. It also shares implementation details and pitfalls around a shared workspace, file-based conversation memory, MCP endpoint registration, execution timeouts, permission isolation, and sandbox fallback. The goal is to show how teams can choose a framework by validating infrastructure completeness, customization, ecosystem openness, and community activity against their critical business paths, then extend a mature framework with modular capabilities.

    1. Background: Starting from an Agent Project

    Last year, we used a mainstream Java development framework to implement RAG retrieval-augmented generation, conversational window memory, and basic function calling. The overall conclusion was that it worked, but it was still some distance from a proper AI agent. Over the following year, these frameworks gradually added key capabilities such as tool-protocol integration, skill-package management, and sandboxed code execution, making it increasingly practical to build complete agent applications on the Java side.

    Before deciding how to evolve, we compared several typical agent development approaches in the Java ecosystem. Their positioning differs:

    • Deep integration with Spring: low ramp-up cost and configuration-driven usage; suitable for teams already on the Spring stack, but deep customization requires understanding internal framework conventions.
    • Lightweight standalone framework: no dependency on a specific container, flexible API design, and an emphasis on chained orchestration; suitable for scenarios requiring fine-grained control over execution flow, but lower-level infrastructure such as persistence and scheduling must be built separately.
    • Agent extension from a lightweight application framework: very small footprint and fast startup; suitable for resource-sensitive or embedded deployment scenarios, though the ecosystem is relatively new.
    • Community-driven newer approach: maintained by an active developer community with rapid iteration and a quick response to new features such as sandbox execution and skill packages; suitable for teams willing to grow alongside the project.

    Our conclusion was that framework selection should not focus only on whether the API is pleasant to use. The extensibility of the following five modules should be treated as core evaluation dimensions. The rest of this article follows our practice and discusses them one by one.

    2. Memory Management: Combining Short-Term Sessions with Long-Term Knowledge

    Most out-of-the-box memory implementations are in-memory, so history is lost when the process restarts. That is clearly insufficient for an agent. Drawing on common practices from terminal-based agent products, we split memory into two layers and place both under a shared workspace:

    Layer Who writes Location How it reaches the model
    Short-term conversation history Written automatically by the framework One file per session ID under {workspace}/conversations/ History is injected automatically each turn
    Long-term knowledge Decided by the model Files organized by topic under {workspace}/memory/ Read on demand through prompt conventions and tool functions

    The shared workspace is the integration point. Short-term memory is handled by the framework: each incoming message is appended automatically, imposing zero mental burden on the developer. Long-term memory is managed by the model itself, which decides what is worth remembering and which file it belongs in, and then persists it through a “write memory” tool function. The two layers have separate responsibilities and do not interfere with each other.

    For implementation, short-term memory only requires a file-based ChatMemoryRepository: one YAML file per session, with frontmatter recording timestamps and session metadata and the body containing the message list. A human can open the file in an editor and review it directly. An illustrative structure:

    1. createdAt: 2025-01-10T09:00:00
    2. channel: customer-a
    3. messages:
    4. - role: user
    5. content: Please organize yesterday's retrospective highlights.
    6. - role: assistant
    7. content: The highlights have been generated and written to long-term memory...

    One important pitfall in practice is that read and write permissions for long-term memory must be constrained. Initially, we allowed the model to read every file in the workspace. As a result, it sometimes read another customer’s conversation content into context, creating an unauthorized-access issue. We solved this by adding path allowlisting and channel-based isolation to the validation logic in the tool layer.

    3. Task Scheduling: Giving Agents Long-Running Execution

    Agents inherently need the ability to “say something today and act tomorrow,” such as scheduled patrols and periodic summaries. A common industry approach is to introduce a mature distributed task scheduling component that supports one-time delayed tasks, fixed-time tasks, and cron-based periodic tasks. Our approach was:

    1. Define a set of “agent task” entities containing the target description, bound conversation, trigger policy, and maximum retry count.
    2. On each trigger, the scheduling layer assembles a conversation initiated under the system identity and hands it to the agent for execution.
    3. Execution results are written back to the conversation history and long-term memory to keep context continuous.

    The key details are idempotency and timeouts. Model calls can be slow or even time out, so the scheduler must have explicit execution timeouts and retry limits; otherwise, a failed periodic task may accumulate a large number of retries. We set a hard deadline and a state machine for each task (pending, triggered, succeeded, failed, abandoned), and the admin side can directly see the reason for failure.

    4. Hot-Pluggable Skill Packages: Changing Skills Without Restarting the Agent

    The industry calls this kind of capability Skills. In essence, prompt templates, scripts, and resource files are packaged in a directory structure, allowing capabilities to be loaded dynamically per request. The common official approach is to define a directory convention. Our implementation added three points:

    • Lifecycle management: Skill packages have clear states (registered/enabled/disabled/uninstalled). On enable, the system validates prompt effectiveness and registers tool functions; on disable, it performs reverse cleanup to avoid dangling references.
    • Isolation and retrieval: When there are many skills, they cannot all be inserted into the context. We build an index by name and description so the model can first use a tool to search for “which skills exist” and then load details on demand, significantly reducing token consumption.
    • Security review: Skill packages may include scripts. Before loading, they must pass allowlisting and static checks to prevent arbitrary command injection.

    The value of hot plugging lies in the operating rhythm: when an operations team member changes a skill package file, the change takes effect on the next request without going through a release process.

    5. Tool Protocol Integration: Reusing the Existing Tool Ecosystem

    The model context protocol (MCP), an open specification for tool integration, offers its greatest value through ecosystem reuse. Many existing tool services—file, browser, and database front-end services, for example—need only protocol integration, after which the agent immediately gains the corresponding capabilities. We focused on solving “dynamic registration”:

    • A configuration center maintains a list of MCP service endpoints. The application listens for changes and automatically performs the handshake, tool discovery, and registration when endpoints are added or removed.
    • Each endpoint receives connectivity liveness checks and timeout isolation, preventing one slow endpoint from dragging down the entire tool-call chain.
    • When tool names conflict, they are isolated with namespace prefixes to prevent same-named tools from overwriting one another.

    A pitfall: some endpoints expose tools at a very fine granularity, so a single conversation may trigger dozens of calls. We later added a call budget (an upper limit on tool calls per conversation turn) and used prompts to guide the model toward combining calls. Stability improved noticeably.

    6. Sandboxed Code Execution: Containing Generated Code in a Container

    Sandbox execution (a common agent-sandbox capability) is key to letting the model actually run generated code and observe the output, roughly equivalent to the “code interpreter” experience in general-purpose assistant products. Implementation points:

    1. Container isolation: start an ephemeral container for each execution; limit CPU, memory, execution time, and network egress; and destroy it after execution.
    2. File transfer: mount the workspace into the container as a shared volume; restrict code reads and writes to allowlisted paths.
    3. Result return: capture standard output, exit code, and artifact files, and have the framework relay them to the model for further reasoning.
    4. Fallback strategy: when the container quota is exhausted or the runtime is unavailable, degrade to “static analysis + model self-check” to keep the chain available and uninterrupted.

    7. Back to Framework Selection: Our Criteria

    Based on a year of practice, when evaluating whether a Java agent development approach fits your needs, we recommend focusing on four points: infrastructure completeness (whether memory and scheduling are available out of the box), extensibility of the human–agent boundary (whether hot-pluggable business customization is allowed), ecosystem openness (whether general tool protocols can be reused), and community activity (iteration speed and issue responsiveness). No framework is absolutely better or worse. The most reliable approach is to move away from the habit of comparing parameters and popularity and instead validate the framework against the critical paths in your own business.

    For us, the final technical route was to build on a mature framework and fill the gaps with our own implementations of the five modules described above. This is also the core methodology this article aims to convey: a framework solves the zero-to-one problem; modular design solves the one-to-strong problem.