Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkbrnd committed Feb 12, 2025
1 parent 7643003 commit 2650976
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 20 deletions.
117 changes: 117 additions & 0 deletions cookbook/examples/apps/tic_tac_toe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Tic Tac Toe AI Battle

This example demonstrates how to build an interactive Tic Tac Toe game where AI agents compete against each other. The application showcases how to:
- Coordinate multiple AI agents in a turn-based game
- Use different language models for different players
- Create an interactive web interface with Streamlit
- Handle game state and move validation
- Display real-time game progress and move history

## Features
- Multiple AI models support (GPT-4, Claude, Gemini, etc.)
- Real-time game visualization
- Move history tracking with board states
- Interactive player selection
- Game state management
- Move validation and coordination

### 1. Create a virtual environment

```shell
python3 -m venv .venv
source .venv/bin/activate
```

### 2. Install dependencies

```shell
pip install -r cookbook/examples/apps/tic_tac_toe/requirements.txt
```

### 3. Export API Keys

The game supports multiple AI models. Export the API keys for the models you want to use:

```shell
# Required for OpenAI models (GPT-4, GPT-3.5)
export OPENAI_API_KEY=***

# Optional - for additional models
export ANTHROPIC_API_KEY=*** # For Claude models
export GOOGLE_API_KEY=*** # For Gemini models
export GROQ_API_KEY=*** # For Groq models
```

### 4. Run the Game

```shell
streamlit run cookbook/examples/apps/tic_tac_toe/app.py
```

- Open [localhost:8501](http://localhost:8501) to view the game interface

## How It Works

The game consists of three main components:

1. **Master Agent (Referee)**
- Coordinates the game
- Validates moves
- Maintains game state
- Determines game outcome

2. **Player Agents**
- Make strategic moves
- Analyze board state
- Follow game rules
- Respond to opponent moves

3. **Web Interface**
- Displays game board
- Shows move history
- Allows model selection
- Provides game controls

## Available Models

The game supports various AI models:
- GPT-4 (OpenAI)
- Claude (Anthropic)
- Gemini (Google)
- GPT-3.5 Mini
- Llama 3

## Game Features

1. **Interactive Board**
- Real-time updates
- Visual move tracking
- Clear game status display

2. **Move History**
- Detailed move tracking
- Board state visualization
- Player action timeline

3. **Game Controls**
- Start/Pause game
- Reset board
- Select AI models
- View game history

4. **Performance Analysis**
- Move timing
- Strategy tracking
- Game statistics

## Contributing

Feel free to contribute to this example by:
- Adding new AI models
- Improving the UI/UX
- Enhancing game strategies
- Adding new features

## Support

Join our [Discord community](https://agno.link/discord) for help and discussions.
4 changes: 2 additions & 2 deletions cookbook/examples/apps/tic_tac_toe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ def main():
st.markdown("### Game Controls")

available_models = {
"Gemini": "gemini",
"GPT-4o": "gpt-4o",
"Claude": "claude",
"GPT-o3-mini": "gpt-o3-mini",
"Gemini": "gemini",
"Claude": "claude",
"Llama 3": "llama",
}

Expand Down
1 change: 1 addition & 0 deletions cookbook/examples/apps/tic_tac_toe/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ agno
openai
anthropic
ollama
google-genai

python-dotenv
pathlib
Expand Down
55 changes: 37 additions & 18 deletions cookbook/examples/apps/tic_tac_toe/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This file was autogenerated by uv via the following command:
# ./generate_requirements.sh
agno==1.0.8
# via -r requirements.in
agno==1.1.0
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
altair==5.5.0
# via streamlit
annotated-types==0.7.0
# via pydantic
anthropic==0.45.2
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
anyio==4.8.0
# via
# anthropic
Expand All @@ -22,7 +22,9 @@ blinker==1.9.0
build==1.2.2.post1
# via pip-tools
cachetools==5.5.1
# via streamlit
# via
# google-auth
# streamlit
certifi==2025.1.31
# via
# httpcore
Expand All @@ -36,7 +38,7 @@ click==8.1.8
# streamlit
# typer
dataclasses==0.8
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
distro==1.9.0
# via
# anthropic
Expand All @@ -49,6 +51,10 @@ gitpython==3.1.44
# via
# agno
# streamlit
google-auth==2.38.0
# via google-genai
google-genai==1.1.0
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
h11==0.14.0
# via httpcore
httpcore==1.0.7
Expand Down Expand Up @@ -85,16 +91,16 @@ mdurl==0.1.2
narwhals==1.26.0
# via altair
nest-asyncio==1.6.0
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
numpy==2.2.2
# via
# pandas
# pydeck
# streamlit
ollama==0.4.7
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
openai==1.61.1
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
packaging==24.2
# via
# altair
Expand All @@ -103,23 +109,30 @@ packaging==24.2
pandas==2.2.3
# via streamlit
pathlib==1.0.1
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
pillow==11.1.0
# via
# -r requirements.in
# -r cookbook/examples/apps/tic_tac_toe/requirements.in
# streamlit
pip==25.0.1
# via pip-tools
pip-tools==7.4.1
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
protobuf==5.29.3
# via streamlit
pyarrow==19.0.0
# via streamlit
pyasn1==0.6.1
# via
# pyasn1-modules
# rsa
pyasn1-modules==0.4.1
# via google-auth
pydantic==2.10.6
# via
# agno
# anthropic
# google-genai
# ollama
# openai
# pydantic-settings
Expand All @@ -139,7 +152,7 @@ python-dateutil==2.9.0.post0
# via pandas
python-dotenv==1.0.1
# via
# -r requirements.in
# -r cookbook/examples/apps/tic_tac_toe/requirements.in
# agno
# pydantic-settings
python-multipart==0.0.20
Expand All @@ -153,17 +166,21 @@ referencing==0.36.2
# jsonschema
# jsonschema-specifications
requests==2.32.3
# via streamlit
# via
# google-genai
# streamlit
rich==13.9.4
# via
# -r requirements.in
# -r cookbook/examples/apps/tic_tac_toe/requirements.in
# agno
# streamlit
# typer
rpds-py==0.22.3
# via
# jsonschema
# referencing
rsa==4.9
# via google-auth
setuptools==75.8.0
# via pip-tools
shellingham==1.5.4
Expand All @@ -178,7 +195,7 @@ sniffio==1.3.1
# anyio
# openai
streamlit==1.42.0
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
tenacity==9.0.0
# via streamlit
toml==0.10.2
Expand All @@ -192,7 +209,7 @@ tqdm==4.67.1
typer==0.15.1
# via agno
typing==3.10.0.0
# via -r requirements.in
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
typing-extensions==4.12.2
# via
# agno
Expand All @@ -209,7 +226,9 @@ tzdata==2025.1
# via pandas
urllib3==2.3.0
# via requests
uv==0.5.29
# via -r requirements.in
uv==0.5.30
# via -r cookbook/examples/apps/tic_tac_toe/requirements.in
websockets==14.2
# via google-genai
wheel==0.45.1
# via pip-tools

0 comments on commit 2650976

Please sign in to comment.