This is the official implementation of the paper: HyLaT:Efficient Multi-Agent Communication via Hybrid Latent-Text Protocol.
HyLAT enables language model agents to communicate through a hybrid channel that combines continuous latent tokens (compressed cognitive signals) and discrete text tokens (explicit responses). This goes beyond conventional text-only communication by allowing agents to share nuanced, information-dense reasoning states that are too costly to express fully in natural language.
hylat/
βββ hylat/ # Training code
β βββ train.py # Stage 1 training
β βββ train_mas_dual.py # Stage 2 training (2 homogeneous agents)
β βββ train_mas_general.py # Stage 2 training (N agents)
β βββ train_mas_dual_hetero.py # Stage 2 training (heterogeneous agents)
β βββ src/
β β βββ model.py # Stage 1 model
β β βββ model_decoder_mas_dual.py # Stage 2 dual-agent model (HyLAT)
β β βββ model_decoder_mas_general.py # Stage 2 N-agent model
β β βββ model_decoder_mas_dual_hetero.py # Stage 2 heterogeneous model
β βββ configs/
β βββ stage1_llama.yaml # Example Stage 1 config
β βββ stage2_dual_llama.yaml # Example Stage 2 config
β βββ stage2_hetero_llama_qwen.yaml # Example Stage 2 hetero config
β βββ test_mas.yaml # Evaluation config
βββ eval/ # Evaluation code (MAD tasks)
βββ scripts/
β βββ eval_hylat.sh # Run HyLaT evaluation
β βββ eval_nl.sh # Run NL baseline
βββ src/
βββ main_latent.py # Evaluation entry point (HyLaT)
βββ main.py # Evaluation entry point (baselines)
βββ models/agents/ # Agent implementations
βββ tasks/ # Task definitions (debate, IA, workflow)
The training framework proceeds in two stages:
| Stage | Script | Description |
|---|---|---|
| Stage 1 | hylat/train.py |
Train a single agent to produce hybrid latent+text outputs via self-distillation based on CODI |
| Stage 2 | hylat/train_mas_dual.py |
Train two agents to mutually understand and respond to each other's hybrid outputs (You can also use hylat/train_mas_general.py for more than two agents, or hylat/train_mas_dual_hetero.py for heterogeneous agents) |
Clone the repository:
git clone https://github.com/xymou/hylat.git
cd hylat/hylatCreate environment:
conda create -n hylat python=3.12.12
conda activate hylat
pip install -r requirements.txtEach training sample is a JSON object with a messages list. Each message contains:
{
"messages": [
{
"role": "user",
"content": "...",
"short_answer": "",
"long_answer": ""
},
{
"role": "assistant",
"content": "",
"short_answer": "...",
"long_answer": "..."
}
]
}| Field | Description |
|---|---|
content |
The input question, only set for "user" msg |
short_answer |
Concise answer (content of text channel), only set for "assistant" msg |
long_answer |
Elaborate reasoning or explanations (content of latent channel) , only set for "assistant" msg |
Each sample is a multi-turn dialogue between two agents (it can also be extended to more than 2 agents):
{
"messages": [
{
"role": "user",
"question_agent1": "Solve: Janet's ducks lay 16 eggs per day...",
"question_agent2": "Solve: Janet's ducks lay 16 eggs per day...",
},
{
"role": "assistant",
"long_answer": "...",
"short_answer": "...",
"agent": 1
},
{
"role": "assistant",
"long_answer": "...",
"short_answer": "...",
"agent": 2
},
...
],
"mask_inter_res": true
}| Field | Description |
|---|---|
question_agent1 |
Question seen by Agent 1 |
question_agent2 |
Question seen by Agent 2 (question_agent1 and question_agent2 can be the same to simulate debating or may differ to simulate information asymmetry) |
short_answer |
Concise answer (content of text channel) |
long_answer |
Elaborate reasoning or explanations (content of latent channel) |
agent |
id of the agents |
mask_inter_res |
If true, only the final turn is supervised |
Stage 1 (single agent):
torchrun --nproc_per_node=8 train.py --conf ./configs/stage1_llama.yamlStage 2 (two homogeneous agents):
torchrun --nproc_per_node=8 train_mas_dual.py --conf ./configs/stage2_dual_llama.yamlEdit the corresponding config file in ./configs/ to set model_name_or_path, data_name, output_dir and etc before running.
We evaluate HyLaT on multi-agent debating (MAD) tasks using a framework built on top of SDE.
Install the evaluation dependencies (separate from training):
cd eval
conda create -n SDE python=3.10.16
conda activate SDE
pip install -r requirements.txtConfigure data and project paths in eval/src/root_path.py:
DATA_ROOT_PATH = "/path/to/data" # root directory of evaluation datasets
ROOT_PATH = "/path/to/eval" # root directory of this eval folderPrepare the evaluation config
Edit hylat/configs/test_mas.yaml: set ckpt_dir to your trained Stage 2 checkpoint path and ensure model_name_or_path, num_latent, prj_dim match the training config.
Run HyLaT agents on the MAD tasks:
cd eval
bash scripts/eval_hylat.shThis calls src/main_latent.py with --method latent_stage2 and iterates over all datasets. The key arguments are:
| Argument | Description |
|---|---|
--config_file |
Debate configuration (e.g., configs/debate.json) |
--model_name_or_path |
Path to the base LLM |
--conf_path |
Path to the HyLaT test config (set the ckpt path in the yaml) |
--dataset |
Dataset name |
--method |
Agent communication method |
--output_dir |
Directory to save results |
--temperature |
Sampling temperature |
For setting more MAD methods or datasets, plz refer to SDE.
If you find this repo helpful, please cite:
@article{mou2026hylat,
title = {HyLaT: Efficient Multi-Agent Communication via Hybrid Latent-Text Protocol},
author = {Xinyi Mou and Siyuan Wang and Zejun Li and Yulan He and Zhongyu Wei},
year = {2026},
journal = {arXiv preprint arXiv:2605.25421}
}@article{shen2025codi,
title={CODI: Compressing Chain-of-Thought into Continuous Space via Self-Distillation},
author={Zhenyi Shen and Hanqi Yan and Linhai Zhang and Zhanghao Hu and Yali Du and Yulan He},
year={2025},
journal={arXiv preprint arxiv:2502.21074},
}