brokkr-models::models::agent_labels
Rust
Agent Label Module
This module defines structures and methods for managing agent labels in the system.
Data Model
Agent labels are used to categorize and organize agents. They are stored in the agent_labels table
with the following structure:
id: UUID, primary keyagent_id: UUID, foreign key referencing theagentstablelabel: VARCHAR(255), the label associated with the agent
Usage
Agent labels can be used to group agents, filter them, or provide additional metadata. This can be useful for organizing agents based on their roles, environments, or any other relevant categorization.
Constraints
- The
agent_idmust be a valid, non-nil UUID. - The
labelmust be a non-empty string. - The
labelmust not exceed 64 characters. - The
labelcannot contain whitespace.
Structs
Section titled “Structs”struct AgentLabel
Section titled “struct AgentLabel”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema
Represents an agent label in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the agent label. |
agent_id |
Uuid |
ID of the agent this label is associated with. |
label |
String |
The label text (max 64 characters, no whitespace). |
struct NewAgentLabel
Section titled “struct NewAgentLabel”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new agent label to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
ID of the agent this label is associated with. |
label |
String |
The label text (max 64 characters, no whitespace). |
Methods
Section titled “Methods”pub
fn new(agent_id: Uuid, label: String) -> Result<Self, String>Creates a new NewAgentLabel instance.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
UUID of the agent to associate the label with. |
label |
String |
The label text. Must be non-empty, max 64 characters, and contain no whitespace. |
Returns:
Returns Ok(NewAgentLabel) if all parameters are valid, otherwise returns an Err with a description of the validation failure.
Source
pub fn new(agent_id: Uuid, label: String) -> Result<Self, String> { // Validate agent_id if agent_id.is_nil() { return Err("Invalid agent ID".to_string()); }
// Validate label if label.is_empty() { return Err("Label cannot be empty".to_string()); } if label.len() > 64 { return Err("Label cannot exceed 64 characters".to_string()); } if label.contains(char::is_whitespace) { return Err("Label cannot contain whitespace".to_string()); }
Ok(NewAgentLabel { agent_id, label }) }