Javier-Jimenez99/JokerNet

๐Ÿค– AI-powered Balatro automation system using multiagent orchestration, computer vision, and Docker. Features LangGraph, Azure OpenAI integration, and Streamlit web interface for autonomous gameplay.

Python

0

81 commits

updated Aug 31, 2025

See the code

README

๐ŸŽฎ JokerNet: AI-Powered Balatro Automation System

Python Docker Streamlit Azure OpenAI License

Transform your Balatro gameplay with JokerNet ๐Ÿค–โœจ

JokerNet screenshot

JokerNet represents a foundational framework for AI-powered game automation that can be extended far beyond Balatro. This section outlines potential enhancements and broader applications that demonstrate the scalability and versatility of the current multiagent architecture. ๐Ÿค–โœจ

The system integrates Azure OpenAI for intelligent reasoning, Docker for scalable deployment, and custom mods for enhanced game interaction, making it a comprehensive solution for automated gaming.

Built with state-of-the-art AI frameworks like LangChain and LangGraph, this project exemplifies expertise in AI agent orchestration, full-stack development, and containerized gaming environments. As a software engineer specializing in AI and automation, I've crafted JokerNet to demonstrate innovative approaches to game AI - from sophisticated multiagent coordination to real-time visual analysis and precise control simulation.

๐Ÿ“‹ Table of Contents

๐Ÿš€ Key Features

๐ŸŽฏ AI-Powered Gameplay๐ŸŽฎ Dual Control Methods๐Ÿ‘๏ธ Real-Time Vision
Multiagent orchestration using LangGraph for coordinated strategic decisionsGamepad control (primary) + Mouse control (under development)Computer vision-powered game state recognition and dynamic planning
Learn more โ†’See interface โ†’Explore architecture โ†’
๐ŸŒ Modern Web UI๐Ÿณ Containerized๐Ÿ”ง Custom Mods
Responsive Streamlit interface for configuration and real-time monitoringFully containerized Balatro environment with noVNC remote accessEnhanced game experience with auto-start and automation features
View interface โ†’Setup guide โ†’Mod details โ†’
  • ๐Ÿ”— MCP Integration: Model Context Protocol server for seamless AI tool integration
  • ๐ŸŒ REST API: Comprehensive HTTP endpoints for programmatic control
  • ๐Ÿง  Azure OpenAI Integration: Advanced reasoning capabilities for strategic gameplay
  • โšก Performance Optimized: GPU support, model caching, and low-latency controls

๐Ÿ—๏ธ System Architecture

JokerNet operates through a sophisticated multi-layered architecture designed for maximum scalability and modularity:

graph TB
    subgraph "User Interface Layer"
        A[Streamlit Interface<br/>Port 8501]
    end

    subgraph "AI Orchestration Layer"
        C[Multiagent System<br/>LangGraph]
    end

    subgraph "๐Ÿณ Docker Container<br/>Complete Game Environment"
        subgraph "API Services"
            F[REST API<br/>Port 8000]
            G[MCP Server<br/>Port 8001]
        end

        subgraph "Game Runtime"
            B[noVNC<br/>Port 6080]
            D[Balatro Game<br/>Love2D Engine]
            E[Custom Mods<br/>BalatroLogger]
        end

        subgraph "Display System"
            H[Xvfb<br/>Virtual Display]
            I[x11vnc<br/>VNC Server]
        end

        B --> I
        I --> H
        H --> D
        F --> D
        G --> D
        E --> D
    end

    A --> F
    A --> B
    A --> C
    C --> A
    C --> G

    style A fill:#e1f5fe
    style C fill:#f3e5f5
    style D fill:#e8f5e8
    style F fill:#fff3e0

Architecture Highlights:

  • ๐Ÿ”„ Multi-layered Design: Clear separation between external UI, AI orchestration, and containerized game environment
  • ๐Ÿณ Docker Encapsulation: All game execution components (display, APIs, game engine, mods) are contained within a single Docker image for easy deployment and portability
  • ๐Ÿ“ก Service Mesh: Streamlit interfaces with API, VNC, and multiagent system independently
  • ๐Ÿ›ก๏ธ Fault Tolerance: Isolated components with graceful error handling
  • โšก Performance: Optimized for responsive game automation and AI processing
  • ๐Ÿ”— Dual Control Paths: Both REST API and MCP server provide game control capabilities
  • ๐Ÿ”„ Game Agnostic Design: With minimal modifications, the same Docker environment can support different games by swapping the game engine and mods
  • ๐Ÿ”— Bidirectional Communication: Multiagent system communicates directly with both Streamlit interface and MCP server for seamless coordination

For detailed agent orchestration, see Multiagent System

๐Ÿค– Multiagent System with LangGraph

At the heart of JokerNet lies a sophisticated multiagent system built using LangGraph, a powerful framework for orchestrating complex AI workflows. This system intelligently decomposes the challenging task of autonomous Balatro gameplay into coordinated, specialized agents that collaborate seamlessly.

๐ŸŽญ Agent Roles and Coordination

The multiagent architecture features three specialized agents, each with distinct responsibilities:

