Overview
The base module defines the abstract interfaces for Codenames agents. All agent implementations must inherit from eitherHintGiver or Guesser and implement their abstract methods.
HintResponse
Data class representing a hint from the spymaster.The hint word (must be a single word with no spaces)
Number of words that relate to the hint (must be positive)
Methods
validate()
Validates the hint response. Returns:Tuple[bool, str]
- First element:
Trueif valid,Falseotherwise - Second element: Error message if invalid, empty string if valid
- Hint word must be a non-empty string
- Count must be a positive integer
- Hint must be a single word (no spaces)
HintGiver
Abstract base class for hint giver (spymaster) agents. The hint giver sees all word colors and must give a one-word hint plus a number indicating how many words relate to that hint.Constructor
The team this agent represents (Team.RED or Team.BLUE)
Methods
get_model_name()
Get the model name for this agent. Returns:str - Model identifier (e.g., “OpenRouterDevstral”, “GPT4oMini”)
Subclasses should override this to return their actual model name. Default implementation returns the class name.
give_hint()
Generate a hint for the team. This is an abstract method that must be implemented.List of unrevealed words belonging to this agent’s team
List of unrevealed opponent words
List of unrevealed neutral words
List of bomb words (if not revealed)
List of already revealed words
All words on the board (for reference)
HintResponse - Contains hint word and count
Implementation Notes:
- Hint word must be a single word (no spaces)
- Hint word should not be any word currently on the board
- Count indicates how many of your team’s words relate to the hint
- Avoid hints that could lead to bomb or opponent words
Guesser
Abstract base class for guesser (field operative) agents. The guesser only sees the words on the board (not colors) and must guess words based on the hint from their team’s hint giver.Constructor
The team this agent represents (Team.RED or Team.BLUE)
Methods
get_model_name()
Get the model name for this agent. Returns:str - Model identifier (e.g., “OpenRouterDevstral”, “GPT4oMini”)
Subclasses should override this to return their actual model name. Default implementation returns the class name.
make_guesses()
Make guesses based on the hint. This is an abstract method that must be implemented.The hint word given by the hint giver
Number of words the hint relates to
All words on the board
List of already revealed words
List[str] - List of words to guess (in order of preference)
Implementation Notes:
- Can return 1 to (hint_count + 1) guesses
- Standard strategy: guess up to hint_count words
- Extra guess allowed (hint_count + 1) for previous hints
- Guessing stops when wrong word is revealed
- Must only guess from unrevealed words
- Should return empty list to pass turn
process_result()
Optional feedback method called after each guess.The word that was guessed
Whether it was the team’s word
The actual color of the word (RED, BLUE, NEUTRAL, or BOMB)
- This is called after each guess
- Agents can use this to adjust their strategy
- Default implementation does nothing