Skip to content

Commit 0ba729a

Browse files
committed
chore: improve anda_assistant
1 parent 07c20dd commit 0ba729a

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
]
1313

1414
[workspace.package]
15-
version = "0.9.1"
15+
version = "0.9.2"
1616
description = "Anda is an AI agent framework built with Rust, powered by ICP and TEEs."
1717
repository = "https://github.com/ldclabs/anda"
1818
homepage = "https://github.com/ldclabs/anda"

agents/anda_assistant/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "anda_assistant"
33
description = "Anda -- an AI Assistant powered by the Knowledge Interaction Protocol (KIP)."
44
repository = "https://github.com/ldclabs/anda/tree/main/agents/anda_assistant"
55
publish = true
6-
version = "0.4.2"
6+
version = "0.4.3"
77
edition.workspace = true
88
keywords.workspace = true
99
categories.workspace = true

agents/anda_assistant/src/agent.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use anda_cognitive_nexus::{CognitiveNexus, ConceptPK};
22
use anda_core::{
3-
Agent, AgentContext, AgentOutput, BoxError, CompletionRequest, Document, Documents, Message,
4-
Principal, Resource, StateFeatures, Tool, ToolSet, Usage, evaluate_tokens, update_resources,
3+
Agent, AgentContext, AgentOutput, BoxError, CacheExpiry, CacheFeatures, CompletionRequest,
4+
Document, Documents, Message, Principal, Resource, StateFeatures, Tool, ToolSet, Usage,
5+
evaluate_tokens, update_resources,
56
};
67
use anda_db::{database::AndaDB, index::BTree};
78
use anda_engine::{
@@ -18,7 +19,7 @@ use anda_kip::{
1819
META_SELF_NAME, PERSON_SELF_KIP, PERSON_SYSTEM_KIP, PERSON_TYPE, SELF_INSTRUCTIONS,
1920
SYSTEM_INSTRUCTIONS, parse_kml,
2021
};
21-
use std::{collections::BTreeMap, sync::Arc};
22+
use std::{collections::BTreeMap, sync::Arc, time::Duration};
2223

2324
#[derive(Clone)]
2425
pub struct Assistant {
@@ -188,29 +189,36 @@ impl Agent<AgentCtx> for Assistant {
188189
return Err("anonymous caller not allowed".into());
189190
}
190191

191-
let user_name = ctx
192-
.meta()
193-
.user
194-
.clone()
195-
.unwrap_or_else(|| caller.to_string());
192+
let caller_key = format!("Running:{}", caller);
193+
let created_at = unix_ms();
194+
let ok = ctx
195+
.cache_set_if_not_exists(
196+
&caller_key,
197+
(created_at, Some(CacheExpiry::TTL(Duration::from_secs(300)))),
198+
)
199+
.await;
200+
if !ok {
201+
return Err("Only one prompt can run at a time for you".into());
202+
}
203+
196204
let caller_info = self
197205
.memory
198206
.describe_caller(caller)
199207
.await
200208
.unwrap_or_else(|_| {
201209
serde_json::json!({
202-
"id": caller.to_string(),
203-
"name": user_name
210+
"type": "Person",
211+
"name": caller.to_string(),
212+
"attributes": {},
204213
})
205214
});
206215

207216
let created_at = unix_ms();
208217
let primer = self.memory.describe_primer().await?;
209218
let instructions = format!(
210219
"{}\n---\n# Your Identity & Knowledge Domain Map\n{}\n",
211-
SYSTEM_INSTRUCTIONS, primer
220+
self.system_instructions, primer
212221
);
213-
214222
let (mut conversations, mut cursor) = self
215223
.memory
216224
.list_conversations_by_user(caller, None, Some(7))
@@ -280,7 +288,7 @@ impl Agent<AgentCtx> for Assistant {
280288
format!(
281289
"Current Datetime: {}\n---\n{}",
282290
rfc3339_datetime(created_at).unwrap_or_else(|| format!("unix_ms:{created_at}")),
283-
Documents::new("history".to_string(), history_docs)
291+
Documents::new("user_context".to_string(), history_docs)
284292
)
285293
.into(),
286294
],
@@ -424,6 +432,7 @@ impl Agent<AgentCtx> for Assistant {
424432
Ok::<(), BoxError>(())
425433
};
426434

435+
ctx.cache_delete(&caller_key).await;
427436
match rt().await {
428437
Ok(_) => {}
429438
Err(err) => {

0 commit comments

Comments
 (0)