crv.core.ids
Experimental API
crv.core.ids
Typed identifiers used across core schemas and table rows.
Responsibilities
- Provide NewType wrappers for domain identifiers (RunId, AgentId, TokenId, VenueId, SignatureId).
- Expose a helper make_run_id(prefix) that enforces lower_snake prefixes and adds a short hex suffix.
- Document naming constraints for serialized fields (lower_snake) used by schemas and descriptors.
Zero-IO Guarantee - This module has no side effects and uses only stdlib.
Downstream usage
- Schemas and descriptors use these types for intent clarity and static checking.
- make_run_id(prefix) ensures lower_snake namespaces and short, human-scannable suffixes.
Typical usage by table/row - messages: sender_agent_id: AgentId; token_id: TokenId (optional in some contexts) - exchange: venue_id: VenueId; token_id: TokenId; actor_agent_id: AgentId - identity_edges (unified): subject_id/object_id/related_agent_id: AgentId (or TokenId for object slots per schema) - decisions: agent_id: AgentId - oracle_calls: agent_id: AgentId; signature_id: SignatureId; persona_id: str (free-form label) - scenarios_seen: observer_agent_id: AgentId; token_id: TokenId - runs/manifests (outside core tables, e.g. crv.io): run_id: RunId
Naming Policy
- All serialized field names are lower_snake (enforced in schema validators).
- ID string contents are generally free-form but should be stable and lowercase.
When generated by helpers here, IDs follow <prefix>_[0-9a-f]{6}.
Examples
Create a namespaced run id and validate the pattern:
from crv.core.ids import make_run_id rid = make_run_id("run") rid.startswith("run_") and len(rid.split("_")[1]) == 6 True
Enforce lower_snake prefixes:
from crv.core.ids import make_run_id try: ... make_run_id("NotLower") ... except ValueError: ... ok = True ok True
Tags
ids, typing, lower_snake, run-id, schemas
crv.core.ids.make_run_id
Create a short, human-scannable run identifier.
Format
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Lower_snake prefix for the ID namespace. Defaults to "run". Must satisfy the core grammar lower_snake policy. |
'run'
|
Returns:
| Name | Type | Description |
|---|---|---|
RunId |
crv.core.ids.RunId
|
Newly created run identifier string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided prefix is not lower_snake. |
Notes
- Uses
secrets.token_hex(3)for 24 bits of entropy (6 hex chars). - This function does not attempt global uniqueness; callers should supply additional disambiguation if needed at higher layers.