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
4 changes: 2 additions & 2 deletions crates/openfang-api/src/channel_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ChannelBridgeHandle for KernelBridgeAdapter {
async fn send_message(&self, agent_id: AgentId, message: &str) -> Result<String, String> {
let result = self
.kernel
.send_message(agent_id, message)
.send_message_channel_reply(agent_id, message)
.await
.map_err(|e| format!("{e}"))?;
// Silent/NO_REPLY responses should not be forwarded to channels
Expand Down Expand Up @@ -105,7 +105,7 @@ impl ChannelBridgeHandle for KernelBridgeAdapter {
};
let result = self
.kernel
.send_message_with_blocks(agent_id, &text, blocks)
.send_message_channel_reply_with_blocks(agent_id, &text, blocks)
.await
.map_err(|e| format!("{e}"))?;
Ok(result.response)
Expand Down
1 change: 1 addition & 0 deletions crates/openfang-api/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ pub async fn send_message(
content_blocks,
req.sender_id,
req.sender_name,
false,
)
.await
{
Expand Down
50 changes: 50 additions & 0 deletions crates/openfang-kernel/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,50 @@ impl OpenFangKernel {
Some(blocks),
None,
None,
false,
)
.await
}

/// Send a message in a channel-reply context: the caller (a channel
/// bridge) will deliver the agent's text response back to the originating
/// user-visible channel verbatim. Sets `text_reply_is_delivery = true`
/// so the phantom-action detector does not misfire on legitimate
/// text-only replies that describe channel actions.
pub async fn send_message_channel_reply(
&self,
agent_id: AgentId,
message: &str,
) -> KernelResult<AgentLoopResult> {
let handle: Option<Arc<dyn KernelHandle>> = self
.self_handle
.get()
.and_then(|w| w.upgrade())
.map(|arc| arc as Arc<dyn KernelHandle>);
self.send_message_with_handle_and_blocks(agent_id, message, handle, None, None, None, true)
.await
}

/// Multimodal channel-reply variant; see [`Self::send_message_channel_reply`].
pub async fn send_message_channel_reply_with_blocks(
&self,
agent_id: AgentId,
message: &str,
blocks: Vec<openfang_types::message::ContentBlock>,
) -> KernelResult<AgentLoopResult> {
let handle: Option<Arc<dyn KernelHandle>> = self
.self_handle
.get()
.and_then(|w| w.upgrade())
.map(|arc| arc as Arc<dyn KernelHandle>);
self.send_message_with_handle_and_blocks(
agent_id,
message,
handle,
Some(blocks),
None,
None,
true,
)
.await
}
Expand All @@ -1873,6 +1917,7 @@ impl OpenFangKernel {
None,
sender_id,
sender_name,
false,
)
.await
}
Expand All @@ -1886,6 +1931,7 @@ impl OpenFangKernel {
/// Per-agent locking ensures that concurrent messages for the same agent
/// are serialized (preventing session corruption), while messages for
/// different agents run in parallel.
#[allow(clippy::too_many_arguments)]
pub async fn send_message_with_handle_and_blocks(
&self,
agent_id: AgentId,
Expand All @@ -1894,6 +1940,7 @@ impl OpenFangKernel {
content_blocks: Option<Vec<openfang_types::message::ContentBlock>>,
sender_id: Option<String>,
sender_name: Option<String>,
text_reply_is_delivery: bool,
) -> KernelResult<AgentLoopResult> {
// Acquire per-agent lock to serialize concurrent messages for the same agent.
// This prevents session corruption when multiple messages arrive in quick
Expand Down Expand Up @@ -1931,6 +1978,7 @@ impl OpenFangKernel {
content_blocks,
sender_id,
sender_name,
text_reply_is_delivery,
)
.await
};
Expand Down Expand Up @@ -2637,6 +2685,7 @@ impl OpenFangKernel {
content_blocks: Option<Vec<openfang_types::message::ContentBlock>>,
sender_id: Option<String>,
sender_name: Option<String>,
text_reply_is_delivery: bool,
) -> KernelResult<AgentLoopResult> {
// Check metering quota before starting
self.metering
Expand Down Expand Up @@ -2969,6 +3018,7 @@ impl OpenFangKernel {
ctx_window,
Some(&self.process_manager),
content_blocks,
text_reply_is_delivery,
)
.await
.map_err(KernelError::OpenFang)?;
Expand Down
Loading
Loading