AgentRoleSpecializationKey Functions
๐Ÿง  Planner AgentStrategic DirectorHigh-level decision makingTask decomposition, strategic planning
๐Ÿ‘๏ธ Visualizer AgentVision SpecialistComputer vision analysisScreenshot processing, game state extraction
โš™๏ธ Worker AgentExecution ExpertAction implementationGamepad control (primary), mouse interaction (under development)

๐Ÿ“Š Visual Workflow Diagram

---
config:
  flowchart:
    curve: linear
---
graph TD;
	__start__([<p>__start__</p>]):::first
	planner_visualizer(planner_visualizer)
	planner(planner)
	worker_visualizer(worker_visualizer)
	worker(worker)
	tool(tool)
	output(output)
	__end__([<p>__end__</p>]):::last
	__start__ --> planner_visualizer;
	planner -. &nbsp;end&nbsp; .-> output;
	planner -.-> worker_visualizer;
	planner_visualizer --> planner;
	tool --> worker_visualizer;
	worker -.-> planner;
	worker -.-> tool;
	worker_visualizer --> worker;
	output --> __end__;
	classDef default fill:#f2f0ff,line-height:1.2
	classDef first fill-opacity:0
	classDef last fill:#bfb6fc

๐Ÿ” Workflow Breakdown:

  1. ๐Ÿš€ START Node: Initial user input processing and system initialization
  2. ๐Ÿง  Planner-Visualizer Node: Strategic analysis with visual context capture
  3. ๐Ÿ“‹ Planner Node: High-level task decomposition and strategic planning
  4. ๐Ÿ”€ Conditional Routing: Intelligent decision branching based on planner actions
  5. ๐Ÿ‘๏ธ Worker-Visualizer Node: Context-aware screenshot capture for execution
  6. โš™๏ธ Worker Node: Precise action planning and tool orchestration
  7. ๐ŸŽฎ Tool Node: Direct game control execution (gamepad actions - mouse under development)
  8. ๐Ÿ”„ Conditional Worker Routing: Adaptive loop control with success/failure handling
  9. ๐Ÿ“ค Output Node: Final result formatting and user response delivery

๐Ÿ›ก๏ธ Advanced Flow Control Features:

  • โฑ๏ธ Max Step Limits: Prevents infinite loops (5 planner steps, 3 worker steps)
  • ๐Ÿ’พ State Persistence: Maintains conversation history and game state across iterations
  • ๐Ÿ›Ÿ Error Handling: Graceful degradation and intelligent completion detection
  • ๐Ÿ”ง Tool Integration: Exclusive MCP server integration for game control (no direct API usage)

This architecture enables complex decision-making while ensuring system reliability and user control. For the web interface that interacts with these agents, see Streamlit Interface

๐ŸŒ Streamlit Web Interface

JokerNet features a modern, responsive Streamlit application that provides an intuitive and powerful interface for configuration, monitoring, and interaction with the AI agents.

โœจ Main Features

FeatureDescriptionBenefits
๐Ÿ“บ Live Game ViewEmbedded noVNC viewer for game monitoringVisual feedback and control
โš™๏ธ Agent ConfigurationDirect API calls for game and agent settingsFlexible automation strategies
๐Ÿ’ฌ Chat InterfaceNatural language interaction with AI agentsIntuitive user experience
๐ŸŽฏ Run ConfigurationDeck selection, stake adjustment via APICustomized gameplay scenarios
๐Ÿ“Š Progress MonitoringLive updates on agent actions and game stateTransparent automation process

๐Ÿ“ธ Interface Screenshots

๐Ÿ  Main Dashboard

Main Dashboard Screenshot

โš™๏ธ Agent Configuration

Agent Configuration Screenshot


๐Ÿƒ Game Configuration

Game Configuration Screenshot


๐ŸŽฎ Game Control Panel

Game Control Screenshot

๐Ÿณ Docker Environment: Balatro with Enhanced Automation

JokerNet includes a comprehensive Docker setup that containerizes the entire Balatro gaming environment, complete with custom mods, API servers, and remote access capabilities.

๐Ÿ›๏ธ Container Architecture

The Docker environment provides a fully isolated and optimized gaming ecosystem with all services running within a single container:

graph TB
    subgraph "๐Ÿณ Docker Container<br/>Internal Architecture"
        subgraph "API Services"
            F[REST API<br/>Port 8000]
            G[MCP Server<br/>Port 8001]
        end

        subgraph "Game Runtime"
            B[noVNC<br/>Port 6080]
            D[Balatro Game<br/>Love2D Engine]
            E[Custom Mods<br/>BalatroLogger]
        end

        subgraph "Display System"
            H[Xvfb<br/>Virtual Display]
            I[x11vnc<br/>VNC Server]
        end

        B --> I
        I --> H
        H --> D
        F --> D
        G --> D
        E --> D
    end

    style D fill:#e8f5e8
    style F fill:#fff3e0

๐Ÿ”ง Internal Service Flow:

  • ๐ŸŒ External Access: noVNC (Port 6080) provides web-based game interface, while VNC (Port 5900) offers native client access
  • ๐Ÿš€ API Layer: REST API (Port 8000) handles HTTP requests, MCP Server (Port 8001) manages AI agent integration
  • ๐ŸŽฎ Game Control: Both API services communicate directly with the Balatro game engine for programmatic control
  • ๐Ÿ–ฅ๏ธ Display Pipeline: Xvfb creates virtual display โ†’ x11vnc serves VNC โ†’ noVNC provides web proxy
  • ๐Ÿ”ง Mod Integration: Custom mods enhance game functionality and enable automation features

