Skip to content

Commit dc42eb9

Browse files
authored
Merge pull request #30 from altaidevorg/cleanup
Code cleanup
2 parents 4028c69 + b8c0e17 commit dc42eb9

3 files changed

Lines changed: 7 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "isanagent"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2021"
55
license = "Apache-2.0"
66
repository = "https://github.com/altaidevorg/isanagent"

src/agent/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ fn trim_context_to_budget(context: &mut Vec<crate::utils::ChatMessage>, max_toke
134134
// This is the same heuristic used by the existing compaction logic.
135135
let estimate_msg_tokens = |msg: &crate::utils::ChatMessage| -> usize {
136136
let text_len = msg.content.as_ref().map_or(0, |c| c.text_content().len());
137-
let args_len = msg
138-
.tool_calls
139-
.as_ref()
140-
.map_or(0, |tcs| tcs.iter().map(|t| t.function.arguments.len()).sum());
137+
let args_len = msg.tool_calls.as_ref().map_or(0, |tcs| {
138+
tcs.iter().map(|t| t.function.arguments.len()).sum()
139+
});
141140
(text_len + args_len) / 4
142141
};
143142

@@ -164,8 +163,8 @@ fn trim_context_to_budget(context: &mut Vec<crate::utils::ChatMessage>, max_toke
164163
block_end += 1;
165164
}
166165
// Subtract the tokens for this entire block
167-
for idx in trim_pos..block_end {
168-
remaining = remaining.saturating_sub(estimate_msg_tokens(&context[idx]));
166+
for msg in context[trim_pos..block_end].iter() {
167+
remaining = remaining.saturating_sub(estimate_msg_tokens(msg));
169168
}
170169
context.drain(trim_pos..block_end);
171170
trimmed = true;
@@ -1640,7 +1639,6 @@ impl AgentLogic {
16401639

16411640
// Trim context to stay within token budget before calling the provider
16421641
trim_context_to_budget(&mut context, MAX_CONTEXT_TOKENS_DEFAULT);
1643-
16441642
let _ = logger_tx.send(BusMessage::Log(
16451643
LogEvent::debug(
16461644
&name,

src/utils.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,7 @@ impl LLMClient {
475475
match serde_json::from_value::<Vec<ToolCallRequest>>(tc_json) {
476476
Ok(calls) => Some(calls),
477477
Err(e) => {
478-
warn!(
479-
"Failed to parse tool_calls from provider response: {}",
480-
e
481-
);
478+
warn!("Failed to parse tool_calls from provider response: {}", e);
482479
None
483480
}
484481
}

0 commit comments

Comments
 (0)