Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
A lightweight framework for building LLM-based agents
| Date | Stars |
|---|---|
| 2026-07-31 | 2273 |
| 2026-08-03 | 2274 |
| 2026-08-06 | 2274 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
<div id="top"></div>
<div align="center">
<img src="docs/imgs/lagent_logo.png" width="450"/>
[](https://lagent.readthedocs.io/en/latest/)
[](https://pypi.org/project/lagent)
[](https://github.com/InternLM/lagent/tree/main/LICENSE)
[](https://github.com/InternLM/lagent/issues)
[](https://github.com/InternLM/lagent/issues)




</div>
<p align="center">
👋 join us on <a href="https://twitter.com/intern_lm" target="_blank">𝕏 (Twitter)</a>, <a href="https://discord.gg/xa29JuW87d" target="_blank">Discord</a> and <a href="https://r.vansin.top/?r=internwx" target="_blank">WeChat</a>
</p>
## Installation
Install from source:
```bash
git clone https://github.com/InternLM/lagent.git
cd lagent
pip install -e .
```
## Usage
Lagent is inspired by the design philosophy of PyTorch. We expect that the analogy of neural network layers will make the workflow clearer and more intuitive, so users only need to focus on creating layers and defining message passing between them in a Pythonic way. This is a simple tutorial to get you quickly started with building multi-agent applications.
### Models as Agents
Agents use `AgentMessage` for communication.
```python
from typing import Dict, List
from lagent.agents import Agent
from lagent.schema import AgentMessage
from lagent.llms import VllmModel, INTERNLM2_META
llm = VllmModel(
path='Qwen/Qwen2-7B-Instruct',
meta_template=INTERNLM2_META,
tp=1,
top_k=1,
temperature=1.0,
stop_words=['<|im_end|>'],
max_new_tokens=1024,
)
system_prompt = '你的回答只能从“典”、“孝”、“急”三个字中选一个。'
agent = Agent(llm, system_prompt)
user_msg = AgentMessage(sender='user', content='今天天气情况')
bot_msg = agent(user_msg)
print(bot_msg)
```
```
content='急' sender='Agent' formatted=None extra_info=None type=None receiver=None stream_state=<AgentStatusCode.END: 0>
```
### Memory as State
Both input and output messages will be added to the memory of `Agent` in each forward pass. This is performed in `__call__` rather than `forward`. See the following pseudo code
```python
def __call__(self, *message):
message = pre_hooks(message)
add_memory(message)
message = self.forward(*message)
add_memory(message)
message = post_hooks(message)
return message
```
Inspect the memory in two ways
```python
memory: List[AgentMessage] = agent.memory.get_memory()
print(memory)
print('-' * 120)
dumped_memory: Dict[str, List[dict]] = agent.state_dict()
print(dumped_memory['memory'])
```
```
[AgentMessage(content='今天天气情况', sender='user', formatted=None, extra_info=None, type=None, receiver=None, stream_state=<AgentStatusCode.END: 0>), AgentMessage(content='急', sender='Agent', formatted=None, extra_info=None, type=None, receiver=None, stream_state=<AgentStatusCode.END: 0>)]
------------------------------------------------------------------------------------------------------------------------
[{'content': '今天天气情况', 'sender': 'user', 'formatted': None, 'extra_info': None, 'type': None, 'receiver': None, 'stream_state': <AgentStatusCode.END: 0>}, {'content': '急', 'sender': 'Agent', 'formatted': None, 'extra_info': None, 'type': None, 'receiver': None, 'stream_state': <AgentStatusCode.END: 0>}]
```
Clear the memory of this session(`session_id=0` by default):
```python
agent.reset()
```
### Custom Message Aggregation
`DefaExcerpt of 22,997 characters
Read on GitHub44
liukuikun · PJLab · China
31
BraisedPork · China
30
loveSnowBest · USTC · China
8
4
Ma Zerun · OpenMMLab · China
3
vansin · United States
3
Wenwei Zhang · MMLab, NTU · Singapore
3
2
2
Zhihao Lin · @AWS · China
2
Shanghai AI Laboratory · China
2
Qi Fan · China
2
1
1
1
Ikko Eltociear Ashimine · Japan
1
1
Kai Chen · @open-mmlab @internlm · China
1
Lyu Han · China
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:12a9977c0cdddb85, topic:llm, topic:gpt