Skip to main content

systemprompt_cli/commands/admin/agents/
mod.rs

1//! `admin agents` command group: manage A2A agent configurations and runtime.
2//!
3//! Exposes [`AgentsCommands`] covering the agent lifecycle — list, show,
4//! validate, create, edit, delete, status, logs — plus A2A interaction
5//! (registry discovery, message, task, tools) and direct `run`. Each variant
6//! dispatches to a sibling module that returns a
7//! [`crate::shared::CommandOutput`].
8//!
9//! Copyright (c) systemprompt.io — Business Source License 1.1.
10//! See <https://systemprompt.io> for licensing details.
11
12pub mod types;
13
14mod client;
15pub mod create;
16pub mod delete;
17mod edit;
18mod edit_apply;
19mod list;
20pub mod logs;
21pub mod logs_db;
22pub mod logs_disk;
23mod message;
24mod message_request;
25mod message_streaming;
26pub mod process_stop;
27pub mod registry;
28mod run;
29pub mod shared;
30pub mod show;
31mod status;
32mod task;
33mod tools;
34pub mod validate;
35
36use anyhow::{Context, Result, bail};
37use clap::Subcommand;
38
39use crate::context::CommandContext;
40use crate::descriptor::DataImpact;
41use crate::shared::render_result;
42
43#[derive(Debug, Subcommand)]
44pub enum AgentsCommands {
45    #[command(about = "List configured agents")]
46    List(list::ListArgs),
47
48    #[command(about = "Display agent configuration")]
49    Show(show::ShowArgs),
50
51    #[command(about = "Check agent configs for errors")]
52    Validate(validate::ValidateArgs),
53
54    #[command(about = "Create new agent")]
55    Create(create::CreateArgs),
56
57    #[command(about = "Edit agent configuration")]
58    Edit(edit::EditArgs),
59
60    #[command(about = "Delete an agent")]
61    Delete(delete::DeleteArgs),
62
63    #[command(about = "Show agent process status")]
64    Status(status::StatusArgs),
65
66    #[command(about = "View agent logs")]
67    Logs(logs::LogsArgs),
68
69    #[command(about = "Get running agents from gateway registry (A2A discovery)")]
70    Registry(registry::RegistryArgs),
71
72    #[command(about = "Send a message to an agent via A2A protocol")]
73    Message(message::MessageArgs),
74
75    #[command(about = "Get task details and response from an agent")]
76    Task(task::TaskArgs),
77
78    #[command(about = "List MCP tools available to an agent")]
79    Tools(tools::ToolsArgs),
80
81    #[command(about = "Run an agent server directly (bypasses orchestration)")]
82    Run(run::RunArgs),
83}
84
85pub async fn execute(command: AgentsCommands, ctx: &CommandContext) -> Result<()> {
86    let result = match command {
87        AgentsCommands::List(args) => {
88            list::execute(args, &ctx.cli).context("Failed to list agents")?
89        },
90        AgentsCommands::Show(args) => {
91            show::execute(args, ctx.prompter(), &ctx.cli).context("Failed to show agent")?
92        },
93        AgentsCommands::Validate(args) => {
94            let (result, valid) =
95                validate::execute(&args, &ctx.cli).context("Failed to validate agents")?;
96            render_result(&result, &ctx.cli);
97            if !valid {
98                bail!("Agent validation failed");
99            }
100            return Ok(());
101        },
102        AgentsCommands::Create(args) => {
103            create::execute(args, ctx.prompter(), &ctx.cli).context("Failed to create agent")?
104        },
105        AgentsCommands::Edit(args) => {
106            edit::execute(&args, ctx.prompter(), &ctx.cli).context("Failed to edit agent")?
107        },
108        AgentsCommands::Delete(args) => delete::execute(args, ctx)
109            .await
110            .context("Failed to delete agent")?,
111        AgentsCommands::Status(args) => status::execute(args, ctx)
112            .await
113            .context("Failed to get agent status")?,
114        AgentsCommands::Logs(args) => logs::execute(args, ctx.prompter(), &ctx.cli)
115            .await
116            .context("Failed to get agent logs")?,
117        AgentsCommands::Registry(args) => registry::execute(args, &ctx.cli)
118            .await
119            .context("Failed to get agent registry")?,
120        AgentsCommands::Message(args) => message::execute(args, ctx)
121            .await
122            .context("Failed to send message to agent")?,
123        AgentsCommands::Task(args) => task::execute(args, ctx)
124            .await
125            .context("Failed to get task details")?,
126        AgentsCommands::Tools(args) => Box::pin(tools::execute(args, ctx))
127            .await
128            .context("Failed to list agent tools")?,
129        AgentsCommands::Run(args) => {
130            return run::execute(args).await.context("Failed to run agent");
131        },
132    };
133    render_result(&result, &ctx.cli);
134    Ok(())
135}
136
137impl AgentsCommands {
138    pub const fn data_impact(&self) -> DataImpact {
139        match self {
140            Self::Delete(_) => DataImpact::Destructive,
141            Self::List(_)
142            | Self::Show(_)
143            | Self::Validate(_)
144            | Self::Create(_)
145            | Self::Edit(_)
146            | Self::Status(_)
147            | Self::Logs(_)
148            | Self::Registry(_)
149            | Self::Message(_)
150            | Self::Task(_)
151            | Self::Tools(_)
152            | Self::Run(_) => DataImpact::Preserving,
153        }
154    }
155}