agent-code-lib 0.16.1

Agent engine library: LLM providers, tools, query loop, memory
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
//! Multi-agent coordinator.
//!
//! Routes tasks to specialized agents based on the task type.
//! The coordinator acts as an orchestrator, spawning agents with
//! appropriate configurations and aggregating their results.
//!
//! # Agent types
//!
//! - `general-purpose`: default agent with full tool access
//! - `explore`: fast read-only agent for codebase exploration
//! - `plan`: planning agent restricted to analysis tools
//!
//! Agents are defined as configurations that customize the tool
//! set, system prompt, and permission mode.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::Mutex;
use tracing::{debug, info, warn};

/// Definition of a specialized agent type.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentDefinition {
    /// Unique agent type name.
    pub name: String,
    /// Description of what this agent specializes in.
    pub description: String,
    /// System prompt additions for this agent type.
    pub system_prompt: Option<String>,
    /// Model override (if different from default).
    pub model: Option<String>,
    /// Tools to include (if empty, use all).
    pub include_tools: Vec<String>,
    /// Tools to exclude.
    pub exclude_tools: Vec<String>,
    /// Whether this agent runs in read-only mode.
    pub read_only: bool,
    /// Maximum turns for this agent type.
    pub max_turns: Option<usize>,
}

/// Registry of available agent types.
pub struct AgentRegistry {
    agents: HashMap<String, AgentDefinition>,
}

impl AgentRegistry {
    /// Create the registry with built-in agent types.
    pub fn with_defaults() -> Self {
        let mut agents = HashMap::new();

        agents.insert(
            "general-purpose".to_string(),
            AgentDefinition {
                name: "general-purpose".to_string(),
                description: "General-purpose agent with full tool access.".to_string(),
                system_prompt: None,
                model: None,
                include_tools: Vec::new(),
                exclude_tools: Vec::new(),
                read_only: false,
                max_turns: None,
            },
        );

        agents.insert(
            "explore".to_string(),
            AgentDefinition {
                name: "explore".to_string(),
                description: "Fast read-only agent for searching and understanding code."
                    .to_string(),
                system_prompt: Some(
                    "You are a fast exploration agent. Focus on finding information \
                     quickly. Use Grep, Glob, and FileRead to answer questions about \
                     the codebase. Do not modify files."
                        .to_string(),
                ),
                model: None,
                include_tools: vec![
                    "FileRead".into(),
                    "Grep".into(),
                    "Glob".into(),
                    "Bash".into(),
                    "WebFetch".into(),
                ],
                exclude_tools: Vec::new(),
                read_only: true,
                max_turns: Some(20),
            },
        );

        agents.insert(
            "plan".to_string(),
            AgentDefinition {
                name: "plan".to_string(),
                description: "Planning agent that designs implementation strategies.".to_string(),
                system_prompt: Some(
                    "You are a software architect agent. Design implementation plans, \
                     identify critical files, and consider architectural trade-offs. \
                     Do not modify files directly."
                        .to_string(),
                ),
                model: None,
                include_tools: vec![
                    "FileRead".into(),
                    "Grep".into(),
                    "Glob".into(),
                    "Bash".into(),
                ],
                exclude_tools: Vec::new(),
                read_only: true,
                max_turns: Some(30),
            },
        );

        Self { agents }
    }

    /// Look up an agent definition by type name.
    pub fn get(&self, name: &str) -> Option<&AgentDefinition> {
        self.agents.get(name)
    }

    /// Register a custom agent type.
    pub fn register(&mut self, definition: AgentDefinition) {
        self.agents.insert(definition.name.clone(), definition);
    }

    /// List all available agent types.
    pub fn list(&self) -> Vec<&AgentDefinition> {
        let mut agents: Vec<_> = self.agents.values().collect();
        agents.sort_by_key(|a| &a.name);
        agents
    }

    /// Load agent definitions from disk (`.agent/agents/` and `~/.config/agent-code/agents/`).
    /// Each `.md` file is parsed for YAML frontmatter with agent configuration.
    pub fn load_from_disk(&mut self, cwd: Option<&std::path::Path>) {
        // Project-level agents.
        if let Some(cwd) = cwd {
            let project_dir = cwd.join(".agent").join("agents");
            self.load_agents_from_dir(&project_dir);
        }

        // User-level agents.
        if let Some(config_dir) = dirs::config_dir() {
            let user_dir = config_dir.join("agent-code").join("agents");
            self.load_agents_from_dir(&user_dir);
        }
    }

