Skip to content

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 key
  • agent_id: UUID, foreign key referencing the agents table
  • stack_id: UUID, foreign key referencing the stacks table

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_id and stack_id must be valid, non-nil UUIDs.
  • There is a unique constraint on the combination of agent_id and stack_id to prevent duplicate associations.

pub

Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema

Represents an agent target in the database.

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.

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema

Represents a new agent target to be inserted into the database.

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.

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 })
}