๐Ÿณ Docker Container Benefits:

  • ๐ŸŽฎ Complete Game Environment: Everything needed to run and interact with the game is encapsulated in a single container
  • ๐Ÿ”ง Easy Deployment: One-command deployment with all dependencies and services pre-configured
  • ๐Ÿ”„ Game Swapping: Simple replacement of game files and mods enables support for different games
  • ๐Ÿ“ฆ Portability: Consistent environment across different host systems
  • ๐Ÿ› ๏ธ Isolation: Clean separation between host system and game environment

๐Ÿ”ง Services Overview

All services are expertly managed by Supervisor for reliable, production-grade operation:

ServicePortPurposeTechnology
๐Ÿ–ฅ๏ธ XvfbN/AVirtual X server for headless displayX11
๐Ÿ“ก x11vnc5900VNC server for remote desktop accessVNC Protocol
๐ŸŒ noVNC6080Web-based VNC client (no installation needed)WebRTC
๐Ÿš€ FastAPI8000REST API server for game controlPython/FastAPI
๐Ÿค– MCP Server8001AI agent integration and tool orchestrationPython/MCP

๐ŸŽฏ Custom Mods and Enhancements

JokerNet includes several custom modifications to dramatically enhance automation capabilities:

๐Ÿ“ฆ Installed Mods

  • ๐Ÿ’‰ Lovely Injector: Core mod loading framework for Love2D games
  • ๐ŸŽฎ Steamodded (SMODS): Comprehensive modding framework for Balatro
  • ๐Ÿ“Š BalatroLogger: Custom mod for automated game state logging and control
  • โญ Saturn Mod: Enhanced UI and gameplay features

๐Ÿ› ๏ธ Custom BalatroLogger Mod

I've developed a custom mod (BalatroLogger) that significantly improves automation capabilities:

-- Key features from auto_start.lua
function love.update(dt)
    if config and config.auto_start then
        if G then
            -- Automatic deck and stake configuration
            if config.deck and G.P_CENTERS[config.deck] then
                G.GAME.viewed_back = G.P_CENTERS[config.deck]
            end

            -- Programmatic game start
            if G.FUNCS and G.FUNCS.start_run then
                G.FUNCS.start_run(nil, {
                    stake = config.stake or 1,
                    seed = (config.seed and config.seed ~= "random") and config.seed or nil
                })
            end
        end
    end
end

๐ŸŽฎ Mod Capabilities:

  • ๐Ÿš€ Auto-start functionality: Programmatic game initialization with custom parameters
  • ๐Ÿ’พ Configuration persistence: Settings saved across game sessions
  • ๐Ÿ“ˆ Enhanced logging: Detailed game state tracking for AI analysis
  • ๐Ÿ”— API integration: Direct communication with external automation systems

๐ŸŒ Access Points

ServiceURLDescriptionPrimary Use
๐ŸŒ noVNC Directhttp://localhost:6080Primary web-based game accessMain game interface
๐Ÿ“š REST APIhttp://localhost:8000/docsInteractive API documentationDevelopment & integration
๐Ÿค– MCP Serverhttp://localhost:8001AI agent integration endpointAgent communication
๐Ÿ’ป VNC Nativelocalhost:5900Traditional VNC client accessAdvanced users

๐Ÿ”Œ API Capabilities

The REST API provides comprehensive control with intuitive endpoints:

# ๐ŸŽฎ Game control via gamepad
curl -X POST "http://localhost:8000/gamepad/buttons" \
     -H "Content-Type: application/json" \
     -d '{"sequence": "A RIGHT B", "duration": 0.1}'

# โš™๏ธ Auto-start configuration
curl -X POST "http://localhost:8000/auto_start" \
     -H "Content-Type: application/json" \
     -d '{"auto_start": true, "deck": "b_magic", "stake": 5}'

# ๐Ÿ“ธ Screenshot capture
curl "http://localhost:8000/screenshot" > game_state.png

๐Ÿค– MCP Server Integration

The Model Context Protocol server enables seamless AI agent integration with powerful tools:

# Available tools for AI agents
- press_buttons(sequence): Gamepad control
- mouse_click(x, y): Mouse interaction (under development)
- get_screen(): Screenshot capture
- locate_element(description): UI element detection

For setup instructions, see Installation Guide

โš ๏ธ Mouse Controller Status

โš ๏ธ WARNING: Mouse control is currently under development and does not work yet.

The system supports both gamepad and mouse control modes, but mouse functionality is not operational. The gamepad controller works reliably for automated gameplay, while mouse interaction requires additional development work.

Technical Challenges

I attempted to implement mouse control using AI vision models (HuggingFace ASKUI/PTA-1) for object detection, but encountered significant challenges:

  • Card Detection: The AI model couldn't reliably identify Balatro's playing cards
  • UI Recognition: Difficulty detecting buttons and interactive elements
  • Visual Complexity: Balatro's artistic designs and animations made detection challenging
  • Real-time Performance: Game state changes faster than AI processing

