agenticmem 0.1.4.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agenticmem-0.1.4.5/PKG-INFO +86 -0
- agenticmem-0.1.4.5/README.md +61 -0
- agenticmem-0.1.4.5/agenticmem/__init__.py +96 -0
- agenticmem-0.1.4.5/agenticmem/cache.py +125 -0
- agenticmem-0.1.4.5/agenticmem/client.py +1358 -0
- agenticmem-0.1.4.5/agenticmem/client_utils.py +12 -0
- agenticmem-0.1.4.5/pyproject.toml +32 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: agenticmem
|
|
3
|
+
Version: 0.1.4.5
|
|
4
|
+
Summary: A Python client for the AgenticMem API
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: AgenticMem Team
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: agenticmem-commons (==0.1.4.5)
|
|
15
|
+
Requires-Dist: aiohttp (>=3.12.9,<4.0.0)
|
|
16
|
+
Requires-Dist: griffe (==0.48.0)
|
|
17
|
+
Requires-Dist: mkdocs-with-pdf (>=0.9.3,<0.10.0)
|
|
18
|
+
Requires-Dist: mkdocstrings[python] (>=0.18.0)
|
|
19
|
+
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
|
|
20
|
+
Requires-Dist: python-dateutil (>=2.8.0,<3.0.0)
|
|
21
|
+
Requires-Dist: requests (>=2.25.0,<3.0.0)
|
|
22
|
+
Requires-Dist: weasyprint (>=66.0,<67.0)
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# /user_profiler/agenticmem/agenticmem_client
|
|
26
|
+
Description: Python SDK for remote async access to AgenticMem API
|
|
27
|
+
|
|
28
|
+
## Main Entry Points
|
|
29
|
+
|
|
30
|
+
- **Client**: `agenticmem/client.py` - `AgenticMemClient`
|
|
31
|
+
- **Utils**: `agenticmem/client_utils.py` - Helper utilities
|
|
32
|
+
|
|
33
|
+
## Purpose
|
|
34
|
+
|
|
35
|
+
1. **Remote API access** - Async SDK for applications to call AgenticMem backend
|
|
36
|
+
2. **Authentication** - Handle login and Bearer token management
|
|
37
|
+
3. **Type-safe interface** - Auto-parsing responses into Pydantic models
|
|
38
|
+
|
|
39
|
+
## API Methods
|
|
40
|
+
|
|
41
|
+
**Authentication:**
|
|
42
|
+
- `login(email, password)` - Get auth token
|
|
43
|
+
|
|
44
|
+
**Publishing:**
|
|
45
|
+
- `publish_interaction(request_id, user_id, interactions, source, agent_version)` - Publish interactions (triggers profile/feedback/evaluation)
|
|
46
|
+
|
|
47
|
+
**Profiles:**
|
|
48
|
+
- `search_profiles(request)` - Semantic search
|
|
49
|
+
- `get_profiles(request)` - Get all for user
|
|
50
|
+
- `get_all_profiles(limit, status_filter)` - Get all profiles across all users
|
|
51
|
+
- `delete_profile(user_id, profile_id, search_query)` - Delete profiles
|
|
52
|
+
- `get_profile_change_log()` - Get history
|
|
53
|
+
- `rerun_profile_generation(request)` - Regenerate profiles from interactions
|
|
54
|
+
|
|
55
|
+
**Interactions:**
|
|
56
|
+
- `search_interactions(request)` - Semantic search
|
|
57
|
+
- `get_interactions(request)` - Get all for user
|
|
58
|
+
- `delete_interaction(user_id, interaction_id)` - Delete interaction
|
|
59
|
+
|
|
60
|
+
**Requests:**
|
|
61
|
+
- `get_requests(request)` - Get request groups with associated interactions
|
|
62
|
+
- `delete_request(request_id)` - Delete a request and its interactions
|
|
63
|
+
- `delete_request_group(request_group)` - Delete all requests in a group
|
|
64
|
+
|
|
65
|
+
**Feedback:**
|
|
66
|
+
- `get_raw_feedbacks(request)` - Raw feedback from interactions
|
|
67
|
+
- `add_raw_feedback(request)` - Add raw feedback directly to storage
|
|
68
|
+
- `get_feedbacks(request)` - Aggregated feedback with status
|
|
69
|
+
- `rerun_feedback_generation(request)` - Regenerate feedback for agent version
|
|
70
|
+
- `run_feedback_aggregation(request)` - Aggregate raw feedbacks into insights
|
|
71
|
+
|
|
72
|
+
**Evaluation:**
|
|
73
|
+
- `get_agent_success_evaluation_results(request)` - Get agent success evaluation results
|
|
74
|
+
|
|
75
|
+
**Configuration:**
|
|
76
|
+
- `set_config(config)` - Update org config (extractors, evaluators, storage)
|
|
77
|
+
- `get_config()` - Get current config
|
|
78
|
+
|
|
79
|
+
## Architecture Pattern
|
|
80
|
+
|
|
81
|
+
- **All async** - Uses `aiohttp` for HTTP requests
|
|
82
|
+
- **Type-safe** - Pydantic models from `agenticmem_commons`
|
|
83
|
+
- **Auto-parsing** - Responses → Pydantic models
|
|
84
|
+
- **Flexible input** - Accepts Pydantic models or dicts
|
|
85
|
+
- **Bearer auth** - Automatic token handling
|
|
86
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# /user_profiler/agenticmem/agenticmem_client
|
|
2
|
+
Description: Python SDK for remote async access to AgenticMem API
|
|
3
|
+
|
|
4
|
+
## Main Entry Points
|
|
5
|
+
|
|
6
|
+
- **Client**: `agenticmem/client.py` - `AgenticMemClient`
|
|
7
|
+
- **Utils**: `agenticmem/client_utils.py` - Helper utilities
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
1. **Remote API access** - Async SDK for applications to call AgenticMem backend
|
|
12
|
+
2. **Authentication** - Handle login and Bearer token management
|
|
13
|
+
3. **Type-safe interface** - Auto-parsing responses into Pydantic models
|
|
14
|
+
|
|
15
|
+
## API Methods
|
|
16
|
+
|
|
17
|
+
**Authentication:**
|
|
18
|
+
- `login(email, password)` - Get auth token
|
|
19
|
+
|
|
20
|
+
**Publishing:**
|
|
21
|
+
- `publish_interaction(request_id, user_id, interactions, source, agent_version)` - Publish interactions (triggers profile/feedback/evaluation)
|
|
22
|
+
|
|
23
|
+
**Profiles:**
|
|
24
|
+
- `search_profiles(request)` - Semantic search
|
|
25
|
+
- `get_profiles(request)` - Get all for user
|
|
26
|
+
- `get_all_profiles(limit, status_filter)` - Get all profiles across all users
|
|
27
|
+
- `delete_profile(user_id, profile_id, search_query)` - Delete profiles
|
|
28
|
+
- `get_profile_change_log()` - Get history
|
|
29
|
+
- `rerun_profile_generation(request)` - Regenerate profiles from interactions
|
|
30
|
+
|
|
31
|
+
**Interactions:**
|
|
32
|
+
- `search_interactions(request)` - Semantic search
|
|
33
|
+
- `get_interactions(request)` - Get all for user
|
|
34
|
+
- `delete_interaction(user_id, interaction_id)` - Delete interaction
|
|
35
|
+
|
|
36
|
+
**Requests:**
|
|
37
|
+
- `get_requests(request)` - Get request groups with associated interactions
|
|
38
|
+
- `delete_request(request_id)` - Delete a request and its interactions
|
|
39
|
+
- `delete_request_group(request_group)` - Delete all requests in a group
|
|
40
|
+
|
|
41
|
+
**Feedback:**
|
|
42
|
+
- `get_raw_feedbacks(request)` - Raw feedback from interactions
|
|
43
|
+
- `add_raw_feedback(request)` - Add raw feedback directly to storage
|
|
44
|
+
- `get_feedbacks(request)` - Aggregated feedback with status
|
|
45
|
+
- `rerun_feedback_generation(request)` - Regenerate feedback for agent version
|
|
46
|
+
- `run_feedback_aggregation(request)` - Aggregate raw feedbacks into insights
|
|
47
|
+
|
|
48
|
+
**Evaluation:**
|
|
49
|
+
- `get_agent_success_evaluation_results(request)` - Get agent success evaluation results
|
|
50
|
+
|
|
51
|
+
**Configuration:**
|
|
52
|
+
- `set_config(config)` - Update org config (extractors, evaluators, storage)
|
|
53
|
+
- `get_config()` - Get current config
|
|
54
|
+
|
|
55
|
+
## Architecture Pattern
|
|
56
|
+
|
|
57
|
+
- **All async** - Uses `aiohttp` for HTTP requests
|
|
58
|
+
- **Type-safe** - Pydantic models from `agenticmem_commons`
|
|
59
|
+
- **Auto-parsing** - Responses → Pydantic models
|
|
60
|
+
- **Flexible input** - Accepts Pydantic models or dicts
|
|
61
|
+
- **Bearer auth** - Automatic token handling
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
2
|
+
|
|
3
|
+
__app_name__ = "agenticmem"
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = version(__app_name__)
|
|
7
|
+
except PackageNotFoundError:
|
|
8
|
+
# Package is not installed (e.g., running from source without installing)
|
|
9
|
+
__version__ = "0.0.0-dev"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from .client import AgenticMemClient
|
|
13
|
+
from agenticmem_commons.api_schema.service_schemas import (
|
|
14
|
+
UserActionType,
|
|
15
|
+
ProfileTimeToLive,
|
|
16
|
+
InteractionData,
|
|
17
|
+
Interaction,
|
|
18
|
+
UserProfile,
|
|
19
|
+
PublishUserInteractionRequest,
|
|
20
|
+
PublishUserInteractionResponse,
|
|
21
|
+
DeleteUserProfileRequest,
|
|
22
|
+
DeleteUserProfileResponse,
|
|
23
|
+
DeleteUserInteractionRequest,
|
|
24
|
+
DeleteUserInteractionResponse,
|
|
25
|
+
RawFeedback,
|
|
26
|
+
AddRawFeedbackRequest,
|
|
27
|
+
AddRawFeedbackResponse,
|
|
28
|
+
RerunProfileGenerationRequest,
|
|
29
|
+
RerunProfileGenerationResponse,
|
|
30
|
+
RerunFeedbackGenerationRequest,
|
|
31
|
+
RerunFeedbackGenerationResponse,
|
|
32
|
+
Status,
|
|
33
|
+
FeedbackStatus,
|
|
34
|
+
)
|
|
35
|
+
from agenticmem_commons.api_schema.retriever_schema import (
|
|
36
|
+
SearchInteractionRequest,
|
|
37
|
+
SearchUserProfileRequest,
|
|
38
|
+
SearchInteractionResponse,
|
|
39
|
+
SearchUserProfileResponse,
|
|
40
|
+
)
|
|
41
|
+
from agenticmem_commons.config_schema import (
|
|
42
|
+
StorageConfigTest,
|
|
43
|
+
StorageConfigLocal,
|
|
44
|
+
StorageConfigS3,
|
|
45
|
+
StorageConfigSupabase,
|
|
46
|
+
StorageConfig,
|
|
47
|
+
ProfileExtractorConfig,
|
|
48
|
+
FeedbackAggregatorConfig,
|
|
49
|
+
AgentFeedbackConfig,
|
|
50
|
+
AgentSuccessConfig,
|
|
51
|
+
ToolUseConfig,
|
|
52
|
+
Config,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
debug = False
|
|
56
|
+
log = None # Set to either 'debug' or 'info', controls console logging
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
__all__ = [
|
|
60
|
+
"AgenticMemClient",
|
|
61
|
+
"UserActionType",
|
|
62
|
+
"ProfileTimeToLive",
|
|
63
|
+
"InteractionData",
|
|
64
|
+
"Interaction",
|
|
65
|
+
"UserProfile",
|
|
66
|
+
"PublishUserInteractionRequest",
|
|
67
|
+
"PublishUserInteractionResponse",
|
|
68
|
+
"DeleteUserProfileRequest",
|
|
69
|
+
"DeleteUserProfileResponse",
|
|
70
|
+
"DeleteUserInteractionRequest",
|
|
71
|
+
"DeleteUserInteractionResponse",
|
|
72
|
+
"RawFeedback",
|
|
73
|
+
"AddRawFeedbackRequest",
|
|
74
|
+
"AddRawFeedbackResponse",
|
|
75
|
+
"RerunProfileGenerationRequest",
|
|
76
|
+
"RerunProfileGenerationResponse",
|
|
77
|
+
"RerunFeedbackGenerationRequest",
|
|
78
|
+
"RerunFeedbackGenerationResponse",
|
|
79
|
+
"SearchInteractionRequest",
|
|
80
|
+
"SearchUserProfileRequest",
|
|
81
|
+
"SearchInteractionResponse",
|
|
82
|
+
"SearchUserProfileResponse",
|
|
83
|
+
"StorageConfigTest",
|
|
84
|
+
"StorageConfigLocal",
|
|
85
|
+
"StorageConfigS3",
|
|
86
|
+
"StorageConfigSupabase",
|
|
87
|
+
"StorageConfig",
|
|
88
|
+
"ProfileExtractorConfig",
|
|
89
|
+
"FeedbackAggregatorConfig",
|
|
90
|
+
"AgentFeedbackConfig",
|
|
91
|
+
"AgentSuccessConfig",
|
|
92
|
+
"ToolUseConfig",
|
|
93
|
+
"Config",
|
|
94
|
+
"Status",
|
|
95
|
+
"FeedbackStatus",
|
|
96
|
+
]
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""In-memory cache module for AgenticMem client."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import threading
|
|
6
|
+
from datetime import datetime, timedelta
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class InMemoryCache:
|
|
11
|
+
"""
|
|
12
|
+
Thread-safe in-memory cache with time-based expiration.
|
|
13
|
+
|
|
14
|
+
Stores function results in memory to avoid redundant API calls.
|
|
15
|
+
Cache entries expire after a specified TTL (default: 10 minutes).
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, ttl_seconds: int = 600):
|
|
19
|
+
"""
|
|
20
|
+
Initialize the in-memory cache.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
ttl_seconds (int): Time-to-live for cache entries in seconds. Default is 600 (10 minutes).
|
|
24
|
+
"""
|
|
25
|
+
self._cache: dict[str, dict[str, Any]] = {}
|
|
26
|
+
self._lock = threading.Lock()
|
|
27
|
+
self._ttl_seconds = ttl_seconds
|
|
28
|
+
|
|
29
|
+
def _generate_cache_key(self, method_name: str, **kwargs) -> str:
|
|
30
|
+
"""
|
|
31
|
+
Generate a unique cache key from method name and parameters.
|
|
32
|
+
|
|
33
|
+
Handles datetime objects, None values, and nested dictionaries.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
method_name (str): Name of the cached method
|
|
37
|
+
**kwargs: Method parameters to include in the cache key
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
str: Unique cache key hash
|
|
41
|
+
"""
|
|
42
|
+
# Create a normalized representation of the parameters
|
|
43
|
+
normalized_params = {}
|
|
44
|
+
for key, value in sorted(kwargs.items()):
|
|
45
|
+
if isinstance(value, datetime):
|
|
46
|
+
# Convert datetime to ISO format string
|
|
47
|
+
normalized_params[key] = value.isoformat()
|
|
48
|
+
elif value is None:
|
|
49
|
+
normalized_params[key] = None
|
|
50
|
+
elif hasattr(value, "model_dump"):
|
|
51
|
+
# Handle Pydantic models
|
|
52
|
+
normalized_params[key] = value.model_dump()
|
|
53
|
+
elif isinstance(value, dict):
|
|
54
|
+
normalized_params[key] = value
|
|
55
|
+
else:
|
|
56
|
+
normalized_params[key] = value
|
|
57
|
+
|
|
58
|
+
# Create a stable JSON representation
|
|
59
|
+
key_data = {"method": method_name, "params": normalized_params}
|
|
60
|
+
key_string = json.dumps(key_data, sort_keys=True, default=str)
|
|
61
|
+
|
|
62
|
+
# Generate hash for the cache key
|
|
63
|
+
return hashlib.sha256(key_string.encode()).hexdigest()
|
|
64
|
+
|
|
65
|
+
def get(self, method_name: str, **kwargs) -> Optional[Any]:
|
|
66
|
+
"""
|
|
67
|
+
Retrieve a cached value if it exists and is not expired.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
method_name (str): Name of the cached method
|
|
71
|
+
**kwargs: Method parameters used to generate cache key
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Optional[Any]: Cached value if found and valid, None otherwise
|
|
75
|
+
"""
|
|
76
|
+
cache_key = self._generate_cache_key(method_name, **kwargs)
|
|
77
|
+
|
|
78
|
+
with self._lock:
|
|
79
|
+
if cache_key not in self._cache:
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
entry = self._cache[cache_key]
|
|
83
|
+
|
|
84
|
+
# Check if entry has expired
|
|
85
|
+
if datetime.now() > entry["expires_at"]:
|
|
86
|
+
# Remove expired entry
|
|
87
|
+
del self._cache[cache_key]
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
return entry["data"]
|
|
91
|
+
|
|
92
|
+
def set(self, method_name: str, value: Any, **kwargs) -> None:
|
|
93
|
+
"""
|
|
94
|
+
Store a value in the cache with automatic expiration.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
method_name (str): Name of the cached method
|
|
98
|
+
value (Any): Value to cache
|
|
99
|
+
**kwargs: Method parameters used to generate cache key
|
|
100
|
+
"""
|
|
101
|
+
cache_key = self._generate_cache_key(method_name, **kwargs)
|
|
102
|
+
|
|
103
|
+
with self._lock:
|
|
104
|
+
self._cache[cache_key] = {
|
|
105
|
+
"data": value,
|
|
106
|
+
"timestamp": datetime.now(),
|
|
107
|
+
"expires_at": datetime.now() + timedelta(seconds=self._ttl_seconds),
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
# Cleanup expired entries periodically (every 100 sets)
|
|
111
|
+
if len(self._cache) % 100 == 0:
|
|
112
|
+
self._cleanup_expired()
|
|
113
|
+
|
|
114
|
+
def _cleanup_expired(self) -> None:
|
|
115
|
+
"""
|
|
116
|
+
Remove all expired entries from the cache.
|
|
117
|
+
|
|
118
|
+
Note: This method assumes the lock is already acquired by the caller.
|
|
119
|
+
"""
|
|
120
|
+
now = datetime.now()
|
|
121
|
+
expired_keys = [
|
|
122
|
+
key for key, entry in self._cache.items() if now > entry["expires_at"]
|
|
123
|
+
]
|
|
124
|
+
for key in expired_keys:
|
|
125
|
+
del self._cache[key]
|