LatentMAS
A multi-agent reasoning framework that exchanges latent thoughts instead of long textual reasoning traces.
What does this agent do, and when should you use it?
LatentMAS is an experiment-oriented framework for multi-agent reasoning that moves collaboration from token space into a model's latent space. Agents pass latent thoughts through working memory rather than continually exchanging long textual traces. Experiments are launched through run.py, with models.py, data.py, prompts.py, and three method implementations: baseline.py, text_mas.py, and latent_mas.py. The repository covers GSM8K, AIME24/25, GPQA, ARC-Easy/Challenge, MBPP+, HumanEval+, and MedQA, with single-agent, text-based multi-agent, and latent-space multi-agent modes. Its standard path uses Hugging Face models; an optional hybrid vLLM flow uses vLLM for final text generation and a Hugging Face model for latent rollout and hidden-state alignment.
run.py selects baseline, text_mas, or latent_mas through --method, loads a task through --task, and uses prompts.py to construct prompts. models.py wraps Hugging Face execution, vLLM execution, and latent realignment behavior; the latent_mas route carries latent states across multi-step collaboration before producing text output. Users can choose sequential or hierarchical prompting with --prompt, tune --latent_steps from 0 to 80, and enable latent-to-embedding alignment with --latent_space_realign. The repository also includes example interaction logs for sequential MBPP+ and hierarchical HumanEval+ runs.
- A reasoning researcher comparing a single-model baseline, text-space collaboration, and latent-space collaboration on GSM8K.
- An ML engineer reproducing LatentMAS commands with Qwen/Qwen3-4B, Qwen/Qwen3-8B, or Qwen/Qwen3-14B.
- A developer evaluating multi-agent code generation on MBPP+ or HumanEval+ and inspecting the supplied interaction logs.
- An experiment team testing sequential versus hierarchical collaboration on AIME24/25, GPQA, ARC, or MedQA.
- A two-GPU user who wants vLLM for final generation while retaining Hugging Face latent rollouts.
What are this agent's strengths and limitations?
- Uses latent thoughts and working memory for collaboration, rather than offering only a text-based multi-agent loop.
- Places baseline, TextMAS, and LatentMAS behind the same CLI for controlled method comparisons.
- Documents both a standard Hugging Face backend and an optional vLLM-based final-generation path.
- Names nine reasoning and code-generation task families and includes two full example logs.
- Its experiment overview reports roughly 50–80% fewer tokens and roughly 3×–7× wall-clock speedups versus standard Text-MAS or chain-of-thought baselines.
- Reproduction depends on Hugging Face model and dataset downloads, local cache configuration, and network access.
- The vLLM path modifies part of vLLM's internal package; the project notes that vLLM does not officially support KV-cache modification or latent-embedding prompting.
- vLLM and standard Hugging Face runs can differ numerically because of decoding strategies, and the documented recommendation for official results is the Hugging Face backend.
- The hybrid vLLM arrangement is documented as using two GPUs: one for vLLM and one for the auxiliary Hugging Face model.
- Whether to enable latent_space_realign is task- and model-dependent, so adopters need to tune that hyperparameter.
How do you install or deploy this agent?
The documented setup requires Python 3.10, conda, and a shell. Set the cache location with: export HF_HOME=/path/to/huggingface; export TRANSFORMERS_CACHE=$HF_HOME; export HF_DATASETS_CACHE=$HF_HOME. Then run: conda create -n latentmas python=3.10 -y; conda activate latentmas; pip install -r requirements.txt. Models and datasets are downloaded into $HF_HOME. For vLLM support, also run: pip install vllm. No API key or other credential is specified.
How do you use this agent?
From the repository directory, a first baseline run is: python run.py --method baseline --model_name Qwen/Qwen3-14B --task gsm8k --max_samples -1 --max_new_tokens 2048. For text-based collaboration: python run.py --method text_mas --model_name Qwen/Qwen3-14B --task gsm8k --prompt sequential --max_samples -1 --max_new_tokens 2048. For latent collaboration: python run.py --method latent_mas --model_name Qwen/Qwen3-4B --task gsm8k --prompt sequential --max_samples -1 --max_new_tokens 2048. The hybrid vLLM configuration uses --use_vllm --use_second_HF_model --enable_prefix_caching --device2 cuda:1 and is documented as a two-GPU setup.
How does this agent compare with similar options?
The repository exposes three comparison paths: baseline for a single model, TextMAS for token/text-space multi-agent collaboration, and LatentMAS for latent-space collaboration. Its experiment overview compares LatentMAS token and timing results with standard Text-MAS and chain-of-thought baselines.