Deep Dive into Open-Source Long-Horizon AI Agent Models: Long Context, Sparse Attention, and Tool Calling

    This article explores the technical architecture and engineering practices of open-source long-horizon AI agent models. It covers the transition to Mixture of Experts (MoE) architectures, the implementation of dynamic sparse attention and Delta attention for ultra-long contexts, reinforcement learning post-training, low-bit quantization, and flexible inference budgets. Additionally, it provides practical guidance on tool calling, context management, and deployment performance optimization.

    1. Background: Why Long-Horizon Agents Require New Model Capabilities

    As AI agents transition from single-turn Q&A to multi-step task execution, models must simultaneously handle longer contexts, more complex tool calling chains, and uncertain execution environments. Traditional models often struggle with context loss, unstable reasoning, and tool call misalignment when dealing with long documents, code repositories, terminal operation logs, or design tasks.

    The core challenges of long-horizon agents can be summarized in three points:

    1. Significant Increase in Context Scale: A complete software engineering task may involve multiple source files, terminal outputs, test logs, and historical operation records. The context can easily reach hundreds of thousands or even millions of tokens.
    2. Higher Requirements for State Tracking: The model must not only understand the current input but also continuously remember the intent of previous steps, completed modifications, failure reasons, and the next plan.
    3. Rising Attention Computation Costs: For ultra-long sequences, traditional full attention mechanisms struggle to balance latency, VRAM, and performance. More efficient sparse attention solutions are required.

    Therefore, models designed for long-horizon agents require collaborative optimization across architecture design, training methods, and inference deployment, rather than merely increasing parameters or stacking more data.

    2. Overall Architecture: Mixture of Experts and Ultra-Long Context

    The open-source long-horizon model discussed adopts a Mixture of Experts (MoE) architecture. Its parameter scale can be summarized as approximately 2.8T total parameters and 104B activated parameters. The advantage of the MoE approach is that it only activates a portion of the expert networks during inference, controlling the per-token computation cost while maintaining a large model capacity.

    2.1 Why MoE?

    The MoE model splits the feedforward network into multiple expert modules. Each token selects a subset of experts for computation based on a routing strategy. For long-horizon agent tasks, MoE offers several practical benefits:

    • Decoupling Capacity and Efficiency: The total model capacity is large, covering more complex knowledge distributions; however, only a fraction of parameters are activated during inference, keeping latency controllable.
    • Better Multi-task Adaptability: Different experts can handle distinct functions such as code understanding, document analysis, mathematical reasoning, or tool calling.
    • More Suitable for Long Context Serving: In ultra-long sequence scenarios, the limited activated parameters mean that KV cache and computation pressure do not scale linearly with the total parameter count.

    Of course, MoE also introduces challenges like training stability, expert load balancing, and inference scheduling complexity. Actual deployment requires specialized optimizations for expert parallelism, batching, and caching strategies within the framework.

    2.2 Native Image-Text Input and Multimodal Extension

    The model supports image-text input, enabling agents to understand not only code and document text but also UI screenshots, architecture diagrams, design drafts, or CAD images. For scenarios like terminal operations, software engineering, and 3D design, visual information is often more intuitive than plain text.

    In practical applications, image-text input can be used to:

    • Read UI states to determine if an operation was successful;
    • Understand dimensions, annotations, and structural relationships in design drawings;
    • Combine console screenshots with logs to locate runtime errors;
    • Assist in 3D model generation by understanding reference images or schematic structures.

    Multimodal capabilities must work in tandem with tool calling. After viewing a screenshot, the model should convert it into the next operation or repair command, rather than merely describing the image.

    3. Attention Mechanism: From Full Attention to Sparse Attention

    This model features a significant modification in the attention layers: replacing the original Gated Multi-head Latent Attention in certain layers with Gated Dynamic Sparse Attention, used in combination with another type of Delta Attention layer. As a result, during long sequence computation, the model no longer allows every token to interact with all historical tokens. Instead, it dynamically selects a subset of historical tokens for computation.

    3.1 Basic Concept of Sparse Attention

    In a standard Transformer, every query token must compute attention weights against all key-value tokens. As sequence length increases, computation and VRAM usage grow quadratically. Sparse attention aims to reduce the number of key-values participating in the computation through a selection mechanism.

    The model’s approach can be understood as: within the relevant attention layers, each query token selects about 2,048 tokens from the historical sequence to participate in attention computation. This selection is not a fixed sliding window but is dynamically based on the match between the query and history, balancing efficiency and information recall.

    3.2 Combination with Delta Attention Layers

    The model does not use the same attention structure across all layers. Public information indicates that it combines dynamic sparse attention with a Delta Attention mechanism. Delta attention is typically used to capture changes or incremental information within a sequence, which is crucial in long-horizon tasks.

    During agent execution, the model needs to distinguish “which historical states are outdated,” “which operations changed the environment,” and “which outputs are still valid.” The Delta mechanism helps the model perceive state changes more acutely, while sparse attention reduces overall computation overhead.

    3.3 Engineering Implementation Notes

    The actual performance of sparse attention heavily depends on implementation quality. The inference framework must support:

    • Dynamic Top-K selection kernels;
    • Efficient KV cache management;
    • Correct backpropagation and quantization for sparse selection results;
    • Compatibility with batching and parallelism strategies.

    If the deployment layer is not optimized for sparse attention, the actual latency may fail to meet expectations due to low kernel efficiency, even if the algorithm reduces computation. Therefore, during technology selection, focus on the inference framework’s joint optimization capabilities for sparse attention and MoE.

    4. Training and Quantization: RL Post-Training and Low-Bit Weights

    Built upon a base model, this model underwent large-scale joint reinforcement learning (RL) post-training covering hundreds of downstream domains. Compared to supervised fine-tuning alone, joint RL is more effective at improving the model’s exploration, error correction, and tool calling capabilities in multi-step tasks.

    4.1 Reinforcement Learning for Agents

    Long-horizon agent tasks often lack a single standard answer. The model must learn to try, observe feedback, and adjust strategies in uncertain environments. RL provides more flexible optimization signals for such tasks.

    Typical training tasks include:

    • Terminal Operations: Given a goal, the model executes commands, observes output, and fixes errors in a simulated environment;
    • Code Repair: Addressing test failures or bug reports, the model locates issues and submits fixes;
    • Document Processing: Parsing long documents, extracting key information, and generating structured results;
    • Design Generation: Generating CAD structures or 3D designs based on constraints.

    The key to joint RL is task diversity. Optimizing for a single domain may cause the model to overfit specific tool formats or environmental features, degrading generalization. Covering multiple downstream domains helps the model learn more general planning, execution, and correction strategies.

    4.2 Low-Bit Weight Quantization

    The model provides a low-bit weight format. This format reduces VRAM usage and loading overhead while maintaining inference accuracy. For ultra-large parameter models, low-bit quantization is a common method to lower deployment barriers.

    It is important to note that quantization is not lossless. Different layers have varying sensitivities to quantization. Attention layers, routing layers, and feedforward layers may require differentiated handling. A reasonable quantization scheme usually combines calibration data, layer-wise error analysis, and mixed-precision strategies. It is recommended to verify the performance loss on the target task set before deployment.

    5. Inference Tiers: Allocating Thinking Budgets for Different Tasks

    The model offers three inference thinking budgets: Low, High, and Max. This design allows users to flexibly adjust the model’s reasoning depth based on task complexity and latency requirements.

    5.1 Meaning of the Thinking Budget

    The thinking budget represents the reasoning resources the model can consume before providing a final answer, including thinking steps, intermediate reasoning tokens, or internal planning rounds. A higher budget gives the model more room for multi-step reasoning, self-checking, and alternative evaluation, but latency and cost also increase.

    5.2 Applicable Scenarios for the Three Tiers

    • Low: Suitable for low-complexity tasks like simple information extraction, short text classification, and basic Q&A. Low latency and controllable cost.
    • High: Suitable for medium-complexity tasks like code review, document analysis, and tabular reasoning. The model can perform more internal deductions.
    • Max: Suitable for scenarios requiring deep reasoning, such as long-horizon planning, complex debugging, multi-tool collaboration, and design generation. Sufficient timeout and retry strategies should be reserved here.

    In practice, a task routing strategy can automatically select the tier. For example, a lightweight model first evaluates task complexity, then decides whether to invoke Max tier inference. This optimizes overall resource consumption while ensuring performance.

    5.3 Relationship with Tool Calling

    The thinking budget also affects the rhythm of tool calling. Under a high budget, the model may plan more thoroughly before calling a tool; under a low budget, it may initiate the call faster but with less planning. For agent scenarios requiring multiple tool calls, it is advisable to use a higher budget at key decision points and a lower budget for mechanical operation steps.

    6. Typical Application Scenarios and Engineering Practices

    6.1 Code Development and Terminal Operations

    In code development scenarios, the agent needs to read repository structures, search relevant files, modify code, and run tests. Ultra-long context allows it to retain more file content and operation history, reducing repeated reads caused by context truncation.

    A typical code repair workflow is as follows:

    1. 1. Read the issue description and repository structure
    2. 2. Search for relevant source code and configuration files
    3. 3. Locate the suspicious code segment
    4. 4. Modify the code
    5. 5. Run tests or static checks
    6. 6. Determine whether to continue fixing based on the output
    7. 7. Output the final patch and change description

    In this workflow, the model must save the tool call results and decision basis for each step. During multi-turn tool calling, the complete history of thoughts and tool messages should be retained in the context to prevent the model from forgetting previous steps due to truncation.

    6.2 Knowledge Work and Document Processing

    Knowledge work scenarios include web search, financial research, and office document processing. These tasks demand high capabilities in long document understanding, information integration, and structured output.

    An actual system can be designed as:

    • Retrieval Phase: The model generates queries and calls search tools;
    • Reading Phase: Segmenting, reading, and summarizing retrieval results;
    • Reasoning Phase: Forming conclusions based on multi-source information;
    • Output Phase: Generating reports, tables, or decision recommendations.

    Since the context may contain massive retrieval results and intermediate notes, sparse attention and long-context capabilities offer distinct advantages in such tasks.

    6.3 3D Design and CAD Generation

    In 3D design and CAD generation, the model needs to understand spatial constraints, parameter relationships, and tool interfaces. Image-text input helps the model read design sketches or current model screenshots and adjust generation results based on feedback.

    A common workflow includes:

    1. 1. Parse design requirements and constraints
    2. 2. Generate parametric designs or scripts
    3. 3. Call modeling tools to generate 3D structures
    4. 4. Adjust parameters based on rendering results or geometric inspection feedback
    5. 5. Output the final design file

    This scenario requires high integrity for the tool calling chain. Any lost generation result or format error in a step may cause subsequent steps to fail. Therefore, the system should record the input, output, and status of each tool call, and support replay or breakpoint recovery upon errors.

    7. Tool Calling and Context Management

    7.1 Multi-Turn Tool Calling Requires Complete History

    In long-horizon agent tasks, the model needs to access tools repeatedly. Unlike single-turn Q&A, multi-turn tool calling involves the following message types:

    • User messages;
    • Model thinking messages;
    • Tool call requests;
    • Tool return results;
    • Model’s subsequent reasoning on the results;
    • Next round of tool calls.

    These messages collectively form the agent’s execution state. Simply truncating or summarizing historical messages during inference may cause the model to lose critical context, especially detailed error messages, file contents, or status codes from tool returns. Therefore, deployment should strive to retain the complete history or adopt a verified context compression strategy.

    7.2 Tool Interface Compatibility

    Model services typically provide interfaces compatible with common agent frameworks, such as OpenAI or Anthropic style APIs. This facilitates quick integration with existing agent frameworks. Note that different frameworks define tool calling message formats differently, so field mapping should be handled carefully during integration.

    A generic tool call request can be represented as:

    1. {
    2. "role": "assistant",
    3. "content": "Call the terminal command to view the current directory",
    4. "tool_calls": [
    5. {
    6. "id": "call_001",
    7. "type": "function",
    8. "function": {
    9. "name": "run_command",
    10. "arguments": "{\"command\":\"pwd\"}"
    11. }
    12. }
    13. ]
    14. }

    The server should ensure that the tool call ID is unique throughout the session and correctly associated in the return result.

    7.3 Timeout and Retry Strategies

    Long-horizon tasks are often accompanied by network fluctuations, tool timeouts, or environmental exceptions. Production-grade systems need robust fault tolerance mechanisms:

    • Set reasonable timeouts for tool calls;
    • Support automatic retries with exponential backoff;
    • Record status for non-retryable operations to avoid duplicate execution;
    • Allow recovery from the latest checkpoint after a model inference timeout;
    • Parse and repair output format errors.

    These engineering strategies are as important as the model’s own capabilities, directly determining whether the agent system can run stably in real business scenarios.

    8. Deployment and Performance Considerations

    8.1 Inference Framework Support

    The model weights can be loaded in various inference frameworks, commonly including vLLM, SGLang, etc. Different frameworks offer varying levels of support for MoE, sparse attention, and low-bit quantization. Evaluate based on hardware environment and concurrency requirements before deployment.

    Key metrics to consider include:

    • Time to first token;
    • Per-token generation speed;
    • Maximum concurrency;
    • VRAM usage under long contexts;
    • Stability of sparse attention kernels;
    • Compatibility with existing service gateways.

    8.2 Hardware Selection Recommendations

    For a model with 2.8T total parameters and 104B activated parameters, single-GPU inference is usually impractical. The standard approach is to use multi-GPU tensor parallelism and expert parallelism. Specific hardware configurations depend on the quantization format, context length, and concurrency targets.

    It is recommended to conduct benchmark tests before deployment, focusing on:

    • Throughput under different parallelism strategies;
    • VRAM bottlenecks during long sequence inference;
    • Scheduling efficiency under large batch requests;
    • Impact of low-bit weights on output quality.

    8.3 Context Length and Cost-Effectiveness

    Although the model supports ultra-long context, not all tasks require the maximum length. More input tokens lead to larger KV caches and higher inference costs. A reasonable approach is to control the context length dynamically based on task type:

    • Simple tasks: carry only necessary background;
    • Medium tasks: retain key files and tool results;
    • Long-horizon tasks: use complete history.

    Additionally, historical messages can be managed in tiers, keeping high-priority information intact while summarizing or archiving low-priority information to strike a balance between performance and cost.

    9. Licensing and Compliance Considerations

    The model weights use a specific license, rather than a common permissive open-source protocol. Enterprises should carefully read the license terms before using this model in commercial products, focusing on:

    • Whether commercial use is allowed;
    • Whether derivative models must be open-sourced;
    • Provisions regarding output ownership and liability;
    • Redistribution restrictions for modified weights;
    • Constraints on providing inference in cloud services.

    Unlike Apache 2.0 or MIT licenses for code repositories, model weight licenses may impose additional restrictions. Legal teams should complete compliance assessments before integration to avoid subsequent business risks.

    10. Conclusion and Technology Selection Advice

    Open-source long-horizon agent models show clear trends in architecture, attention mechanisms, training methods, and inference tiers: ultra-long context, sparse attention, joint reinforcement learning, low-bit quantization, and flexible thinking budgets are becoming the key capability combination in this field.

    For developers and enterprise teams, consider the following points during technology selection and implementation:

    1. Task Match: Prioritize evaluating the model’s actual performance in target scenarios rather than solely looking at general benchmarks.
    2. Deployment Cost: Calculate the per-request cost based on quantization format, parallelism strategy, and hardware conditions.
    3. Toolchain Compatibility: Confirm the match between the model service interface and existing agent frameworks.
    4. Stability Engineering: Design timeout, retry, breakpoint recovery, and log tracing mechanisms for long tasks.
    5. Compliance Risks: Carefully review model licenses and dataset usage terms.

    Long-horizon agents are not about a single model capability, but rather a system engineering endeavor encompassing architecture design, training strategies, inference optimization, and engineering governance. Understanding these underlying mechanisms helps teams make more robust architectural decisions in a rapidly changing technical landscape.