Current Solution & Future Plans

  • Use Gamepad Control: Primary method that works reliably
  • Manual Mouse: Direct interaction through noVNC interface when needed
  • Future Development: Custom vision models and computer vision pipelines for mouse control

๐Ÿ“ฆ Installation and Setup

โšก Prerequisites

# ๐Ÿ–ฅ๏ธ Host system requirements
sudo modprobe uinput
sudo chmod 666 /dev/uinput

๐Ÿš€ Quick Start

1๏ธโƒฃ Clone and Setup

git clone https://github.com/Javier-Jimenez99/JokerNet.git
cd JokerNet
uv sync  # Install dependencies
cp .env.example .env  # Configure environment variables

2๏ธโƒฃ Launch Docker Environment

cd BalatroDocker
docker-compose up -d

3๏ธโƒฃ Start Streamlit Interface

cd src
streamlit run app.py

4๏ธโƒฃ Access Services

ServiceURLPurpose
๐ŸŽฎ Gamehttp://localhost:6080noVNC interface
๐ŸŒ Interfacehttp://localhost:8501Streamlit web app
๐Ÿ“š API Docshttp://localhost:8000/docsREST API documentation

๐Ÿš€ Uso del Script de Inicio

Ejecuta ./startup.sh para iniciar en modo CPU. Usa ./startup.sh --gpu para activar GPU si estรก disponible.

๐Ÿ“ Project Structure

JokerNet/
โ”œโ”€โ”€ ๐Ÿ”ง .env                    # Environment configuration
โ”œโ”€โ”€ ๐Ÿ“ฆ pyproject.toml         # Project dependencies
โ”œโ”€โ”€ ๐Ÿ”’ uv.lock               # Dependency lock file
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ ๐ŸŒ app.py           # Streamlit application
โ”‚   โ”œโ”€โ”€ ๐Ÿ”— api.py           # API client
โ”‚   โ”œโ”€โ”€ ๐Ÿค– agents/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿง  planner.py   # Strategic planning agent
โ”‚   โ”‚   โ”œโ”€โ”€ โš™๏ธ worker.py    # Execution agent
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“‹ models/      # Pydantic models
โ”‚   โ””โ”€โ”€ ๐ŸŽจ ui_components/    # Streamlit UI modules
โ”œโ”€โ”€ ๐Ÿณ BalatroDocker/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Dockerfile       # Container definition
โ”‚   โ”œโ”€โ”€ ๐Ÿ”„ docker-compose.yml # Service orchestration
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ scripts/         # Setup and startup scripts
โ”‚   โ”œโ”€โ”€ โš™๏ธ config/          # Configuration files
โ”‚   โ””โ”€โ”€ ๐Ÿ”ง src/             # API and MCP servers
โ”œโ”€โ”€ ๐Ÿ““ notebooks/           # Development and testing
โ””โ”€โ”€ ๐ŸŽญ assets/             # Static resources

๐Ÿ”ง Configuration

๐Ÿง  Azure OpenAI Setup

Configure your .env from .env.example file:

# Azure OpenAI Configuration (required for AI agent)
AZURE_OPENAI_ENDPOINT=https://your-azure-endpoint.openai.azure.com/
AZURE_OPENAI_API_KEY=your_api_key_here
AZURE_OPENAI_MODEL=gpt-4.1
AZURE_OPENAI_API_VERSION=2025-01-01-preview

# LangSmith Configuration
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=BalatroAgent-Worker
LANGCHAIN_API_KEY=your_langchain_api_key_here

# Docker/Steam Configuration
STEAM_USER=your_steam_username
STEAM_PASS=your_steam_password
GAME_SPEED=16

๐ŸŽฎ Game Parameters

Available Deck Options:

  • ๐Ÿ”ด b_red - Red Deck
  • ๐Ÿ”ต b_blue - Blue Deck (recommended)
  • ๐Ÿช„ b_magic - Magic Deck
  • ๐ŸŒŒ b_nebula - Nebula Deck
  • ๐Ÿ‘ป b_ghost - Ghost Deck
  • โšก b_plasma - Plasma Deck

Stake Levels: 1-8 (1=easiest, 8=hardest)

๐Ÿš€ Future Work & Extensions

JokerNet's modular architecture enables easy extension to other games and advanced AI capabilities.

๐ŸŽฎ Multi-Game Support

  • Strategy Games: Civilization VI, Factorio
  • Action/RPG: Slay the Spire, Hades
  • Simulation: Cities: Skylines, The Sims 4

๐Ÿ› ๏ธ Technical Enhancements

  • Reinforcement Learning: PPO/DQN for complex decisions
  • Multi-Modal AI: Visual + textual + audio processing
  • Performance: Edge computing, model quantization
  • Controls: Voice control, gesture recognition, mouse control

๐Ÿ“„ License

This project showcases professional-level software engineering with a focus on AI-driven automation, game development integration, and scalable system design.


๐ŸŽฏ Ready to Experience Autonomous Balatro Gameplay?

Start your AI-powered gaming journey today! ๐Ÿš€

Built with โค๏ธ by Javier Jimenez

GitHub LinkedIn

agents
artificial-intelligence
computer-vision
docker
game-automation
gaming
langgraph
machine-learning
python
streamlit

Javier-Jimenez99/JokerNet

