diff --git a/python/examples/advanced_agents/game_builder/.env.example b/python/examples/advanced_agents/game_builder/.env.example new file mode 100644 index 00000000000..c54c01f4f09 --- /dev/null +++ b/python/examples/advanced_agents/game_builder/.env.example @@ -0,0 +1,2 @@ +OPENAI_API_KEY=KEY +COMPOSIO_API_KEY=KEY \ No newline at end of file diff --git a/python/examples/advanced_agents/game_builder/main.py b/python/examples/advanced_agents/game_builder/main.py new file mode 100644 index 00000000000..9e923088722 --- /dev/null +++ b/python/examples/advanced_agents/game_builder/main.py @@ -0,0 +1,55 @@ +import os +import dotenv +from composio_llamaindex import App, ComposioToolSet +from llama_index.core.agent import FunctionCallingAgentWorker +from llama_index.core.llms import ChatMessage +from llama_index.llms.openai import OpenAI +from llama_index.llms.groq import Groq + +dotenv.load_dotenv() +composio_toolset = ComposioToolSet() +tools = composio_toolset.get_tools(apps=[App.EXA, App.SHELLTOOL, App.FILETOOL, App.CODEINTERPRETER]) + +#llm = Groq(model="llama3-70b-8192", api_key=os.environ['GROQ_API_KEY']) +llm = OpenAI(model='gpt-4o') +prefix_messages = [ + ChatMessage( + role="system", + content=( + "You are a Game Creation Agent specialized in designing and implementing games. " + "Your role is to help users create games by:" + "1. Understanding their game concept and requirements" + "2. Breaking down the game into core mechanics and features" + "3. Suggesting appropriate implementation approaches" + "4. Helping with code structure and game logic" + "5. Providing guidance on best practices for game development" + "THE GAME SHOULD BE PLAYABLE and WORKING WHEN RUN WITH THE SHELL TOOL" + "BUILD USING PYGAME AND THEN RUN THE GAME CODE AT THE END" + "You can use various tools to create, modify, and test game code, manage files, " + "and interpret code results. Always aim to create well-structured, maintainable games." + ), + ) +] + +while True: + main_task = input("Describe your game idea (or type 'exit' to quit): ") + main_task_refined = llm.complete(f"Refine this into a better prompt for someone building this game. Give detail on the gameplay mechanics, what 3 single player core features of the game are and more, and detailed. Not long and unnecessary but better prompt:{main_task}. The core idea should be same") + if main_task.lower() == 'exit': + break + + agent = FunctionCallingAgentWorker( + tools=tools, # type: ignore + llm=llm, + prefix_messages=prefix_messages, + max_function_calls=10, + allow_parallel_tool_calls=False, + verbose=True, + ).as_agent() + + response = agent.chat( + f"Let's create a game based on this idea: {main_task_refined.text}. " + "Create the game in a file called game.py in the current directory" + "After that is done use the Anthropic tool to find the file and run it" + "Or use the shell tool to run it." + ) + print("Response:", response) \ No newline at end of file diff --git a/python/examples/advanced_agents/game_builder/readme.md b/python/examples/advanced_agents/game_builder/readme.md new file mode 100644 index 00000000000..eb7934285a5 --- /dev/null +++ b/python/examples/advanced_agents/game_builder/readme.md @@ -0,0 +1,30 @@ +# Game Builder Agent Guide + +This guide provides detailed steps to create a Game Builder Agent that leverages Composio, agentic frameworks such as LlamaIndex and GPT to create a Game Builder agent. Ensure you have Python 3.8 or higher installed. + + +## Steps to Run + +**Navigate to the Project Directory:** +Change to the directory where the `setup.sh`, `main.py`, `requirements.txt`, and `README.md` files are located. For example: +```sh +cd path/to/project/directory +``` + +### 1. Run the Setup File +Make the setup.sh Script Executable (if necessary): +On Linux or macOS, you might need to make the setup.sh script executable: +```shell +chmod +x setup.sh +``` +Execute the setup.sh script to set up the environment and install dependencies: +```shell +./setup.sh +``` +Now, fill in the `.env` file with your secrets. + +### 2. Run the Python Script +```shell +python cookbook/python-examples/advanced_agents/game_builder/main.py +``` + diff --git a/python/examples/advanced_agents/game_builder/requirements.txt b/python/examples/advanced_agents/game_builder/requirements.txt new file mode 100644 index 00000000000..d6f23587909 --- /dev/null +++ b/python/examples/advanced_agents/game_builder/requirements.txt @@ -0,0 +1,4 @@ +composio-llamaindex +python-dotenv +llama-index-llms-groq +pygame \ No newline at end of file diff --git a/python/examples/advanced_agents/game_builder/setup.sh b/python/examples/advanced_agents/game_builder/setup.sh new file mode 100644 index 00000000000..dd36418bff7 --- /dev/null +++ b/python/examples/advanced_agents/game_builder/setup.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Create a virtual environment +echo "Creating virtual environment..." +python3 -m venv ~/.venvs/game_builder + +# Activate the virtual environment +echo "Activating virtual environment..." +source ~/.venvs/game_builder/bin/activate + +# Install libraries from requirements.txt +echo "Installing libraries from requirements.txt..." +pip install -r requirements.txt + +# Login to your account +echo "Login to your Composio acount" +composio login + +composio add exa + +# Copy env backup to .env file +if [ -f ".env.example" ]; then + echo "Copying .env.example to .env..." + cp .env.example .env +else + echo "No .env.example file found. Creating a new .env file..." + touch .env +fi + +# Prompt user to fill the .env file +echo "Please fill in the .env file with the necessary environment variables." + +echo "Setup completed successfully!" \ No newline at end of file