Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint

on:
push:
branches: [main]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
- run: uv python install 3.10
- run: uv pip install ruff
- run: uv run ruff check .
- run: uv run ruff format --check .
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.2
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
47 changes: 18 additions & 29 deletions computer_use/games/ace_attorney/ace_agent.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
import time
import numpy as np
import concurrent.futures
import argparse
from collections import deque, Counter
import shutil
import threading
from concurrent.futures import ThreadPoolExecutor
import concurrent.futures
import datetime

import os
import json
import re
import pyautogui
# from games.ace_attorney.reflection_worker import ReflectionTracker

import time
from collections import Counter

# from games.ace_attorney.reflection_worker import ReflectionTracker
from games.ace_attorney.workers import (
ace_attorney_worker,
perform_move,
ace_evidence_worker,
short_term_memory_worker,
vision_only_reasoning_worker,
long_term_memory_worker,
memory_retrieval_worker,
vision_only_ace_attorney_worker,
ace_attorney_worker,
ace_evidence_worker,
check_end_statement,
check_skip_conversation,
handle_skip_conversation
handle_skip_conversation,
long_term_memory_worker,
perform_move,
short_term_memory_worker,
vision_only_ace_attorney_worker,
)
from tools.utils import str2bool, encode_image, log_output, get_annotate_img, capture_game_window, log_game_event
from collections import Counter

from tools.utils import log_game_event, str2bool

# Global base cache directory
BASE_CACHE_DIR = "cache/ace_attorney"
Expand Down Expand Up @@ -184,7 +173,7 @@ def main():
print(f"\nThread {i} Analysis:")
print(f"├── Game State: {result['game_state']}")
print(f"├── Move: {result['move'].strip().lower()}")
print(f"├── Thought Process:")
print("├── Thought Process:")
print(f"│ ├── Primary Reasoning: {result['thought']}")
if "dialog" in result:
if isinstance(result['dialog'], dict) and 'name' in result['dialog'] and 'text' in result['dialog']:
Expand Down Expand Up @@ -228,7 +217,7 @@ def main():
print(f"│ ├── Votes: {count}")
# Find all thoughts associated with this move
move_indices = [i for i, m in enumerate(moves) if m == move]
print(f"│ ├── Supporting Thoughts:")
print("│ ├── Supporting Thoughts:")
for idx in move_indices:
print(f"│ │ ├── Thought: {thoughts[idx]}")
if dialogs[idx]:
Expand All @@ -253,7 +242,7 @@ def main():
print("\n=== Final Decision ===")
print(f"├── Game State: {chosen_game_state}")
print(f"├── Chosen Move: {chosen_move}")
print(f"├── Decision Reasoning:")
print("├── Decision Reasoning:")
print(f"│ ├── Primary Thought: {chosen_thought}")
if chosen_dialog:
if isinstance(chosen_dialog, dict) and 'name' in chosen_dialog and 'text' in chosen_dialog:
Expand All @@ -263,7 +252,7 @@ def main():
if chosen_evidence:
print(f"│ ├── Evidence Context: {chosen_evidence['name']}: {chosen_evidence['description']}")
print(f"│ └── Scene Context: {chosen_scene[:200]}...")
print(f"└── Execution Status: Pending")
print("└── Execution Status: Pending")
print("="*70 + "\n")

