Core API Reference¶
This page provides detailed documentation for the core GUM module.
Main Class¶
gum.gum
¶
Attributes¶
Classes¶
gum(user_name: str, model: str, *observers: Observer, propose_prompt: str | None = None, similar_prompt: str | None = None, revise_prompt: str | None = None, audit_prompt: str | None = None, data_directory: str = '~/.cache/gum', db_name: str = 'gum.db', max_concurrent_updates: int = 4, verbosity: int = logging.INFO, audit_enabled: bool = False, api_base: str | None = None, api_key: str | None = None, session_id: str | None = None)
¶
A class for managing general user models.
This class provides functionality for observing user behavior, generating and managing propositions about user behavior, and maintaining relationships between observations and propositions.
The system uses a unified AI client that supports multiple providers: - Text completion: OpenAI (default), Azure OpenAI, Vertex AI, or Google AI Studio (Gemini API key via litellm) - Vision completion: OpenAI (default), OpenRouter, Vertex AI, or Google AI Studio (Gemini API key via litellm)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_name
|
str
|
The name of the user being modeled. |
required |
*observers
|
Observer
|
Variable number of observer instances to track user behavior. |
()
|
propose_prompt
|
str
|
Custom prompt for proposition generation. |
None
|
similar_prompt
|
str
|
Custom prompt for similarity analysis. |
None
|
revise_prompt
|
str
|
Custom prompt for proposition revision. |
None
|
audit_prompt
|
str
|
Custom prompt for auditing. |
None
|
data_directory
|
str
|
Directory for storing data. Defaults to "~/.cache/gum". |
'~/.cache/gum'
|
db_name
|
str
|
Name of the database file. Defaults to "gum.db". |
'gum.db'
|
max_concurrent_updates
|
int
|
Maximum number of concurrent updates. Defaults to 4. |
4
|
verbosity
|
int
|
Logging verbosity level. Defaults to logging.INFO. |
INFO
|
audit_enabled
|
bool
|
Whether to enable auditing. Defaults to False. |
False
|
api_base
|
str
|
Deprecated, use environment variables instead. |
None
|
api_key
|
str
|
Deprecated, use environment variables instead. |
None
|
Source code in gum/gum.py
Attributes¶
Session = None
instance-attribute
¶
ai_client = None
instance-attribute
¶
audit_enabled = audit_enabled
instance-attribute
¶
audit_prompt = audit_prompt or AUDIT_PROMPT
instance-attribute
¶
engine = None
instance-attribute
¶
logger = logging.getLogger('gum')
instance-attribute
¶
model = model
instance-attribute
¶
observers: list[Observer] = list(observers)
instance-attribute
¶
propose_prompt = propose_prompt or PROPOSE_PROMPT
instance-attribute
¶
revise_prompt = revise_prompt or REVISE_PROMPT
instance-attribute
¶
session_id = session_id
instance-attribute
¶
similar_prompt = similar_prompt or SIMILAR_PROMPT
instance-attribute
¶
update_handlers: list[Callable[[Observer, Update], None]] = []
instance-attribute
¶
user_name = user_name
instance-attribute
¶
Functions¶
__aenter__()
async
¶
Async context manager entry point.
Returns:
| Name | Type | Description |
|---|---|---|
gum |
The instance of the gum class. |
__aexit__(exc_type, exc, tb)
async
¶
Async context manager exit point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
The type of exception if any. |
required | |
exc
|
The exception instance if any. |
required | |
tb
|
The traceback if any. |
required |
Source code in gum/gum.py
add_observer(observer: Observer)
¶
Add an observer to track user behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observer
|
Observer
|
The observer to add. |
required |
connect_db()
async
¶
Initialize the database connection if not already connected.
Source code in gum/gum.py
drain_background_tasks() -> None
async
¶
Wait for any background tasks spawned by pipeline processing.
process_update(observer: Observer | str, update: Update, *, run_stage: str = 'through-suggestions') -> Observation
async
¶
Process one update through a selected pipeline boundary.
Source code in gum/gum.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 | |
query(user_query: str, *, limit: int = 3, mode: str = 'OR', start_time: datetime | None = None, end_time: datetime | None = None) -> list[tuple[Proposition, float]]
async
¶
Query the database for propositions matching the user query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_query
|
str
|
The query string to search for. |
required |
limit
|
int
|
Maximum number of results to return. Defaults to 3. |
3
|
mode
|
str
|
Search mode ("OR" or "AND"). Defaults to "OR". |
'OR'
|
start_time
|
datetime
|
Start time for filtering results. Defaults to None. |
None
|
end_time
|
datetime
|
End time for filtering results. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[Proposition, float]]
|
list[tuple[Proposition, float]]: List of tuples containing propositions and their relevance scores. |
Source code in gum/gum.py
register_update_handler(fn: Callable[[Observer, Update], None])
¶
Register a custom update handler function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[Observer, Update], None]
|
The handler function to register. |
required |
remove_observer(observer: Observer)
¶
Remove an observer from tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observer
|
Observer
|
The observer to remove. |
required |
start_update_loop()
¶
Start the asynchronous update loop for processing observer updates.
stop_update_loop()
async
¶
Stop the asynchronous update loop and clean up resources.