autogpt 0.4.1

🦀 A Pure Rust Framework For Building AGIs.
Documentation
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[cfg(feature = "cli")]
use colored::Colorize;
#[cfg(feature = "cli")]
use indicatif::{ProgressBar, ProgressStyle};
#[cfg(feature = "cli")]
use std::time::Duration;
#[cfg(feature = "cli")]
use termimad::{MadSkin, crossterm::style::Color};
#[cfg(feature = "cli")]
use tracing::{error, info, warn};

/// Terminal width used for box drawings.
#[cfg(feature = "cli")]
const BOX_WIDTH: usize = 80;

#[cfg(feature = "cli")]
pub use crate::cli::models::ProviderModel;

/// Status variants for task progress indicators.
#[cfg(feature = "cli")]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TaskStatus {
    Pending,
    InProgress,
    Completed,
    Failed,
    Skipped,
}

/// Prints the AutoGPT gradient pixel-art ASCII banner.
///
/// Each column of the banner is coloured across a hot-pink → lavender → cyan gradient
/// using `colored`'s true-colour support, giving visual depth similar to the Gemini CLI.
#[cfg(feature = "cli")]
pub fn print_banner() {
    let logo_lines = [
        " █████╗ ██╗   ██╗████████╗ ██████╗  ██████╗ ██████╗ ████████╗",
        "██╔══██╗██║   ██║╚══██╔══╝██╔═══██╗██╔════╝ ██╔══██╗╚══██╔══╝",
        "███████║██║   ██║   ██║   ██║   ██║██║  ███╗██████╔╝   ██║   ",
        "██╔══██║██║   ██║   ██║   ██║   ██║██║   ██║██╔═══╝    ██║   ",
        "██║  ██║╚██████╔╝   ██║   ╚██████╔╝╚██████╔╝██║        ██║   ",
        "╚═╝  ╚═╝ ╚═════╝    ╚═╝    ╚═════╝  ╚═════╝ ╚═╝        ╚═╝   ",
    ];

    let gradient_stops: &[(u8, u8, u8)] = &[
        (255, 80, 180),
        (220, 110, 200),
        (180, 140, 230),
        (140, 170, 245),
        (100, 210, 250),
        (60, 230, 240),
    ];

    info!("");
    for (line_idx, line) in logo_lines.iter().enumerate() {
        let (r, g, b) = gradient_stops[line_idx % gradient_stops.len()];
        info!("{}", line.truecolor(r, g, b).bold());
    }
    info!("");
}

/// Prints the startup tips greeting block.
#[cfg(feature = "cli")]
pub fn print_greeting() {
    info!("{}", "Tips for getting started:".bold());
    info!(
        "  {}. Describe your project; AutoGPT will decompose and execute it autonomously.",
        "1".bright_cyan()
    );
    info!(
        "  {}. Review and approve the generated plan before execution begins.",
        "2".bright_cyan()
    );
    info!(
        "  {}. Use {} to list all available commands.",
        "3".bright_cyan(),
        "/help".bright_magenta().bold()
    );
    info!(
        "  {}. Use {} for unattended, continuous execution.",
        "4".bright_cyan(),
        "-y / --yolo".bright_yellow()
    );
    info!(
        "  {}. Press {} during execution to interrupt!",
        "5".bright_cyan(),
        "ESC".yellow().bold()
    );
    info!("");
}

/// Renders a yellow warning box to the terminal.
///
/// Used for home-directory warnings, update notifications, and other advisory messages.
/// All output is routed through `tracing::warn!`.
#[cfg(feature = "cli")]
pub fn render_warning_box(message: &str) {
    let inner_width = BOX_WIDTH - 2;
    let top = format!("{}", "".repeat(inner_width));
    let bot = format!("{}", "".repeat(inner_width));

    warn!("{}", top.bright_yellow());
    for line in message.lines() {
        let padded = format!("│ {:<width$} │", line, width = inner_width - 2);
        warn!("{}", padded.bright_yellow());
    }
    warn!("{}", bot.bright_yellow());
    warn!("");
}

/// Renders a version-update banner in yellow.
#[cfg(feature = "cli")]
pub fn render_update_banner(current: &str, latest: &str) {
    let msg = format!(
        "AutoGPT update available! {}{}\nRun `cargo install autogpt --all-features` to update.",
        current, latest
    );
    render_warning_box(&msg);
}

/// Renders the help table for all available slash commands.
#[cfg(feature = "cli")]
pub fn render_help_table() {
    info!("");
    info!("{}", "Available Commands".bright_cyan().bold());
    info!("{}", "".repeat(BOX_WIDTH).bright_black());

    let commands: &[(&str, &str)] = &[
        (
            "/help",
            "Display this help table with all available commands",
        ),
        (
            "/sessions",
            "List and interactively resume a previous session",
        ),
        (
            "/models",
            "List available models for the current provider and switch",
        ),
        ("/clear", "Clear the screen and reprint the AutoGPT banner"),
        (
            "/status",
            "Show current session info, task progress, and model",
        ),
        ("/workspace", "Display the current workspace directory path"),
        ("/provider", "Show and switch the active LLM provider"),
        ("exit / quit", "Save the current session and exit AutoGPT"),
    ];

    for (cmd, desc) in commands {
        info!("  {:<15}  {}", cmd.bright_magenta().bold(), desc.white());
    }

    info!("{}", "".repeat(BOX_WIDTH).bright_black());
    #[cfg(feature = "cli")]
    render_mcp_help_entries();
    info!("");
}

