Skip to content

NoWall-572/PolyGraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ•ธ๏ธ PolyGraph: Autonomous System for Trace Analysis

(Formerly named as ASTRA in the sourse code)

License: MIT Python 3.8+ PyTorch Framework Code Style

๐Ÿ’ก Naming Convention Note In case of ambiguity ๐Ÿ“Œ PolyGraph is the name of our method as presented in the academic paper (previously named ASTRA in the code).

๐Ÿ“Œ PolyGen is our data generation engine (referenced in the codebase as ASTRA-Gen 3.0).

โš ๏ธ Please note: While the conceptual descriptions below use the new terminology (PolyGraph/PolyGen), the source code, file structures, and command lines retain the original astra namespace to ensure reproducibility.


๐Ÿ“– Abstract

PolyGraph is a cutting-edge, end-to-end framework for multi-agent system fault attribution ๐Ÿ•ต๏ธโ€โ™‚๏ธ. It seamlessly combines Graph Neural Networks (GNN) ๐Ÿ•ธ๏ธ and Large Language Models (LLM) ๐Ÿค– to achieve surgical precision in fault localization within complex multi-agent environments.

The system employs a smart Coarse-to-Fine ๐Ÿ“‰ two-stage strategy:

  1. ๐Ÿš€ Stage 1: Using GNN to rapidly identify top-K candidate agents.
  2. ๐Ÿ”ฌ Stage 2: Using LLM for fine-grained, reasoning-based analysis.

โœจ Key Features

Feature Description
๐ŸŽฒ Dynamic Causal Simulation PolyGen (ASTRA-Gen 3.0) generates highly realistic multi-agent interaction traces.
๐Ÿ•ธ๏ธ DHCG Dynamic Heterogeneous Causal Graph captures intricate temporal โณ and causal ๐Ÿ”— relationships.
๐Ÿง  PolyGraph-MoE Model STGAT-based GNN equipped with a Mixture of Experts for robust coarse-grained fault attribution.
๐Ÿ”ง LLM Fine-tuning Specialized Qwen 8B model fine-tuned for deep-dive fault analysis.
๐ŸŽฏ Coarse-to-Fine Eval A sophisticated two-stage evaluation system delivering high accuracy.

๐Ÿ“‚ Project Structure

The codebase retains the astra package structure as follows:

ASTRA_Release/
โ”œโ”€โ”€ astra/                      # ๐Ÿ“ฆ Main source code package
โ”‚   โ”œโ”€โ”€ generation/             # ๐Ÿญ Stage 1: Data generation
โ”‚   โ”‚   โ””โ”€โ”€ generator.py        # PolyGen (ASTRA-Gen 3.0) generator
โ”‚   โ”œโ”€โ”€ parsing/                # ๐Ÿงฉ Stage 1: Graph parsing
โ”‚   โ”‚   โ””โ”€โ”€ dhcg_parser/        # DHCG parser implementation
โ”‚   โ”œโ”€โ”€ data/                   # ๐Ÿ”„ Stage 2: Data adapter
โ”‚   โ”‚   โ”œโ”€โ”€ adapter.py          # GraphDataConverter
โ”‚   โ”‚   โ””โ”€โ”€ graph_data.py       # HeteroGraph data structure
โ”‚   โ”œโ”€โ”€ model/                  # ๐Ÿง  Stage 3: Model architecture
โ”‚   โ”‚   โ”œโ”€โ”€ gnn.py              # PolyGraph-MoE (ASTRA-MoE) model
โ”‚   โ”‚   โ”œโ”€โ”€ stgat.py            # STGAT implementation
โ”‚   โ”‚   โ””โ”€โ”€ loss.py             # Loss functions
โ”‚   โ”œโ”€โ”€ training/               # ๐Ÿ‹๏ธ Stage 3 & 4: Training scripts
โ”‚   โ”‚   โ”œโ”€โ”€ train_gnn.py        # GNN training script
โ”‚   โ”‚   โ””โ”€โ”€ prep_llm_data.py    # LLM data preparation
โ”‚   โ””โ”€โ”€ evaluation/             # ๐Ÿ“Š Stage 5: Evaluation
โ”‚       โ”œโ”€โ”€ eval_pipeline.py    # Coarse-to-fine evaluation
โ”‚       โ””โ”€โ”€ eval_benchmark.py   # Benchmark evaluation
โ”œโ”€โ”€ scripts/                    # ๐Ÿ› ๏ธ Utility scripts
โ”‚   โ”œโ”€โ”€ parse_dataset.py        # Dataset parsing
โ”‚   โ””โ”€โ”€ preprocess_external.py  # External dataset preprocessing
โ”œโ”€โ”€ examples/                   # ๐Ÿ“ Sample data
โ”‚   โ”œโ”€โ”€ golden_sample.json      # โœ… Golden trace example
โ”‚   โ”œโ”€โ”€ fatal_sample.json       # โŒ Fatal trace example
โ”‚   โ””โ”€โ”€ healed_sample.json      # ๐Ÿ’Š Healed trace example
โ”œโ”€โ”€ requirements.txt            # ๐Ÿ“‹ Python dependencies
โ””โ”€โ”€ README.md                   # ๐Ÿ“„ This file

โš™๏ธ Installation

Prerequisites

  • ๐Ÿ Python >= 3.8
  • ๐ŸŽฎ CUDA >= 11.8 (for GPU acceleration)
  • ๐Ÿง  16GB+ RAM recommended
  • ๐Ÿ’พ 20GB+ disk space for models and data

