File size: 4,814 Bytes
1274fa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444a11a
 
 
 
 
 
 
 
 
 
 
 
1274fa3
 
444a11a
1274fa3
 
 
 
 
 
 
 
444a11a
1274fa3
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import random
from poke_env import AccountConfiguration, ServerConfiguration
from agents import OpenAIAgent, GeminiAgent, MistralAgent, MaxDamagePlayer

# Custom server configuration
CUSTOM_SERVER_URL = "wss://jofthomas.com/showdown/websocket"
CUSTOM_ACTION_URL = 'https://play.pokemonshowdown.com/action.php?'
custom_config = ServerConfiguration(CUSTOM_SERVER_URL, CUSTOM_ACTION_URL)

# Avatar mappings for different agent types
AGENT_AVATARS = {
    'openai': ['giovanni', 'lusamine', 'guzma'],
    'mistral': ['alder', 'lance', 'cynthia'],
    'gemini': ['steven', 'diantha', 'leon'],
    'maxdamage': ['red'],
    'random': ['youngster']
}

def create_agent(agent_type: str, api_key: str = None, model: str = None, username_suffix: str = None):
    """
    Factory function to create different types of Pokemon agents.
    
    Args:
        agent_type (str): Type of agent ('openai', 'gemini', 'mistral', 'maxdamage', 'random')
        api_key (str, optional): API key for AI agents
        model (str, optional): Specific model to use
        username_suffix (str, optional): Suffix for username uniqueness
    
    Returns:
        Player: A Pokemon battle agent
    """
    if not username_suffix:
        username_suffix = str(random.randint(1000, 9999))
    
    agent_type = agent_type.lower()
    
    if agent_type == 'openai':
        if not api_key:
            raise ValueError("API key required for OpenAI agent")
        
        model = model or "gpt-4o"
        username = f"OpenAI-{username_suffix}"
        avatar = random.choice(AGENT_AVATARS['openai'])
        
        return OpenAIAgent(
            account_configuration=AccountConfiguration(username, None),
            server_configuration=custom_config,
            api_key=api_key,
            model=model,
            avatar=avatar,
            max_concurrent_battles=1,
            battle_delay=0.1,
            save_replays="battle_replays",
        )
    
    elif agent_type == 'gemini':
        if not api_key:
            raise ValueError("API key required for Gemini agent")
        
        model = model or "gemini-1.5-flash"
        username = f"Gemini-{username_suffix}"
        avatar = random.choice(AGENT_AVATARS['gemini'])
        
        return GeminiAgent(
            account_configuration=AccountConfiguration(username, None),
            server_configuration=custom_config,
            api_key=api_key,
            model=model,
            avatar=avatar,
            max_concurrent_battles=1,
            battle_delay=0.1,
            save_replays="battle_replays",
        )
    
    elif agent_type == 'mistral':
        if not api_key:
            raise ValueError("API key required for Mistral agent")
        
        model = model or "mistral-large-latest"
        username = f"Mistral-{username_suffix}"
        avatar = random.choice(AGENT_AVATARS['mistral'])
        
        return MistralAgent(
            account_configuration=AccountConfiguration(username, None),
            server_configuration=custom_config,
            api_key=api_key,
            model=model,
            avatar=avatar,
            max_concurrent_battles=1,
            battle_delay=0.1,
            save_replays="battle_replays",
        )
    
    elif agent_type == 'maxdamage':
        username = f"MaxDamage-{username_suffix}"
        avatar = random.choice(AGENT_AVATARS['maxdamage'])
        
        return MaxDamagePlayer(
            account_configuration=AccountConfiguration(username, None),
            server_configuration=custom_config,
            max_concurrent_battles=1,
            save_replays="battle_replays",
            avatar=avatar,
        )
    
    # Random agents removed to prevent automatic random move selection
    # elif agent_type == 'random':
    #     username = f"Random-{username_suffix}"
    #     avatar = random.choice(AGENT_AVATARS['random'])
    #     
    #     return RandomPlayer(
    #         account_configuration=AccountConfiguration(username, None),
    #         server_configuration=custom_config,
    #         max_concurrent_battles=1,
    #         save_replays="battle_replays",
    #         avatar=avatar,
    #     )
    
    else:
        raise ValueError(f"Unknown agent type: {agent_type}. Supported types: openai, gemini, mistral, maxdamage")

def get_supported_agent_types():
    """
    Returns a list of supported agent types.
    
    Returns:
        list: List of supported agent type strings
    """
    return ['openai', 'gemini', 'mistral', 'maxdamage']

def get_default_models():
    """
    Returns default models for each AI agent type.
    
    Returns:
        dict: Mapping of agent types to default models
    """
    return {
        'openai': 'gpt-4o',
        'gemini': 'gemini-1.5-flash',
        'mistral': 'mistral-large-latest'
    }