Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
275 commits
Select commit Hold shift + click to select a range
c2bff4c
delete obselete observation prep
hannw Jul 15, 2025
02d90ba
temp commit test_engine.py
hannw Jul 15, 2025
dabde36
day of actions in event log rendered correctly now
hannw Jul 15, 2025
9617951
separate day and night event logs into two shades in werewolf.js
hannw Jul 15, 2025
426c53c
Event log rendering order completed correctly in werewolf.js
hannw Jul 16, 2025
2d86ca9
add moderator announcement to event log in werewolf.js
hannw Jul 16, 2025
5477cb5
UI related fixes
hannw Jul 17, 2025
00aa200
add llm harness for werewolf
hannw Jul 21, 2025
aef05e7
fix the bug that reasoning and voting details were revealed to all pl…
hannw Jul 21, 2025
35e6ab9
moderator announce roles and their abilities
hannw Jul 22, 2025
8d0d1bc
support better end game logging
hannw Jul 22, 2025
b320b8e
fix supported llm model names
hannw Jul 23, 2025
f1d1856
refactor player schema in config
hannw Jul 23, 2025
58ab350
add try except in llm werewolf harness
hannw Jul 24, 2025
e97fea8
add display name to agent schema
hannw Jul 24, 2025
e53a7c0
add more supported models to llm harness
hannw Jul 24, 2025
7840fa6
refactor llm harness to have better instruction template to delineate…
hannw Jul 27, 2025
f3cd5fc
pass agent_config to llm harness
hannw Jul 27, 2025
a0c0050
fixed infinite voting loop problem and elected not eliminated problems
hannw Jul 27, 2025
8df3c4a
resolve infinite voting loop bug
hannw Jul 27, 2025
29e6cd8
add retry logic
hannw Jul 28, 2025
c6a334f
minor fixes
hannw Jul 28, 2025
8cf1fb8
add event truncation to LLMWerewolfAgent
hannw Jul 29, 2025
3a8a05f
add pydantic to requirements
hannw Jul 29, 2025
fbb8bae
fix prompt template json fences and wording
hannw Aug 1, 2025
464aa5a
record timestamp during history entry creation
hannw Aug 1, 2025
d45646a
change default voting scheme to sequential voting
hannw Aug 1, 2025
d8b1eb7
simplify visuals in werewolf.js
hannw Aug 1, 2025
413201a
add player capsules in werewolf rendering
hannw Aug 1, 2025
51880b2
fix night action reasoning and actor id rendering
hannw Aug 1, 2025
ed49f6e
improve line spacing of moderator and game over messsage
hannw Aug 2, 2025
1eadc42
fix issues in SequentialVoting protocol
hannw Aug 2, 2025
58fae65
refactor action queue to use action specific queue
hannw Aug 2, 2025
7f7d4eb
adjust phase separator style
hannw Aug 2, 2025
c812502
add perceived threat level to backend and frontend
hannw Aug 2, 2025
53e9305
improve json schema export for pydantic basemodel
hannw Aug 4, 2025
32ea70f
change the threat level indicator from aura to solid circle
hannw Aug 4, 2025
f8f93fa
refactor __run_interpreter to remove duplicated code
hannw Aug 4, 2025
cb6bc89
add comments to address debug mode branching
hannw Aug 4, 2025
6bacbeb
Refactoring interpreter() for readability and adding some high level …
chuckcoder Aug 6, 2025
0c92aca
minor new line improvement
hannw Aug 4, 2025
71b7bc4
add checks to ensure all player ids are unique
hannw Aug 4, 2025
26b7049
refactor phase transition to be more robust
hannw Aug 4, 2025
74d23ed
make sure allow doctor self save is configurable
hannw Aug 5, 2025
283bc74
Add actor id capsule to event log updates
hannw Aug 5, 2025
b5df7a3
fix sequential voting bug
hannw Aug 5, 2025
d4eda12
add voter capsule to day votes
hannw Aug 5, 2025
8b59f89
add timeout display in werewolf.js
hannw Aug 6, 2025
25093b8
adding additional llm models with quota for testing
chuckcoder Aug 11, 2025
0a98644
adding snippet to track token usage
chuckcoder Aug 11, 2025
f619daf
fixing bug where single element instead of list is being returned
chuckcoder Aug 11, 2025
150472d
Adding additonal packages that seem to be required from base image
chuckcoder Aug 11, 2025
94dec4c
fixing issue with undefined 2d array for moderator and player roles n…
chuckcoder Aug 12, 2025
bf48565
making some options required
chuckcoder Aug 12, 2025
5cb7197
Adding README.md to werwolf with bare bones example
chuckcoder Aug 12, 2025
61c0370
adding branch to werewolf_harness
chuckcoder Aug 12, 2025
910e8db
adding branch to werewolf_harness
chuckcoder Aug 12, 2025
6811836
adding a flat() call as moderator results can be 2d, kind of a hack f…
chuckcoder Aug 12, 2025
525ba8e
adding a flat() call as moderator results can be 2d, kind of a hack f…
chuckcoder Aug 12, 2025
374805f
add werewolf runner scripts for simple testing and experimentation
hannw Aug 12, 2025
3144123
remove print statements and use logger instead
hannw Aug 13, 2025
4923f98
revert the voting index change
hannw Aug 13, 2025
10fc7b2
add TTS to werewolf game replay
hannw Aug 6, 2025
a1d0382
Add continual audio to front end
hannw Aug 6, 2025
a7466ec
Add voices and association with model
hannw Aug 6, 2025
81c03d6
fix werewolf.js black screen issue reporting "Waiting for game data..."
hannw Aug 6, 2025
3533a93
making the audio speed bar persistent across playbacks
hannw Aug 6, 2025
f5929eb
minor fixes for dump_audio.py
hannw Aug 6, 2025
501af44
add announcements to audio event
hannw Aug 7, 2025
0c47ca4
add action announcements to audio event
hannw Aug 7, 2025
33ca64a
add 3d background
hannw Aug 7, 2025
8a99713
add 3d background rendering and portable replay folder
hannw Aug 7, 2025
3c3b7f1
refactor dump_audio.py to be more modularized
hannw Aug 7, 2025
25b3c0d
added wolf and windmill
hannw Aug 8, 2025
897a40f
loaded 8 stickmans and idle animation
hannw Aug 10, 2025
ebf6247
adjusted stickman directions and numbers
hannw Aug 10, 2025
51bd942
add nameplate on top of the stickman
hannw Aug 10, 2025
5694a8b
add local image into asset for serving thumbnail
hannw Aug 10, 2025
066aa4d
nameplate text aligned center
hannw Aug 11, 2025
b8a40c0
fix z placement of nameplate
hannw Aug 11, 2025
67decf6
add moon to the scene
hannw Aug 11, 2025
dd0d495
add file dump
hannw Aug 11, 2025
f4ef22d
render audio script
hannw Aug 11, 2025
77968f5
refactor dump_audio.py to enable debug path to play simple audio
hannw Aug 11, 2025
08f1a10
refactor werewolf.js to have hover effect and select event to playback
hannw Aug 11, 2025
372cd02
change text color during audio playback event
hannw Aug 11, 2025
d93dc80
refactor base.py instructions
hannw Aug 11, 2025
902b2fb
fix finding audio key issues
hannw Aug 12, 2025
cacab28
add gpt-oss model
hannw Aug 12, 2025
da5cb2c
add new audio generation instructions and examples
hannw Aug 12, 2025
76d298b
Improve on the audio prompts
hannw Aug 12, 2025
9e8d901
add 3d werewolf script
hannw Aug 12, 2025
e176413
add assets
hannw Aug 12, 2025
8302c67
resolve moderator obs bug
hannw Aug 13, 2025
e73bf26
use logger for self_play.py
hannw Aug 13, 2025
ba17ac8
resolve sequential voting protocol bug
hannw Aug 13, 2025
1f7de7e
refactor dump_audio.py
hannw Aug 13, 2025
40f3a31
add instructions for audio generation in README.md
hannw Aug 13, 2025
c7dae78
add instructions for audio generation in README.md
hannw Aug 13, 2025
25c0843
add flask and gym back
hannw Aug 13, 2025
a97ca8d
remove redundant files
hannw Aug 14, 2025
b5bced0
clean up tests
hannw Aug 14, 2025
e3f8ec0
add agent action error code handling, default to game end if there is…
hannw Aug 14, 2025
4ade683
fix out and err context
hannw Aug 14, 2025
97c740e
fix input args of interpreter loop
hannw Aug 14, 2025
d5ba30b
improve exemplar formatting
hannw Aug 14, 2025
866e984
Change the debug mode for tests to False for testing prod paths
hannw Aug 14, 2025
7b38284
add game rules
hannw Aug 14, 2025
16c4979
add violent language filter to discussion protocols
hannw Aug 15, 2025
330c2db
enforce violent language filter in action initializer level
hannw Aug 15, 2025
f56a2dd
add optional reveal night elimination or day exile role
hannw Aug 15, 2025
9cf377a
Fix bid driven discussion state machine and add turn by turn bidding …
hannw Aug 1, 2025
5127eb4
refactor action queue to a single class and refine bidding driven dis…
hannw Aug 15, 2025
700c4db
add bid data entry and bid result data entry
hannw Aug 16, 2025
4c66922
use deterministic tie breaking mechanisms for UrgencyBidProtocol
hannw Aug 16, 2025
b25e89b
add bid_result_public to properties
hannw Aug 16, 2025
79e55ba
add test_turn_by_turn_bidding_discussion
hannw Aug 16, 2025
6beaf79
3d view changes
twmmason Aug 12, 2025
229423d
Improved 3d layout
twmmason Aug 12, 2025
5b383c9
Player list css improvements
twmmason Aug 12, 2025
25ac213
Fix for emojis
twmmason Aug 12, 2025
dc3662d
3d scene effects
twmmason Aug 12, 2025
7711de6
Player logo fading
twmmason Aug 12, 2025
aa101cc
Adjusted panel margins
twmmason Aug 12, 2025
b88642f
fix for flipped players
twmmason Aug 12, 2025
f6eb9b7
Day/night transitions
twmmason Aug 12, 2025
0f3f160
Nameplate adjustments
twmmason Aug 12, 2025
db496f6
Status panel
twmmason Aug 12, 2025
bb4a6d6
fix animation so backward replay restore past state
hannw Aug 16, 2025
b037a0d
fix event log so backward replay restore past log state
hannw Aug 16, 2025
fc1905c
add moderator announcement back to event log
hannw Aug 17, 2025
37c73bc
fix play bar event loop step alignment
hannw Aug 17, 2025
1c270ed
disable key control of scene
hannw Aug 18, 2025
3987619
add block experiment code for role balanced sampling
hannw Aug 18, 2025
f42bef5
add spotlight logic
hannw Aug 18, 2025
9210b54
add more supported models
hannw Aug 18, 2025
dd2d8ba
report cost of inference for LLMs
hannw Aug 19, 2025
36b75fb
enable configuring LLMWerewolfAgent and add text mode prompts
hannw Aug 19, 2025
4388b62
add script to measure cost
hannw Aug 19, 2025
f6d3117
add bid action to llm harness
hannw Aug 19, 2025
a5fc8f2
enable harness bid reasoning config options and add cost tracker
hannw Aug 20, 2025
bcb1a26
refactor measure_cost.py to use new cost trackers
hannw Aug 20, 2025
d8ec634
fix day addition bug in engine.py
hannw Aug 20, 2025
00270da
fix token trajectory plot
hannw Aug 20, 2025
3bf6326
add agent reset mechanism to solve global agent state carry over acro…
hannw Aug 20, 2025
dddddc2
Load usage directly from litellm for cost analysis
hannw Aug 20, 2025
b2740ae
fix trajectory loading in measure_cost.py
hannw Aug 20, 2025
ec6fe31
add run.py script and refactor run_block.py to use it
hannw Aug 20, 2025
b021c61
rearrange config files
hannw Aug 20, 2025
db2b2c3
add toggle for reasoning traces
hannw Aug 21, 2025
67c7eb4
Fix pulse and spotlight animation misalignment with actor
hannw Aug 22, 2025
45f1989
add targeting arcs
hannw Aug 22, 2025
49cb4f6
Improved vote target visualizer
hannw Aug 22, 2025
48b939b
Change color of arcs for different actions
hannw Aug 22, 2025
84089cc
Fixed day/night timing and werewolf turns red during night time
hannw Aug 22, 2025
9c943e4
fix day voting arcs
hannw Aug 22, 2025
b5cfcf7
add phase divider logic to cleanly segment events
hannw Aug 23, 2025
0252637
separate allEvents and visibleEvents to remove undisplayed events fro…
hannw Aug 24, 2025
59d85db
fix night werewolf red light glitches
hannw Aug 24, 2025
2116ef9
Fix night eliminated werewolf resurrection issues
hannw Aug 24, 2025
e75fb35
fix phase indicator on left panel
hannw Aug 25, 2025
e355d22
remove redundant code, change event log phase indicator text
hannw Aug 25, 2025
cf69712
Resolve event log duplication bug
hannw Aug 25, 2025
aba837d
Resolve game end phase indicator to no day count
hannw Aug 25, 2025
3ef5ee6
change thumbnail size on left panel, clean up console logs
hannw Aug 25, 2025
9c5a3db
Add display_name rendering and adjust thumbnail background to be white
hannw Aug 25, 2025
c400033
Add optional display name to 3d player nameplate
hannw Aug 25, 2025
df0f328
refactor run_block.py to use run.py as subprocess and parallelize the…
hannw Aug 25, 2025
73bfd40
add option to append timestamp to output dir
hannw Aug 25, 2025
5f9e1a3
add option to shuffle player ids
hannw Aug 25, 2025
e9ae14d
revise run_block.py instructions
hannw Aug 25, 2025
37f836b
add LogExecutionTime context manager to keep track of task time
hannw Aug 25, 2025
eb8d11b
add instructions to configure agents
hannw Aug 25, 2025
c0e9a44
fix generate unique role permutations
hannw Aug 26, 2025
c6ddb6a
Add register agent method
hannw Aug 27, 2025
801f295
add litellm_models.yaml config to register litellm model for cost pro…
hannw Aug 27, 2025
e976597
remove capital P from player logs
hannw Aug 27, 2025
655008f
Fix reveal day and night elimination bug
hannw Aug 27, 2025
6bc289b
Fix reveal text for no reveal situation in visualizer
hannw Aug 27, 2025
cf5300a
Update player capsule to show display name (placeholder for model name)
hannw Aug 27, 2025
a81ebbc
Handle capsule parsing better
hannw Aug 27, 2025
178eb2a
add doctor and seer night glow
hannw Aug 28, 2025
346de15
add options to choose random first actor for roundrobiin discussion a…
hannw Aug 28, 2025
feb44c5
fix sequential voting protocol voter bug and history visibility bug
hannw Aug 28, 2025
9203beb
Minor format improvement to llm harness
hannw Aug 28, 2025
72243c1
Minor format improvement
hannw Aug 28, 2025
4b0bb16
Fix capsule regex for parsing "... <player_name>."
hannw Aug 29, 2025
4623fed
correct threat level text
hannw Aug 29, 2025
36ac40a
use orb as self assessed threat level detector
hannw Aug 29, 2025
26cf831
add sound wave animation to speaker
hannw Aug 29, 2025
51e96b0
change random message.
hannw Aug 29, 2025
573496b
fix role_msg
hannw Aug 29, 2025
5dc4899
add censor words, refactor censor pattern compile to global
hannw Aug 29, 2025
0657867
add llm query logs, fix no cost logging
hannw Aug 29, 2025
5a56b39
add flag to shuffle roles
hannw Aug 29, 2025
3133722
refactor llm harness for better error handling and logging
hannw Aug 29, 2025
b7989ef
fix tally exposing player role bug
hannw Aug 29, 2025
a5e4428
add global toggle for turning reasoning on/off
hannw Aug 30, 2025
d80a0e3
add reveal rule messages in moderator announcement
hannw Aug 30, 2025
256f3e8
refactor action schema for player
hannw Aug 30, 2025
a735a15
improve role specification formatting
hannw Aug 30, 2025
5fbc99a
fix schema_for_player return None bug
hannw Aug 30, 2025
291b439
add action to ActionDataMixin
hannw Aug 30, 2025
8a2e6f8
add player first person view on click of player card at left panel
hannw Aug 30, 2025
7c1a100
add reset button for 3d camera position
hannw Aug 30, 2025
49d9cb8
fix query_parse bug, remove observation from action obj
hannw Aug 30, 2025
df53ce9
remove observations from actions.py which is causing recursive memory…
hannw Aug 30, 2025
c535a34
optimize imports
hannw Aug 30, 2025
85171fc
[critical] fix public view bug resulted from Mixin method resolution …
hannw Aug 30, 2025
226d68b
add missing error prompt
hannw Aug 30, 2025
8d3c682
Refactor history entry access patterns
hannw Aug 31, 2025
7b58189
Add visible history entry type control
hannw Aug 31, 2025
4ae7a4a
fix raw observation key bug
hannw Aug 31, 2025
a444989
make actor data observable to the actor by specifying source
hannw Aug 31, 2025
86d39f5
cache schema_for_player for better latency
hannw Aug 31, 2025
1b0433a
refactor raw_observation consumer to use getter and setter
hannw Aug 31, 2025
901c2e7
refactor llm harness to record self action and reasoning
hannw Aug 31, 2025
13d9c35
Introduce StrEnum to be better json serializable and clearer types
hannw Aug 31, 2025
9da18fe
add configs for llm experiment
hannw Sep 1, 2025
9acab3e
add packages to requirements.txt
hannw Sep 1, 2025
b049df1
add pairwise zero sum game tournament
hannw Sep 1, 2025
4307ae7
add task shuffling to reduce LLM api load
hannw Sep 1, 2025
531b28f
reuse run_single_game_cli code
hannw Sep 1, 2025
fe0a71d
add display name to the right panel player name tag
hannw Sep 4, 2025
e805b15
revise self_play.py to run n games from a given config
hannw Sep 5, 2025
cb3b8f8
add "random" and "no exile" tie exile options in SimultaneousMajority…
hannw Sep 5, 2025
b365e87
Add RoundByRoundBiddingDiscussion
hannw Sep 5, 2025
11fa4b1
refactor _handle_night_await_actions() into smaller methods for reada…
Sep 8, 2025
d53c035
Remove check for GOOGLE_APPLICATION_CREDENTIALS as sdk looks for them…
Sep 8, 2025
8b5b305
Updating docs to remove internal OCTO project
Sep 8, 2025
410604b
Refactor to use event driven architecture for Role extensibility
hannw Sep 9, 2025
ad5c048
Refactor protocols to be modules
hannw Sep 9, 2025
20074c3
Improve on player id annotations
hannw Sep 9, 2025
f1449ad
standardize variable names from history entry to event
hannw Sep 10, 2025
69d9a33
fix harness phase error
hannw Sep 10, 2025
68f840d
add cost to litellm models
hannw Sep 10, 2025
65e8491
remove general confirmation of action event to player
hannw Sep 10, 2025
a633b0c
Fix StrEnum repr
hannw Sep 10, 2025
64462fc
Improve on prompting
hannw Sep 10, 2025
1236b8d
Improve the state machine transition to be explicit in engine.py
hannw Sep 11, 2025
f8d7ec2
Add phase category as attribute of DetailedPhase
hannw Sep 11, 2025
d744d49
Resolve detailed_phase naming issue
hannw Sep 11, 2025
91ef619
add utility to log git hash
hannw Sep 11, 2025
ea3394e
use wait random exponential to avoid "thundering herd" VM crash
hannw Sep 12, 2025
49a0290
Use threadpool instead
hannw Sep 12, 2025
0fd484c
refactor voting to use Ballot
hannw Sep 12, 2025
67f59f4
Refactor Role initialization to use role_params dict
hannw Sep 14, 2025
98792e2
Refactor day/night elimination reveal to use RevealLevel
hannw Sep 14, 2025
7d8c99a
Fix seer team reveal level result blob
hannw Sep 15, 2025
1c435e2
Add option to disallow doctor consecutive saving of same player
hannw Sep 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/logo/chatgpt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo/claude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo/deepseek.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo/gemini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo/grok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo/kimi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo/qwen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/moon4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/stickman.fbx
Binary file not shown.
Binary file added assets/stickman.glb
Binary file not shown.
4 changes: 4 additions & 0 deletions kaggle_environments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from importlib import import_module
from os import listdir
from .agent import Agent
Expand All @@ -26,6 +27,9 @@
"make", "register", "utils", "__version__",
"get_episode_replay", "list_episodes", "list_episodes_for_team", "list_episodes_for_submission"]

