From 26509769f5dce01d5c9b597fabc17ebe9c43d13e Mon Sep 17 00:00:00 2001 From: Dirk Brand Date: Wed, 12 Feb 2025 16:10:40 +0200 Subject: [PATCH] Add README --- cookbook/examples/apps/tic_tac_toe/README.md | 117 ++++++++++++++++++ cookbook/examples/apps/tic_tac_toe/app.py | 4 +- .../examples/apps/tic_tac_toe/requirements.in | 1 + .../apps/tic_tac_toe/requirements.txt | 55 +++++--- 4 files changed, 157 insertions(+), 20 deletions(-) diff --git a/cookbook/examples/apps/tic_tac_toe/README.md b/cookbook/examples/apps/tic_tac_toe/README.md index e69de29bb2..2ddbb3c7e2 100644 --- a/cookbook/examples/apps/tic_tac_toe/README.md +++ b/cookbook/examples/apps/tic_tac_toe/README.md @@ -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. diff --git a/cookbook/examples/apps/tic_tac_toe/app.py b/cookbook/examples/apps/tic_tac_toe/app.py index a50730014f..7b28908725 100644 --- a/cookbook/examples/apps/tic_tac_toe/app.py +++ b/cookbook/examples/apps/tic_tac_toe/app.py @@ -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", } diff --git a/cookbook/examples/apps/tic_tac_toe/requirements.in b/cookbook/examples/apps/tic_tac_toe/requirements.in index d87a45423a..a9bdf88c30 100644 --- a/cookbook/examples/apps/tic_tac_toe/requirements.in +++ b/cookbook/examples/apps/tic_tac_toe/requirements.in @@ -7,6 +7,7 @@ agno openai anthropic ollama +google-genai python-dotenv pathlib diff --git a/cookbook/examples/apps/tic_tac_toe/requirements.txt b/cookbook/examples/apps/tic_tac_toe/requirements.txt index e839673443..43e73dd60c 100644 --- a/cookbook/examples/apps/tic_tac_toe/requirements.txt +++ b/cookbook/examples/apps/tic_tac_toe/requirements.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -153,10 +166,12 @@ 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 @@ -164,6 +179,8 @@ 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 @@ -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 @@ -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 @@ -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