Skip to content

Commit d4c4b4e

Browse files
committed
improve agent
1 parent ad7c277 commit d4c4b4e

File tree

2 files changed

+14
-53
lines changed

2 files changed

+14
-53
lines changed

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ async fn main() -> color_eyre::Result<()> {
6060
dotenv::dotenv().ok();
6161

6262
tracing_subscriber::fmt()
63-
.with_env_filter(
64-
tracing_subscriber::EnvFilter::new("debug,h2::codec::framed_read=off")
65-
)
63+
.with_env_filter(tracing_subscriber::EnvFilter::new(
64+
"debug,h2::codec::framed_read=off,twilight_gateway::shard=off,twilight_http_ratelimiting::in_memory=info,rustls::client=info,hyper::client::connect=info",
65+
))
6666
.init();
6767

6868
let mut cfg = Config::parse();

src/memory_creator.rs

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ use r2d2_sqlite::SqliteConnectionManager;
77
use serde::{Deserialize, Serialize};
88
use serde_rusqlite::from_row;
99
use std::{collections::HashMap, sync::Arc};
10-
use wb_sqlite::InsertSync;
1110

12-
use crate::{
13-
config::Config,
14-
database::{Memory, User},
15-
};
11+
use crate::{config::Config, database::User};
1612

1713
/// JSON response structure for memory creation
1814
#[derive(Debug, Serialize, Deserialize)]
@@ -58,45 +54,21 @@ Respond ONLY with valid JSON in this exact format:
5854
IMPORTANT GUIDELINES:
5955
- Only create memories if there's meaningful information from THIS conversation
6056
- Each user should have AT MOST ONE memory entry per unique "key" category
61-
- The "key" should be a broad category like "preferences", "hobbies", "work", "personality", "relationships", "recent_activity"
57+
- The "key" should be a broad category like "preferences", "hobbies", "work", "personality", "relationships", "recent_activity" but can be anything like outside_hobbies could work too
6258
- The "content" should combine ALL related facts for that category into ONE comprehensive entry
6359
- Use exact usernames as they appear in the conversation
6460
- If there's nothing meaningful to remember, return an empty memories array
6561
66-
EXAMPLE - CORRECT (combining multiple facts under one key):
67-
{{
68-
"memories": [
69-
{{
70-
"username": "tricked.",
71-
"key": "preferences",
72-
"content": "Likes cats, dislikes insects"
73-
}}
74-
]
75-
}}
76-
77-
EXAMPLE - WRONG (duplicate keys for same user):
78-
{{
79-
"memories": [
80-
{{"username": "tricked.", "key": "preferences", "content": "Likes cats"}},
81-
{{"username": "tricked.", "key": "preferences", "content": "Dislikes insects"}}
82-
]
83-
}}
84-
8562
Remember: Output ONLY valid JSON, nothing else. Combine related information under the same key."#,
8663
context = context,
8764
participants = participants
8865
)
8966
}
9067

9168
/// Resolve usernames to user IDs using the database
92-
fn resolve_username_to_id(
93-
database: &r2d2::Pool<SqliteConnectionManager>,
94-
username: &str,
95-
) -> Option<u64> {
69+
fn resolve_username_to_id(database: &r2d2::Pool<SqliteConnectionManager>, username: &str) -> Option<u64> {
9670
let db = database.get().ok()?;
97-
let mut stmt = db
98-
.prepare("SELECT * FROM user WHERE name = ? COLLATE NOCASE")
99-
.ok()?;
71+
let mut stmt = db.prepare("SELECT * FROM user WHERE name = ? COLLATE NOCASE").ok()?;
10072

10173
stmt.query_one([username], |row| {
10274
from_row::<User>(row).map_err(|_| rusqlite::Error::QueryReturnedNoRows)
@@ -108,12 +80,7 @@ fn resolve_username_to_id(
10880
/// Insert a new memory in the database
10981
/// If a memory with the same user_id and key exists, delete it first then insert the new one
11082
/// This ensures the new memory has the latest timestamp and will be in the top 5 most recent
111-
fn insert_memory(
112-
database: &r2d2::Pool<SqliteConnectionManager>,
113-
user_id: u64,
114-
key: &str,
115-
content: &str,
116-
) -> Result<()> {
83+
fn insert_memory(database: &r2d2::Pool<SqliteConnectionManager>, user_id: u64, key: &str, content: &str) -> Result<()> {
11784
let db = database.get()?;
11885

11986
// Delete any existing memory with the same user_id and key
@@ -122,23 +89,17 @@ fn insert_memory(
12289
rusqlite::params![user_id.to_string(), key],
12390
)?;
12491

125-
// Insert the new memory (will get a new ID and timestamp)
126-
let memory = Memory {
127-
id: 0, // Will be auto-generated
128-
user_id: user_id.to_string(),
129-
content: content.to_string(),
130-
key: key.to_string(),
131-
};
132-
memory.insert_sync(&db)?;
92+
// Insert the new memory (id will be auto-generated by AUTOINCREMENT)
93+
db.execute(
94+
"INSERT INTO memory (user_id, content, key) VALUES (?, ?, ?)",
95+
rusqlite::params![user_id.to_string(), content, key],
96+
)?;
13397

13498
Ok(())
13599
}
136100

137101
/// Process memory creation response and store in database
138-
fn process_memory_response(
139-
database: &r2d2::Pool<SqliteConnectionManager>,
140-
response_text: &str,
141-
) -> Result<usize> {
102+
fn process_memory_response(database: &r2d2::Pool<SqliteConnectionManager>, response_text: &str) -> Result<usize> {
142103
log::info!("Raw memory response: {}", response_text);
143104

144105
// Try to extract JSON from the response (in case the model adds extra text)

0 commit comments

Comments
 (0)