Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/openfang-kernel/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5715,6 +5715,12 @@ impl KernelHandle for OpenFangKernel {
.collect()
}

fn touch_agent(&self, agent_id: &str) {
if let Ok(id) = agent_id.parse::<AgentId>() {
self.registry.touch(id);
}
}

fn kill_agent(&self, agent_id: &str) -> Result<(), String> {
let id: AgentId = agent_id
.parse()
Expand Down
8 changes: 8 additions & 0 deletions crates/openfang-kernel/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ impl AgentRegistry {
Ok(())
}

/// Touch an agent — refresh last_active without changing any other state.
/// Used by the agent loop to prevent heartbeat false-positives during long LLM calls.
pub fn touch(&self, id: AgentId) {
if let Some(mut entry) = self.agents.get_mut(&id) {
entry.last_active = chrono::Utc::now();
}
}

/// Update an agent's system prompt (hot-swap, takes effect on next message).
pub fn update_system_prompt(&self, id: AgentId, new_prompt: String) -> OpenFangResult<()> {
let mut entry = self
Expand Down
6 changes: 6 additions & 0 deletions crates/openfang-runtime/src/agent_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ pub async fn run_agent_loop(
cb(LoopPhase::Thinking);
}

// Stamp last_active before the (potentially long) LLM call so the
// heartbeat monitor doesn't flag us as unresponsive mid-iteration.
if let Some(k) = &kernel {
k.touch_agent(&agent_id_str);
}

// Call LLM with retry, error classification, and circuit breaker
let provider_name = manifest.model.provider.as_str();
let mut response = call_with_retry(&*driver, request, Some(provider_name), None).await?;
Expand Down
6 changes: 6 additions & 0 deletions crates/openfang-runtime/src/kernel_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ pub trait KernelHandle: Send + Sync {
Err("Channel file data send not available".to_string())
}

/// Refresh an agent's last_active timestamp without changing any other state.
/// Called by the agent loop before long LLM calls to prevent heartbeat false-positives.
fn touch_agent(&self, agent_id: &str) {
let _ = agent_id;
}

/// Spawn an agent with capability inheritance enforcement.
/// `parent_caps` are the parent's granted capabilities. The kernel MUST verify
/// that every capability in the child manifest is covered by `parent_caps`.
Expand Down
Loading