InstaPolitics

image

Inspiration

InstaPolitics was inspired by the growing role of social media in modern political campaigns. It was built with the goal of providing students, especially business, education, and political science majors, with a tool to study how politicians can influence voters through social media. The simulation allows users to explore how political figures use digital platforms to craft their messages, sway public opinion, and shape elections.

What it does

InstaPolitics is a full-stack web app that simulates the dynamics of political campaigns and voter influence. Users can define personalities for both political candidates (politician agents) and voters (citizen agents), creating a custom scenario to simulate. Politician agents post content on a custom-built social media platform, while citizen agents interact with these posts, get influenced, and ultimately decide who to vote for.

The simulation offers a real-time environment where users can see how political figures' strategies affect public opinion, making it a great educational tool for understanding the impact of social media in elections.

How I built it

Component Tech Used Purpose
Frontend React, MaterialUI, Socket.IO Responsive UI, real-time updates
Backend Flask, Python State management, API handling
Agent Framework Customer Framework over Langchain Decision-making and content generation for agents
Search ChromaDB, BM25 Vector search and ranking for relevance
LLM Support Claude, OpenAI, Gemini, Ollama, Groq Generating realistic political content
Real-Time Communication Socket.IO Live updates and interactions
Data Storage ChromaDB Storing embeddings for agent memory and search
Ranking BM25 Ranking social media posts based on influence
  • Frontend: The user interface is built with React, providing an interactive, dynamic environment for users to create political agents, define scenarios, and observe the simulation in real-time, thanks to Web Sockets.
  • Backend: The backend is developed using Python and Flask, which exposes APIs to manage the agents, scenarios, and the simulation state.
  • Agent Simulation Framework: A custom agentic framework built on top of Langchain was developed to simulate political figures (politician agents) and citizens (citizen agents). This includes decision-making based on various factors, such as personalities and interactions with content.
  • Chromadb: I integrated Chromadb for vector storage, which supports search and similarity matching. This enables politician and citizen agents to find relevant posts in the social media environment, based on their preferences and interests.
  • BM25 Ranking: The BM25 ranking system was implemented for information retrieval, helping to determine the relevance of posts for the citizen agents, ensuring that the most influential posts are highlighted.
  • Sockets: Real-time data sharing is handled via sockets, which ensures that interactions between agents and the simulation update immediately on the frontend.
  • Multi-LLM Support: The simulation supports multiple large language models (LLMs), including Claude, OpenAI, Gemini, models from Ollama and Groq, to generate diverse political content and interactions, enriching the political discourse.

Challenges I ran into

  • Custom Agentic Framework: I was very excited to write my own agentic framework on top of Langchain, to support this idea. This was my first time coding a system where information retrieval played a major part, so I learned how to apply things from my coursework into an actual project that would be useful to students.
  • Balancing Agent Personalities: Creating realistic, diverse personalities for both political figures and citizens was challenging, as we had to ensure that agents' responses to social media posts aligned with their defined traits and decision-making processes.
  • Real-Time Simulation: Ensuring that the simulation worked seamlessly in real-time, especially with many agents interacting simultaneously, required careful optimization, particularly around backend performance and socket communication.
  • Data Retrieval and Ranking: Tuning the BM25 ranking system to accurately rank the relevancy of posts based on citizen agents' preferences was difficult. It required several iterations to ensure the system delivered useful and engaging content.

Accomplishments that I'm proud of

  • Dynamic, Agent-Based Simulation: I successfully created a simulation where users can define agents' personalities and watch political influence unfold in real time. The dynamic interactions between political posts and citizen behavior provide an engaging experience.
  • Real-Time Updates: Thanks to socket communication, the simulation updates in real-time, showing how posts evolve and how citizen agents react and vote as the campaign progresses.
  • Custom Social Media Platform: The custom-built social media platform allows citizen agents to read and search posts and make informed voting decisions based on what they see. This adds a level of immersion and realism to the simulation.

What I learned

  • Agent-Based Simulation Design: Designing agents with nuanced personalities and behaviors took careful planning. Ensuring that agents behave realistically in response to content was key to making the simulation feel authentic.
  • Real-Time Data Management: Handling real-time interactions between the frontend and backend through sockets taught me a bit about data synchronization and how to optimize for large-scale simulations, given that I'm not much of a web developer.
  • Effective Use of LLMs: Working with multiple LLMs and integrating them into a coherent system required a deep understanding of each model's capabilities. A Llama 3.1 70b model always does better than a Llama 3.1 8b model in terms of realism in text generation.
  • Optimizing Search and Ranking: Implementing a solid ranking system for content retrieval was crucial for making the simulation's posts relevant and impactful. I learned a lot about search algorithms like BM25 and how they can enhance a simulation's realism.

What's next for InstaPolitics

  • Enhancing Agent Personalities: I plan to add more depth to agent personalities, including complex emotional and behavioral traits, making them react to political content in more diverse and nuanced ways.
  • Deeper Analytics: I wish to integrate advanced analytics to allow users to track how different strategies and types of content impact voting decisions over time.
  • Multiplayer Features: Future versions will allow multiple users to run campaigns simultaneously, letting them compete for influence and see how their posts compare in swaying public opinion.
  • AI-Generated Content: Incorporating more advanced AI-driven content generation to provide richer, more complex posts for politician agents.
  • Cross-Platform Deployment: I plan to expand InstaPolitics to other platforms, such as mobile. I might have to learn Flutter for that, and I'm excited about learning new things!

Built With

Share this project:

Updates