brokkr-models::models::agent_targets
Rust
Agent Target Module
This module defines structures and methods for managing agent targets in the system.
Data Model
Agent targets represent the association between agents and stacks. They are stored in the
agent_targets table with the following structure:
id: UUID, primary keyagent_id: UUID, foreign key referencing theagentstablestack_id: UUID, foreign key referencing thestackstable
Usage
Agent targets are used to define which stacks an agent is responsible for or associated with. This relationship allows the system to determine which agents should interact with specific stacks, enabling efficient distribution and management of workloads across agents.
Constraints
- Both
agent_idandstack_idmust be valid, non-nil UUIDs. - There is a unique constraint on the combination of
agent_idandstack_idto prevent duplicate associations.
Structs
Section titled “Structs”struct AgentTarget
Section titled “struct AgentTarget”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema
Represents an agent target in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the agent target. |
agent_id |
Uuid |
ID of the agent associated with this target. |
stack_id |
Uuid |
ID of the stack associated with this target. |
struct NewAgentTarget
Section titled “struct NewAgentTarget”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new agent target to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
ID of the agent to associate with a stack. |
stack_id |
Uuid |
ID of the stack to associate with an agent. |
Methods
Section titled “Methods”pub
fn new(agent_id: Uuid, stack_id: Uuid) -> Result<Self, String>Creates a new NewAgentTarget instance.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
UUID of the agent to associate with a stack. |
stack_id |
Uuid |
UUID of the stack to associate with an agent. |
Returns:
Returns Ok(NewAgentTarget) if both UUIDs are valid and non-nil,
otherwise returns an Err with a description of the validation failure.
Source
pub fn new(agent_id: Uuid, stack_id: Uuid) -> Result<Self, String> { // Validate agent_id if agent_id.is_nil() { return Err("Invalid agent ID".to_string()); }
// Validate stack_id if stack_id.is_nil() { return Err("Invalid stack ID".to_string()); }
Ok(NewAgentTarget { agent_id, stack_id }) }