A Python framework to transform your AI from reactive to proactive with intelligent timing and context-aware wake-up patterns - Your agent decides when to speak!
Project description
ProactiveAgent
Time-awareness for your AI Agent
Transform your AI from reactive to proactive with intelligent timing and context-aware wake-up patterns
What is ProactiveAgent?
ProactiveAgent is an open-source Python library that wraps AI models with intelligent proactive behavior. Unlike traditional agents that only respond when prompted, ProactiveAgent creates AI agents that:
- Think before speaking - Multi-factor decision engine determines if and when to respond
- Sleep intelligently - Dynamic timing system calculates smart response intervals
- Understand context - Analyzes conversation flow, user engagement, and urgency
- Stay flexible - Fully customizable decision engines and sleep calculators
Quick Start
Installation
pip install proactiveagent
Basic Usage
from proactiveagent import ProactiveAgent, OpenAIProvider
# Create a proactive agent
agent = ProactiveAgent(
provider=OpenAIProvider(model="gpt-5-nano",),
system_prompt="You are a casual bored teenager. Answer like you're texting a friend",
# Define in natural language the frequency of response
decision_config={
'wake_up_pattern': "Use the pace of a normal text chat",
}
)
# Add response callback
def on_response(response: str):
print(f"🤖 AI: {response}")
agent.add_callback(on_response)
# Start the agent thread and chat
agent.start()
agent.send_message("Hey! whatsup?")
# You can add a loop to keep sending the agent more messages! see our examples.
How It Works
ProactiveAgent operates on a 3-step decision cycle:
1. Decision Engine - "Should I Respond?"
The Decision Engine analyzes multiple factors to determine if the AI should respond. Our default engine:
- Context Analysis: Evaluates questions, urgency keywords, and conversation flow
- Time Factors: Considers elapsed time since the last user message
- AI Reasoning: Leverages native AI decision-making capabilities
- Engagement Level: Monitors user activity patterns and conversation intensity
We have other engines that you can choose TODO LINK. You can also define your own Engine like using our abstract class TODO LINK. (essa frase pode ficar com um design diferente no readme) TODO: See Multi-Factor Scoring for more info:
2. Message Generation - "Respond"
When the decision engine determines a response is appropriate, the agent:
- Generates contextually appropriate responses
- Considers conversation history and timing
- Maintains natural conversation flow
- Triggers all registered response callbacks
3. Sleep Calculator - "How Long Should I Wait?"
Finally, the Sleep Calculator determines optimal wait time before the next decision cycle. There are different Sleep Calculator available, for example:
- AI-Based (default): Uses AI to interpret natural language patterns like "Respond in a frequency of a normal internet chat" or "You are a anxious person"
- Pattern-Based: Keyword matching for different conversation states
- Function-Based: Define your own function for adaptive timing
- Static: Fixed intervals for predictable behavior
You can also create your own SleepCalculator TODO LINK
Customization & Flexibility
Decision Engines
Choose or create your own decision-making logic:
from proactiveagent import AIBasedDecisionEngine, SimpleDecisionEngine
# Option 1 - AI-powered decisions (default)
ai_engine = AIBasedDecisionEngine(provider)
# Option 2 - Simple time-based decisions
simple_engine = SimpleDecisionEngine()
# Option 3 - Your custom logic
class MyDecisionEngine(DecisionEngine):
async def should_respond(self, messages, last_time, context, config, triggered_by_user):
# Your custom decision logic here
return should_respond, "reasoning"
agent = ProactiveAgent(provider=provider, decision_engine=MyDecisionEngine())
Sleep Time Calculators
Control when your agent "wakes up" to make decisions:
from proactiveagent import AIBasedSleepCalculator, StaticSleepCalculator
# Option 1 - AI interprets natural language patterns (default)
ai_calc = AIBasedSleepCalculator(provider)
# Option 2 - Fixed intervals
static_calc = StaticSleepCalculator(sleep_time=120) # Every 2 minutes
# Option 3 - Your own custom adaptive logic
class SmartCalculator(SleepTimeCalculator):
async def calculate_sleep_time(self, config, context):
engagement = context.get('user_engagement', 'medium')
if engagement == 'high':
return 30, "High engagement - checking frequently"
elif engagement == 'low':
return 300, "Low engagement - checking less often"
return 120, "Medium engagement - standard interval"
agent.scheduler.set_sleep_time_calculator(SmartCalculator())
Real-Time Monitoring
Track your agent's behavior with callbacks:
def on_response(response: str):
print(f"Response: {response}")
def on_decision(should_respond: bool, reasoning: str):
status = "RESPOND" if should_respond else "WAIT"
print(f"Decision: {status} - {reasoning}")
def on_sleep_time(sleep_time: int, reasoning: str):
print(f"Sleeping {sleep_time}s - {reasoning}")
# Register callbacks
agent.add_callback(on_response)
agent.add_decision_callback(on_decision)
agent.add_sleep_time_callback(on_sleep_time)
Configuration Options
Fine-tune your agent's behavior with comprehensive configuration:
agent = ProactiveAgent(
provider=provider,
decision_config={
# Response timing bounds
'min_response_interval': 30, # Minimum seconds between responses
'max_response_interval': 600, # Maximum seconds before forced response
'probability_weight': 0.3, # AI decision weight
# Sleep calculation
'wake_up_pattern': "Check around 2-3 minutes when user is active",
'min_sleep_time': 30, # Minimum sleep seconds
'max_sleep_time': 600, # Maximum sleep seconds
}
)
You can also add your own config parameters for you customized engines and calculator. See example TODO link
Examples
Explore our examples in the examples/ directory:
Getting Started
ultra_simple_chat.py- Minimal WhatsApp-style chatall_config_parameters.py- Complete configuration guide
Decision Engines
ai_based_decision_engine.py- AI-powered decisionssimple_decision_engine.py- Time-based logiccustom_decision_engine.py- Build your own
Sleep Calculators
ai_based_sleep_calculator.py- Natural language patternsfunction_based_sleep_calculator.py- Adaptive timingpattern_based_sleep_calculator.py- Keyword matching
Monitoring & Callbacks
comprehensive_callbacks.py- Full callback system
Advanced Features
Context Management
# Set conversation context
agent.set_context('user_mood', 'excited')
agent.set_context('topic_urgency', 'high')
# Context automatically influences decisions
mood = agent.get_context('user_mood')
Runtime Configuration
# Update configuration while running
agent.update_config({
'min_response_interval': 5, # Respond faster
'engagement_threshold': 0.3 # Lower threshold
})
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
Support
- Star this repo if ProactiveAgent helps your project!
Made with ❤️ by the internet
Mainteiner: Leonardo Mariga
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file proactiveagent-0.1.0.tar.gz.
File metadata
- Download URL: proactiveagent-0.1.0.tar.gz
- Upload date:
- Size: 41.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb90e5cfb047b99867e8e49b8fd5d1877a12d59ed7e11343f84f803c27a3c5f9
|
|
| MD5 |
04d08e80819555d03e3bee6d6fd4a0b4
|
|
| BLAKE2b-256 |
2567141ef2371b2357df00742f63ecff4fd55c2b10daf0a073660365a01bf185
|
File details
Details for the file proactiveagent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: proactiveagent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3517cd60adbbb716e885ed5f4b8ffa8586513364a4dc16c6e51a3737663a404
|
|
| MD5 |
e09aa751749739c8b33bac16587a0470
|
|
| BLAKE2b-256 |
0cf80a37b9d76df6046963f6fb4d85c846defb82ca845e5b0a2e05f48ed5da92
|