Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy MkDocs site to GitHub Pages

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mkdocs-material mkdocstrings pymdown-extensions

- name: Build MkDocs site
run: mkdocs build --strict

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
31 changes: 30 additions & 1 deletion AIDojoCoordinator/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@

class AgentServer(asyncio.Protocol):
"""
Class used for serving the agents when conneting to the game run by th GameCoordinator.
Class used for serving the agents when connecting to the game run by the GameCoordinator.

Attributes:
actions_queue (asyncio.Queue): Queue for actions from agents.
answers_queues (dict): Mapping of agent addresses to their response queues.
max_connections (int): Maximum allowed concurrent agent connections.
current_connections (int): Current number of connected agents.
logger (logging.Logger): Logger for the AgentServer.
"""
def __init__(self, actions_queue, agent_response_queues, max_connections):
"""
Initialize the AgentServer.

Args:
actions_queue (asyncio.Queue): Queue for actions from agents.
agent_response_queues (dict): Mapping of agent addresses to their response queues.
max_connections (int): Maximum allowed concurrent agent connections.
"""
self.actions_queue = actions_queue
self.answers_queues = agent_response_queues
self.max_connections = max_connections
Expand All @@ -26,6 +41,9 @@ def __init__(self, actions_queue, agent_response_queues, max_connections):
async def handle_agent_quit(self, peername:tuple):
"""
Helper function to handle agent disconnection.

Args:
peername (tuple): The address of the disconnecting agent.
"""
# Send a quit message to the Coordinator
self.logger.info(f"\tHandling agent quit for {peername}.")
Expand All @@ -35,6 +53,10 @@ async def handle_agent_quit(self, peername:tuple):
async def handle_new_agent(self, reader, writer):
"""
Handle a new agent connection.

Args:
reader (asyncio.StreamReader): Stream reader for the agent.
writer (asyncio.StreamWriter): Stream writer for the agent.
"""
# get the peername of the writer
peername = writer.get_extra_info("peername")
Expand Down Expand Up @@ -102,6 +124,13 @@ async def handle_new_agent(self, reader, writer):
# swallow exceptions on close to avoid crash on cleanup
pass
async def __call__(self, reader, writer):
"""
Allow the server instance to be called as a coroutine.

Args:
reader (asyncio.StreamReader): Stream reader for the agent.
writer (asyncio.StreamWriter): Stream writer for the agent.
"""
await self.handle_new_agent(reader, writer)

class GameCoordinator:
Expand Down
Loading