Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ window/gen/
window/permissions/autogenerated/
window/ui/node_modules/
window/ui/dist/
evals/runs/
evals/__pycache__/
31 changes: 28 additions & 3 deletions agentcore/src/turn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,33 @@ fn fit(mut result: Value, most: usize) -> Value {
/// again is stuck, and the result says so from the `REPEATS`th time on.
#[derive(Default)]
struct Repeats {
prev: u64,
last: u64,
times: u32,
cycle_times: u32,
}

impl Repeats {
/// Gives the model's copy of `call`'s `result`, with the note when it is a repeat.
/// Gives the model's copy of `call`'s `result`, with a nudge when the model is stuck in a
/// consecutive repeat (`A, A, A`) or an oscillating 2-call cycle (`A, B, A, B, A, B`).
fn note(&mut self, call: &Call, mut result: Value) -> Value {
let mut hash = DefaultHasher::new();
(&call.name, &call.arguments, result["content"].as_str()).hash(&mut hash);
let hash = hash.finish();
self.times = if hash == self.last { self.times + 1 } else { 1 };
self.last = hash;
if hash == self.last {
self.times += 1;
self.cycle_times = 0;
} else if hash == self.prev && self.last != 0 {
self.times = 1;
self.cycle_times += 1;
self.prev = self.last;
self.last = hash;
} else {
self.times = 1;
self.cycle_times = 0;
self.prev = self.last;
self.last = hash;
}
if self.times >= REPEATS
&& let Some(content) = result["content"].as_str()
{
Expand All @@ -334,6 +349,16 @@ impl Repeats {
self.times
)
.into();
} else if self.cycle_times >= REPEATS
&& let Some(content) = result["content"].as_str()
{
result["content"] = format!(
"{content}\n[You have alternated between the same two calls with the same results \
{} times. Repeating this cycle will not change it: try another approach, or \
answer with what you have.]",
self.cycle_times
)
.into();
}
result
}
Expand Down
Loading
Loading