Spaces:
Running
Running
### Step 1: Define Multiple Players with LLM Backend | |
```python | |
from agentreview.agent import Player | |
from agentreview.backends import OpenAIChat | |
# Describe the environment (which is shared by all players) | |
environment_description = "It is in a university classroom ..." | |
# A "Professor" player | |
player1 = Player(name="Professor", backend=OpenAIChat(), | |
role_desc="You are a professor in ...", | |
global_prompt=environment_description) | |
# A "Student" player | |
player2 = Player(name="Student", backend=OpenAIChat(), | |
role_desc="You are a student who is interested in ...", | |
global_prompt=environment_description) | |
# A "Teaching Assistant" player | |
player3 = Player(name="Teaching assistant", backend=OpenAIChat(), | |
role_desc="You are a teaching assistant of the module ...", | |
global_prompt=environment_description) | |
``` | |
### Step 2: Create a Language Game Environment | |
You can also create a language model-driven environment and add it to the ChatArena: | |
```python | |
from agentreview.environments.conversation import Conversation | |
env = Conversation(player_names=[p.name for p in [player1, player2, player3]]) | |
``` | |
### Step 3: Run the Language Game using Arena | |
`Arena` is a utility class to help you run language games: | |
```python | |
from agentreview.arena import Arena | |
arena = Arena(players=[player1, player2, player3], | |
environment=env, global_prompt=environment_description) | |
# Run the game for 10 steps | |
arena.run(num_steps=10) | |
# Alternatively, you can run your own main loop | |
for _ in range(10): | |
arena.step() | |
# Your code goes here ... | |
``` | |
You can easily save your gameplay history to file: | |
```python | |
arena.save_history(path=...) | |
``` | |
and save your game config to file: | |
```python | |
arena.save_config(path=...) | |
``` | |