1use agent::{AgentTool, OpenTool, TerminalTool};
2use agent_settings::AgentProfileId;
3use anyhow::Result;
4use async_trait::async_trait;
5
6use crate::example::{Example, ExampleContext, ExampleMetadata, JudgeAssertion};
7
8pub struct Planets;
9
10#[async_trait(?Send)]
11impl Example for Planets {
12 fn meta(&self) -> ExampleMetadata {
13 ExampleMetadata {
14 name: "planets".to_string(),
15 url: "https://github.com/roc-lang/roc".to_string(), // This commit in this repo is just the Apache2 license,
16 revision: "59e49c75214f60b4dc4a45092292061c8c26ce27".to_string(), // so effectively a blank project.
17 language_server: None,
18 max_assertions: None,
19 profile_id: AgentProfileId::default(),
20 existing_thread_json: None,
21 max_turns: 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}