/// Renders an interactive model selector and returns the zero-based index of the chosen model.
///
/// Uses `dialoguer::Select` for a terminal-native selection UI with keyboard navigation.
#[cfg(feature = "cli")]
pub fn render_model_selector(models: &[ProviderModel], current_idx: usize) -> usize {
    use dialoguer::{Select, theme::ColorfulTheme};

    info!("");
    info!("{}", "Select Model".bright_cyan().bold());
    info!("{}", "".repeat(BOX_WIDTH).bright_black());

    let labels: Vec<String> = models
        .iter()
        .enumerate()
        .map(|(i, m)| {
            let bullet = if i == current_idx { "" } else { " " };
            if m.description.is_empty() {
                format!("{} {}", bullet, m.display_name)
            } else {
                format!("{} {} - {}", bullet, m.display_name, m.description)
            }
        })
        .collect();

    let selection = Select::with_theme(&ColorfulTheme::default())
        .items(&labels)
        .default(current_idx)
        .interact()
        .unwrap_or(current_idx);

    info!("{}", "".repeat(BOX_WIDTH).bright_black());
    selection
}

/// Renders markdown content using `termimad`, applying syntax colour to code blocks.
///
/// `termimad` writes directly to stdout - this is intentional for rich terminal output
/// that cannot be easily proxied through `tracing`.
#[cfg(feature = "cli")]
pub fn render_markdown(content: &str) {
    let mut skin = MadSkin::default();
    skin.code_block.set_fg(Color::Cyan);
    skin.inline_code.set_fg(Color::Cyan);
    skin.bold.set_fg(Color::White);
    skin.print_text(content);
}

/// Creates and starts a themed spinner with autogpt-inspired tick animation.
#[cfg(feature = "cli")]
pub fn create_spinner(message: &str) -> ProgressBar {
    let spinner = ProgressBar::new_spinner();
    spinner.set_style(
        ProgressStyle::with_template("{spinner:.magenta} {msg:.cyan}")
            .unwrap()
            .tick_strings(&[
                "⟳ synthesizing ",
                "⟲ processing  ",
                "↻ computing   ",
                "↺ reasoning   ",
                "⟳ executing   ",
                "⟲ reflecting  ",
                "↻ verifying   ",
                "↺ finalizing  ",
            ]),
    );
    spinner.set_message(message.to_string());
    spinner.enable_steady_tick(Duration::from_millis(100));
    spinner
}

/// Logs a task item with a coloured status icon via `tracing::info!`.
#[cfg(feature = "cli")]
pub fn print_task_item(description: &str, status: TaskStatus) {
    let (icon, coloured) = match status {
        TaskStatus::Pending => ("", format!("{}", description).bright_black().to_string()),
        TaskStatus::InProgress => (
            "",
            format!("{}", description)
                .bright_yellow()
                .bold()
                .to_string(),
        ),
        TaskStatus::Completed => (
            "",
            format!("{}", description)
                .bright_green()
                .bold()
                .to_string(),
        ),
        TaskStatus::Failed => (
            "",
            format!("{}", description).bright_red().bold().to_string(),
        ),
        TaskStatus::Skipped => ("", format!("{}", description).bright_black().to_string()),
    };
    let _ = icon;
    info!("  {}", coloured);
}

/// Logs a section header with a coloured divider via `tracing::info!`.
#[cfg(feature = "cli")]
pub fn print_section(title: &str) {
    info!("");
    info!("{} {}", "".bright_cyan(), title.bold().white());
}

/// Logs an agent-tagged message via `tracing::info!`.
#[cfg(feature = "cli")]
pub fn print_agent_msg(tag: &str, message: &str) {
    info!(
        "{} {}",
        format!("[AutoGPT·{}]", tag).bright_magenta().bold(),
        message.white()
    );
}

/// Logs a warning message via `tracing::warn!` with yellow colouring.
#[cfg(feature = "cli")]
pub fn print_warning(message: &str) {
    warn!("{}  {}", "".bright_yellow(), message.bright_yellow());
}

/// Logs an error message via `tracing::error!` with red colouring.
#[cfg(feature = "cli")]
pub fn print_error(message: &str) {
    error!("{}  {}", "".bright_red(), message.bright_red());
}

/// Logs a success message via `tracing::info!` with green colouring.
#[cfg(feature = "cli")]
pub fn print_success(message: &str) {
    info!("{}  {}", "".bright_green(), message.bright_green().bold());
}