๐Ÿค– AI-powered Balatro automation system using multiagent orchestration, computer vision, and Docker. Features LangGraph, Azure OpenAI integration, and Streamlit web interface for autonomous gameplay.

Python

0

81 commits

updated Aug 31, 2025

See the code

README

๐ŸŽฎ JokerNet: AI-Powered Balatro Automation System

Python Docker Streamlit Azure OpenAI License

Transform your Balatro gameplay with JokerNet ๐Ÿค–โœจ

JokerNet screenshot

JokerNet represents a foundational framework for AI-powered game automation that can be extended far beyond Balatro. This section outlines potential enhancements and broader applications that demonstrate the scalability and versatility of the current multiagent architecture. ๐Ÿค–โœจ

The system integrates Azure OpenAI for intelligent reasoning, Docker for scalable deployment, and custom mods for enhanced game interaction, making it a comprehensive solution for automated gaming.

Built with state-of-the-art AI frameworks like LangChain and LangGraph, this project exemplifies expertise in AI agent orchestration, full-stack development, and containerized gaming environments. As a software engineer specializing in AI and automation, I've crafted JokerNet to demonstrate innovative approaches to game AI - from sophisticated multiagent coordination to real-time visual analysis and precise control simulation.

๐Ÿ“‹ Table of Contents

๐Ÿš€ Key Features

๐ŸŽฏ AI-Powered Gameplay๐ŸŽฎ Dual Control Methods๐Ÿ‘๏ธ Real-Time Vision
Multiagent orchestration using LangGraph for coordinated strategic decisionsGamepad control (primary) + Mouse control (under development)Computer vision-powered game state recognition and dynamic planning
Learn more โ†’See interface โ†’Explore architecture โ†’
๐ŸŒ Modern Web UI๐Ÿณ Containerized๐Ÿ”ง Custom Mods
Responsive Streamlit interface for configuration and real-time monitoringFully containerized Balatro environment with noVNC remote accessEnhanced game experience with auto-start and automation features
View interface โ†’Setup guide โ†’Mod details โ†’
  • ๐Ÿ”— MCP Integration: Model Context Protocol server for seamless AI tool integration
  • ๐ŸŒ REST API: Comprehensive HTTP endpoints for programmatic control
  • ๐Ÿง  Azure OpenAI Integration: Advanced reasoning capabilities for strategic gameplay
  • โšก Performance Optimized: GPU support, model caching, and low-latency controls

๐Ÿ—๏ธ System Architecture

JokerNet operates through a sophisticated multi-layered architecture designed for maximum scalability and modularity:

graph TB
    subgraph "User Interface Layer"
        A[Streamlit Interface<br/>Port 8501]
    end

    subgraph "AI Orchestration Layer"
        C[Multiagent System<br/>LangGraph]
    end

    subgraph "๐Ÿณ Docker Container<br/>Complete Game Environment"
        subgraph "API Services"
            F[REST API<br/>Port 8000]
            G[MCP Server<br/>Port 8001]
        end

        subgraph "Game Runtime"
            B[noVNC<br/>Port 6080]
            D[Balatro Game<br/>Love2D Engine]
            E[Custom Mods<br/>BalatroLogger]
        end

        subgraph "Display System"
            H[Xvfb<br/>Virtual Display]
            I[x11vnc<br/>VNC Server]
        end

        B --> I
        I --> H
        H --> D
        F --> D
        G --> D
        E --> D
    end

    A --> F
    A --> B
    A --> C
    C --> A
    C --> G

    style A fill:#e1f5fe
    style C fill:#f3e5f5
    style D fill:#e8f5e8
    style F fill:#fff3e0

Architecture Highlights:

  • ๐Ÿ”„ Multi-layered Design: Clear separation between external UI, AI orchestration, and containerized game environment
  • ๐Ÿณ Docker Encapsulation: All game execution components (display, APIs, game engine, mods) are contained within a single Docker image for easy deployment and portability
  • ๐Ÿ“ก Service Mesh: Streamlit interfaces with API, VNC, and multiagent system independently
  • ๐Ÿ›ก๏ธ Fault Tolerance: Isolated components with graceful error handling
  • โšก Performance: Optimized for responsive game automation and AI processing
  • ๐Ÿ”— Dual Control Paths: Both REST API and MCP server provide game control capabilities
  • ๐Ÿ”„ Game Agnostic Design: With minimal modifications, the same Docker environment can support different games by swapping the game engine and mods
  • ๐Ÿ”— Bidirectional Communication: Multiagent system communicates directly with both Streamlit interface and MCP server for seamless coordination

For detailed agent orchestration, see Multiagent System

๐Ÿค– Multiagent System with LangGraph

At the heart of JokerNet lies a sophisticated multiagent system built using LangGraph, a powerful framework for orchestrating complex AI workflows. This system intelligently decomposes the challenging task of autonomous Balatro gameplay into coordinated, specialized agents that collaborate seamlessly.

๐ŸŽญ Agent Roles and Coordination

The multiagent architecture features three specialized agents, each with distinct responsibilities:

AgentRoleSpecializationKey Functions
๐Ÿง  Planner AgentStrategic DirectorHigh-level decision makingTask decomposition, strategic planning
๐Ÿ‘๏ธ Visualizer AgentVision SpecialistComputer vision analysisScreenshot processing, game state extraction
โš™๏ธ Worker AgentExecution ExpertAction implementationGamepad control (primary), mouse interaction (under development)

๐Ÿ“Š Visual Workflow Diagram

---
config:
  flowchart:
    curve: linear
---
graph TD;
	__start__([<p>__start__</p>]):::first
	planner_visualizer(planner_visualizer)
	planner(planner)
	worker_visualizer(worker_visualizer)
	worker(worker)
	tool(tool)
	output(output)
	__end__([<p>__end__</p>]):::last
	__start__ --> planner_visualizer;
	planner -. &nbsp;end&nbsp; .-> output;
	planner -.-> worker_visualizer;
	planner_visualizer --> planner;
	tool --> worker_visualizer;
	worker -.-> planner;
	worker -.-> tool;
	worker_visualizer --> worker;
	output --> __end__;
	classDef default fill:#f2f0ff,line-height:1.2
	classDef first fill-opacity:0
	classDef last fill:#bfb6fc

๐Ÿ” Workflow Breakdown:

  1. ๐Ÿš€ START Node: Initial user input processing and system initialization
  2. ๐Ÿง  Planner-Visualizer Node: Strategic analysis with visual context capture
  3. ๐Ÿ“‹ Planner Node: High-level task decomposition and strategic planning
  4. ๐Ÿ”€ Conditional Routing: Intelligent decision branching based on planner actions
  5. ๐Ÿ‘๏ธ Worker-Visualizer Node: Context-aware screenshot capture for execution
  6. โš™๏ธ Worker Node: Precise action planning and tool orchestration
  7. ๐ŸŽฎ Tool Node: Direct game control execution (gamepad actions - mouse under development)
  8. ๐Ÿ”„ Conditional Worker Routing: Adaptive loop control with success/failure handling
  9. ๐Ÿ“ค Output Node: Final result formatting and user response delivery

๐Ÿ›ก๏ธ Advanced Flow Control Features:

  • โฑ๏ธ Max Step Limits: Prevents infinite loops (5 planner steps, 3 worker steps)
  • ๐Ÿ’พ State Persistence: Maintains conversation history and game state across iterations
  • ๐Ÿ›Ÿ Error Handling: Graceful degradation and intelligent completion detection
  • ๐Ÿ”ง Tool Integration: Exclusive MCP server integration for game control (no direct API usage)

This architecture enables complex decision-making while ensuring system reliability and user control. For the web interface that interacts with these agents, see Streamlit Interface

๐ŸŒ Streamlit Web Interface

JokerNet features a modern, responsive Streamlit application that provides an intuitive and powerful interface for configuration, monitoring, and interaction with the AI agents.

โœจ Main Features

FeatureDescriptionBenefits
๐Ÿ“บ Live Game ViewEmbedded noVNC viewer for game monitoringVisual feedback and control
โš™๏ธ Agent ConfigurationDirect API calls for game and agent settingsFlexible automation strategies
๐Ÿ’ฌ Chat InterfaceNatural language interaction with AI agentsIntuitive user experience
๐ŸŽฏ Run ConfigurationDeck selection, stake adjustment via APICustomized gameplay scenarios
๐Ÿ“Š Progress MonitoringLive updates on agent actions and game stateTransparent automation process

๐Ÿ“ธ Interface Screenshots

๐Ÿ  Main Dashboard

Main Dashboard Screenshot

โš™๏ธ Agent Configuration

Agent Configuration Screenshot


๐Ÿƒ Game Configuration

Game Configuration Screenshot


๐ŸŽฎ Game Control Panel

Game Control Screenshot

๐Ÿณ Docker Environment: Balatro with Enhanced Automation

JokerNet includes a comprehensive Docker setup that containerizes the entire Balatro gaming environment, complete with custom mods, API servers, and remote access capabilities.

๐Ÿ›๏ธ Container Architecture

The Docker environment provides a fully isolated and optimized gaming ecosystem with all services running within a single container:

graph TB
    subgraph "๐Ÿณ Docker Container<br/>Internal Architecture"
        subgraph "API Services"
            F[REST API<br/>Port 8000]
            G[MCP Server<br/>Port 8001]
        end

        subgraph "Game Runtime"
            B[noVNC<br/>Port 6080]
            D[Balatro Game<br/>Love2D Engine]
            E[Custom Mods<br/>BalatroLogger]
        end

        subgraph "Display System"
            H[Xvfb<br/>Virtual Display]
            I[x11vnc<br/>VNC Server]
        end

        B --> I
        I --> H
        H --> D
        F --> D
        G --> D
        E --> D
    end

    style D fill:#e8f5e8
    style F fill:#fff3e0

๐Ÿ”ง Internal Service Flow:

  • ๐ŸŒ External Access: noVNC (Port 6080) provides web-based game interface, while VNC (Port 5900) offers native client access
  • ๐Ÿš€ API Layer: REST API (Port 8000) handles HTTP requests, MCP Server (Port 8001) manages AI agent integration
  • ๐ŸŽฎ Game Control: Both API services communicate directly with the Balatro game engine for programmatic control
  • ๐Ÿ–ฅ๏ธ Display Pipeline: Xvfb creates virtual display โ†’ x11vnc serves VNC โ†’ noVNC provides web proxy
  • ๐Ÿ”ง Mod Integration: Custom mods enhance game functionality and enable automation features

๐Ÿณ Docker Container Benefits:

  • ๐ŸŽฎ Complete Game Environment: Everything needed to run and interact with the game is encapsulated in a single container
  • ๐Ÿ”ง Easy Deployment: One-command deployment with all dependencies and services pre-configured
  • ๐Ÿ”„ Game Swapping: Simple replacement of game files and mods enables support for different games
  • ๐Ÿ“ฆ Portability: Consistent environment across different host systems
  • ๐Ÿ› ๏ธ Isolation: Clean separation between host system and game environment

๐Ÿ”ง Services Overview

All services are expertly managed by Supervisor for reliable, production-grade operation:

ServicePortPurposeTechnology
๐Ÿ–ฅ๏ธ XvfbN/AVirtual X server for headless displayX11
๐Ÿ“ก x11vnc5900VNC server for remote desktop accessVNC Protocol
๐ŸŒ noVNC6080Web-based VNC client (no installation needed)WebRTC
๐Ÿš€ FastAPI8000REST API server for game controlPython/FastAPI
๐Ÿค– MCP Server8001AI agent integration and tool orchestrationPython/MCP

๐ŸŽฏ Custom Mods and Enhancements

JokerNet includes several custom modifications to dramatically enhance automation capabilities:

๐Ÿ“ฆ Installed Mods

  • ๐Ÿ’‰ Lovely Injector: Core mod loading framework for Love2D games
  • ๐ŸŽฎ Steamodded (SMODS): Comprehensive modding framework for Balatro
  • ๐Ÿ“Š BalatroLogger: Custom mod for automated game state logging and control
  • โญ Saturn Mod: Enhanced UI and gameplay features

๐Ÿ› ๏ธ Custom BalatroLogger Mod

I've developed a custom mod (BalatroLogger) that significantly improves automation capabilities:

-- Key features from auto_start.lua
function love.update(dt)
    if config and config.auto_start then
        if G then
            -- Automatic deck and stake configuration
            if config.deck and G.P_CENTERS[config.deck] then
                G.GAME.viewed_back = G.P_CENTERS[config.deck]
            end

            -- Programmatic game start
            if G.FUNCS and G.FUNCS.start_run then
                G.FUNCS.start_run(nil, {
                    stake = config.stake or 1,
                    seed = (config.seed and config.seed ~= "random") and config.seed or nil
                })
            end
        end
    end
end

๐ŸŽฎ Mod Capabilities:

  • ๐Ÿš€ Auto-start functionality: Programmatic game initialization with custom parameters
  • ๐Ÿ’พ Configuration persistence: Settings saved across game sessions
  • ๐Ÿ“ˆ Enhanced logging: Detailed game state tracking for AI analysis
  • ๐Ÿ”— API integration: Direct communication with external automation systems

๐ŸŒ Access Points

ServiceURLDescriptionPrimary Use
๐ŸŒ noVNC Directhttp://localhost:6080Primary web-based game accessMain game interface
๐Ÿ“š REST APIhttp://localhost:8000/docsInteractive API documentationDevelopment & integration
๐Ÿค– MCP Serverhttp://localhost:8001AI agent integration endpointAgent communication
๐Ÿ’ป VNC Nativelocalhost:5900Traditional VNC client accessAdvanced users

๐Ÿ”Œ API Capabilities

The REST API provides comprehensive control with intuitive endpoints:

# ๐ŸŽฎ Game control via gamepad
curl -X POST "http://localhost:8000/gamepad/buttons" \
     -H "Content-Type: application/json" \
     -d '{"sequence": "A RIGHT B", "duration": 0.1}'

# โš™๏ธ Auto-start configuration
curl -X POST "http://localhost:8000/auto_start" \
     -H "Content-Type: application/json" \
     -d '{"auto_start": true, "deck": "b_magic", "stake": 5}'

# ๐Ÿ“ธ Screenshot capture
curl "http://localhost:8000/screenshot" > game_state.png

๐Ÿค– MCP Server Integration

The Model Context Protocol server enables seamless AI agent integration with powerful tools:

# Available tools for AI agents
- press_buttons(sequence): Gamepad control
- mouse_click(x, y): Mouse interaction (under development)
- get_screen(): Screenshot capture
- locate_element(description): UI element detection

For setup instructions, see Installation Guide

โš ๏ธ Mouse Controller Status

โš ๏ธ WARNING: Mouse control is currently under development and does not work yet.

The system supports both gamepad and mouse control modes, but mouse functionality is not operational. The gamepad controller works reliably for automated gameplay, while mouse interaction requires additional development work.

Technical Challenges

I attempted to implement mouse control using AI vision models (HuggingFace ASKUI/PTA-1) for object detection, but encountered significant challenges:

  • Card Detection: The AI model couldn't reliably identify Balatro's playing cards
  • UI Recognition: Difficulty detecting buttons and interactive elements
  • Visual Complexity: Balatro's artistic designs and animations made detection challenging
  • Real-time Performance: Game state changes faster than AI processing