# Log the final decision
Expand Down Expand Up @@ -334,7 +323,7 @@ def main():
)
dialog_new = {
"name": "Phoenix",
"text": f"I revceive a new evidence 'Mia's Memo'."
"text": "I revceive a new evidence 'Mia's Memo'."
}
long_term_memory_worker(
system_prompt,
Expand Down
27 changes: 18 additions & 9 deletions computer_use/games/ace_attorney/workers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import time
import json
import os
import pyautogui
import numpy as np
import re
import time

from tools.utils import encode_image, log_output, get_annotate_img, capture_game_window, log_request_cost
from tools.serving.api_providers import anthropic_completion, anthropic_text_completion, openai_completion, openai_text_reasoning_completion, gemini_completion, gemini_text_completion, deepseek_text_reasoning_completion, together_ai_completion
import pyautogui
from tools.api_cost_calculator import calculate_all_costs_and_tokens, convert_string_to_messsage
import re
import json

from tools.serving.api_providers import (
anthropic_completion,
anthropic_text_completion,
deepseek_text_reasoning_completion,
gemini_completion,
gemini_text_completion,
openai_completion,
openai_text_reasoning_completion,
together_ai_completion,
)
from tools.utils import capture_game_window, encode_image, log_request_cost

# Default cache directory (can be overridden by passing cache_dir parameter)
DEFAULT_CACHE_DIR = "cache/ace_attorney"
Expand Down Expand Up @@ -966,7 +975,7 @@ def check_skip_conversation(dialog, episode_name):
# Check if dialog matches any key in the skip conversations
episode_convs = skip_conversations.get(episode_name, {})
if dialog_entry in episode_convs:
print(f">>> MATCH FOUND! Dialog matches key in skip conversations")
print(">>> MATCH FOUND! Dialog matches key in skip conversations")
return episode_convs[dialog_entry]

print("No matching key found in skip conversations")
Expand Down Expand Up @@ -995,7 +1004,7 @@ def handle_skip_conversation(system_prompt, api_provider, model_name, prev_respo
print("=== Starting Skip Conversation ===")
print(f"├── Episode: {episode_name}")
print(f"├── Number of dialogs to skip: {len(skip_dialogs) - 1}")
print(f"└── Dialog sequence:")
print("└── Dialog sequence:")
for i, skip_dialog in enumerate(skip_dialogs):
print(f" {i+1}. {skip_dialog}")
print("="*70 + "\n")
Expand Down
10 changes: 5 additions & 5 deletions computer_use/games/candy/candy_agent.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import time
import numpy as np
import concurrent.futures
import argparse
import os
import shutil
import time
from collections import deque

from games.candy.workers import candy_crush_worker

from tools.utils import str2bool
import os
import shutil

# System prompt remains constant
system_prompt = (
"You are a highly intelligent Candy Crush gameplay agent trained to achieve the highest possible score "
Expand Down
25 changes: 14 additions & 11 deletions computer_use/games/candy/workers.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import time
import os
import time

import pyautogui
import numpy as np

from tools.utils import encode_image, log_output, extract_python_code, get_annotate_img
from tools.serving.api_providers import anthropic_completion, openai_completion, gemini_completion, anthropic_text_completion, gemini_text_completion, openai_text_reasoning_completion, openai_vision_reasoning_completion, deepseek_text_reasoning_completion
from tools.serving.api_providers import (
anthropic_completion,
anthropic_text_completion,
deepseek_text_reasoning_completion,
gemini_completion,
gemini_text_completion,
openai_completion,
openai_text_reasoning_completion,
openai_vision_reasoning_completion,
)
from tools.utils import encode_image, get_annotate_img, log_output

cache_dir = "cache/candy_crush"

import time
import os
import pyautogui
import numpy as np

from tools.utils import encode_image, log_output, extract_python_code, get_annotate_img
from tools.serving.api_providers import anthropic_completion, openai_completion, gemini_completion
import re
import json
import re

CACHE_DIR = "cache/candy_crush"

Expand Down
14 changes: 5 additions & 9 deletions computer_use/games/game_2048/2048_agent.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import time
import numpy as np
import concurrent.futures
import argparse
from collections import deque, Counter
import concurrent.futures
import datetime

import os
import json
import re
import pyautogui
import time
from collections import Counter, deque

import pyautogui
from games.game_2048.workers import game_2048_worker

from tools.utils import str2bool
from collections import Counter

CACHE_DIR = "cache/2048"
os.makedirs(CACHE_DIR, exist_ok=True)
Expand Down
5 changes: 2 additions & 3 deletions computer_use/games/game_2048/game.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import json
import os
import sys
import time
from copy import deepcopy

import pygame
from pygame.locals import *

from logic import *
import os
from pygame.locals import *

# TODO: Add a RULES button on start page
# TODO: Add score keeping
Expand Down
6 changes: 3 additions & 3 deletions computer_use/games/game_2048/game_logic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import sys
import argparse
import pygame
import json
import os

import pygame
from game import playGame

# Default window size
Expand Down
14 changes: 7 additions & 7 deletions computer_use/games/game_2048/workers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import time
import os
import pyautogui
import numpy as np
import datetime
import json
import os
import re
import shutil
import time

import pyautogui

from tools.utils import encode_image, log_output, get_annotate_img
from tools.serving.api_manager import APIManager
import re
import json
from tools.utils import get_annotate_img, log_output

CACHE_DIR = "cache/2048"

Expand Down
30 changes: 16 additions & 14 deletions computer_use/games/sokoban/end_to_end_sokoban/sokoban_agent.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# filename: gamingagent/agents/sokoban_agent.py
import numpy as np
import time
import argparse # Added for command-line arguments
import base64
import io
import os
import re
import json
import sys
from collections import deque # Added for MemoryModule
import time
import traceback
from collections import deque # Added for MemoryModule

from gamingagent.envs.sokoban_env import CustomSokobanEnv
from PIL import Image

from tools.serving.api_providers import (
anthropic_completion, anthropic_text_completion,
openai_completion, openai_text_reasoning_completion,
gemini_completion, gemini_text_completion,
anthropic_completion,
anthropic_text_completion,
deepseek_text_reasoning_completion,
gemini_completion,
gemini_text_completion,
openai_completion,
openai_text_reasoning_completion,
together_ai_completion,
xai_grok_completion
xai_grok_completion,
)
from gamingagent.utils.utils import convert_to_json_serializable # Added for JSONL logging
import argparse # Added for command-line arguments
import io
import base64
from PIL import Image
import traceback

CACHE_DIR = "cache/sokoban"
os.makedirs(CACHE_DIR, exist_ok=True)
Expand Down
14 changes: 8 additions & 6 deletions computer_use/games/sokoban/end_to_end_sokoban/sokoban_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#!/usr/bin/env python

# --- Add local gym-sokoban to path ---
import sys
import os
import sys

# Get the directory containing this file (envs/)
envs_dir = os.path.dirname(os.path.abspath(__file__))
# Go up one level to gamingagent/
Expand All @@ -24,11 +25,12 @@

# Now the regular imports start
import gymnasium as gym

# Try importing gym_sokoban, handle potential import error
try:
import gym_sokoban
from gym_sokoban.envs.sokoban_env import SokobanEnv, ACTION_LOOKUP, CHANGE_COORDINATES
import gym_sokoban # noqa: F401
from gym_sokoban.envs.render_utils import room_to_rgb
from gym_sokoban.envs.sokoban_env import ACTION_LOOKUP, CHANGE_COORDINATES, SokobanEnv
except ImportError:
print("Warning: gym_sokoban not found. Please install it: pip install gym-sokoban")
# Define dummy classes/variables if needed for type hinting or basic structure
Expand All @@ -39,10 +41,10 @@ class SokobanEnv(gym.Env): pass
CHANGE_COORDINATES = {}
def room_to_rgb(room_state, room_fixed): return None

import numpy as np
import sys
import pygame # For render mode check
import json # Added missing import for potential future use loading dims/levels

import numpy as np
import pygame # For render mode check

# Mapping from your level file characters to gym-sokoban internal state codes.
# See gym_sokoban.envs.room_utils for original code definitions:
Expand Down
10 changes: 5 additions & 5 deletions computer_use/games/sokoban/sokoban.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!../bin/python

import sys
import pygame
import string
import queue
import copy
import json
import os
import copy
import queue
import sys

import pygame

CACHE_DIR = "cache/sokoban"

Expand Down
Loading