-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: game builder agent added #1342
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OPENAI_API_KEY=KEY | ||
COMPOSIO_API_KEY=KEY | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||||||||||||||
import os | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script is missing module-level docstring and type hints. Consider adding: \"\"\"
Game Builder Agent using Composio and LlamaIndex.
This module provides an interactive interface for creating games using AI assistance.
It leverages PyGame for game development and OpenAI/Groq for AI guidance.
\"\"\"
from typing import Optional, List, Dict Also consider breaking down the script into smaller functions with proper docstrings for better maintainability. |
||||||||||||||||||
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') | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The OpenAI model name 📝 Committable Code Suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a typo in the model name - |
||||||||||||||||||
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: | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main game creation loop lacks error handling. Consider wrapping the LLM calls and agent execution in try-except blocks to handle potential API errors, rate limits, or network issues gracefully. Example: while True:
try:
main_task = input("Describe your game idea (or type 'exit' to quit): ")
if main_task.lower() == 'exit':
break
main_task_refined = llm.complete(...)
agent = FunctionCallingAgentWorker(...)
response = agent.chat(...)
except Exception as e:
print(f"Error occurred: {e}")
continue |
||||||||||||||||||
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") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check for 'exit' before calling llm.complete to avoid unnecessary API calls. |
||||||||||||||||||
if main_task.lower() == 'exit': | ||||||||||||||||||
break | ||||||||||||||||||
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
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" | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentions 'Anthropic tool', but it's not included in the tools list; verify intended tool.
Suggested change
|
||||||||||||||||||
"Or use the shell tool to run it." | ||||||||||||||||||
) | ||||||||||||||||||
print("Response:", response) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The path in the run command seems incorrect: python cookbook/python-examples/advanced_agents/game_builder/main.py Should be: python python/examples/advanced_agents/game_builder/main.py Also consider adding:
|
||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composio-llamaindex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requirements.txt is missing some key dependencies:
Consider updating it to:
|
||
python-dotenv | ||
llama-index-llms-groq |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: change 'composio acount' to 'composio account'.
Suggested change
|
||||||
composio login | ||||||
|
||||||
composio add exa | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incomplete command 📝 Committable Code Suggestion
Suggested change
|
||||||
|
||||||
# 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!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sensitive API keys should not be committed to version control. Use placeholder values like
your_key_here
in example files to prevent accidental key exposure.📝 Committable Code Suggestion