-
Notifications
You must be signed in to change notification settings - Fork 1
/
agent.rs
85 lines (78 loc) 路 2.19 KB
/
agent.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! # `Agent` trait.
//!
//! This trait defines basic functionalities for agents.
//!
//! # Examples
//!
//! ```rust
//! use autogpt::common::utils::{Communication, Status};
//! use autogpt::traits::agent::Agent;
//! use std::borrow::Cow;
//!
//! /// A simple agent implementation.
//! #[derive(Debug)]
//! struct SimpleAgent {
//! objective: Cow<'static, str>,
//! position: Cow<'static, str>,
//! status: Status,
//! memory: Vec<Communication>,
//! }
//!
//! impl Agent for SimpleAgent {
//! fn new(objective: Cow<'static, str>, position: Cow<'static, str>) -> Self {
//! SimpleAgent {
//! objective,
//! position,
//! status: Status::Idle,
//! memory: Vec::new(),
//! }
//! }
//!
//! fn update(&mut self, status: Status) {
//! self.status = status;
//! }
//!
//! fn objective(&self) -> &Cow<'static, str> {
//! &self.objective
//! }
//!
//! fn position(&self) -> &Cow<'static, str> {
//! &self.position
//! }
//!
//! fn status(&self) -> &Status {
//! &self.status
//! }
//!
//! fn memory(&self) -> &Vec<Communication> {
//! &self.memory
//! }
//! }
//!
use crate::common::utils::{Communication, Status};
use std::borrow::Cow;
use std::fmt::Debug;
/// A trait defining basic functionalities for agents.
pub trait Agent: Debug {
/// Creates a new instance of an agent.
///
/// # Arguments
///
/// * `objective` - The objective of the agent.
/// * `position` - The position of the agent.
fn new(objective: Cow<'static, str>, position: Cow<'static, str>) -> Self;
/// Updates the status of the agent.
///
/// # Arguments
///
/// * `status` - The new status to be assigned to the agent.
fn update(&mut self, status: Status);
/// Retrieves the objective of the agent.
fn objective(&self) -> &Cow<'static, str>;
/// Retrieves the position of the agent.
fn position(&self) -> &Cow<'static, str>;
/// Retrieves the current status of the agent.
fn status(&self) -> &Status;
/// Retrieves the memory of the agent containing exchanged messages.
fn memory(&self) -> &Vec<Communication>;
}