agent_tk/
decision.rs

1//! This module handle the decision for the agent.
2
3use crate::{agent, delegation, execution, module, uuid};
4
5pub mod default;
6
7//  ___                   _   __  __
8// |_ _|_ __  _ __  _   _| |_|  \/  | ___  ___ ___  __ _  __ _  ___
9//  | || '_ \| '_ \| | | | __| |\/| |/ _ \/ __/ __|/ _` |/ _` |/ _ \
10//  | || | | | |_) | |_| | |_| |  | |  __/\__ \__ \ (_| | (_| |  __/
11// |___|_| |_| .__/ \__,_|\__|_|  |_|\___||___/___/\__,_|\__, |\___|
12//           |_|                                         |___/
13
14/// Input messages to the decision module
15#[derive(Clone)]
16pub enum InputMessage
17{
18  /// Request to take a decision on a CFP
19  DecideCFPAcceptance
20  {
21    /// CFP
22    cfp: delegation::CFP,
23  },
24  /// Queue the execution of a task
25  QueueExecution
26  {
27    /// uuid of the task
28    uuid: uuid::Uuid,
29    /// Uri of the requester agent
30    requester_uri: String,
31  },
32  /// Cancel the execution of a task
33  CancelExecution
34  {
35    /// uuid of the task
36    uuid: uuid::Uuid,
37  },
38}
39
40//   ___        _               _   __  __
41//  / _ \ _   _| |_ _ __  _   _| |_|  \/  | ___  ___ ___  __ _  __ _  ___
42// | | | | | | | __| '_ \| | | | __| |\/| |/ _ \/ __/ __|/ _` |/ _` |/ _ \
43// | |_| | |_| | |_| |_) | |_| | |_| |  | |  __/\__ \__ \ (_| | (_| |  __/
44//  \___/ \__,_|\__| .__/ \__,_|\__|_|  |_|\___||___/___/\__,_|\__, |\___|
45//                 |_|                                         |___/
46
47/// Output messages of the decision module
48#[derive(Clone)]
49pub enum OutputMessage
50{
51  /// Proposal for a CFP
52  CFPProposal
53  {
54    /// Proposal for a CFP
55    proposal: delegation::Proposal,
56  },
57  /// Result of queuing the execution of a task
58  QueueExecutionResult
59  {
60    /// uuid of the task
61    uuid: uuid::Uuid,
62    /// Uri of the requester agent
63    requester_uri: String,
64    /// True if the execution was accepted and queued
65    accepted: bool,
66  },
67}
68
69//  __  __           _       _      ___       _             __
70// |  \/  | ___   __| |_   _| | ___|_ _|_ __ | |_ ___ _ __ / _| __ _  ___ ___
71// | |\/| |/ _ \ / _` | | | | |/ _ \| || '_ \| __/ _ \ '__| |_ / _` |/ __/ _ \
72// | |  | | (_) | (_| | |_| | |  __/| || | | | ||  __/ |  |  _| (_| | (_|  __/
73// |_|  |_|\___/ \__,_|\__,_|_|\___|___|_| |_|\__\___|_|  |_|  \__,_|\___\___|
74
75/// Module interface for the decision module
76pub type ModuleInterface = module::ModuleInterface<InputMessage, OutputMessage>;
77
78//  __  __           _       _
79// |  \/  | ___   __| |_   _| | ___
80// | |\/| |/ _ \ / _` | | | | |/ _ \
81// | |  | | (_) | (_| | |_| | |  __/
82// |_|  |_|\___/ \__,_|\__,_|_|\___|
83
84/// Trait to define the interface to decision module
85pub trait Module:
86  module::Module<InputMessage = InputMessage, OutputMessage = OutputMessage> + Sized
87{
88  /// Options structure used to start the decision module
89  type Options;
90  /// Create a new delegation module
91  fn start(
92    agent_data: agent::AgentData,
93    module_interfaces: (ModuleInterface, Self::ModulePrivateInterface),
94    execution_interface: execution::ModuleInterface,
95    options: Self::Options,
96  ) -> impl std::future::Future<Output = ()> + std::marker::Send + 'static;
97}