Open Agent Memory Protocol (OAMP) types for Python
Project description
oamp-types
Python types for the Open Agent Memory Protocol (OAMP) v1.0.0.
Built on Pydantic v2 for validation and serialization.
Install
pip install oamp-types
Quick Start
from oamp_types import (
KnowledgeEntry,
KnowledgeCategory,
KnowledgeSource,
KnowledgeStore,
UserModel,
CommunicationProfile,
ExpertiseDomain,
ExpertiseLevel,
Correction,
StatedPreference,
validate_knowledge_entry,
validate_knowledge_store,
validate_user_model,
)
# Create a knowledge entry
entry = KnowledgeEntry(
user_id="user-123",
category=KnowledgeCategory.correction,
content="Never use unwrap() — use ? operator instead",
confidence=0.98,
source=KnowledgeSource(session_id="session-42"),
)
# Validate
errors = validate_knowledge_entry(entry)
assert len(errors) == 0
# Serialize to JSON (exclude null optional fields for spec compliance)
json_str = entry.model_dump_json(exclude_none=True)
# Parse from dict or JSON
parsed = KnowledgeEntry.model_validate_json(json_str)
# Create a user model
model = UserModel(user_id="user-123")
model.communication = CommunicationProfile(
verbosity=-0.6,
formality=0.3,
prefers_examples=True,
prefers_explanations=False,
languages=["en", "de"],
)
model.expertise.append(
ExpertiseDomain(
domain="rust",
level=ExpertiseLevel.expert,
confidence=0.95,
)
)
# Bulk export
store = KnowledgeStore(user_id="user-123", entries=[entry])
Serialization
Pydantic models support multiple serialization modes:
# Exclude None values (matches Rust's skip_serializing_if = "Option::is_none")
json_str = entry.model_dump_json(exclude_none=True)
# Include all fields (useful for debugging)
json_str = entry.model_dump_json()
# Python dict output
d = entry.model_dump(exclude_none=True)
Note: For spec-compliant output, use exclude_none=True to omit optional
fields that are not set (e.g., decay, agent_id). This matches the behavior
of the Rust and TypeScript reference implementations.
Validation
Two levels of validation are provided:
Pydantic field validators (automatic)
Creating or parsing models through Pydantic automatically validates:
- Required fields must be present
oamp_versionmust be"1.0.0"typemust match the expected document typeconfidencemust be in [0.0, 1.0]- String fields must not be empty where required
- Unknown fields are rejected (
extra = "forbid") - Ranges like
verbosity(-1.0 to 1.0) andformality(-1.0 to 1.0)
Semantic validation functions (for data bypassing Pydantic)
from oamp_types import validate_knowledge_entry, validate_knowledge_store, validate_user_model
# Returns list of error strings; empty list means valid
errors = validate_knowledge_entry(entry)
if errors:
raise ValueError(f"Validation failed: {errors}")
These functions validate data that may have been constructed via
model_construct() or loaded from untrusted sources where Pydantic's
field validators were bypassed.
API
KnowledgeEntry
| Field | Type | Required | Description |
|---|---|---|---|
oamp_version |
str |
✅ | Defaults to "1.0.0" |
type |
str |
✅ | Defaults to "knowledge_entry" |
id |
str |
✅ | UUID v4, auto-generated |
user_id |
str |
✅ | User identifier |
category |
KnowledgeCategory |
✅ | fact, preference, pattern, correction |
content |
str |
✅ | Natural language knowledge |
confidence |
float |
✅ | 0.0–1.0 |
source |
KnowledgeSource |
✅ | Provenance info |
decay |
KnowledgeDecay | None |
❌ | Temporal decay params |
tags |
list[str] |
❌ | Free-form tags |
metadata |
dict[str, Any] |
❌ | Vendor extensions |
UserModel
| Field | Type | Required | Description |
|---|---|---|---|
oamp_version |
str |
✅ | Defaults to "1.0.0" |
type |
str |
✅ | Defaults to "user_model" |
user_id |
str |
✅ | User identifier |
model_version |
int |
✅ | ≥ 1, defaults to 1 |
updated_at |
datetime |
✅ | Auto-set to now (UTC) |
communication |
CommunicationProfile | None |
❌ | Communication preferences |
expertise |
list[ExpertiseDomain] |
❌ | Domain expertise |
corrections |
list[Correction] |
❌ | Agent corrections |
stated_preferences |
list[StatedPreference] |
❌ | Declared preferences |
metadata |
dict[str, Any] |
❌ | Vendor extensions |
Python Version
Requires Python ≥ 3.9. Uses str, Enum pattern for category/level enums
(available since Python 3.11 as StrEnum, backported for 3.9 compatibility).
License
MIT
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 oamp_types-1.0.1.tar.gz.
File metadata
- Download URL: oamp_types-1.0.1.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c349e3dcfe0ac5685f03b596677d5a6c54b94422e3c9422b26e095347b9c3784
|
|
| MD5 |
a1ebe8e3a74fbcaad27f8b53487bde3a
|
|
| BLAKE2b-256 |
73a8a42ff5c6cbe993fe0ab3d3937053121268793a2f9f25ede50b0395b5ef46
|
File details
Details for the file oamp_types-1.0.1-py3-none-any.whl.
File metadata
- Download URL: oamp_types-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08698d883aae7f6d84dbddf76bba8e95ba1cb7b91afd3dbc2f45cb8a64b6f347
|
|
| MD5 |
034e7fb8cbccc35ece3e324a99ddc3d8
|
|
| BLAKE2b-256 |
45e4e299245ddd915b10f457626e3efab5cbfd6f6e6c5b5ec8eeff923683b2d3
|