|
| 1 | +use a3s_code_core::orchestrator::{AgentOrchestrator, OrchestratorEvent, SubAgentConfig}; |
| 2 | +use a3s_code_core::Agent; |
| 3 | +use std::sync::Arc; |
| 4 | +use tempfile::tempdir; |
| 5 | + |
| 6 | +#[tokio::main] |
| 7 | +async fn main() -> anyhow::Result<()> { |
| 8 | + let temp = tempdir()?; |
| 9 | + let workspace = temp.path().join("workspace"); |
| 10 | + let skills_dir = temp.path().join("skills"); |
| 11 | + std::fs::create_dir_all(&workspace)?; |
| 12 | + std::fs::create_dir_all(&skills_dir)?; |
| 13 | + |
| 14 | + let skill_path = skills_dir.join("scoring-video-adapter.md"); |
| 15 | + std::fs::write( |
| 16 | + &skill_path, |
| 17 | + r#"--- |
| 18 | +name: scoring-video-adapter |
| 19 | +description: "Subagent skill invocation smoke test" |
| 20 | +kind: tool |
| 21 | +--- |
| 22 | +# Scoring Video Adapter |
| 23 | +
|
| 24 | +You are a smoke test skill. |
| 25 | +Reply with exactly: SKILL_OK |
| 26 | +"#, |
| 27 | + )?; |
| 28 | + |
| 29 | + let config_path = temp.path().join("agent_kimi_env.hcl"); |
| 30 | + std::fs::write( |
| 31 | + &config_path, |
| 32 | + r#"default_model = "openai/kimi-k2.5" |
| 33 | +
|
| 34 | +providers { |
| 35 | + name = "openai" |
| 36 | + api_key = env("KIMI_API_KEY") |
| 37 | + base_url = env("KIMI_BASE_URL") |
| 38 | +
|
| 39 | + models { |
| 40 | + id = "kimi-k2.5" |
| 41 | + name = "KIMI K2.5" |
| 42 | + } |
| 43 | +} |
| 44 | +
|
| 45 | +storage_backend = "memory" |
| 46 | +max_tool_rounds = 8 |
| 47 | +"#, |
| 48 | + )?; |
| 49 | + |
| 50 | + let agent = Arc::new(Agent::create(config_path.display().to_string()).await?); |
| 51 | + let orchestrator = AgentOrchestrator::from_agent(agent); |
| 52 | + let handle = orchestrator |
| 53 | + .spawn_subagent( |
| 54 | + SubAgentConfig::new( |
| 55 | + "general", |
| 56 | + "You must call the Skill tool for scoring-video-adapter. \ |
| 57 | + Use the tool rather than answering directly. \ |
| 58 | + Set skill_name to scoring-video-adapter. \ |
| 59 | + After the tool returns, output only the final answer.", |
| 60 | + ) |
| 61 | + .with_description("Kimi subagent skill smoke test") |
| 62 | + .with_workspace(workspace.display().to_string()) |
| 63 | + .with_skill_dirs(vec![skills_dir.display().to_string()]) |
| 64 | + .with_permissive(true) |
| 65 | + .with_max_steps(6), |
| 66 | + ) |
| 67 | + .await?; |
| 68 | + |
| 69 | + let mut events = handle.events(); |
| 70 | + let event_task = tokio::spawn(async move { |
| 71 | + let mut saw_skill_tool = false; |
| 72 | + let mut saw_skill_ok = false; |
| 73 | + |
| 74 | + while let Some(event) = |
| 75 | + tokio::time::timeout(std::time::Duration::from_secs(60), events.recv()).await? |
| 76 | + { |
| 77 | + match event { |
| 78 | + OrchestratorEvent::ToolExecutionStarted { tool_name, .. } => { |
| 79 | + println!("EVENT tool_start {}", tool_name); |
| 80 | + if tool_name == "Skill" { |
| 81 | + saw_skill_tool = true; |
| 82 | + } |
| 83 | + } |
| 84 | + OrchestratorEvent::ToolExecutionCompleted { |
| 85 | + tool_name, result, .. |
| 86 | + } => { |
| 87 | + println!( |
| 88 | + "EVENT tool_end {} => {}", |
| 89 | + tool_name, |
| 90 | + result.replace('\n', " ") |
| 91 | + ); |
| 92 | + if tool_name == "Skill" && result.contains("SKILL_OK") { |
| 93 | + saw_skill_ok = true; |
| 94 | + } |
| 95 | + } |
| 96 | + OrchestratorEvent::SubAgentCompleted { |
| 97 | + success, output, .. |
| 98 | + } => { |
| 99 | + println!( |
| 100 | + "EVENT subagent_completed success={} output={}", |
| 101 | + success, |
| 102 | + output.replace('\n', " ") |
| 103 | + ); |
| 104 | + break; |
| 105 | + } |
| 106 | + _ => {} |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + Ok::<(bool, bool), anyhow::Error>((saw_skill_tool, saw_skill_ok)) |
| 111 | + }); |
| 112 | + |
| 113 | + let output = tokio::time::timeout(std::time::Duration::from_secs(90), handle.wait()).await??; |
| 114 | + let (saw_skill_tool, saw_skill_ok) = event_task.await??; |
| 115 | + |
| 116 | + println!("FINAL_OUTPUT={}", output.replace('\n', " ")); |
| 117 | + println!("SAW_SKILL_TOOL={}", saw_skill_tool); |
| 118 | + println!("SAW_SKILL_OK={}", saw_skill_ok); |
| 119 | + |
| 120 | + if !saw_skill_tool { |
| 121 | + anyhow::bail!("Skill tool was not called"); |
| 122 | + } |
| 123 | + if !output.contains("SKILL_OK") { |
| 124 | + anyhow::bail!("Final output did not contain SKILL_OK: {}", output); |
| 125 | + } |
| 126 | + |
| 127 | + Ok(()) |
| 128 | +} |
0 commit comments