Skip to content

Commit 478b057

Browse files
prompt engineering
1 parent ad8317b commit 478b057

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/main.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,26 @@ fn set_args(chat: &mut Agent, key: &str, value: &str) {
6565
}
6666

6767
fn invoke_tool(toolset: &tools::ToolSet, request: &str) -> Result<String> {
68-
let (tool, args) = parse_tool_invoke_json(request)?;
69-
let result = toolset.invoke(&tool, &args)?;
70-
Ok(result)
68+
if let Ok((tool, args)) = parse_tool_invoke_json(request) {
69+
let result = toolset.invoke(&tool, &args)?;
70+
Ok(result)
71+
} else if request.contains("[[[[DOCUMENT]]]]") {
72+
Ok(r#"File has been documented. Please keep up the good work!
73+
74+
Or, if you think you have finished your task and want to stop,
75+
please just output a special token [[[[DONE]]]]."#
76+
.to_string())
77+
} else {
78+
Err(anyhow::anyhow!(
79+
r#"
80+
I cannot find correct tool name or arguments in the request.
81+
Please check the format of the request and try again.
82+
83+
If you think you have finished your task and want to stop,
84+
please just output a special token [[[[DONE]]]].
85+
"#
86+
))
87+
}
7188
}
7289

7390
fn run_pipeline(agent: &mut Agent, toolset: &tools::ToolSet) {
@@ -173,13 +190,14 @@ fn main() {
173190
let mut chat_agent = Agent::new_with_config_file(Path::new(&config_file)).unwrap();
174191
let prompt = format!(
175192
r#"
176-
I would like you to help read a codebase. There are some tools you can use.
177-
You can call them by providing the tool name and the arguments in JSON.
193+
I would like you to help write documentation for all source files (including those in the sub-crates) in a codebase.
194+
195+
There are some tools you can use. You can call them by providing the tool name and the arguments in JSON.
178196
Here are the tools:
179197
{}
180198
181199
Now tell me what you want to do and I will return you the output of the tool.
182-
Please output the special heading and than follow the format (must be wrapped in triple backticks):
200+
Please output a special heading and than JSON requests following the format (must be wrapped in triple backticks):
183201
184202
[[[[INVOKE]]]]
185203
```json
@@ -190,11 +208,14 @@ Please output the special heading and than follow the format (must be wrapped in
190208
}}
191209
}}
192210
193-
If you feel that you have finished your task, please return the output in the following token:
194-
[[[[DONE]]]]
211+
If you would like to document a file, please output a special heading and than the documentation in Rust standard format:
212+
[[[[DOCUMENT]]]]
213+
<file name here with path on a new line>
214+
215+
Some documentation here...
195216
```
196217
197-
Please note that you can only call one tool at a time.
218+
Please note that you can only call **one** tool **once** at a time. Otherwise errors will be returned.
198219
"#,
199220
help
200221
);

src/tools/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ struct TreeToolProtocol {
2424
path: String,
2525

2626
#[tool_protocol(
27-
help = "The maximum depth to recurse into the directory (will be clamped to [1, 3] to avoid flushing).",
27+
help = "The maximum depth to recurse into the directory.",
2828
default = 2,
29-
example = 1
29+
example = 3
3030
)]
3131
depth: u32,
3232
}

0 commit comments

Comments
 (0)