    fn load_agents_from_dir(&mut self, dir: &std::path::Path) {
        let entries = match std::fs::read_dir(dir) {
            Ok(e) => e,
            Err(_) => return,
        };

        for entry in entries.flatten() {
            let path = entry.path();
            if path.extension().is_some_and(|e| e == "md")
                && let Some(def) = parse_agent_file(&path)
            {
                self.agents.insert(def.name.clone(), def);
            }
        }
    }
}

/// Parse an agent definition from a markdown file with YAML frontmatter.
///
/// Expected format:
/// ```markdown
/// ---
/// name: my-agent
/// description: A specialized agent
/// model: gpt-4.1-mini
/// read_only: false
/// max_turns: 20
/// include_tools: [FileRead, Grep, Glob]
/// exclude_tools: [Bash]
/// ---
///
/// System prompt additions go here...
/// ```
fn parse_agent_file(path: &std::path::Path) -> Option<AgentDefinition> {
    let content = std::fs::read_to_string(path).ok()?;

    // Parse YAML frontmatter.
    if !content.starts_with("---") {
        return None;
    }
    let end = content[3..].find("---")?;
    let frontmatter = &content[3..3 + end];
    let body = content[3 + end + 3..].trim();

    let mut name = path
        .file_stem()
        .and_then(|s| s.to_str())
        .unwrap_or("custom")
        .to_string();
    let mut description = String::new();
    let mut model = None;
    let mut read_only = false;
    let mut max_turns = None;
    let mut include_tools = Vec::new();
    let mut exclude_tools = Vec::new();

    for line in frontmatter.lines() {
        let line = line.trim();
        if let Some((key, value)) = line.split_once(':') {
            let key = key.trim();
            let value = value.trim();
            match key {
                "name" => name = value.to_string(),
                "description" => description = value.to_string(),
                "model" => model = Some(value.to_string()),
                "read_only" => read_only = value == "true",
                "max_turns" => max_turns = value.parse().ok(),
                "include_tools" => {
                    include_tools = value
                        .trim_matches(|c| c == '[' || c == ']')
                        .split(',')
                        .map(|s| s.trim().to_string())
                        .filter(|s| !s.is_empty())
                        .collect();
                }
                "exclude_tools" => {
                    exclude_tools = value
                        .trim_matches(|c| c == '[' || c == ']')
                        .split(',')
                        .map(|s| s.trim().to_string())
                        .filter(|s| !s.is_empty())
                        .collect();
                }
                _ => {}
            }
        }
    }

    let system_prompt = if body.is_empty() {
        None
    } else {
        Some(body.to_string())
    };

    Some(AgentDefinition {
        name,
        description,
        system_prompt,
        model,
        include_tools,
        exclude_tools,
        read_only,
        max_turns,
    })
}

// ---- Coordinator Runtime ----

/// A running agent instance.
#[derive(Debug, Clone)]
pub struct AgentInstance {
    /// Unique instance ID.
    pub id: String,
    /// Human-readable name.
    pub name: String,
    /// Agent type definition.
    pub definition: AgentDefinition,
    /// Current status.
    pub status: AgentStatus,
    /// Messages received from other agents.
    pub inbox: Vec<AgentMessage>,
}

/// Status of a running agent.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AgentStatus {
    /// Agent is waiting to be started.
    Pending,
    /// Agent is currently executing.
    Running,
    /// Agent completed successfully.
    Completed,
    /// Agent failed with an error.
    Failed(String),
}

/// A message sent between agents.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentMessage {
    /// ID of the sending agent.
    pub from: String,
    /// Message content.
    pub content: String,
    /// Timestamp.
    pub timestamp: String,
}

/// Result from a completed agent.
#[derive(Debug, Clone)]
pub struct AgentResult {
    /// Agent instance ID.
    pub agent_id: String,
    /// Agent name.
    pub agent_name: String,
    /// Output text from the agent.
    pub output: String,
    /// Whether the agent succeeded.
    pub success: bool,
}

