LoongFlow Documentation

repository·main·Indexed 19 days ago

https://github.com/baidu-baige/loongflow

An expert-grade Agent development framework designed for complex, long-range reasoning tasks. LoongFlow utilizes the PES (Planning-Execution-Summary) paradigm to enable structured thinking and continuous learning through a Multi-Structure Fusion Memory system. It features the PESAgent for evolutionary workflows and the ReActAgent for tool-driven tasks, supporting OpenAI-compatible APIs and providing a real-time visualization server for tracking agent evolution.

Tokens
37.4K
Snippets
98
Records
143
Agent score
66%

What's inside LoongFlow

  1. Explore LoongFlow examples

    main

    LoongFlow includes several categories of examples to demonstrate its capabilities:

    • General Agent: Focuses on flexible coding tasks with progressive difficulty (Beginner to Expert). Examples include a TODO list app, a file processor, a bug hunter, and circle packing.
    • Mathematical Challenges: Demonstrates SOTA performance on geometry and algebra problems (e.g., circle packing, hexagon packing, autocorrelation inequalities).
    • MLE-bench (Kaggle Challenges): Shows high-performance results across various machine learning competitions (e.g., aerial cactus identification, cancer detection, etc.).

    For a structured learning path, refer to the Complete Tutorial.

  2. Key features of LoongFlow memory

    main

    The memory system provides several automated capabilities:

    • Evolution State Management: Handles island allocation, population management, and elite archiving.
    • History Compression: Uses LLMs to intelligently compress message history to stay within token limits.
    • Persistent Storage: Supports both in-memory and file-based storage backends.
    • Automatic Management: Includes automatic token counting, memory cleanup, and compression triggers.
  3. Performance Benchmarks and Metrics for LoongFlow

    main

    LoongFlow utilizes the PES (Plan-Execute-Summarize) thinking paradigm to achieve expert-level performance in mathematical discovery and machine learning.

    Key Performance Metrics

    Evolutionary Efficiency

    • Math Convergence: ~50 iterations to reach State-of-the-Art (SOTA).
    • ML Convergence: ~30 iterations to reach Gold level in Kaggle-style competitions.
    • Cost: Approximately $0.05-$0.10 per iteration when using Gemini 3 Pro.

    Stability and Success Rates

    • Success Rates:
      • Math Optimization: 95%
      • Machine Learning: 90%
      • Algorithm Discovery: 85%
    • Failure Recovery: 85% of local optima escapes succeed within 5 generations.
    • Experience Reuse: 80% of successful strategies are reusable across different problem domains.

    Computational Resource Requirements

    • Base Memory Usage: ~500MB RAM.
    • Incremental Memory: ~100MB extra RAM per evolutionary island.
    • Cycle Latency: 5-43 seconds per complete PES cycle.

    Comparison with Other Approaches

    MetricPrompt-based AgentsOpenEvolveLoongFlow
    Reasoning DepthShallowLimitedDeeply Structured
    Learning CapabilityNonePartialComplete PES Learning
    StabilityFragileUnstableHigh Stability
    Expert-level PerformanceRareSometimesConsistent
  4. What is PESAgent?

    main

    PESAgent is an evolutionary agent designed for long-horizon tasks using a "Planner-Executor-Summary" paradigm. It mimics human research workflows by transforming single-step generation into a continuous evolutionary process through three stages:

    1. Planner (Strategist): Analyzes the global evolutionary state and historical trajectory to propose high-value directions for the next iteration.
    2. Executor (Engineer): Implements suggestions, generates code/solutions, runs self-tests, and submits results for evaluation.
    3. Summary (Reviewer): Analyzes execution results, extracts insights (successes/failures), updates evolutionary memory, and refines the knowledge base.

    It supports an Island Model Evolution, allowing concurrent evolution across multiple "islands" with migration mechanisms to maintain diversity and escape local optima.

  5. What is LoongFlow and its core paradigm

    main

    LoongFlow is an expert-grade Agent development framework designed for complex, long-range reasoning tasks. It uses the PES (Planning-Execution-Summary) paradigm to enable structured thinking, allowing Agents to tackle high-difficulty tasks with a rigorous mindset similar to a human scientist.

    Key features include:

    • Intelligent Thinking: The PES paradigm provides a structured loop for long-horizon reasoning.
    • Continuous Learning: Uses a Multi-Structure Fusion Memory to synthesize experience during task iterations, enabling a "run-and-improve" mechanism without heavy retraining.
  6. What is PESAgent and its core components?

    main

    PESAgent is an evolutionary agent designed for long-horizon tasks using the "Planner-Executor-Summary" (PES) paradigm. It mimics a human researcher's exploratory workflow by transforming single-step generation into a continuous evolutionary process.

    Core Components

    • Planner: The strategist. Analyzes global evolutionary state and historical trajectories to propose high-value improvement directions for the next iteration.
    • Executor: The engineer. Implements the Planner's suggestions, generates code/solutions, runs self-tests, and submits results for evaluation.
    • Summary: The reviewer. Analyzes execution results, extracts insights (successes/failures), updates evolutionary memory, and optimizes the knowledge base.

    Key Features

    • Three-stage Evolution: Optimization cycles are split into Planning (direction), Execution (implementation), and Summary (reflection).
    • Island Model Evolution: Supports concurrent evolution across multiple "islands" with migration mechanisms to maintain population diversity and avoid local optima.
    • Advanced Memory: Uses MAP-Elites and Boltzmann sampling for efficient solution population management.
  7. What is the PES thinking paradigm?

    main

    The PES (Plan-Execute-Summarize) thinking paradigm is the core reasoning structure used by LoongFlow agents to solve long-horizon complex reasoning problems. Every agent iteration follows these three stages:

    1. Plan: Understand tasks and constraints, and design high-quality execution blueprints.
    2. Execute: Conduct structured experiments and verify intermediate results.
    3. Summarize: Deeply reflect on successes and failures to extract reusable insights.

    This paradigm, combined with a multi-structure fusion memory system, enables agents to achieve 'leapfrog reasoning' by breaking through the limitations of local search through continuous learning and evolution.

  8. Configure Automatic Compression in GradeMemory

    main

    When the total token count in the memory layers exceeds the configured token_threshold, GradeMemory automatically triggers a compression workflow:

    1. It merges messages from the STM and MTM layers.
    2. It uses an LLM to generate a concise summary of the merged content.
    3. It clears the session memory (STM) and retains the new summary in the MTM layer.

    To customize the compression logic, you can use the LLMCompressor class.

    from loongflow.agentsdk.memory.grade.compressor import LLMCompressor
    compressor = LLMCompressor(model)
  9. Use self-deployed or custom LLMs with LoongFlow

    main
    LoongFlow supports any OpenAI-compatible API, including commercial providers (OpenAI, Google) and local deployments (vLLM, sglang). To use your own model, configure the llm_config in your settings to point to your specific endpoint.
  10. How Grade Memory's three-layer architecture works

    main

    Grade Memory manages agent conversation history using a hierarchical three-layer architecture designed to balance access speed, context retention, and token efficiency:

    1. Short-Term Memory (STM): Stores the most recent conversation history. It provides fast access but is non-persistent and typically defaults to in-memory storage.
    2. Medium-Term Memory (MTM): Stores compressed summaries of previous conversations. It is persistable across sessions and uses LLMs to perform automatic compression.
    3. Long-Term Memory (LTM): Stores permanent facts and knowledge. This layer supports file persistence for long-term retrieval.

    This structure allows the agent to maintain a sense of recent context (STM) while retaining high-level summaries (MTM) and critical facts (LTM) without exceeding token limits.

  11. How the ML Evolve Agent architecture works

    main

    The ML Evolve Agent uses an evolutionary algorithm framework to automate machine learning. The workflow follows this cycle:

    1. ML Planner: Analyzes data and task requirements to formulate a pipeline strategy.
    2. Evocoder: Generates machine learning code (preprocessing, training, etc.) in stages.
    3. ML Executor: Runs the code and manages resource allocation (GPU/CPU).
    4. ML Evaluator: Calculates performance metrics and verifies submission formats.
    5. ML Summary: Analyzes results and generates improvement suggestions.
    6. Memory: Stores insights which are then fed back into the ML Planner for the next iteration.
  12. Understand the Message Component core concepts

    main

    The Message Component is the standard for inter-agent communication in LoongFlow. It relies on two primary abstractions:

    Message Roles (Role)

    • system: Instructions or context.
    • user: User input.
    • assistant: Agent responses.
    • tool: Tool call results.

    MIME Type Support

    Messages can contain various media types via MimeType:

    • text/plain: Plain text.
    • application/json: JSON data.
    • image/jpeg, image/png: Images.
    • audio/mpeg: Audio.
    • video/mp4: Video.