Skip to content

ProactiveAgent

The main agent class for creating proactive AI agents.

proactiveagent.agent.ProactiveAgent

Python
ProactiveAgent(provider: BaseProvider, callbacks: Optional[List[Callable]] = None, decision_config: Optional[Dict[str, Any]] = None, decision_engine: Optional[DecisionEngine] = None, system_prompt: Optional[str] = None, log_level: str = 'WARNING')

Main class for creating proactive AI agents

Initialize Proactive AI Agent

Parameters:

Name Type Description Default
provider BaseProvider

AI provider instance (e.g., OpenAIProvider)

required
callbacks Optional[List[Callable]]

List of callback functions for responses

None
decision_config Optional[Dict[str, Any]]

Configuration for decision engine (includes wake_up_pattern and max_sleep_time)

None
decision_engine Optional[DecisionEngine]

Custom decision engine instance (defaults to AIBasedDecisionEngine)

None
system_prompt Optional[str]

Optional system prompt for the AI

None
log_level str

Logging level (DEBUG, INFO, WARNING, ERROR)

'WARNING'

add_callback

Python
add_callback(callback: Callable) -> None

Add a callback function for receiving AI responses

Parameters:

Name Type Description Default
callback Callable

Function that takes (response: str) as parameter

required

remove_callback

Python
remove_callback(callback: Callable) -> None

Remove a callback function

add_sleep_time_callback

Python
add_sleep_time_callback(callback: Callable) -> None

Add a callback function for sleep time estimation events

Parameters:

Name Type Description Default
callback Callable

Function that takes (sleep_time: int, reasoning: str) as parameters

required

remove_sleep_time_callback

Python
remove_sleep_time_callback(callback: Callable) -> None

Remove a sleep time callback function

add_decision_callback

Python
add_decision_callback(callback: Callable) -> None

Add a callback function for decision engine events

Parameters:

Name Type Description Default
callback Callable

Function that takes (should_respond: bool, reasoning: str) as parameters

required

remove_decision_callback

Python
remove_decision_callback(callback: Callable) -> None

Remove a decision callback function

send_message

Python
send_message(message: str, role: str = 'user') -> None

Send a message to the conversation

Parameters:

Name Type Description Default
message str

Message content

required
role str

Message role ('user' or 'assistant')

'user'

start

Python
start() -> None

Start the active agent in a separate thread

stop

Python
stop() -> None

Stop the active agent

get_conversation_history

Python
get_conversation_history() -> List[Dict[str, Any]]

Get the full conversation history

clear_conversation_history

Python
clear_conversation_history() -> None

Clear the conversation history

update_config

Python
update_config(new_config: Dict[str, Any]) -> None

Update agent configuration

Parameters:

Name Type Description Default
new_config Dict[str, Any]

Dictionary containing configuration updates

required

set_context

Python
set_context(key: str, value: Any) -> None

Set a context value

get_context

Python
get_context(key: str, default: Any = None) -> Any

Get a context value

is_active

Python
is_active() -> bool

Check if the agent is currently running

__enter__

Python
__enter__()

Context manager entry

__exit__

Python
__exit__(exc_type, exc_val, exc_tb)

Context manager exit