/// Team definition for multi-agent orchestration.
#[derive(Debug, Clone)]
pub struct Team {
    /// Team ID.
    pub id: String,
    /// Team name.
    pub name: String,
    /// Agent instances in this team.
    pub agents: Vec<String>,
    /// Working directory for the team.
    pub cwd: PathBuf,
}

/// Orchestrates multiple agent instances, routing messages and
/// collecting results.
pub struct Coordinator {
    /// Agent registry for looking up definitions.
    registry: AgentRegistry,
    /// Running agent instances, keyed by ID.
    instances: Arc<Mutex<HashMap<String, AgentInstance>>>,
    /// Active teams.
    teams: Arc<Mutex<HashMap<String, Team>>>,
    /// Working directory.
    cwd: PathBuf,
}

/// Build a subprocess command for running an agent.
///
/// Shared by `run_agent()` and `run_team()` to avoid duplication.
fn build_agent_command(
    definition: &AgentDefinition,
    prompt: &str,
    cwd: &std::path::Path,
) -> tokio::process::Command {
    let full_prompt = if let Some(ref sys) = definition.system_prompt {
        format!("{sys}\n\n{prompt}")
    } else {
        prompt.to_string()
    };

    let agent_binary = std::env::current_exe()
        .map(|p| p.display().to_string())
        .unwrap_or_else(|_| "agent".to_string());

    let mut cmd = tokio::process::Command::new(agent_binary);
    cmd.arg("--prompt")
        .arg(full_prompt)
        .current_dir(cwd)
        .stdout(std::process::Stdio::piped())
        .stderr(std::process::Stdio::piped());

    if let Some(ref model) = definition.model {
        cmd.arg("--model").arg(model);
    }
    if let Some(max_turns) = definition.max_turns {
        cmd.arg("--max-turns").arg(max_turns.to_string());
    }
    if definition.read_only {
        cmd.arg("--permission-mode").arg("plan");
    }

    // Pass through API keys so subagents use the same provider.
    for var in &[
        "AGENT_CODE_API_KEY",
        "ANTHROPIC_API_KEY",
        "OPENAI_API_KEY",
        "OPENROUTER_API_KEY",
        "AGENT_CODE_API_BASE_URL",
        "AGENT_CODE_MODEL",
    ] {
        if let Ok(val) = std::env::var(var) {
            cmd.env(var, val);
        }
    }

    cmd
}

impl Coordinator {
    /// Create a new coordinator.
    pub fn new(cwd: PathBuf) -> Self {
        let mut registry = AgentRegistry::with_defaults();
        registry.load_from_disk(Some(&cwd));

        Self {
            registry,
            instances: Arc::new(Mutex::new(HashMap::new())),
            teams: Arc::new(Mutex::new(HashMap::new())),
            cwd,
        }
    }

    /// Spawn an agent instance.
    ///
    /// Returns the instance ID. The agent is created in `Pending` status
    /// and must be started with `run_agent()`.
    pub async fn spawn_agent(
        &self,
        agent_type: &str,
        name: Option<String>,
    ) -> Result<String, String> {
        let definition = self
            .registry
            .get(agent_type)
            .ok_or_else(|| format!("Unknown agent type: {agent_type}"))?
            .clone();

        let id = uuid::Uuid::new_v4()
            .to_string()
            .split('-')
            .next()
            .unwrap_or("agent")
            .to_string();

        let display_name = name.unwrap_or_else(|| format!("{}-{}", definition.name, &id[..4]));

        let instance = AgentInstance {
            id: id.clone(),
            name: display_name.clone(),
            definition,
            status: AgentStatus::Pending,
            inbox: Vec::new(),
        };

        self.instances.lock().await.insert(id.clone(), instance);
        info!("Spawned agent '{display_name}' ({id}) type={agent_type}");

        Ok(id)
    }

