A smart office assistant that processes requests through Slack and manages various office tasks.
.env file private.
- Clone the repository:
git clone https://github.com/yourusername/office-assistant.git
cd office-assistant- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your actual credentials- Front Desk: Handles Slack communication, message formatting, and direct execution of known tasks
- NLPProcessor: Performs quick, rule-based natural language processing and task classification
- CEO: Creates new recipes for unknown tasks and handles complex decision making
- CookbookManager: Stores manages recipes/chains, matching requests to recipes, informing Front Desk of missing information or recipe
- TaskManager: Executes recipes and manages task state with priority-based processing
- GPTClient: Handles AI-powered decision making with fallback capabilities
The system processes messages through the following flows:
Message -> NLP Processor [intent=conversational]
|
v
Front Desk -> GPT Response -> User
Message -> NLP Processor [intent=task]
|
v
Front Desk -> Request Tracker [create]
|
v
CookbookManager [recipe found]
|
v
TaskManager [execute]
|
v
User
Message -> NLP Processor [intent=task]
|
v
Front Desk -> Request Tracker [create]
|
v
CookbookManager [missing_info]
|
v
Front Desk -> Request Info -> User
Message -> NLP Processor [intent=task]
|
v
Front Desk -> Request Tracker [create]
|
v
CookbookManager [not_found]
|
v
CEO [create_recipe]
|
v
CookbookManager [store]
|
v
TaskManager [execute]
|
v
User
Message -> NLP Processor [extract entities]
|
v
Front Desk -> Request Tracker [get_active]
|
v
CookbookManager [validate]
|
v
TaskManager [execute] or Front Desk [request more info]
|
v
User
-
Intelligent Task Routing:
- Automatic recognition of known vs unknown tasks
- Direct execution path for existing recipes
- Complex task handling through CEO
- Recipe creation and storage for future use
- Priority-based task execution with urgency levels
- FIFO ordering for equal-priority tasks
-
Natural Language Processing:
- Intent detection (email, scheduling, research, etc.)
- Entity extraction (emails, dates, numbers)
- Task complexity assessment
- Recipe matching
- Temporal context understanding
- User context tracking
- Urgency detection and prioritization
-
Slack Integration:
- Real-time message processing via Socket Mode
- Smart response formatting
- Thread support
- Comprehensive error handling
- Channel management
- Error recovery and graceful degradation
-
Task Management:
- Recipe-based task matching
- Multi-step task handling
- Priority-based processing
- Consultation detection
- Error task handling and recovery
- Task history tracking
- Concurrent task processing
- CEO Analysis: When an unknown request is received, the CEO component analyzes it using GPT-4 and available ingredients
- Recipe Generation: A new recipe is created following the standard YAML format:
name: <clear name> description: <clear description> intent: <main intent> common_triggers: - <trigger phrase 1> - <trigger phrase 2> required_entities: - <required entity 1> - <required entity 2> steps: - action: <ingredient action> params: param1: value1 success_criteria: - <criterion 1> - <criterion 2>
- Validation: The recipe is validated against available ingredients
- Storage: Valid recipes are stored in
src/office/cookbook/recipes.yaml - NLP Update: NLP processors automatically refresh their lexicons
- Testing: New recipes should be tested using the test suite in
tests/test_office_flow.py
To test a recipe:
- Add test cases to
tests/test_office_flow.py - Include both successful and error scenarios
- Test the complete flow:
- NLP processing
- Recipe matching
- Entity collection
- Task execution
- Monitor the detailed logging output to verify each step
When creating new recipes:
- Use only actions from
src/office/cookbook/ingredients.yaml - Ensure all required fields are present
- Provide clear success criteria
- Include common trigger phrases
- List all required entities
- Install dependencies:
pip install -r requirements.txt- Set up environment variables in
.env:
SLACK_BOT_TOKEN=xoxb-your-token
SLACK_APP_TOKEN=xapp-your-token
OPENAI_API_KEY=your-openai-key
- Configure your Slack app:
- Enable Socket Mode
- Subscribe to these events:
- message.channels
- message.groups
- app_mention
- Add necessary bot scopes:
- chat:write
- channels:history
- channels:join
- channels:read
- groups:history
- app_mentions:read
Start the Front Desk service:
python run_front_desk.pyFor testing Socket Mode specifically:
python test_socket_mode.pyRun the test suite:
python -m pytest tests/Run specific test modules:
# Test message flow
python -m pytest tests/test_message_flow.py -v
# Test NLP processor
python -m pytest tests/test_nlp_processor.py
# Test Front Desk
python -m pytest tests/test_front_desk.py
# Test CEO responses
python -m pytest tests/test_ceo_responses.py
# Test integration flows
python -m pytest tests/test_integration_flows.pyFor verbose output and debugging:
python -m pytest tests/test_message_flow.py -v --log-cli-level=DEBUGThe test suite includes:
- Unit tests for all components
- Integration tests for component interactions
- Flow tests for end-to-end scenarios
- Error handling and recovery tests
- Priority queue and task ordering tests
- Concurrency and race condition tests
User Message → FrontDesk
↓
Request Created
↓
NLP Processing → Updates intent/entities
↓
Cookbook Matching → Updates recipe/requirements
↓
[If needed] CEO Consultation → Updates priority/recipe
↓
Task Manager Execution → Updates status/completion
↓
Response to User
- Handles all Slack communication via Socket Mode
- Maintains professional tone
- Routes messages through NLP
- Formats responses for users
- Handles message deduplication
- Manages error recovery and retries
- Quick, rule-based text analysis
- Intent and entity extraction
- Urgency detection
- Temporal context analysis
- Priority assessment
- High-level decision making with GPT integration
- Task prioritization
- Resource allocation
- Consultation management
- Fallback handling when GPT is unavailable
- Priority-based task queue
- FIFO ordering for equal priorities
- Concurrent task processing
- Error handling and recovery
- Task history tracking
- Resource management
- Recipe matching
- Task decomposition
- Capability tracking
- Success criteria management
- Recipe validation
The system uses a comprehensive logging system with multiple log types:
- Location:
logs/flow_logs/ - Format:
log_HHMMam_MonDD.txt(e.g.,log_1123am_Feb11.txt) - Purpose: Tracks the complete flow of user interactions and system responses
- Features:
- One log file per session
- Clear session start header
- Timestamped events
- Structured component logging
- Detailed event information
- Error tracking
Example flow log format:
================================================================================
Session Started: 11:23:55 AM Feb 11, 2025
================================================================================
================================================================================
[11:23:55 AM] System - Initialization
----------------------------------------
status: initialized
components:
- FrontDesk
- NLPProcessor
- CookbookManager
- TaskManager
- CEO
- RequestTracker
-
Debug Log:
logs/front_desk_debug_YYYYMMDD.log- Detailed debugging information
- Component initialization
- State changes
- Performance metrics
-
Error Log:
logs/front_desk_error_YYYYMMDD.log- Error tracking
- Exception details
- Stack traces
- Recovery attempts
- Real-time status updates
- Service initialization
- Component status
- Critical errors
- User interactions
- Fork the repository
- Create a feature branch
- Submit a pull request
- Socket Mode integration
- NLP processing
- CEO decision making
- Recipe matching
- Response formatting
- Error recovery
- Thread support
- Priority-based task processing
- Task history tracking
- Error task handling
- Analytics dashboard
- Voice command support
The following credentials are required:
-
Slack Configuration
- Bot Token (
SLACK_BOT_TOKEN) - App Token (
SLACK_APP_TOKEN) - Required scopes:
- channels:manage
- chat:write
- channels:read
- channels:join
- channels:history
- groups:history
- im:history
- conversations.connect:write
- app_mentions:read
- im:write
- groups:read
- mpim:history
- mpim:write
- users:read
- Bot Token (
-
OpenAI Configuration
- API Key (
OPENAI_API_KEY)
- API Key (
-
Google Configuration
- Credentials file
- Token directory
- Required scopes for Gmail, Drive, Calendar, etc.
-
Trello Configuration
- API Key
- Token
-
Email Configuration
- IMAP settings
- App-specific password
Copy .env.example to .env and fill in your credentials. Never commit the .env file to version control.
- Enhanced NLP processing with prioritized intent classification
- Improved entity extraction for time and participants
- Better handling of conversational vs task intents
- Refined follow-up response handling
- Added robust error handling and user-friendly messages
- Improved time format recognition (12/24 hour formats, AM/PM)
- Better participant name extraction from natural language
- Enhanced context preservation across messages
- Smarter merging of entities from follow-up messages
- Comprehensive test suite for message flow
- Mock setup for async Slack client operations
- Entity extraction validation tests
- Conversation state management tests
- Error handling and recovery tests
- Enhanced intent classification with confidence scores
- Improved conversation state management
- Better urgency calculation based on multiple factors
- Refined temporal context extraction
- Enhanced pattern matching for various message types