/// Renders a single labelled status bar line showing working context.
#[cfg(feature = "cli")]
pub fn print_status_bar(cwd: &str, model: &str, provider: &str) {
    info!(
        "  {}  {}  {}",
        cwd.bright_blue(),
        model.bright_magenta(),
        provider.bright_black()
    );
}

/// Renders a summary table of all registered MCP servers.
#[cfg(all(feature = "cli", feature = "mcp"))]
pub fn render_mcp_list(infos: &[crate::mcp::types::McpServerInfo]) {
    use crate::mcp::types::McpServerStatus;
    print_section("MCP Servers");
    if infos.is_empty() {
        print_warning("No MCP servers configured. Use `autogpt mcp add` or `/mcp add`.");
        return;
    }
    let col_name = 20usize;
    let col_status = 14usize;
    let col_tools = 8usize;
    info!(
        "  {:<col_name$}  {:<col_status$}  {:<col_tools$}  Description",
        "Name".bold(),
        "Status".bold(),
        "Tools".bold(),
    );
    info!("  {}", "".repeat(BOX_WIDTH - 2));
    for info in infos {
        let status_str = match info.status {
            McpServerStatus::Connected => "● connected".bright_green().bold().to_string(),
            McpServerStatus::Connecting => "⟳ connecting".bright_yellow().to_string(),
            McpServerStatus::Disconnected => "○ offline".bright_red().to_string(),
        };
        let tool_count = info.tools.len().to_string();
        let desc = info.description.chars().take(40).collect::<String>();
        info!(
            "  {:<col_name$}  {:<col_status$}  {:<col_tools$}  {}",
            info.name.bright_magenta().bold(),
            status_str,
            tool_count.bright_cyan(),
            desc.bright_black(),
        );
        if let Some(ref err) = info.error {
            info!(
                "    {}  {}",
                "".bright_yellow(),
                err.to_string().bright_red()
            );
        }
    }
    info!("");
}

/// Renders detailed information about a single MCP server, including its tools.
#[cfg(all(feature = "cli", feature = "mcp"))]
pub fn render_mcp_inspect(
    info: &crate::mcp::types::McpServerInfo,
    config: &crate::mcp::settings::McpServerConfig,
) {
    print_section(&format!("MCP Server: {}", info.name));
    info!(
        "  {}  {}",
        "Transport:".bright_black(),
        config.transport.to_string().bright_cyan()
    );
    info!(
        "  {}  {}",
        "Connection:".bright_black(),
        config.connection_display().bright_white()
    );
    info!(
        "  {}  {}",
        "Status:   ".bright_black(),
        info.status.to_string().bright_cyan()
    );
    if let Some(ref desc) = config.description {
        info!(
            "  {}  {}",
            "Description:".bright_black(),
            desc.to_string().bright_white()
        );
    }
    info!(
        "  {}  {}",
        "Trust:    ".bright_black(),
        if config.trust {
            "yes".bright_green()
        } else {
            "no".bright_black()
        }
    );
    if config.timeout_ms != 500_000 {
        info!(
            "  {}  {}ms",
            "Timeout:  ".bright_black(),
            config.timeout_ms.to_string().bright_cyan()
        );
    }
    if let Some(ref err) = info.error {
        print_error(&format!("Last connection error: {err}"));
    }

    if info.tools.is_empty() {
        print_warning("No tools discovered (server may be offline or has no tools).");
    } else {
        print_section(&format!("Available Tools ({}):", info.tools.len()));
        for tool in &info.tools {
            info!(
                "  {}  {}",
                tool.name.bright_magenta().bold(),
                tool.description.bright_black()
            );
            for (param_name, param) in &tool.params {
                let req = if param.required {
                    "*".bright_red().bold().to_string()
                } else {
                    " ".to_string()
                };
                info!(
                    "    {} {}: {} - {}",
                    req,
                    param_name.bright_cyan(),
                    param.param_type.bright_black(),
                    param.description.bright_black(),
                );
            }
        }
    }
    info!("");
}

/// Appends MCP entries to the help table rendered by `/help`.
#[cfg(feature = "cli")]
pub fn render_mcp_help_entries() {
    info!("");
    info!("{}", "MCP Commands".bold().bright_magenta());
    info!(
        "  {}  {}",
        "/mcp list".bright_cyan().bold(),
        "Show all configured MCP servers and their status".bright_black()
    );
    info!(
        "  {}  {}",
        "/mcp inspect <name>".bright_cyan().bold(),
        "Inspect a server and list its tools".bright_black()
    );
    info!(
        "  {}  {}",
        "/mcp remove <name>".bright_cyan().bold(),
        "Remove a server registration".bright_black()
    );
    info!(
        "  {}  {}",
        "/mcp call <srv> <tool> [args]".bright_cyan().bold(),
        "Call an MCP tool with JSON args or key=val pairs".bright_black()
    );
    info!("");
}

// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.