    /// Run an agent with the given prompt.
    ///
    /// Executes the agent as a subprocess and returns the result.
    /// The agent's status is updated throughout the lifecycle.
    pub async fn run_agent(&self, agent_id: &str, prompt: &str) -> Result<AgentResult, String> {
        // Single lock acquisition: update status, clone definition and name.
        let (definition, agent_name) = {
            let mut instances = self.instances.lock().await;
            let instance = instances
                .get_mut(agent_id)
                .ok_or_else(|| format!("Agent not found: {agent_id}"))?;
            instance.status = AgentStatus::Running;
            (instance.definition.clone(), instance.name.clone())
        };

        debug!("Running agent '{agent_name}' ({agent_id})");

        let mut cmd = build_agent_command(&definition, prompt, &self.cwd);
        let output = cmd
            .output()
            .await
            .map_err(|e| format!("Spawn failed: {e}"))?;

        let stdout = String::from_utf8_lossy(&output.stdout).to_string();
        let stderr = String::from_utf8_lossy(&output.stderr).to_string();
        let success = output.status.success();

        // Update status.
        {
            let mut instances = self.instances.lock().await;
            if let Some(instance) = instances.get_mut(agent_id) {
                instance.status = if success {
                    AgentStatus::Completed
                } else {
                    AgentStatus::Failed(stderr.clone())
                };
            }
        }

        let result_text = if success {
            stdout
        } else {
            format!("{stdout}\n\nErrors:\n{stderr}")
        };

        Ok(AgentResult {
            agent_id: agent_id.to_string(),
            agent_name,
            output: result_text,
            success,
        })
    }

    /// Run multiple agents in parallel and collect all results.
    pub async fn run_team(
        &self,
        tasks: Vec<(&str, &str, &str)>, // (agent_type, name, prompt)
    ) -> Vec<AgentResult> {
        let mut handles = Vec::new();

        for (agent_type, name, prompt) in tasks {
            let agent_id = match self.spawn_agent(agent_type, Some(name.to_string())).await {
                Ok(id) => id,
                Err(e) => {
                    warn!("Failed to spawn agent '{name}': {e}");
                    continue;
                }
            };

            let coordinator_instances = Arc::clone(&self.instances);
            let cwd = self.cwd.clone();
            let prompt = prompt.to_string();
            let agent_id_clone = agent_id.clone();

            // Each agent runs in its own tokio task.
            let handle = tokio::spawn(async move {
                // We need to re-create a minimal coordinator for the subprocess call.
                // This is because the coordinator borrows self which can't move into spawn.
                let definition = {
                    let instances = coordinator_instances.lock().await;
                    instances.get(&agent_id_clone).map(|i| i.definition.clone())
                };

                let Some(definition) = definition else {
                    return AgentResult {
                        agent_id: agent_id_clone,
                        agent_name: "unknown".into(),
                        output: "Agent not found".into(),
                        success: false,
                    };
                };

                let agent_name = {
                    let instances = coordinator_instances.lock().await;
                    instances
                        .get(&agent_id_clone)
                        .map(|i| i.name.clone())
                        .unwrap_or_default()
                };

                // Update status.
                {
                    let mut instances = coordinator_instances.lock().await;
                    if let Some(inst) = instances.get_mut(&agent_id_clone) {
                        inst.status = AgentStatus::Running;
                    }
                }

                let mut cmd = build_agent_command(&definition, &prompt, &cwd);

                match cmd.output().await {
                    Ok(output) => {
                        let stdout = String::from_utf8_lossy(&output.stdout).to_string();
                        let stderr = String::from_utf8_lossy(&output.stderr).to_string();
                        let success = output.status.success();

                        {
                            let mut instances = coordinator_instances.lock().await;
                            if let Some(inst) = instances.get_mut(&agent_id_clone) {
                                inst.status = if success {
                                    AgentStatus::Completed
                                } else {
                                    AgentStatus::Failed(stderr.clone())
                                };
                            }
                        }

                        AgentResult {
                            agent_id: agent_id_clone,
                            agent_name,
                            output: if success {
                                stdout
                            } else {
                                format!("{stdout}\nErrors:\n{stderr}")
                            },
                            success,
                        }
                    }
                    Err(e) => {
                        {
                            let mut instances = coordinator_instances.lock().await;
                            if let Some(inst) = instances.get_mut(&agent_id_clone) {
                                inst.status = AgentStatus::Failed(e.to_string());
                            }
                        }
                        AgentResult {
                            agent_id: agent_id_clone,
                            agent_name,
                            output: format!("Spawn failed: {e}"),
                            success: false,
                        }
                    }
                }
            });

            handles.push(handle);
        }

        // Wait for all agents to complete.
        let mut results = Vec::new();
        for handle in handles {
            match handle.await {
                Ok(result) => results.push(result),
                Err(e) => warn!("Agent task panicked: {e}"),
            }
        }

        info!(
            "Team completed: {}/{} succeeded",
            results.iter().filter(|r| r.success).count(),
            results.len()
        );
        results
    }

