This is a communications agent that can read and process messages from a shared thread with a scheduler agent in the same Azure AI Project.
- ✅ Read the last posted message from a shared thread
- ✅ Monitor a shared thread for new messages
- ✅ Process messages from the scheduler agent
- ✅ Send acknowledgments back to the thread
- ✅ Handle different message types and content
-
Make sure you have the required environment variables set:
PROJECT_CONNECTION_STRING=your_azure_project_connection_string MODEL_DEPLOYMENT_NAME=your_model_deployment_name
-
Optional: Set the shared thread ID as an environment variable:
SHARED_THREAD_ID=thread_abc123xyz
Use the simple check script to quickly read the last message from a shared thread:
python check_messages.pyMake sure to set the THREAD_ID variable in the script or the SHARED_THREAD_ID environment variable.
Run the main agent with full functionality:
python main.py- Reads the most recent message from a thread
- Returns message details including content, role, and timestamp
- Handles different content types (text, files, etc.)
- Continuously monitors a thread for new messages
- Processes messages from the scheduler agent
- Can send acknowledgments back to the thread
- Configurable check interval (default: 30 seconds)
- Processes messages from the scheduler agent
- Detects scheduling-related keywords
- Can trigger notifications or other actions
- Sends acknowledgments back to the thread
- Scheduler Agent posts a message to the shared thread
- Communications Agent detects the new message
- Communications Agent processes the message content
- Communications Agent can:
- Send notifications (email, SMS, Slack, etc.)
- Update databases
- Send acknowledgment back to the thread
- Trigger other workflows
# Read the last message from a shared thread
last_message = await read_last_message_from_thread(project_client, "thread_abc123")
# Monitor a shared thread continuously
await monitor_shared_thread("thread_abc123", check_interval=10)
# Display recent messages from a thread
await utilities.display_thread_messages(project_client, "thread_abc123", limit=5)To continuously monitor a shared thread:
- Set the
existing_thread_idvariable inmain.py - Uncomment the
monitor_shared_thread()call - Run the script - it will continuously check for new messages
The agent includes comprehensive error handling for:
- Connection issues
- Invalid thread IDs
- Message parsing errors
- Network timeouts
You can customize the agent by:
- Modifying the message processing logic in
process_scheduler_message() - Adding custom notification methods
- Changing the monitoring interval
- Adding filters for specific message types
- Implementing custom response templates
- Email Notifications: Send emails when schedule changes are detected
- SMS Alerts: Send text messages for urgent schedule updates
- Slack/Teams Integration: Post messages to communication channels
- Database Updates: Update scheduling databases with changes
- Calendar Integration: Sync with calendar applications
- Webhook Triggers: Trigger external systems via webhooks