OASIS Documentation

repository·main·Indexed 26 days ago

https://github.com/camel-ai/oasis

OASIS (camel-oasis v0.2.5) is a scalable, open-source social media simulator that uses LLM agents to mimic up to one million users on platforms like Twitter and Reddit. It is designed for studying social phenomena such as information spread, polarization, and herd behavior. The library provides tools for creating agent graphs, defining social agent personas via custom profiles, and executing simulations using ManualAction or LLMAction.

Tokens
34.3K
Snippets
75
Records
121
Agent score
89%

What's inside OASIS

  1. Overview of OASIS

    main

    OASIS (Open Agent Social Interaction Simulations) is an open-source social media simulator designed to mimic the behavior of up to one million users on platforms like Twitter and Reddit. It combines Large Language Models (LLMs) with rule-based agents to study social phenomena such as information spread, group polarization, and herd behavior.

    Key capabilities include:

    • Scalability: Supports up to one million agents.
    • Dynamic Environments: Adapts to real-time changes in social networks and content.
    • Diverse Action Spaces: Agents can perform 23 different actions (e.g., following, commenting, reposting, quoting).
    • Recommendation Systems: Includes interest-based and hot-score-based algorithms to simulate content discovery.
  2. Understand the OASIS System Architecture

    main

    OASIS (Open Agent Social Interaction Simulations) is a framework for simulating social media environments using LLM-powered agents. The architecture consists of five core components:

    1. Platform: The central infrastructure (e.g., Twitter-like or Reddit-like) that manages user accounts, content, social relationships, and engagement metrics.
    2. Agents: LLM-powered users with unique profiles and decision-making processes.
    3. Actions: Operations agents can perform, such as creating posts, commenting, liking, and following.
    4. Recommendation System: Algorithms that determine content distribution in agent feeds.
    5. Simulation Engine: The orchestration layer that manages time progression, agent activation, and simulation flow.
  3. Understand default User Info Templates

    main

    If no user_info_template is provided, OASIS uses default templates based on the social platform style:

    • Twitter Style: Focuses on a name and a user_profile within profile['other_info']. The system message includes an OBJECTIVE, SELF-DESCRIPTION, and RESPONSE METHOD (tool calling).
    • Reddit Style: Includes more granular demographic details from profile['other_info'] such as gender, age, mbti, and country. The system message follows a similar structure with OBJECTIVE, SELF-DESCRIPTION, and RESPONSE METHOD.
  4. Run a Twitter Simulation with OASIS

    main

    To run a Twitter simulation, you need to set up a model manager (using a round-robin strategy for multiple models), define available actions using ActionType.get_default_twitter_actions(), and generate an agent graph using generate_twitter_agent_graph. You must also specify a database path via the OASIS_DB_PATH environment variable or the database_path parameter in oasis.make().

    Steps:

    1. Deploy a vLLM server.
    2. Create models using ModelFactory.
    3. Initialize a ModelManager with a scheduling_strategy (e.g., 'round_robin').
    4. Generate the agent graph with generate_twitter_agent_graph.
    5. Create the environment with oasis.make() using oasis.DefaultPlatformType.TWITTER.
    6. Use env.reset() to start and env.step(actions) to progress the simulation.
    import asyncio
    import os
    from camel.models import ModelFactory, ModelManager
    from camel.types import ModelPlatformType
    import oasis
    from oasis import (ActionType, LLMAction, ManualAction,
                       generate_twitter_agent_graph)
    
    async def main():
        # 1. Setup Models
        vllm_model_1 = ModelFactory.create(
            model_platform=ModelPlatformType.VLLM,
            model_type="qwen-2",
            url="http://your-vllm-url:8080/v1",
        )
        vllm_model_2 = ModelFactory.create(
            model_platform=ModelPlatformType.VLLM,
            model_type="qwen-2",
            url="http://your-vllm-url:8080/v1",
        )
    
        shared_model_manager = ModelManager(
            models=[vllm_model_1, vllm_model_2],
            scheduling_strategy='round_robin',
        )
    
        # 2. Define Actions and Graph
        available_actions = ActionType.get_default_twitter_actions()
        agent_graph = await generate_twitter_agent_graph(
            profile_path="data/twitter_dataset/your_dataset.csv",
            model=shared_model_manager,
            available_actions=available_actions,
        )
    
        # 3. Setup Environment
        db_path = "./data/twitter_simulation.db"
        os.environ["OASIS_DB_PATH"] = os.path.abspath(db_path)
        
        env = oasis.make(
            agent_graph=agent_graph,
            platform=oasis.DefaultPlatformType.TWITTER,
            database_path=db_path,
        )
    
        # 4. Run Simulation
        await env.reset()
    
        # Example: Manual action for one agent
        actions_1 = {
            env.agent_graph.get_agent(0): ManualAction(
                action_type=ActionType.CREATE_POST,
                action_args={"content": "Earth is flat."}
            )
        }
        await env.step(actions_1)
    
        # Example: LLM actions for specific agents
        actions_2 = {
            agent: LLMAction()
            for _, agent in env.agent_graph.get_agents([1, 3, 5, 7, 9])
        }
        await env.step(actions_2)
    
        await env.close()
    
    if __name__ == "__main__":
        asyncio.run(main())
  5. Run a quick start social media simulation

    main

    To run a simulation, you need to:

    1. Prepare an agent profile JSON file (e.g., user_data_36.json).
    2. Define the LLM model using ModelFactory.
    3. Define available_actions using ActionType.
    4. Generate an agent graph using generate_reddit_agent_graph.
    5. Create the environment using oasis.make.
    6. Execute steps using env.step() with either ManualAction or LLMAction.
    import asyncio
    import os
    
    from camel.models import ModelFactory
    from camel.types import ModelPlatformType, ModelType
    
    import oasis
    from oasis import (ActionType, LLMAction, ManualAction,
                       generate_reddit_agent_graph)
    
    
    async def main():
        # Define the model for the agents
        openai_model = ModelFactory.create(
            model_platform=ModelPlatformType.OPENAI,
            model_type=ModelType.GPT_4O_MINI,
        )
    
        # Define the available actions for the agents
        available_actions = [
            ActionType.LIKE_POST,
            ActionType.DISLIKE_POST,
            ActionType.CREATE_POST,
            ActionType.CREATE_COMMENT,
            ActionType.LIKE_COMMENT,
            ActionType.DISLIKE_COMMENT,
            ActionType.SEARCH_POSTS,
            ActionType.SEARCH_USER,
            ActionType.TREND,
            ActionType.REFRESH,
            ActionType.DO_NOTHING,
            ActionType.FOLLOW,
            ActionType.MUTE,
        ]
    
        agent_graph = await generate_reddit_agent_graph(
            profile_path="./data/reddit/user_data_36.json",
            model=openai_model,
            available_actions=available_actions,
        )
    
        # Define the path to the database
        db_path = "./data/reddit_simulation.db"
    
        # Delete the old database
        if os.path.exists(db_path):
            os.remove(db_path)
    
        # Make the environment
        env = oasis.make(
            agent_graph=agent_graph,
            platform=oasis.DefaultPlatformType.REDDIT,
            database_path=db_path,
        )
    
        # Run the environment
        await env.reset()
    
        actions_1 = {}
        actions_1[env.agent_graph.get_agent(0)] = [
            ManualAction(action_type=ActionType.CREATE_POST,
                         action_args={"content": "Hello, world!"}),
            ManualAction(action_type=ActionType.CREATE_COMMENT,
                         action_args={
                             "post_id": "1",
                             "content": "Welcome to the OASIS World!"
                         })
        ]
        actions_1[env.agent_graph.get_agent(1)] = ManualAction(
            action_type=ActionType.CREATE_COMMENT,
            action_args={
                "post_id": "1",
                "content": "I like the OASIS world."
            })
        await env.step(actions_1)
    
        actions_2 = {
            agent: LLMAction()
            for _, agent in env.agent_graph.get_agents()
        }
    
        # Perform the actions
        await env.step(actions_2)
    
        # Close the environment
        await env.close()
    
    
    if __name__ == "__main__":
        asyncio.run(main())
  6. Configure and Initialize an OASIS Simulation

    main

    To start a simulation, you must complete the following initialization steps:

    1. Create the Platform: Select specific settings (e.g., Twitter-like or Reddit-like).
    2. Load Agent Profiles: Load profiles from files or variables.
    3. Configure LLM Models: Set up models for agent decision-making.
    4. Define Systems: Define available actions, recommendation systems, and toolkits (for external information retrieval).
  7. Report posts in OASIS simulation

    main

    To enable post reporting in your simulation, you must include ActionType.REPORT_POST in the available_actions list when calling generate_twitter_agent_graph.

    Once enabled, you can trigger a report using ManualAction with the following arguments:

    • post_id: The ID of the post being reported.
    • report_reason: A string describing why the post is being reported.

    Reports can be submitted individually or by multiple agents within the same env.step() call, and they can be mixed with other social media actions like CREATE_POST or LIKE_POST.

    # 1. Enable the action in the graph creation
    available_actions = [
        ActionType.CREATE_POST,
        ActionType.LIKE_POST,
        ActionType.REPORT_POST,  # Required for reporting functionality
        ActionType.REPOST,
        ActionType.FOLLOW,
        ActionType.DO_NOTHING,
    ]
    
    agent_graph = await generate_twitter_agent_graph(
        profile_path="path/to/dataset.csv",
        model=openai_model,
        available_actions=available_actions,
    )
    
    # 2. Execute a report action
    report_action = ManualAction(
        action_type=ActionType.REPORT_POST,
        action_args={
            "post_id": 1,
            "report_reason": "This is inappropriate content"
        }
    )
    
    actions = {env.agent_graph.get_agent(0): report_action}
    await env.step(actions)
  8. Integrate LLMs with OASIS via CAMEL

    main

    OASIS uses the CAMEL framework to power agent decision-making. Supported integrations include:

    • OpenAI Models: Support for GPT-4, GPT-3.5.
    • Local Models: Integration with open-source models via VLLM.
    • Scaling Features: Support for load balancing across multiple model instances and customizable prompting for agent reasoning.
  9. Initialize the OASIS simulation environment

    main

    Use the oasis.make function to create a simulation environment. You must provide an agent_graph and specify a platform. You can also define a database_path for SQLite storage and a semaphore to control concurrency.

    import oasis
    from oasis import DefaultPlatformType
    
    # Make the environment
    env = oasis.make(
        agent_graph=agent_graph,
        platform=oasis.DefaultPlatformType.REDDIT,
        database_path="simulation.db",
    )
  10. Configure Mintlify Global Settings via docs.json

    main
    Every Mintlify site requires a docs.json file for core configuration. This file controls the project name, navigation structure, branding (logo, favicon, colors), and various UI components like the top bar, footer, and dark mode toggle.