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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
//! # `Functions` and `AsyncFunctions` traits.
//!
//! These traits define special functions for agents.
//!
//! # Examples
//!
//! ```rust
//! use autogpt::agents::agent::AgentGPT;
//! use autogpt::common::utils::Task;
//! use anyhow::Result;
//! use autogpt::traits::functions::Functions;
//! use autogpt::traits::functions::AsyncFunctions;
//! use autogpt::traits::functions::ReqResponse;
//! use autogpt::common::utils::Communication;
//! use autogpt::prelude::async_trait;
//! use std::borrow::Cow;
//!
//!
//! /// A struct implementing the `Functions` trait.
//! struct SpecialFunctions {
//! agent: AgentGPT,
//! }
//!
//! impl SpecialFunctions {
//! /// Creates a new instance of `SpecialFunctions`.
//! ///
//! /// # Arguments
//! ///
//! /// * `agent` - The agent to associate with the functions.
//! fn new(agent: AgentGPT) -> Self {
//! SpecialFunctions { agent }
//! }
//! }
//!
//! impl Functions for SpecialFunctions {
//! /// Get fields from an agent.
//! ///
//! /// # Returns
//! ///
//! /// A reference to the agent.
//! fn get_agent(&self) -> &AgentGPT {
//! &self.agent
//! }
//! }
//!
//! #[async_trait]
//! impl AsyncFunctions for SpecialFunctions {
//! /// Execute special functions for an agent.
//! ///
//! /// # Arguments
//! ///
//! /// * `tasks` - The tasks associated with the agent.
//! /// * `execute` - A boolean indicating whether to execute the generated code by the agent.
//! /// * `max_tries` - A integer indicating the max number of tries fixing code bugs.
//! ///
//! /// # Returns
//! ///
//! /// A result indicating success or failure.
//! async fn execute<'a>(
//! &'a mut self,
//! tasks: &'a mut Task,
//! _execute: bool,
//! _browse: bool,
//! _max_tries: u64,
//! ) -> Result<()> {
//! Ok(())
//! }
//!
//! /// Saves a communication to long-term memory for the agent.
//! ///
//! /// # Arguments
//! ///
//! /// * `communication` - The communication to save, which contains the role and content.
//! ///
//! /// # Returns
//! ///
//! /// (`Result<()>`): Result indicating the success or failure of saving the communication.
//! async fn save_ltm(&mut self, _communication: Communication) -> Result<()> {
//! Ok(())
//! }
//!
//! /// Retrieves all communications stored in the agent's long-term memory.
//! ///
//! /// # Returns
//! ///
//! /// (`Result<Vec<Communication>>`): A result containing a vector of communications retrieved from the agent's long-term memory.
//! async fn get_ltm(&self) -> Result<Vec<Communication>> {
//! Ok(vec![
//! Communication {
//! role: Cow::Borrowed("system"),
//! content: Cow::Borrowed("System initialized."),
//! },
//! Communication {
//! role: Cow::Borrowed("user"),
//! content: Cow::Borrowed("Hello, autogpt!"),
//! },
//! ])
//! }
//!
//! /// Retrieves the concatenated context of all communications in the agent's long-term memory.
//! ///
//! /// # Returns
//! ///
//! /// (`String`): A string containing the concatenated role and content of all communications stored in the agent's long-term memory.
//! async fn ltm_context(&self) -> String {
//! let comms = [
//! Communication {
//! role: Cow::Borrowed("system"),
//! content: Cow::Borrowed("System initialized."),
//! },
//! Communication {
//! role: Cow::Borrowed("user"),
//! content: Cow::Borrowed("Hello, autogpt!"),
//! },
//! ];
//!
//! comms
//! .iter()
//! .map(|c| format!("{}: {}", c.role, c.content))
//! .collect::<Vec<_>>()
//! .join("\n")
//! }
//!
//! async fn generate(&mut self, _request: &str) -> Result<String> {
//! Ok("".to_string())
//! }
//!
//! async fn imagen(&mut self, _request: &str) -> Result<Vec<u8>> {
//! // TODO: Impl
//! Ok(Default::default())
//! }
//!
//! async fn stream(&mut self, _request: &str) -> Result<ReqResponse> {
//! // TODO: Impl
//! Ok(ReqResponse(None))
//! }
//! }
//!
use crateAgentGPT;
use crateCommunication;
use crate;
use Result;
use async_trait;
use Response;
;
/// Trait to retrieve an agent.
/// Trait defining special functions for agents.\