    /// Send a message to a running agent.
    pub async fn send_message(&self, to: &str, from: &str, content: &str) -> Result<(), String> {
        let mut instances = self.instances.lock().await;

        // Find by ID or name.
        let instance = instances
            .values_mut()
            .find(|i| i.id == to || i.name == to)
            .ok_or_else(|| format!("Agent not found: {to}"))?;

        instance.inbox.push(AgentMessage {
            from: from.to_string(),
            content: content.to_string(),
            timestamp: chrono::Utc::now().to_rfc3339(),
        });

        debug!("Message from '{from}' to '{to}': {content}");
        Ok(())
    }

    /// List all agent instances.
    pub async fn list_agents(&self) -> Vec<AgentInstance> {
        self.instances.lock().await.values().cloned().collect()
    }

    /// Get agent registry.
    pub fn registry(&self) -> &AgentRegistry {
        &self.registry
    }

    /// Create a new team.
    pub async fn create_team(&self, name: &str, agent_types: &[&str]) -> Result<String, String> {
        let team_id = uuid::Uuid::new_v4()
            .to_string()
            .split('-')
            .next()
            .unwrap_or("team")
            .to_string();

        let mut agent_ids = Vec::new();
        for agent_type in agent_types {
            let id = self.spawn_agent(agent_type, None).await?;
            agent_ids.push(id);
        }

        let team = Team {
            id: team_id.clone(),
            name: name.to_string(),
            agents: agent_ids,
            cwd: self.cwd.clone(),
        };

        self.teams.lock().await.insert(team_id.clone(), team);
        info!(
            "Created team '{name}' ({team_id}) with {} agents",
            agent_types.len()
        );

        Ok(team_id)
    }

    /// List active teams.
    pub async fn list_teams(&self) -> Vec<Team> {
        self.teams.lock().await.values().cloned().collect()
    }
}

#[cfg(test)]
mod coordinator_tests {
    use super::*;

    #[test]
    fn test_agent_status_eq() {
        assert_eq!(AgentStatus::Pending, AgentStatus::Pending);
        assert_eq!(AgentStatus::Running, AgentStatus::Running);
        assert_eq!(AgentStatus::Completed, AgentStatus::Completed);
        assert_ne!(AgentStatus::Pending, AgentStatus::Running);
    }

    #[tokio::test]
    async fn test_spawn_agent() {
        let coord = Coordinator::new(std::env::temp_dir());
        let id = coord
            .spawn_agent("general-purpose", Some("test-agent".into()))
            .await;
        assert!(id.is_ok());

        let agents = coord.list_agents().await;
        assert_eq!(agents.len(), 1);
        assert_eq!(agents[0].name, "test-agent");
        assert_eq!(agents[0].status, AgentStatus::Pending);
    }

    #[tokio::test]
    async fn test_spawn_unknown_type() {
        let coord = Coordinator::new(std::env::temp_dir());
        let result = coord.spawn_agent("nonexistent", None).await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_send_message() {
        let coord = Coordinator::new(std::env::temp_dir());
        let id = coord
            .spawn_agent("general-purpose", Some("receiver".into()))
            .await
            .unwrap();

        let result = coord.send_message(&id, "sender", "hello").await;
        assert!(result.is_ok());

        let agents = coord.list_agents().await;
        assert_eq!(agents[0].inbox.len(), 1);
        assert_eq!(agents[0].inbox[0].content, "hello");
    }

    #[tokio::test]
    async fn test_send_message_by_name() {
        let coord = Coordinator::new(std::env::temp_dir());
        coord
            .spawn_agent("explore", Some("explorer".into()))
            .await
            .unwrap();

        let result = coord.send_message("explorer", "lead", "search for X").await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_create_team() {
        let coord = Coordinator::new(std::env::temp_dir());
        let team_id = coord
            .create_team("my-team", &["general-purpose", "explore"])
            .await;
        assert!(team_id.is_ok());

        let teams = coord.list_teams().await;
        assert_eq!(teams.len(), 1);
        assert_eq!(teams[0].agents.len(), 2);

        let agents = coord.list_agents().await;
        assert_eq!(agents.len(), 2);
    }
}