A lightweight WebSocket wrapper around the SimpleAgent Core that provides real-time web interface capabilities without duplicating the core codebase.
This project follows the "Don't Repeat Yourself" (DRY) principle by:
- Not duplicating the SimpleAgent core code
- Using git submodules to reference the official SimpleAgent Core repository
- Acting as a thin wrapper that adds WebSocket functionality
- Staying automatically up-to-date with core improvements
Simple-Agent-Websocket/
βββ main.py # Main entry point
βββ websocket_server.py # Backward compatibility wrapper
βββ websocket_server/ # Modular server package
β βββ __init__.py # Package initialization
β βββ core_loader.py # SimpleAgent core loading
β βββ run_manager.py # WebSocket-enhanced RunManager
β βββ agent_wrapper.py # Agent session management
β βββ event_handlers.py # WebSocket event handlers
β βββ routes.py # HTTP API routes
β βββ server.py # Main server class
βββ test_client_enhanced.html # Enhanced test client with real-time UI
βββ setup_submodule.sh # Linux/Mac setup script
βββ setup_submodule.bat # Windows setup script
βββ requirements.txt # WebSocket-specific dependencies
βββ SimpleAgent/ # β Symlink to SimpleAgent-Core/SimpleAgent
βββ (SimpleAgent Core via git submodule)
- π Real-time Updates: See each step of agent execution as it happens
- π¬ Bidirectional Communication: Send messages to the agent during execution
- π Progress Tracking: Visual progress bars and step indicators
- π¨ Modern UI: Clean, responsive web interface
- π¦ No Code Duplication: Uses the official SimpleAgent Core as a git submodule
- π Auto-sync: Easy updates when the core repository changes
- π Multi-session: Support for multiple concurrent WebSocket sessions
- π§© Modular Design: Clean, maintainable code structure
# Clone this repository
git clone https://github.com/your-username/Simple-Agent-Websocket.git
cd Simple-Agent-Websocket
# Run the setup script to configure git submodules
# Linux/Mac:
chmod +x setup_submodule.sh
./setup_submodule.sh
# Windows:
setup_submodule.batCreate a .env file in the SimpleAgent directory (or copy from the core):
# API Provider (openai, lmstudio, or gemini)
API_PROVIDER=openai
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
# Model settings
DEFAULT_MODEL=gpt-4o
SUMMARIZER_MODEL=gpt-3.5-turbo
# Application settings
MAX_STEPS=10
DEBUG_MODE=False# New modular interface (recommended)
python main.py
# Or with options
python main.py --host 0.0.0.0 --port 8080 --debug
# Backward compatibility (deprecated but still works)
python websocket_server.pyThe server will start on http://localhost:5000 by default.
Open test_client_enhanced.html in your web browser to interact with the agent through a modern web interface.
-
run_agent: Start agent execution{ "instruction": "Your task description", "max_steps": 10, "auto_continue": 0 } -
stop_agent: Stop running agent -
user_input: Send user input during execution{ "input": "User response" } -
get_status: Get current session status
connected: Connection establishedagent_started: Agent execution beganstep_start: New step startedassistant_message: AI assistant responsetool_call: Tool/function executionstep_summary: Step completion summarywaiting_for_input: Agent waiting for user inputtask_completed: Task finished successfullyagent_finished: Agent execution completedagent_error: Error occurred
The beauty of this approach is that you can easily update to the latest SimpleAgent Core:
# Update the SimpleAgent core to the latest version
git submodule update --remote
# Or update and commit the new version
git submodule update --remote
git add SimpleAgent-Core
git commit -m "Update SimpleAgent core to latest version"The server is now organized into clean, modular components:
main.py: Entry point with argument parsingwebsocket_server/core_loader.py: Handles loading SimpleAgent core from submodulewebsocket_server/run_manager.py: WebSocket-enhanced RunManagerwebsocket_server/agent_wrapper.py: Session management and agent wrappingwebsocket_server/event_handlers.py: WebSocket event handlingwebsocket_server/routes.py: HTTP API endpointswebsocket_server/server.py: Main server class and initializationtest_client_enhanced.html: Full-featured test client with real-time UI
Since this is a modular wrapper, you can:
- Extend WebSocket events: Add new event types in
event_handlers.py - Add HTTP endpoints: Extend
routes.pywith new API routes - Enhance the UI: Modify
test_client_enhanced.html - Customize behavior: Override methods in the wrapper classes
- Add new modules: Create new modules in the
websocket_server/package
When the SimpleAgent Core gets updated:
- Your WebSocket wrapper automatically gets the new features
- No need to manually sync code changes
- Just update the submodule and restart the server
python main.py --help--host: Host to bind to (default: localhost)--port: Port to bind to (default: 5000)--debug: Enable debug mode--eager-loading: Use eager loading for tools
All SimpleAgent Core environment variables are supported. See the core documentation for details.
GET /health: Health check and server statusGET /sessions: List active WebSocket sessionsGET /version: Version information for both WebSocket server and coreWebSocket /socket.io/: Main WebSocket endpoint
The new modular structure provides:
- π§ Maintainability: Each component has a single responsibility
- π§ͺ Testability: Individual modules can be tested in isolation
- π Scalability: Easy to add new features without affecting existing code
- π Debuggability: Clear separation makes issues easier to track down
- π₯ Team Development: Multiple developers can work on different modules
- π Documentation: Each module is self-contained and well-documented
- CORS: Currently allows all origins (
*) - configure for production - Authentication: No built-in auth - add as needed for your use case
- Rate Limiting: Consider adding rate limiting for production deployments
- File Access: Inherits SimpleAgent Core's security model (output directory restrictions)
- For WebSocket features: Contribute to this repository
- For core agent features: Contribute to SimpleAgent Core
- For tools: Contribute to Simple-Agent-Tools
This project follows the same license as the SimpleAgent Core.
- Built on top of SimpleAgent Core
- Uses Flask-SocketIO for WebSocket functionality
- Inspired by the need for real-time AI agent interfaces
Why This Approach?
β
No code duplication - Uses official core as submodule
β
Always up-to-date - Easy to sync with core updates
β
Lightweight - Only adds WebSocket functionality
β
Maintainable - Core changes don't require manual updates
β
Focused - This repo only handles WebSocket concerns
β
Modular - Clean, organized code structure
β Alternative approaches we avoided:
- Forking the core (creates maintenance burden)
- Copying core files (leads to version drift)
- Modifying core directly (breaks separation of concerns)
- Monolithic server files (hard to maintain and extend)