Skip to content

Commit d254a0b

Browse files
committed
fix: Fix memory embedding initialization
1 parent e459fde commit d254a0b

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

huly-coder.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
2-
# You can override config in ~\huly-coder.yaml file
2+
# You can override config in ~\huly-coder.yaml file
3+
# or huly-coder-local.yaml file
34
#
45

56
### Example Anthropic config

src/agent/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright © 2025 Huly Labs. Use of this source code is governed by the MIT license.
22
use std::sync::Arc;
3-
use std::sync::RwLock;
43

54
use crate::config::McpClientTransport;
65
use crate::config::McpConfig;
@@ -45,6 +44,7 @@ pub mod event;
4544
pub mod utils;
4645
pub use event::AgentControlEvent;
4746
pub use event::AgentOutputEvent;
47+
use tokio::sync::RwLock;
4848

4949
use self::event::AgentCommandStatus;
5050
use self::event::AgentState;
@@ -95,8 +95,9 @@ impl Agent {
9595
state: AgentState::Paused,
9696
}
9797
}
98-
async fn init_memory_index(&mut self) {
99-
let documents = self.memory.read().unwrap().entities().clone();
98+
99+
pub async fn init_memory_index(&mut self) {
100+
let documents = self.memory.read().await.entities().clone();
100101
let client = rig_fastembed::Client::new();
101102
let model = client.embedding_model(&rig_fastembed::FastembedModel::AllMiniLML6V2);
102103
let embeddings = EmbeddingsBuilder::new(model.clone())
@@ -506,7 +507,6 @@ impl Agent {
506507
.await
507508
.unwrap(),
508509
);
509-
self.init_memory_index().await;
510510
// restore state from messages
511511
self.set_state(if self.messages.is_empty() {
512512
AgentState::WaitingUserPrompt

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ async fn main() -> color_eyre::Result<()> {
112112
output_sender,
113113
history.clone(),
114114
);
115+
agent.init_memory_index().await;
116+
115117
tokio::spawn(async move {
116118
agent.run().await;
117119
});

src/tools/memory/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Copyright © 2025 Huly Labs. Use of this source code is governed by the MIT license.
55
use std::collections::HashSet;
66
use std::fs;
7-
use std::sync::{Arc, RwLock};
7+
use std::sync::Arc;
88

99
use indicium::simple::{Indexable, SearchIndex};
1010
use rig::agent::AgentBuilder;
@@ -33,11 +33,11 @@ macro_rules! create_tool {
3333
($func_name:ident, $tool_name:ident) => {
3434
paste::paste! {
3535
pub struct [<$func_name Tool>] {
36-
manager: Arc<RwLock<MemoryManager>>,
36+
manager: Arc<tokio::sync::RwLock<MemoryManager>>,
3737
}
3838

3939
impl [<$func_name Tool>] {
40-
pub(self) fn new(manager: Arc<RwLock<MemoryManager>>) -> Self {
40+
pub(self) fn new(manager: Arc<tokio::sync::RwLock<MemoryManager>>) -> Self {
4141
Self { manager }
4242
}
4343
}
@@ -63,7 +63,7 @@ macro_rules! create_tool {
6363
}
6464

6565
async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
66-
self.manager.write().unwrap().call_tool(&self.name(), args)
66+
self.manager.write().await.call_tool(&self.name(), args)
6767
}
6868

6969
fn name(&self) -> String {
@@ -374,7 +374,7 @@ create_tool!(MemoryOpenNodes, open_nodes);
374374

375375
pub(crate) fn add_memory_tools<M>(
376376
agent_builder: AgentBuilder<M>,
377-
memory: Arc<RwLock<MemoryManager>>,
377+
memory: Arc<tokio::sync::RwLock<MemoryManager>>,
378378
) -> AgentBuilder<M>
379379
where
380380
M: CompletionModel,

0 commit comments

Comments
 (0)