Skip to content

Commit 2fdd1fc

Browse files
committed
some compression fixes, also fixed feed filter logic
1 parent e5fa202 commit 2fdd1fc

6 files changed

Lines changed: 465 additions & 380 deletions

File tree

crates/pattern_core/src/agent/entity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ impl AgentRecord {
349349
)
350350
} else {
351351
format!(
352-
r#"SELECT *, out.position as snowflake, batch, sequence_num, out.created_at AS msg_created FROM agent_messages
353-
WHERE in = $agent_id AND message_type = "active" AND batch IS NOT NULL
352+
r#"SELECT *, out.position as snowflake, batch, sequence_num, message_type, out.created_at AS msg_created FROM agent_messages
353+
WHERE in = $agent_id AND message_type = 'active' AND batch IS NOT NULL
354354
ORDER BY batch NUMERIC ASC, sequence_num NUMERIC ASC, snowflake NUMERIC ASC, msg_created ASC"#
355355
)
356356
};

crates/pattern_core/src/context/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl Default for ContextConfig {
156156
base_instructions: DEFAULT_BASE_INSTRUCTIONS.to_string(),
157157
memory_char_limit: DEFAULT_CORE_MEMORY_CHAR_LIMIT,
158158
max_context_messages: DEFAULT_MAX_CONTEXT_MESSAGES,
159-
max_context_tokens: Some(130000),
159+
max_context_tokens: Some(128000),
160160
enable_thinking: true,
161161
tool_usage_rules: Vec::new(),
162162
tool_workflow_rules: Vec::new(),
@@ -188,7 +188,7 @@ impl Default for ModelAdjustments {
188188
native_thinking: false,
189189
use_xml_tags: true,
190190
max_context_tokens: None,
191-
token_multiplier: 1.0, // Rough estimate: 1 token ≈ 0.75 words
191+
token_multiplier: 1.5, // Rough estimate: 1 token ≈ 0.75 words
192192
}
193193
}
194194
}

crates/pattern_core/src/context/state.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
db::{DatabaseError, DbEntity},
1616
id::MessageId,
1717
memory::{Memory, MemoryBlock, MemoryPermission, MemoryType},
18-
message::{Message, MessageContent, ToolCall, ToolResponse},
18+
message::{Message, MessageContent, MessageRelationType, ToolCall, ToolResponse},
1919
tool::ToolRegistry,
2020
};
2121

@@ -920,7 +920,7 @@ impl AgentHandle {
920920
// Filter by agent if needed
921921
// Get all message IDs belonging to this agent
922922
let agent_msg_sql = format!(
923-
"SELECT out FROM agent_messages WHERE in = {} AND out IS NOT NULL",
923+
"SELECT message_type, out FROM agent_messages WHERE in = {} AND message_type = 'archived' AND out IS NOT NULL ",
924924
self.agent_id.to_string()
925925
);
926926

@@ -933,12 +933,17 @@ impl AgentHandle {
933933
#[derive(serde::Deserialize)]
934934
struct OutRecord {
935935
out: RecordId,
936+
message_type: MessageRelationType,
936937
}
937938

938939
let out_records: Vec<OutRecord> =
939940
agent_msg_result.take(0).map_err(DatabaseError::from)?;
940941

941-
let agent_msg_ids: Vec<RecordId> = out_records.into_iter().map(|r| r.out).collect();
942+
let agent_msg_ids: Vec<RecordId> = out_records
943+
.into_iter()
944+
.filter(|r| r.message_type != MessageRelationType::Active)
945+
.map(|r| r.out)
946+
.collect();
942947

943948
let agent_msg_id_set: std::collections::HashSet<RecordId> =
944949
agent_msg_ids.into_iter().collect();
@@ -1046,7 +1051,7 @@ impl AgentHandle {
10461051

10471052
// Query the agent_messages relation table directly
10481053
let sql = format!(
1049-
"SELECT position, batch, sequence_num, ->(msg{}) AS messages FROM agent_messages WHERE (in = agent:{} AND out IS NOT NULL) ORDER BY batch NUMERIC DESC, sequence_num NUMERIC DESC, position NUMERIC DESC LIMIT $limit FETCH messages",
1054+
"SELECT position, batch, sequence_num, message_type, ->(msg{}) AS messages FROM agent_messages WHERE (in = agent:{} AND message_type = 'archived' AND out IS NOT NULL) ORDER BY batch NUMERIC DESC, sequence_num NUMERIC DESC, position NUMERIC DESC LIMIT $limit FETCH messages",
10501055
where_clause,
10511056
self.agent_id.to_key()
10521057
);
@@ -1194,7 +1199,7 @@ impl AgentHandle {
11941199
for agent in &agents {
11951200
let agent_id = crate::AgentId::from_record(agent.id.clone());
11961201
let agent_msg_sql = format!(
1197-
"SELECT out FROM agent_messages WHERE in = {} AND out IS NOT NULL",
1202+
"SELECT out FROM agent_messages WHERE in = {} AND out IS NOT NULL AND message_type = 'archived'",
11981203
agent_id.to_string()
11991204
);
12001205

0 commit comments

Comments
 (0)