Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(caps_host): decouple prompt helpers from tinyflows internals

Steven Enamakel004d98594356
diff --git a/crates/openhuman-core/src/flows/caps_host/prompt.rs b/crates/openhuman-core/src/flows/caps_host/prompt.rs
index 8797ee1242..05ace67eb9 100644
--- a/crates/openhuman-core/src/flows/caps_host/prompt.rs
+++ b/crates/openhuman-core/src/flows/caps_host/prompt.rs
@@ -1,59 +1,39 @@
-//! Turning a node's request into a completion, and a completion back into a
-//! node result.
-//!
-//! The pure request/reply handling (the `input_context` carrier, structured
-//! output steering, tolerant JSON extraction) lives in
-//! `tinyflows::nodes::integration::agent_prompt`; this file keeps the host
-//! mapping of its neutral messages onto [`TranscriptMessage`], usage projection and
-//! model pinning.
+//! Host-side inference message and response projection.
-#![allow(unused_imports)]
-
-use std::sync::Arc;
-
-use async_trait::async_trait;
-use serde_json::{json, Value};
-use tinyflows::caps::*;
-use tinyflows::error::{EngineError, Result};
-
-use super::*;
-use crate::config::Config;
-use crate::inference::provider::{is_raw_passthrough_model, BilledUsage};
+use serde_json::{Value, json};
use tinyagents_session::transcript::TranscriptMessage;
-use tinyflows::nodes::integration::agent_prompt;
-
-/// [`agent_prompt::build_completion_messages`] mapped onto the host's
-/// [`TranscriptMessage`] type.
-pub(crate) fn build_completion_messages(request: &Value) -> Vec<TranscriptMessage> {
- agent_prompt::build_completion_messages(request)
- .into_iter()
- .map(|m| match m.role {
- "system" => TranscriptMessage::system(m.content),
- "assistant" => TranscriptMessage::assistant(m.content),
- "tool" => TranscriptMessage::tool(m.content),
- _ => TranscriptMessage::user(m.content),
+use tinyflows_bus::portability::CompletionMessage;
+
+/// Map module-normalized wire messages onto the host's transcript type.
+pub(crate) fn build_completion_messages(messages: &[CompletionMessage]) -> Vec<TranscriptMessage> {
+ messages
+ .iter()
+ .map(|message| match message.role.as_str() {
+ "system" => TranscriptMessage::system(message.content.clone()),
+ "assistant" => TranscriptMessage::assistant(message.content.clone()),
+ "tool" => TranscriptMessage::tool(message.content.clone()),
+ _ => TranscriptMessage::user(message.content.clone()),
})
.collect()
}
-/// Maps a `BilledUsage` (not `Serialize`) into a JSON value field-by-field, so
-/// [`OpenHumanLlm::complete`] can surface it in its response `Value` without
-/// requiring an upstream `Serialize` impl change.
-pub(crate) fn usage_to_json(usage: &Option<BilledUsage>) -> Value {
+/// Maps provider usage onto the established flow completion wire shape.
+pub(crate) fn usage_to_json(usage: &Option<crate::inference::provider::BilledUsage>) -> Value {
match usage {
None => Value::Null,
- Some(u) => json!({
- "input_tokens": u.input_tokens,
- "output_tokens": u.output_tokens,
- "context_window": u.context_window(),
- "cached_input_tokens": u.cached_input_tokens(),
- "cache_creation_tokens": u.cache_creation_tokens,
- "reasoning_tokens": u.reasoning_tokens,
- "charged_amount_usd": u.charged_amount_usd,
+ Some(usage) => json!({
+ "input_tokens": usage.input_tokens,
+ "output_tokens": usage.output_tokens,
+ "context_window": usage.context_window(),
+ "cached_input_tokens": usage.cached_input_tokens(),
+ "cache_creation_tokens": usage.cache_creation_tokens,
+ "reasoning_tokens": usage.reasoning_tokens,
+ "charged_amount_usd": usage.charged_amount_usd,
}),
}
}
+/// Maps a provider response to the established completion result envelope.
pub(crate) fn model_response_to_completion_value(
response: &tinyinference_llm::model::ModelResponse,
) -> Value {