_script_dir = os.path.dirname(os.path.realpath(__file__))
PROJECT_ROOT = os.path.abspath(os.path.join('..', _script_dir))

# Register Environments.

for name in listdir(utils.envs_path):
Expand Down
32 changes: 22 additions & 10 deletions kaggle_environments/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def build_agent(raw, builtin_agents, environment_name):
Returns the agent and whether the agent is parallelizable.
"""
if raw in builtin_agents:
agent = builtin_agents[raw]
# TODO: Below is a hack. Assuming an agent is a global callable is not enough to guarantee it is stateless.
# Kaggle environment should allow more scalable agent initialization and proper agent interface design.
if hasattr(agent, "reset"):
agent.reset()
return builtin_agents[raw], False

# Already callable.
Expand Down Expand Up @@ -163,16 +168,23 @@ def act(self, observation):

# Start the timer.

with StringIO() as out_buffer, StringIO() as err_buffer, redirect_stdout(out_buffer), redirect_stderr(err_buffer):
try:
start = perf_counter()
action = self.agent(*args)
except Exception as e:
traceback.print_exc(file=err_buffer)
action = e

out = out_buffer.getvalue()
err = err_buffer.getvalue()
if self.debug:
# Adding a debugging branch here, since the context manager and try except would prevent
# debugger from functioning properly.
start = perf_counter()
action = self.agent(*args)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear why there have to be two paths for self.debug here, looks like debug path is just removing try/catch and error logging?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping execution loop in try except catch-all would prevent debugger from functioning, defeating the purpose for debugging mode, which is why we separated the two modes here. I can add a comment to address it.

out = ""
err = ""
else:
with StringIO() as out_buffer, StringIO() as err_buffer, redirect_stdout(out_buffer), redirect_stderr(err_buffer):
try:
start = perf_counter()
action = self.agent(*args)
except Exception as e:
traceback.print_exc(file=err_buffer)
action = e
out = out_buffer.getvalue()
err = err_buffer.getvalue()
# Get the maximum log length
# Allow up to 10k (default) log characters per step which is ~10MB per 600 step episode
max_log_length = self.configuration.get('maxLogLength', 10000)
Expand Down
50 changes: 30 additions & 20 deletions kaggle_environments/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,31 +572,34 @@ def update_props(props):
)
return data

def __run_interpreter(self, state, logs):
def __loop_through_interpreter(self, state, logs):
args = [structify(state), self, logs]
new_state = structify(self.interpreter(
*args[:self.interpreter.__code__.co_argcount]))
new_state[0].observation.step = (
0 if self.done
else len(self.steps)
)

for index, agent in enumerate(new_state):
if index < len(logs) and "duration" in logs[index]:
duration = logs[index]["duration"]
overage_time_consumed = max(0, duration - self.configuration.actTimeout)
agent.observation.remainingOverageTime -= overage_time_consumed
if agent.status not in self.__state_schema.properties.status.enum:
self.debug_print(f"Invalid Action: {agent.status}")
agent.status = "INVALID"
if agent.status in ["ERROR", "INVALID", "TIMEOUT"]:
agent.reward = None
return new_state

def __run_interpreter_prod(self, state, logs):
out = None
err = None
# Append any environmental logs to any agent logs we collected.
try:
with StringIO() as out_buffer, StringIO() as err_buffer, redirect_stdout(out_buffer), redirect_stderr(err_buffer):
try:
args = [structify(state), self, logs]
new_state = structify(self.interpreter(
*args[:self.interpreter.__code__.co_argcount]))
new_state[0].observation.step = (
0 if self.done
else len(self.steps)
)

for index, agent in enumerate(new_state):
if index < len(logs) and "duration" in logs[index]:
duration = logs[index]["duration"]
overage_time_consumed = max(0, duration - self.configuration.actTimeout)
agent.observation.remainingOverageTime -= overage_time_consumed
if agent.status not in self.__state_schema.properties.status.enum:
self.debug_print(f"Invalid Action: {agent.status}")
agent.status = "INVALID"
if agent.status in ["ERROR", "INVALID", "TIMEOUT"]:
agent.reward = None
new_state = self.__loop_through_interpreter(state, logs)
return new_state
except Exception as e:
# Print the exception stack trace to our log
Expand Down Expand Up @@ -629,6 +632,13 @@ def __run_interpreter(self, state, logs):
err = err[:-1]
self.debug_print(err)

def __run_interpreter(self, state, logs):
# Append any environmental logs to any agent logs we collected.
if self.debug:
return self.__loop_through_interpreter(state, logs)
else:
return self.__run_interpreter_prod(state, logs)

def __process_specification(self, spec):
if has(spec, path=["reward"]):
reward = spec["reward"]
Expand Down
2 changes: 1 addition & 1 deletion kaggle_environments/envs/connectx/test_connectx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def before_each(state=None, configuration=None):
global env
steps = [] if state == None else [state]
env = make("connectx", steps=steps,
configuration=configuration, debug=True)
configuration=configuration, debug=False)


def test_has_correct_timeouts():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def error_agent():
raise ValueError

def test_llm_20_q_completes():
env = make("llm_20_questions", debug=True)
env = make("llm_20_questions", debug=False)
env.run([custom_questioner, custom_answerer, custom_questioner, custom_answerer])
json = env.toJSON()
assert json["name"] == "llm_20_questions"
assert json["statuses"] == ["DONE", "DONE", "DONE", "DONE"]

def test_llm_20_q_errors_on_bad_answer():
env = make("llm_20_questions", debug=True)
env = make("llm_20_questions", debug=False)
env.run([custom_questioner, custom_answerer, custom_questioner, bad_answerer])
json = env.toJSON()
assert json["name"] == "llm_20_questions"
Expand All @@ -42,7 +42,7 @@ def test_llm_20_q_errors_on_bad_answer():
assert len(json["steps"]) == 3

def test_llm_20_q_errors_on_error_answer():
env = make("llm_20_questions", debug=True)
env = make("llm_20_questions", debug=False)
env.run([custom_questioner, custom_answerer, custom_questioner, error_agent])
json = env.toJSON()
assert json["name"] == "llm_20_questions"
Expand All @@ -51,7 +51,7 @@ def test_llm_20_q_errors_on_error_answer():
assert len(json["steps"]) == 3

def test_llm_20_q_errors_on_error_question():
env = make("llm_20_questions", debug=True)
env = make("llm_20_questions", debug=False)
env.run([custom_questioner, custom_answerer, error_agent, custom_answerer])
json = env.toJSON()
assert json["name"] == "llm_20_questions"
Expand All @@ -60,7 +60,7 @@ def test_llm_20_q_errors_on_error_question():
assert len(json["steps"]) == 2

def test_llm_20_q_errors_on_error_last_guess():
env = make("llm_20_questions", debug=True)
env = make("llm_20_questions", debug=False)
env.run([custom_questioner, custom_answerer, last_round_guesser_error, custom_answerer])
json = env.toJSON()
assert json["name"] == "llm_20_questions"
Expand Down
8 changes: 4 additions & 4 deletions kaggle_environments/envs/tictactoe/test_tictactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def custom6(obs):
def before_each(state=None):
global env
steps = [] if state == None else [state]
env = make("tictactoe", steps=steps, debug=True)
env = make("tictactoe", steps=steps, debug=False)


def test_to_json():
Expand Down Expand Up @@ -201,22 +201,22 @@ def test_can_run_custom_agents():


def test_agents_can_timeout_on_init():
env = make("tictactoe", debug=True)
env = make("tictactoe", debug=False)
state = env.run([custom1, custom3])[-1]
assert state[1]["status"] == "TIMEOUT"
assert state[1]["observation"]["remainingOverageTime"] < 0


def test_agents_can_timeout_on_act():
env = make("tictactoe", debug=True)
env = make("tictactoe", debug=False)
state = env.run([custom1, custom6])[-1]
print(state)
assert state[1]["status"] == "TIMEOUT"
assert state[1]["observation"]["remainingOverageTime"] < 0


def test_run_timeout():
env = make("tictactoe", debug=True, configuration={"actTimeout": 10, "runTimeout": 1})
env = make("tictactoe", debug=False, configuration={"actTimeout": 10, "runTimeout": 1})
try:
state = env.run([custom1, custom3])[-1]
except DeadlineExceeded:
Expand Down
75 changes: 75 additions & 0 deletions kaggle_environments/envs/werewolf/GAME_RULE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Werewolf: Game Rules

Welcome to Werewolf, a game of social deduction, team collaboration, deception, and survival. Players are secretly assigned roles on one of two teams: the Village or the Werewolves.

## Roles

Each player is assigned one of the following roles:

### Village Team

The goal of the Village team is to exile all the werewolves.

* **Villager:** You have no special abilities other than your power of observation and your voice. Use the discussion phase to identify suspicious behavior and vote to exile suspected werewolves.
* **Seer:** Each night, you may choose one player to investigate. You will learn if that player is a Werewolf or not. Your goal is to share this information strategically to help the village without revealing your identity too soon.
* **Doctor:** Each night, you may choose one player to protect. The player you protect cannot be eliminated by the werewolves that night.

### Werewolf Team

* **Werewolf:** Your goal is to eliminate villagers until the number of werewolves equals the number of remaining village members. Each night, you and your fellow werewolves will secretly agree on one player to eliminate.

## Game Phases

The game alternates between a Night phase and a Day phase.

### Night Phase 🐺

During the night, all players close their eyes. The moderator will ask players with special roles to wake up and perform their actions in this order:

1. **Doctor:** Chooses one player to protect.
2. **Seer:** Chooses one player to investigate their alignment.
3. **Werewolves:** Silently vote on one player to eliminate.

### Day Phase ☀️

1. **Announcement:** The moderator announces which player, if any, was eliminated during the night. That player is removed from the game and may not speak or participate further.
2. **Discussion:** The surviving players discuss who they think the werewolves are.
3. **Exile Vote:** Players vote on who to exile from the village. The player who receives the most votes is exiled, removed from the game, and their role is revealed.

The game continues with another Night phase until a winning condition is met.

## Customizable Rules

Before the game begins, the following options must be decided.

### 1. Doctor's Self-Save

* **Option A (Self-Save Allowed):** The Doctor is allowed to choose themselves as the target of their protection.
* **Option B (No Self-Save):** The Doctor must choose another player to protect.

### 2. Discussion Protocol

* **Option A (Parallel Discussion):** All players may speak simultaneously for a number of rounds.
* **Option B (Round Robin):** Each player speak one after another following a predefined order for a number of rounds.

### 3. Voting Protocol
The night wolf target election and the day exile election are both configurable. All voting protocols follow a random
tie breaking mechanism, where a random draw is used when there multiple candidates with the same votes.

* **Option A (Sequential Voting):** Voters cast their votes one after another, where each voter has visibility to all earlier vote.
* **Option B (Parallel Voting):** All voters cast their votes simultaneously.

## Winning the Game

A team wins as soon as their winning condition is met.

* **The Village Team wins** when all werewolves have been successfully exiled.
* **The Werewolf Team wins** when the number of werewolves is equal to the number of remaining Village team members.

### Rewards

All members of the winning team will receive **1 reward**. This includes players who were eliminated before the end of the game.

### Tie Game (Forfeit)

If any back-end inference fails during the game, the match will immediately end. The game will be declared a **tie**, and no players will receive a reward.
Loading