Lingxi Multi-Agent Software Engineering Framework

repository·master·Indexed 42 days ago

https://github.com/lingxi-agent/lingxi

A multi-agent framework version 1.5 designed for automated, repository-level software issue resolution. Lingxi uses specialized agents—including a Supervisor, Problem Decoder, Solution Mapper, Problem Solver, and Reviewer—to locate bugs and generate patches. It supports two primary architectures: a linear Supervisor Graph and a complex Hierarchy Graph for iterative fix validation, integrating with LangGraph Studio for execution and human-in-the-loop interaction.

Tokens
17.6K
Snippets
44
Records
76
Agent score
53%

What's inside Lingxi

  1. Overview of Lingxi Agents

    master

    Lingxi uses several specialized agents to resolve software engineering issues:

    • Supervisor: Oversees the entire workflow and routes tasks to the appropriate agents based on progress.
    • Problem Decoder: Analyzes issue requirements to generate a problem statement (topic, codebase representation/bug localization, current vs. expected behavior). Uses view_directory, search_relevant_files, and view_file_content.
    • Solution Mapper: Generates a detailed code change plan for specific files or functions based on the decoder's output. Uses view_directory, search_relevant_files, and view_file_content.
    • Problem Solver: Implements the change plan by modifying files. Uses view_directory, search_relevant_files, and str_replace_editor.
    • Reviewer: Verifies fixes by generating and executing test cases. Uses view_directory, search_relevant_files, view_file_content, and run_shell_cmd.
    • Multi-Agent Manager (MAM): Coordinates between the issue resolver and reviewer agents to provide feedback/guidance. (Used in hierarchy_graph_demo.py).
  2. How Lingxi graphs work

    master

    Lingxi provides different graph architectures depending on the required complexity:

    • Supervisor Graph (src/agent/supervisor_graph_demo.py): A linear workflow following the sequence: input_handler $\rightarrow$ supervisor $\rightarrow$ problem_decoder $\rightarrow$ solution_mapper $\rightarrow$ problem_solver. It allows for optional human feedback after each step.
    • Hierarchy Graph (src/agent/hierarchy_graph_demo.py): An advanced architecture that wraps the Supervisor Graph as a subgraph. It adds a Multi-Agent Manager and a Reviewer to enable iterative fix validation.
  3. Define System Prompts in LangGraph

    master

    System prompts can be implemented in several ways when defining agents:

    • prompt kwarg: In create_react_agent, passing a str converts it to a SystemMessage prepended to state["messages"].
    • SystemMessage: Manually prepending a SystemMessage to the message list.
    • Callable: A function that takes the full graph state as input and returns the output for the LLM.
    • Runnable: A LangChain runnable that takes the full graph state as input and returns the output for the LLM.
  4. Understand ReACT Agent Subgraphs

    master

    When you create a ReACT agent using create_react_agent, LangGraph automatically generates a subgraph. This subgraph contains specific nodes that manage the agent's reasoning loop:

    • __start__: The entry point of the subgraph.
    • agent: The node where the LLM processes the current state and decides on an action.
    • tools: The node that executes the tool requested by the agent.
    • __end__: The exit point of the subgraph.

    The agent uses conditional edges (often represented as dashed lines in diagrams) to decide whether to transition to the tools node (if a tool call is required) or to __end__ (if a final answer is reached).

  5. Compare Supervisor Graph vs. Hierarchy Graph

    master

    Lingxi provides two primary workflow graphs:

    1. Supervisor Graph

    Defined by issue_resolve_graph. It follows a linear-to-routed workflow:

    • input_handler_node $\rightarrow$ supervisor_node $\rightarrow$ problem_decoder $\rightarrow$ solution_mapper $\rightarrow$ problem_solver.
    • Supports human feedback after each node execution.

    2. Hierarchy Graph

    Defined by hierarchy_graph. It implements a more complex multi-agent coordination pattern:

    • mam_node (Multi-Agent Manager) coordinates an issue_resolve_graph (the Supervisor Graph) and a reviewer_node.
    • This structure allows for iterative review and feedback loops between the resolver and the reviewer.
  6. Understand the Lingxi Agent roles

    master

    The framework uses several specialized agents to resolve repository-level issues. These agents are implemented as LangGraph nodes.

    Core Agents:

    • Supervisor: Oversees the entire workflow and routes tasks to the appropriate agents based on progress.
    • Problem Decoder: Analyzes issue requirements to generate a problem statement (topic, bug localization, current vs. expected behavior). Uses view_directory, search_relevant_files, and view_file_content.
    • Solution Mapper: Reviews the problem statement and codebase to generate a detailed code change plan. Uses view_directory, search_relevant_files, and view_file_content.
    • Problem Solver: Implements the change plan by modifying files. Uses view_directory, search_relevant_files, and str_replace_editor.

    Coordination Agents (Hierarchy Graph only):

    • Multi-Agent Manager (MAM): Coordinates between the issue resolver and reviewer agents to provide feedback/guidance.
    • Reviewer: Verifies fixes by generating and executing test cases. Uses view_directory, search_relevant_files, view_file_content, and run_shell_cmd.
  7. How LangGraph State and MessagesState work

    master

    In LangGraph, agents interact through a shared state.

    • MessagesState: A specialized state used by ReACT agents. It is a dictionary containing a messages key, which holds the conversation history as a list of BaseMessage subclasses (HumanMessage, AIMessage, ToolMessage, etc.).
    • State Updates: The graph automatically updates the messages list. Custom variables in a custom state can be updated by returning a Command(update={"key": "value"}) from a node.
    • Critical Constraint: For ReACT agents, the sequence of messages is strict. An AIMessage (the agent's decision to use a tool) must be followed by a ToolMessage (the tool's output). Removing or altering this sequence will break the workflow.
  8. Create Subgraphs for Complex Workflows

    master

    Subgraphs allow you to compose complex workflows by nesting one graph inside another. When adding a subgraph as a node in a StateGraph, you can use the destinations parameter to map the internal nodes of the subgraph to the parent graph's nodes, facilitating controlled transitions between the parent and the child graph.

    # hierarchy_graph_demo.py
    from langgraph.graph import END, START, StateGraph
    from agent.supervisor_graph_demo import issue_resolve_graph
    
    builder = StateGraph(CustomState)
    builder.add_node(
        "issue_resolve_graph",
        issue_resolve_graph,
        destinations=({"mam_node": "mam_node-issue_resolve_graph"}),
    )
    builder.add_node(
        "mam_node",
        mam_node,
        destinations=(
            {
                "reviewer_node": "mam_node-reviewer_node",
                "issue_resolve_graph": "mam_node-issue_resolve_graph",
            }
        ),
    )
    builder.add_node(
        "reviewer_node",
        reviewer_node,
        destinations=({"mam_node": "mam_node-reviewer_node"}),
    )
    builder.add_edge(START, "mam_node")
    builder.add_edge("issue_resolve_graph", "mam_node")
    hierarchy_graph = builder.compile()
  9. Understand Lingxi Graph Workflows

    master

    Lingxi provides two main graph implementations for issue resolution:

    1. Supervisor Graph

    Defined in src/agent/supervisor_graph_demo.py via the issue_resolve_graph variable. It follows this node sequence:

    1. input_handler_node: Sets up environment from GitHub URL.
    2. supervisor_node: Executes the supervisor agent.
    3. problem_decoder: Executes the decoder agent.
    4. solution_mapper: Executes the mapper agent.
    5. problem_solver: Executes the solver agent.

    2. Hierarchy Graph

    Defined in src/agent/hierarchy_graph_demo.py via the hierarchy_graph variable. It adds a coordination layer:

    1. mam_node: Executes the Multi-Agent Manager.
    2. issue_resolve_graph: Executes the standard Supervisor Graph workflow.
    3. reviewer_node: Executes the reviewer agent to verify the fix.
  10. Configure System Prompts in LangGraph

    master

    System prompts can be provided to agents in several ways:

    1. prompt kwarg: In create_react_agent(..., prompt="..."), the string is converted to a SystemMessage and prepended to the state's message list.
    2. SystemMessage: Manually adding a SystemMessage to the beginning of the messages list in the state.
    3. Callable: A function that accepts the full graph state and returns the output to be passed to the LLM.
    4. Runnable: A LangChain runnable that processes the full graph state for the LLM.
  11. Understand Agent Expected Input and LangGraph State

    master

    The input format depends on the agent type:

    1. Tool-less Agents (Direct LLM): Accept flexible inputs like str, List[str], or List[BaseMessage].
    2. ReACT Agents: Expect a MessagesState object. This is a dictionary (or AnnotatedDict) containing a messages key, which is a list of BaseMessage subclasses (e.g., SystemMessage, HumanMessage, AIMessage).

    Important Constraints:

    • The messages list in MessagesState follows a strict structure for ReACT agents. If an agent uses a tool, an AIMessage (the agent's decision) must be followed by a ToolMessage (the tool's output). Removing messages from this sequence will break the workflow.
    • Custom variables can be added to the state and updated from nodes using the Command class: Command(update={"custom_var": "value"}).
  12. Run Lingxi via LangGraph Studio

    master

    To start the local LangGraph Studio instance and access the UI, use one of the following commands depending on your installation method:

    If installed via pip:

    langgraph dev --no-reload

    If installed via uv:

    uv run --env-file .env langgraph dev --no-reload
    # Using pip installation
    langgraph dev --no-reload
    
    # Using uv
    uv run --env-file .env langgraph dev --no-reload