Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 80f10ab

Browse files
authored
answers as type FunctionReturn in agent history and prompt edits (#872)
1 parent 2ad0455 commit 80f10ab

File tree

4 files changed

+23
-38
lines changed

4 files changed

+23
-38
lines changed

server/bleep/src/agent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl Agent {
258258
// NB: We intentionally discard the summary as it is redundant.
259259
Some((answer, _conclusion)) => {
260260
let encoded = transcoder::encode_summarized(answer, None, "gpt-3.5-turbo")?;
261-
Some(llm_gateway::api::Message::assistant(&encoded))
261+
Some(llm_gateway::api::Message::function_return("none", &encoded))
262262
}
263263

264264
None => None,

server/bleep/src/agent/prompts.rs

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ pub fn functions(add_proc: bool) -> serde_json::Value {
99
"properties": {
1010
"query": {
1111
"type": "string",
12-
"description": "The query with which to search. This should consist of keywords that might match something in the codebase, e.g. 'react functional components', 'contextmanager', 'bearer token'"
12+
"description": "The query with which to search. This should consist of keywords that might match something in the codebase, e.g. 'react functional components', 'contextmanager', 'bearer token'. It should NOT contain redundant words like 'usage' or 'example'."
1313
}
1414
},
1515
"required": ["query"]
1616
}
1717
},
1818
{
1919
"name": "path",
20-
"description": "Search the pathnames in a codebase. Results may not be exact matches, but will be similar by some edit-distance. Use when you want to find a specific file or directory.",
20+
"description": "Search the pathnames in a codebase. Use when you want to find a specific file or directory. Results may not be exact matches, but will be similar by some edit-distance.",
2121
"parameters": {
2222
"type": "object",
2323
"properties": {
@@ -31,7 +31,7 @@ pub fn functions(add_proc: bool) -> serde_json::Value {
3131
},
3232
{
3333
"name": "none",
34-
"description": "You have enough information to answer the user's query. This is the final step, and signals that you have enough information to respond to the user's query. Use this if the user has instructed you to modify some code.",
34+
"description": "Call this to answer the user. Call this only when you have enough information to answer the user's query.",
3535
"parameters": {
3636
"type": "object",
3737
"properties": {
@@ -54,7 +54,7 @@ pub fn functions(add_proc: bool) -> serde_json::Value {
5454
serde_json::json!(
5555
{
5656
"name": "proc",
57-
"description": "Read one or more files and extract the line ranges which are relevant to the search terms. Do not proc more than 10 files at a time.",
57+
"description": "Read one or more files and extract the line ranges that are relevant to the search terms",
5858
"parameters": {
5959
"type": "object",
6060
"properties": {
@@ -66,7 +66,7 @@ pub fn functions(add_proc: bool) -> serde_json::Value {
6666
"type": "array",
6767
"items": {
6868
"type": "integer",
69-
"description": "The indices of the paths to search. paths.len() <= 10"
69+
"description": "The indices of the paths to search. paths.len() <= 5"
7070
}
7171
}
7272
},
@@ -93,24 +93,23 @@ pub fn system<'a>(paths: impl IntoIterator<Item = &'a str>) -> String {
9393
}
9494

9595
s.push_str(
96-
r#"Follow these rules at all times:
96+
r#"Your job is to choose the best action. Call functions to find information that will help answer the user's query. Call functions.none when you have enough information to answer. Follow these rules at all times:
9797
9898
- ALWAYS call a function, DO NOT answer the question directly, even if the query is not in English
9999
- DO NOT call a function that you've used before with the same arguments
100100
- DO NOT assume the structure of the codebase, or the existence of files or folders
101-
- Call functions to find information that will help answer the user's query, until all relevant information has been found
102-
- Only call functions.proc with path indices that are under the PATHS heading above
103-
- If the output of a function is empty, try calling the function again with different arguments OR try calling a different function
104-
- If functions.code or functions.path did not return any relevant information, call them again with a SIGNIFICANTLY different query. The terms in the new query should not overlap with terms in your old one
105-
- Call functions.proc with paths that you have reason to believe might contain relevant information. Either because of the path name, or to expand on code that's already been returned by functions.code
106-
- DO NOT pass more than 5 paths to functions.proc at a time
101+
- Call functions.none with paths that you are confident will help answer the user's query
107102
- In most cases call functions.code or functions.path functions before calling functions.none
108-
- When you have enough information to answer the user call functions.none. DO NOT answer the user directly
109-
- If the user is referring to information that is already in your history, call functions.none
103+
- If the user is referring to, or asking for, information that is in your history, call functions.none
104+
- If after attempting to gather information you are still unsure how to answer the query, call functions.none
105+
- If the query is a greeting, or not a question or an instruction call functions.none
110106
- When calling functions.code or functions.path, your query should consist of keywords. E.g. if the user says 'What does contextmanager do?', your query should be 'contextmanager'. If the user says 'How is contextmanager used in app', your query should be 'contextmanager app'. If the user says 'What is in the src directory', your query should be 'src'
111-
- Only call functions.none with paths that might help answer the user's query
112-
- If after attempting to gather information you are still unsure how to answer the query, respond with the functions.none function
113-
- If the query is a greeting, or not a question or an instruction use functions.none
107+
- If functions.code or functions.path did not return any relevant information, call them again with a SIGNIFICANTLY different query. The terms in the new query should not overlap with terms in your old one
108+
- If the output of a function is empty, try calling the function again with DIFFERENT arguments OR try calling a different function
109+
- Only call functions.proc with path indices that are under the PATHS heading above
110+
- Call functions.proc with paths that might contain relevant information. Either because of the path name, or to expand on code that's already been returned by functions.code
111+
- DO NOT call functions.proc with more than 5 paths
112+
- DO NOT call functions.proc on the same file more than once
114113
- ALWAYS call a function. DO NOT answer the question directly"#);
115114
s
116115
}
@@ -150,24 +149,6 @@ A: "#
150149
)
151150
}
152151

153-
/*
154-
155-
format!(
156-
r#"{context}#####
157-
158-
A user is looking at the code above, they'd like you to answer their queries.
159-
160-
Your output will be interpreted as bloop-markdown which renders with the following rules:
161-
- All github-markdown rules are accepted
162-
- Lines of code can be referenced using the URL format: [foo.rs](src/foo.rs#L50-L78)
163-
- In this example, the link is to the file src/foo.rs and the lines 50 to 78
164-
- Links should be semantically named to help the user understand when they're clicking on
165-
- When referring to lines of code, you must use a link
166-
- When referring to code symbols (functions, methods, fields, classes, structs, types, variables, values, definitions, directories, etc), you must use a link"#
167-
)
168-
169-
*/
170-
171152
pub fn answer_article_prompt(aliases: &[usize], context: &str) -> String {
172153
// Return different prompts depending on whether there is one or many aliases
173154
let one_prompt = format!(

server/bleep/src/agent/tools/code.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Agent {
3434
results.extend(hyde_results);
3535
}
3636

37-
let chunks = results
37+
let mut chunks = results
3838
.into_iter()
3939
.map(|chunk| {
4040
let relative_path = chunk.relative_path;
@@ -49,6 +49,8 @@ impl Agent {
4949
})
5050
.collect::<Vec<_>>();
5151

52+
chunks.sort_by(|a, b| a.alias.cmp(&b.alias).then(a.start_line.cmp(&b.start_line)));
53+
5254
for chunk in chunks.iter().filter(|c| !c.is_empty()) {
5355
self.exchanges
5456
.last_mut()

server/bleep/src/agent/tools/proc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl Agent {
174174
.collect::<Vec<_>>()
175175
.await;
176176

177-
let chunks = processed
177+
let mut chunks = processed
178178
.into_iter()
179179
.flat_map(|(relevant_chunks, path)| {
180180
let alias = self.get_path_alias(&path);
@@ -189,6 +189,8 @@ impl Agent {
189189
})
190190
.collect::<Vec<_>>();
191191

192+
chunks.sort_by(|a, b| a.alias.cmp(&b.alias).then(a.start_line.cmp(&b.start_line)));
193+
192194
for chunk in chunks.iter().filter(|c| !c.is_empty()) {
193195
self.exchanges
194196
.last_mut()

0 commit comments

Comments
 (0)