Package com.ants.platform.client.core
Class AgentIdGenerator
java.lang.Object
com.ants.platform.client.core.AgentIdGenerator
Generates deterministic agent IDs using BLAKE2b-64 hashing.
Formula: agent_id = BLAKE2b-64(agent_name + project_id)
Key Design Decision: Include project_id in hash for transfer safety
- When projects transfer between organizations, projectId stays constant
- organizationId changes, but projectId doesn't
- Result: agent_id remains stable across transfers
Properties:
- Deterministic: Same inputs always produce the same agent_id
- Collision-resistant: BLAKE2b provides cryptographic guarantees
- Compact: 16 hex characters (64 bits of entropy)
- Fast: ~1 microsecond per hash
Example:
String agentId = AgentIdGenerator.generateAgentId("qa_agent", "proj-customer-support");
// Result: "1fdb77db0603771f" (deterministic 16-char hex)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLength of the generated agent ID in hex characters. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateAgentId(String agentName, String projectId) Generates a deterministic agent ID using BLAKE2b-64.
-
Field Details
-
AGENT_ID_LENGTH
public static final int AGENT_ID_LENGTHLength of the generated agent ID in hex characters. BLAKE2b-64 produces 8 bytes = 16 hex characters.- See Also:
-
-
Method Details
-
generateAgentId
Generates a deterministic agent ID using BLAKE2b-64.The agent_id is generated by hashing agent_name followed by project_id. This matches the Python SDK implementation:
hasher = hashlib.blake2b(digest_size=8) hasher.update(agent_name.encode('utf-8')) hasher.update(project_id.encode('utf-8')) agent_id = hasher.hexdigest()- Parameters:
agentName- the agent name (must be a non-empty string)projectId- the project ID (must be a non-empty string)- Returns:
- a 16-character hex string representing the agent ID
- Throws:
IllegalArgumentException- if any parameter is null or empty
-