Skip to content

Instantly share code, notes, and snippets.

@ayavilevich
Created March 24, 2026 16:30
Show Gist options
  • Select an option

  • Save ayavilevich/d3a4c331e3e34adc4cdbf7d18d3ac1ad to your computer and use it in GitHub Desktop.

Select an option

Save ayavilevich/d3a4c331e3e34adc4cdbf7d18d3ac1ad to your computer and use it in GitHub Desktop.
AGENT_WORKSHOP start.sh port for Windows
@echo off
setlocal EnableExtensions EnableDelayedExpansion
cd /d "%~dp0"
set "SHARE=false"
set "WORKERS=4"
set "PORT=8000"
:parse_args
if "%~1"=="" goto args_done
set "ARG=%~1"
if /I "!ARG!"=="--share" set "SHARE=true"
if /I "!ARG:~0,10!"=="--workers=" set "WORKERS=!ARG:~10!"
if /I "!ARG:~0,7!"=="--port=" set "PORT=!ARG:~7!"
shift
goto parse_args
:args_done
if not exist ".venv\Scripts\python.exe" (
echo Creating virtual environment...
py -3 -m venv .venv >nul 2>&1
if errorlevel 1 python -m venv .venv
if errorlevel 1 (
echo Failed to create virtual environment.
exit /b 1
)
)
call ".venv\Scripts\activate.bat"
if errorlevel 1 (
echo Failed to activate virtual environment.
exit /b 1
)
echo Installing requirements...
python -m pip install -q --upgrade pip
if errorlevel 1 exit /b 1
python -m pip install -q -r requirements.txt
if errorlevel 1 exit /b 1
if not exist ".env" (
echo.
echo WARNING: No .env file found. Create one with:
echo echo OPENAI_API_KEY=sk-... ^> .env
echo echo OPENAI_MODEL=gpt-4o-mini ^>^> .env
echo.
)
if /I "%SHARE%"=="true" goto share_mode
goto local_mode
:share_mode
where ngrok >nul 2>&1
if errorlevel 1 (
echo.
echo ngrok not found. Install it first:
echo winget install ngrok.ngrok
echo ngrok config add-authtoken ^<your-token^>
echo.
exit /b 1
)
echo.
echo Share mode: starting ngrok tunnel on port %PORT% with %WORKERS% workers
echo.
set "NGROK_PID="
for /f %%I in ('powershell -NoProfile -Command "$p = Start-Process ngrok -ArgumentList ''http %PORT%'' -WindowStyle Hidden -PassThru; $p.Id"') do set "NGROK_PID=%%I"
set "PUBLIC_URL="
for /f "usebackq delims=" %%U in (`powershell -NoProfile -Command "$url=''; 1..20 ^| %% { Start-Sleep -Milliseconds 500; try { $t=(Invoke-RestMethod -Uri 'http://127.0.0.1:4040/api/tunnels' -ErrorAction Stop).tunnels; $u=($t ^| Where-Object { $_.public_url -like 'https*' } ^| Select-Object -First 1 -ExpandProperty public_url); if ($u) { $url=$u; break } } catch {} }; Write-Output $url"`) do set "PUBLIC_URL=%%U"
if not defined PUBLIC_URL (
echo Could not detect public URL automatically.
echo Check http://127.0.0.1:4040 in your browser for the ngrok URL.
) else (
echo ======================================================
echo Share this URL with participants:
echo %PUBLIC_URL%
echo ======================================================
echo %PUBLIC_URL% | clip >nul 2>&1
start "" "%PUBLIC_URL%"
)
echo Starting server with %WORKERS% workers (no --reload in share mode)...
echo Press Ctrl+C to stop everything.
echo.
uvicorn main:app --workers %WORKERS% --host 127.0.0.1 --port %PORT%
set "APP_EXIT=%ERRORLEVEL%"
if defined NGROK_PID (
taskkill /PID %NGROK_PID% /F >nul 2>&1
echo.
echo Tunnel closed.
)
exit /b %APP_EXIT%
:local_mode
start "" "http://127.0.0.1:%PORT%"
echo.
echo Starting Agent Workshop at http://127.0.0.1:%PORT%
echo Tip: run start.cmd --share to create a public ngrok tunnel.
echo Press Ctrl+C to stop.
echo.
uvicorn main:app --reload --host 127.0.0.1 --port %PORT%
exit /b %ERRORLEVEL%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment