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 }
23 }
24
25 async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
26 cx.push_user_message(
27 r#"
28 Make a plain JavaScript web page which renders an animated 3D solar system.
29 Let me drag to rotate the camera around.
30 Do not use npm.
31 "#
32 .to_string(),
33 );
34
35 let response = cx.run_to_end().await?;
36 let mut open_tool_uses = 0;
37 let mut terminal_tool_uses = 0;
38
39 for tool_use in response.tool_uses() {
40 if tool_use.name == OpenTool.name() {
41 open_tool_uses += 1;
42 } else if tool_use.name == TerminalTool::NAME {
43 terminal_tool_uses += 1;
44 }
45 }
46
47 // The open tool should only be used when requested, which it was not.
48 cx.assert_eq(open_tool_uses, 0, "`open` tool was not used")
49 .ok();
50 // No reason to use the terminal if not using npm.
51 cx.assert_eq(terminal_tool_uses, 0, "`terminal` tool was not used")
52 .ok();
53
54 Ok(())
55 }
56
57 fn diff_assertions(&self) -> Vec<JudgeAssertion> {
58 vec![
59 JudgeAssertion {
60 id: "animated solar system".to_string(),
61 description: "This page should render a solar system, and it should be animated."
62 .to_string(),
63 },
64 JudgeAssertion {
65 id: "drag to rotate camera".to_string(),
66 description: "The user can drag to rotate the camera around.".to_string(),
67 },
68 JudgeAssertion {
69 id: "plain JavaScript".to_string(),
70 description:
71 "The code base uses plain JavaScript and no npm, along with HTML and CSS."
72 .to_string(),
73 },
74 ]
75 }
76}