Setup Steps

  1. Clone the repository:

    git clone <repository-url>
    cd ASTRA_Release
  2. Install dependencies:

    pip install -r requirements.txt
  3. Download pre-trained models (optional):

    • ๐Ÿ“ฅ Qwen 8B base model: Download from HuggingFace or ModelScope.
    • ๐Ÿ“ Place models in the models/ directory.

๐Ÿš€ Usage

๐Ÿ—๏ธ Stage 1: Data Generation (PolyGen) and Graph Parsing

Generate PolyGen Dataset

Run the PolyGen (ASTRA-Gen 3.0) engine to create synthetic tasks:

python -m astra.generation.generator \
    --num_tasks 100 \
    --output_dir outputs/astra_v3 \
    --api_base <your-llm-api-endpoint>

Parse Traces to Graphs

Convert the raw logs into graph structures:

python scripts/parse_dataset.py \
    --input_dir outputs/astra_v3 \
    --output_dir processed_graphs/astra_v3

๐Ÿ”„ Stage 2: Data Conversion

The graph data is automatically converted during the training phase. ๐Ÿง™โ€โ™‚๏ธ The GraphDataConverter handles:

  • ๐Ÿ”น Node feature extraction and encoding
  • ๐Ÿ”น Edge feature extraction
  • ๐Ÿ”น HeteroGraph sequence construction

๐Ÿง  Stage 3: GNN Training (PolyGraph-MoE)

Train the coarse-grained expert model:

python -m astra.training.train_gnn \
    --data_dir processed_graphs/astra_v3 \
    --output_dir checkpoints/astra_moe \
    --epochs 50 \
    --batch_size 8 \
    --device cuda

๐ŸŽ“ Stage 4: LLM Data Preparation and Fine-tuning

Prepare LLM Training Data

Filter data using the GNN checkpoint to create focused samples for the LLM:

python -m astra.training.prep_llm_data \
    --graph_dir processed_graphs/astra_v3 \
    --gnn_checkpoint checkpoints/astra_moe/best_model.pt \
    --output_dir training_data/llm \
    --top_k 4

Fine-tune LLM

Use your preferred fine-tuning framework (e.g., PEFT) to train the PolyGraph reasoning module:

# Use your preferred LLM fine-tuning framework
# Example with PEFT:
python -m astra.training.finetune_llm \
    --base_model Qwen/Qwen3-8B \
    --data_dir training_data/llm \
    --output_dir adapters/qwen8b_astra

๐Ÿ“Š Stage 5: Evaluation

Coarse-to-Fine Evaluation

Run the full PolyGraph pipeline:

python -m astra.evaluation.eval_pipeline \
    --test_data_dir processed_graphs/test \
    --gnn_checkpoint checkpoints/astra_moe/best_model.pt \
    --llm_adapter adapters/qwen8b_astra \
    --base_model_name Qwen/Qwen3-8B \
    --top_k 4 \
    --device cuda

Benchmark Evaluation (TracerTraj)

python -m astra.evaluation.eval_benchmark \
    --test_data_dir processed_graphs/tracertraj \
    --gnn_checkpoint checkpoints/astra_moe/best_model.pt \
    --llm_adapter adapters/qwen8b_astra \
    --base_model_name Qwen/Qwen3-8B \
    --device cuda

๐Ÿ“ Example Data

The examples/ directory contains sample data files for quick testing:

  • โœ… sample_golden.json: A successful multi-agent interaction trace (no fault).
  • โŒ sample_fatal.json: A trace with injected fault.

You can use these to test the parsing and evaluation pipeline. See examples/README.md for more details.

๐Ÿงฉ Key Components

PolyGraph-MoE Model (ASTRA-MoE)

The core GNN architecture consists of:

  • MicroStateEncoder: ๐Ÿ“ท Multi-modal node feature encoder.
  • STGAT: ๐Ÿ•ธ๏ธ Spatio-temporal graph attention network.
  • TemporalReasoning: โณ Causal temporal reasoning with RoPE.
  • MoEHead: ๐Ÿšฆ Uncertainty-aware expert routing.

DHCG Parser

The parser extracts the Dynamic Heterogeneous Causal Graph:

  • Nodes ๐ŸŸฃ: Agents, Tools, Artifacts, Environment.
  • Edges โž–: Invoke, Return, Reference, Communicate, Affect.
  • Features ๐Ÿ“„: Text embeddings, metadata features.

Coarse-to-Fine Strategy

  1. Coarse Stage (GNN) โšก: Predicts top-K candidate agents.
  2. Fine Stage (LLM) ๐Ÿ”: Analyzes candidate logs to identify exact fault agent and step.

๐Ÿ“ˆ Performance

PolyGraph demonstrates state-of-the-art results:

  • ๐Ÿ† Agent Accuracy: ~67.39% on Who&When benchmark, and 77.95% on TracerTraj-Code.
  • ๐ŸŽฏ Step Accuracy: ~40.22% on Who&When benchmark, and 31.50% on TracerTraj-Code.
  • ๐Ÿ“‰ Token Efficiency: Optimized prompt design significantly reduces LLM token usage.

๐Ÿ“„ License

MIT License - See LICENSE file for details.

About

PolyGraph, a novel framework for automated failure attribution in multi-agent systems.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages