Skip to content

Vivianmxmf/Jury_Deliberation_LLMAgents_Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

🔍 Jury Deliberation LLM Agents Simulator

Ever watched 12 Angry Men and wondered what really happens in that jury room? 🤔 How do strangers wrestle with facts, biases, and pressure to reach a unanimous verdict?

This project is an interactive jury deliberation simulator built using Python and Google Gemini AI. It's not just another chatbot—it's an exploration into whether Generative AI can realistically capture the messy, complex dynamics of human jury deliberation.

🎯 Goal

The primary goal is to simulate an interactive jury deliberation process where a human player interacts with AI-driven jurors. We aim to explore the capabilities of Large Language Models (LLMs) like Google Gemini in modeling nuanced human behavior, biases, and group dynamics within the specific context of a jury trial.

📊 Visualizations

Figure1

  • This diagram illustrates the courtroom simulation system flow.

Figure2

  • Human Player In the Flow

Figure3

  • Speaking Order System

✨ Features

  • Interactive Simulation: Play the role of Juror #4 in a murder trial.
  • AI-Powered Jurors: Engage with 5 AI jurors powered by Google Gemini 1.5 Flash via LangChain.
  • Ambiguous Case: Deliberate on a challenging case with conflicting evidence and reasonable doubt.
  • Two Simulation Modes:
    • Scripted Mode: Interact with jurors who have predefined, fixed personas and backstories.
    • Generated Mode: Experience unpredictable dynamics with AI jurors whose personas are dynamically generated by the LLM for each run.
  • Dynamic Deliberation: AI jurors react to each other and the player based on their personas and the conversation history.
  • Player Actions: Influence the discussion, call for votes, or even choose to exit the deliberation (under certain conditions).
  • Performance Evaluation: Receive AI-generated feedback on your participation, reasoning, and influence, along with an overall score.

⚖️ The Case Setup

You are Juror #4 in a murder trial. The key details are:

  • Defendant: Jack Miller, 18, accused of killing his classmate Leo Briggs, 18.
  • Victim: Leo Briggs, found with a single stab wound.
  • Murder Weapon: Jack's heirloom knife was found at the scene, but only the victim's fingerprints were on it.
  • Rival: Kai Sato, Jack's rival, was seen with the knife weeks prior and had a motive. Bloody shoeprints at the scene match Kai's shoe size and brand. Traces of Kai's cologne were found in the knife sheath.
  • Alibi: Jack has a digital alibi (cell tower/router logs) placing him at home, but no eyewitness confirmation.
  • Witness: A neighbor heard shouting around the estimated time of death and saw a figure matching Jack's build/jacket leaving.
  • Context: The evidence is deliberately ambiguous and packed with reasonable doubt.

🧠 Simulation Modes

You can choose how your AI jury colleagues are created at the start:

  1. Scripted Mode:

    • Uses predefined juror profiles stored in SCRIPTED_JURORS_DATA.
    • Each AI juror (Jurors 1, 2, 3, 5, 6) has a fixed, detailed persona, background, and initial leaning.
    • Ideal for controlled testing or experiencing specific predefined dynamics.
  2. Generated Mode:

    • Uses the LLM (generate_jurors() function) to create unique juror personas dynamically at the start of each simulation.
    • Provides high replayability and explores unpredictable group interactions.
    • Ideal for observing emergent behaviors.

Note: All jurors, whether scripted or generated, operate based on a shared behavioral framework (JUROR_TEMPLATE) to ensure consistent instruction format.

🛠️ How It Works / Technical Overview

💬 LLM-Powered AI Agents

  • AI Jurors are implemented as semi-autonomous agents using LangChain and Google Gemini 1.5 Flash.
  • Each juror makes decisions and formulates responses based on:
    • Their defined persona and personality traits (scripted or generated).
    • The complete deliberation history (conversation transcript).
    • Context-aware LLM prompting guiding behavior and response format.
    • Their own internal state (current vote leaning, internal thoughts generated by the LLM).

🔄 Core Gameplay Loop (run_game())

The simulation proceeds turn by turn, alternating between AI actions and player prompts:

  1. AI Turn: An AI juror is selected (based on scoring or randomness) to either respond to the previous statement or initiate a new point. Their response is generated by the LLM based on their persona and the context.
  2. Player Check: After a set number of AI turns (e.g., 5), the game checks if the player needs to be prompted.
  3. Player Turn: If prompted, the player receives hints and can choose an action:
    • Speak: Enter text to contribute to the deliberation.
    • Vote: Initiate a formal voting round.
    • Reject/Skip: Pass the turn.
    • Exit: Leave the deliberation (available after 2 voting rounds).
  4. Voting Phase (if initiated):
    • Each AI juror is prompted by the LLM to state and briefly justify their vote (Guilty/Not Guilty).
    • The player is prompted to enter their vote.
    • Votes are tallied.
  5. End Conditions: The game concludes if:
    • A unanimous verdict (all Guilty or all Not Guilty) is reached after at least one round of discussion post-first vote.
    • The player chooses to exit (after the 2nd voting round).
    • A hung jury state persists after multiple voting rounds (logic can be adjusted).

🧠 Designing Juror Behavior

  • The JUROR_TEMPLATE provides the core instructions to the LLM for how to act as a juror.
  • Each juror's specific persona and personality (from SCRIPTED_JURORS_DATA or generated) are injected into this template.
  • The LLM is prompted to generate internal thoughts (<thinking>) before generating the spoken response, allowing for more nuanced behavior.
  • Speaking and responding scores are dynamically adjusted to create a more natural turn-taking flow.

📈 Player Performance Evaluation

  • After the deliberation ends, the entire conversation transcript and the PERFORMANCE_RUBRIC are sent to the Gemini AI.
  • The AI analyzes the player's (Juror #4) participation based on the rubric.
  • The player receives:
    • Five performance insights (strengths/weaknesses).
    • An overall score out of 100.
    • (Optional) Recommendations for improvement.

⚙️ Setup & Installation

  1. Environment: Ensure you have Python installed. This project is developed in a Jupyter Notebook environment.
  2. Dependencies: Install the required Python packages. Open the notebook and run the first code cell which includes:
    pip install -qU 'langgraph==0.3.21' 'langchain-google-genai==2.1.2' 'langgraph-prebuilt==0.1.7'
    (Note: The first cell also attempts to uninstall potentially conflicting packages in certain environments like Kaggle).
  3. API Key:
    • You need a Google API key enabled for the Gemini API.
    • Store your API key securely. In the provided notebook, it uses Kaggle Secrets:
      from kaggle_secrets import UserSecretsClient
      GOOGLE_API_KEY = UserSecretsClient().get_secret("GOOGLE_API_KEY")
      os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
    • Alternatively, you can set the GOOGLE_API_KEY environment variable directly or pass it during LLM initialization if running locally.

▶️ Usage

  1. Open the capstone-jury-deliberation-simulator.ipynb notebook.
  2. Run the initial setup cells (package installation, API key configuration, LLM initialization).
  3. When the JuryGame class is initialized (usually near the end of the notebook), you will be prompted in the output to choose the AI juror type:
    Choose AI juror companions: type 'generated' or 'scripted':
    
    Type your choice (generated or scripted) and press Enter.
  4. The simulation will initialize, print the case facts and juror summaries.
  5. Follow the prompts to participate as Juror #4. Enter your statements, or use commands like VOTE, REJECT, or EXIT when prompted.
  6. The deliberation continues until an end condition is met.
  7. A final summary and performance evaluation will be printed.

🚀 Future Directions

  • Integrate visual evidence (e.g., crime scene photos) into the deliberation context.
  • Allow players to take on the role of lawyers presenting evidence to AI jurors.
  • Develop more sophisticated AI jurors with emotional intelligence, capable of forming alliances or rivalries.
  • Create a web-based user interface or an open API for broader educational and research use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published