Current Solution & Future Plans

  • Use Gamepad Control: Primary method that works reliably
  • Manual Mouse: Direct interaction through noVNC interface when needed
  • Future Development: Custom vision models and computer vision pipelines for mouse control

๐Ÿ“ฆ Installation and Setup

โšก Prerequisites

# ๐Ÿ–ฅ๏ธ Host system requirements
sudo modprobe uinput
sudo chmod 666 /dev/uinput

๐Ÿš€ Quick Start

1๏ธโƒฃ Clone and Setup

git clone https://github.com/Javier-Jimenez99/JokerNet.git
cd JokerNet
uv sync  # Install dependencies
cp .env.example .env  # Configure environment variables

2๏ธโƒฃ Launch Docker Environment

cd BalatroDocker
docker-compose up -d

3๏ธโƒฃ Start Streamlit Interface

cd src
streamlit run app.py

4๏ธโƒฃ Access Services

ServiceURLPurpose
๐ŸŽฎ Gamehttp://localhost:6080noVNC interface
๐ŸŒ Interfacehttp://localhost:8501Streamlit web app
๐Ÿ“š API Docshttp://localhost:8000/docsREST API documentation

๐Ÿš€ Uso del Script de Inicio

Ejecuta ./startup.sh para iniciar en modo CPU. Usa ./startup.sh --gpu para activar GPU si estรก disponible.

๐Ÿ“ Project Structure

JokerNet/
โ”œโ”€โ”€ ๐Ÿ”ง .env                    # Environment configuration
โ”œโ”€โ”€ ๐Ÿ“ฆ pyproject.toml         # Project dependencies
โ”œโ”€โ”€ ๐Ÿ”’ uv.lock               # Dependency lock file
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ ๐ŸŒ app.py           # Streamlit application
โ”‚   โ”œโ”€โ”€ ๐Ÿ”— api.py           # API client
โ”‚   โ”œโ”€โ”€ ๐Ÿค– agents/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿง  planner.py   # Strategic planning agent
โ”‚   โ”‚   โ”œโ”€โ”€ โš™๏ธ worker.py    # Execution agent
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“‹ models/      # Pydantic models
โ”‚   โ””โ”€โ”€ ๐ŸŽจ ui_components/    # Streamlit UI modules
โ”œโ”€โ”€ ๐Ÿณ BalatroDocker/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ Dockerfile       # Container definition
โ”‚   โ”œโ”€โ”€ ๐Ÿ”„ docker-compose.yml # Service orchestration
โ”‚   โ”œโ”€โ”€ ๐Ÿ“œ scripts/         # Setup and startup scripts
โ”‚   โ”œโ”€โ”€ โš™๏ธ config/          # Configuration files
โ”‚   โ””โ”€โ”€ ๐Ÿ”ง src/             # API and MCP servers
โ”œโ”€โ”€ ๐Ÿ““ notebooks/           # Development and testing
โ””โ”€โ”€ ๐ŸŽญ assets/             # Static resources

๐Ÿ”ง Configuration

๐Ÿง  Azure OpenAI Setup

Configure your .env from .env.example file:

# Azure OpenAI Configuration (required for AI agent)
AZURE_OPENAI_ENDPOINT=https://your-azure-endpoint.openai.azure.com/
AZURE_OPENAI_API_KEY=your_api_key_here
AZURE_OPENAI_MODEL=gpt-4.1
AZURE_OPENAI_API_VERSION=2025-01-01-preview

# LangSmith Configuration
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=BalatroAgent-Worker
LANGCHAIN_API_KEY=your_langchain_api_key_here

# Docker/Steam Configuration
STEAM_USER=your_steam_username
STEAM_PASS=your_steam_password
GAME_SPEED=16

๐ŸŽฎ Game Parameters

Available Deck Options:

  • ๐Ÿ”ด b_red - Red Deck
  • ๐Ÿ”ต b_blue - Blue Deck (recommended)
  • ๐Ÿช„ b_magic - Magic Deck
  • ๐ŸŒŒ b_nebula - Nebula Deck
  • ๐Ÿ‘ป b_ghost - Ghost Deck
  • โšก b_plasma - Plasma Deck

Stake Levels: 1-8 (1=easiest, 8=hardest)

๐Ÿš€ Future Work & Extensions

JokerNet's modular architecture enables easy extension to other games and advanced AI capabilities.

๐ŸŽฎ Multi-Game Support

  • Strategy Games: Civilization VI, Factorio
  • Action/RPG: Slay the Spire, Hades
  • Simulation: Cities: Skylines, The Sims 4

๐Ÿ› ๏ธ Technical Enhancements

  • Reinforcement Learning: PPO/DQN for complex decisions
  • Multi-Modal AI: Visual + textual + audio processing
  • Performance: Edge computing, model quantization
  • Controls: Voice control, gesture recognition, mouse control

๐Ÿ“„ License

This project showcases professional-level software engineering with a focus on AI-driven automation, game development integration, and scalable system design.


๐ŸŽฏ Ready to Experience Autonomous Balatro Gameplay?

Start your AI-powered gaming journey today! ๐Ÿš€

Built with โค๏ธ by Javier Jimenez

GitHub LinkedIn

agents
artificial-intelligence
computer-vision
docker
game-automation
gaming
langgraph
machine-learning
python
streamlit