1use agent_settings::AgentProfileId;
2use anyhow::Result;
3use assistant_tool::Tool;
4use assistant_tools::{OpenTool, TerminalTool};
5use async_trait::async_trait;
6
7use crate::example::{Example, ExampleContext, ExampleMetadata, JudgeAssertion};
8
9pub struct Planets;
10
11#[async_trait(?Send)]
12impl Example for Planets {
13 fn meta(&self) -> ExampleMetadata {
14 ExampleMetadata {
15 name: "planets".to_string(),
16 url: "https://github.com/roc-lang/roc".to_string(), // This commit in this repo is just the Apache2 license,
17 revision: "59e49c75214f60b4dc4a45092292061c8c26ce27".to_string(), // so effectively a blank project.
18 language_server: None,
19 max_assertions: None,
20 profile_id: AgentProfileId::default(),
21 existing_thread_json: None,
22 max_turns: None,
23 }
24 }
25
26 async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
27 cx.push_user_message(
28 r#"
29 Make a plain JavaScript web page which renders an animated 3D solar system.
30 Let me drag to rotate the camera around.
31 Do not use npm.
32 "#
33 .to_string(),
34 );
35
36 let response = cx.run_to_end().await?;
37 let mut open_tool_uses = 0;
38 let mut terminal_tool_uses = 0;
39
40 for tool_use in response.tool_uses() {
41 if tool_use.name == OpenTool.name() {
42 open_tool_uses += 1;
43 } else if tool_use.name == TerminalTool::NAME {
44 terminal_tool_uses += 1;
45 }
46 }
47
48 // The open tool should only be used when requested, which it was not.
49 cx.assert_eq(open_tool_uses, 0, "`open` tool was not used")
50 .ok();
51 // No reason to use the terminal if not using npm.
52 cx.assert_eq(terminal_tool_uses, 0, "`terminal` tool was not used")
53 .ok();
54
55 Ok(())
56 }
57
58 fn diff_assertions(&self) -> Vec<JudgeAssertion> {
59 vec![
60 JudgeAssertion {
61 id: "animated solar system".to_string(),
62 description: "This page should render a solar system, and it should be animated."
63 .to_string(),
64 },
65 JudgeAssertion {
66 id: "drag to rotate camera".to_string(),
67 description: "The user can drag to rotate the camera around.".to_string(),
68 },
69 JudgeAssertion {
70 id: "plain JavaScript".to_string(),
71 description:
72 "The code base uses plain JavaScript and no npm, along with HTML and CSS."
73 .to_string(),
74 },
75 ]
76 }
77}