Skip to content

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

refactor(flows): route copilot helpers through the module bus

Steven Enamakelb46f7a899e55
diff --git a/crates/openhuman-core/src/flows/agents/workflow_builder/mod.rs b/crates/openhuman-core/src/flows/agents/workflow_builder/mod.rs
index 340ec44f00..43821aa333 100644
--- a/crates/openhuman-core/src/flows/agents/workflow_builder/mod.rs
+++ b/crates/openhuman-core/src/flows/agents/workflow_builder/mod.rs
@@ -1,18 +1,8 @@
//! The `workflow_builder` built-in agent: this host's wiring of the tinyflows
//! authoring copilot.
//!
-//! The copilot itself — the standing archetype that teaches the graph DSL and
-//! the propose-only contract, and the turn brief that opens an authoring turn —
-//! lives in `tinyflows-copilot` and names no harness. What is here is the
-//! wiring: [`prompt`] assembles that archetype with this host's runtime
-//! sections (the agent's tool list, the workspace footer), and
-//! `agent.toml` registers the agent with this host's registry.
-//!
-//! [`builder_prompt`] is the historical path the brief was reached by; it is a
-//! re-export now, so `agents::workflow_builder::builder_prompt::BuilderRequest`
-//! keeps resolving.
+//! `prompt` assembles the workflow-builder archetype with this host's runtime
+//! sections, while the asynchronous `flows.build` operation asks the compiled
+//! TinyFlows module to render per-turn builder briefs.
pub mod prompt;
-
-/// The harness-independent turn brief, from `tinyflows-copilot`.
-pub use tinyflows_copilot::builder as builder_prompt;
diff --git a/crates/openhuman-core/src/flows/copilot_bus.rs b/crates/openhuman-core/src/flows/copilot_bus.rs
index a3fde40f5d..dc1e7fd09f 100644
--- a/crates/openhuman-core/src/flows/copilot_bus.rs
+++ b/crates/openhuman-core/src/flows/copilot_bus.rs
@@ -3,12 +3,25 @@
use std::collections::HashMap;
use std::sync::Arc;
-use serde_json::{Value, json};
+use serde::{Serialize, de::DeserializeOwned};
+use serde_json::Value;
use tinyflows_bus::copilot::{ToolCatalogRequest, ToolDescriptor};
use tinytools::{PermissionLevel, Tool, ToolResult};
use crate::config::Config;
+pub(crate) async fn call<R, A>(config: &Config, member: &'static str, args: A) -> Result<R, String>
+where
+ R: DeserializeOwned,
+ A: Serialize,
+{
+ let proxy = crate::modules::tinyflows::copilot_proxy(config).await?;
+ proxy
+ .call(member, args)
+ .await
+ .map_err(|error| error.wire_message())
+}
+
/// The module's tool metadata plus the host-only node-kind overlay for calls.
pub(crate) struct CopilotToolCatalog {
config: Arc<Config>,
diff --git a/crates/openhuman-core/src/flows/ops/approval_manifest.rs b/crates/openhuman-core/src/flows/ops/approval_manifest.rs
index 983db2b21a..50d9ab3d01 100644
--- a/crates/openhuman-core/src/flows/ops/approval_manifest.rs
+++ b/crates/openhuman-core/src/flows/ops/approval_manifest.rs
@@ -96,6 +96,15 @@ pub async fn compute_approval_manifest(config: &Config, graph: &WorkflowGraph) -
entries
}
+/// Approval manifest for a portable graph payload from the Copilot bus.
+pub(crate) async fn approval_manifest_json(
+ config: &Config,
+ graph: Value,
+) -> Result<Vec<Value>, String> {
+ let graph = tinyflows::migrate::deserialize_graph(graph)?;
+ Ok(compute_approval_manifest(config, &graph).await)
+}
+
/// RPC: the approval manifest for a saved flow (by `id`) or a candidate
/// `graph`, joined against the flow's existing `flow_tool_trust` grants so
/// the save+enable card can ask only for what's missing.
diff --git a/crates/openhuman-core/src/flows/ops/builder_gates.rs b/crates/openhuman-core/src/flows/ops/builder_gates.rs
index a5658c0abb..46b90f1ff9 100644
--- a/crates/openhuman-core/src/flows/ops/builder_gates.rs
+++ b/crates/openhuman-core/src/flows/ops/builder_gates.rs
@@ -295,6 +295,47 @@ pub(crate) async fn build_builder_proposal(
Ok(payload)
}
+/// Decode the Copilot bus's portable graph payload and run the host-owned
+/// proposal gates without exposing engine types through the callback adapter.
+#[allow(clippy::too_many_arguments)]
+pub(crate) async fn build_builder_proposal_json(
+ ctx: &DispatchCtx,
+ config: &Config,
+ retry_tool: String,
+ name: String,
+ graph: Value,
+ require_approval: bool,
+ revision: bool,
+ instruction: Option<String>,
+ draft_id: Option<String>,
+ flow_id: Option<String>,
+) -> Result<Value, String> {
+ let graph = tinyflows::migrate::deserialize_graph(graph)?;
+ build_builder_proposal(
+ ctx,
+ config,
+ &retry_tool,
+ &name,
+ &graph,
+ require_approval,
+ revision,
+ instruction,
+ draft_id,
+ flow_id,
+ )
+ .await
+}
+
+/// Run the configured builder gates on the Copilot bus's portable graph payload.
+pub(crate) async fn run_builder_gates_json(
+ ctx: &DispatchCtx,
+ config: &Config,
+ graph: Value,
+) -> Result<Vec<String>, String> {
+ let graph = tinyflows::migrate::deserialize_graph(graph)?;
+ Ok(run_builder_gates(ctx, config, &graph).await)
+}
+
// ─────────────────────────────────────────────────────────────────────────────
// Agent-ref resolvability gate: an `agent` node's `agent_ref` must name a
// real agent, not the runtime's `RegistryFallback` "unknown agent_ref" case
diff --git a/crates/openhuman-core/src/flows/ops/run.rs b/crates/openhuman-core/src/flows/ops/run.rs
index a5bae19b43..aac598d8d1 100644
--- a/crates/openhuman-core/src/flows/ops/run.rs
+++ b/crates/openhuman-core/src/flows/ops/run.rs
@@ -158,6 +158,17 @@ pub async fn flows_run_detached(
))
}
+/// Start the Copilot's confirmed test run as a detached RPC-origin flow run.
+pub(crate) async fn flows_run_copilot(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ flow_id: &str,
+ input: Value,
+ inputs: serde_json::Map<String, Value>,
+) -> Result<Outcome<Value>, String> {
+ flows_run_detached(ctx, config, flow_id, input, inputs, FlowRunTrigger::Rpc).await
+}
+
/// A validated, ready-to-execute flow run: the loaded [`Flow`], the freshly
/// minted `thread_id` (== run id / checkpointer key), and whether the graph has
/// no actionable nodes. Produced by [`prepare_flow_run`] and consumed by both
diff --git a/crates/openhuman-core/src/flows/ops/trail_off.rs b/crates/openhuman-core/src/flows/ops/trail_off.rs
index 986992a887..09ecd23596 100644
--- a/crates/openhuman-core/src/flows/ops/trail_off.rs
+++ b/crates/openhuman-core/src/flows/ops/trail_off.rs
@@ -1,22 +1,17 @@
-use tinyflows_copilot::fallback::{self, ToolResult};
+use super::*;
+use tinyflows_bus::copilot::{TextResponse, ToolResultSummary, TrailOffRequest};
-// The pure text heuristics (`text_looks_like_question`) and the whole
-// trail-off fallback construction live in `tinyflows-copilot`; what stays here
-// is the host adapter that correlates the harness `TranscriptEntry` history
-// into the module's `ToolResult` shape.
-pub(super) use tinyflows_copilot::fallback::combine_trail_off_fallback;
-pub(super) use tinyflows_copilot::text_looks_like_question;
-
-/// Correlates each `ToolResults` entry's `tool_call_id` back to the
-/// `AssistantToolCalls` message that issued it, in chronological order.
-fn correlate_tool_results(
+/// Correlates transcript results back to their tool calls and asks the module
+/// to construct the product's terminal fallback question.
+pub(super) async fn build_trail_off_fallback(
+ config: &Config,
history: &[tinytools_agent::dialect::TranscriptEntry],
-) -> Vec<ToolResult> {
+) -> Result<String, String> {
use tinytools_agent::dialect::TranscriptEntry;
let mut call_names: std::collections::HashMap<String, String> =
std::collections::HashMap::new();
- let mut out = Vec::new();
+ let mut results = Vec::new();
for message in history {
match message {
TranscriptEntry::AssistantToolCalls { tool_calls, .. } => {
@@ -24,9 +19,9 @@ fn correlate_tool_results(
call_names.insert(call.id.clone(), call.name.clone());
}
}
- TranscriptEntry::ToolResults(results) => {
- for result in results {
- out.push(ToolResult {
+ TranscriptEntry::ToolResults(tool_results) => {
+ for result in tool_results {
+ results.push(ToolResultSummary {
tool_name: call_names.get(&result.tool_call_id).cloned(),
content: result.content.clone(),
});
@@ -35,13 +30,43 @@ fn correlate_tool_results(
_ => {}
}
}
- out
+ let response: TextResponse = crate::flows::copilot_bus::call(
+ config,
+ "BuildTrailOffFallback",
+ (TrailOffRequest { history: results },),
+ )
+ .await?;
+ Ok(response.text)
}
-/// Synthesizes the guaranteed user-facing fallback for a trail-off turn from
-/// the run's harness history (construction is `tinyflows-copilot`'s).
-pub(super) fn build_trail_off_fallback(
- history: &[tinytools_agent::dialect::TranscriptEntry],
-) -> String {
- fallback::build_trail_off_fallback(&correlate_tool_results(history))
+pub(super) async fn combine_trail_off_fallback(
+ config: &Config,
+ fallback: &str,
+ original: &str,
+) -> Result<String, String> {
+ let response: TextResponse = crate::flows::copilot_bus::call(
+ config,
+ "CombineTrailOffFallback",
+ (fallback, original),
+ )
+ .await?;
+ Ok(response.text)
+}
+
+pub(super) async fn text_looks_like_question(config: &Config, text: &str) -> Result<bool, String> {
+ crate::flows::copilot_bus::call(config, "TextLooksLikeQuestion", (text,)).await
+}
+
+pub(super) async fn is_backend_or_infrastructure_failure(
+ config: &Config,
+ error: &str,
+) -> Result<bool, String> {
+ crate::flows::copilot_bus::call(config, "IsBackendOrInfrastructureFailure", (error,)).await
+}
+
+pub(super) async fn backend_repair_message(
+ config: &Config,
+ error: &str,
+) -> Result<Option<String>, String> {
+ crate::flows::copilot_bus::call(config, "BackendRepairMessage", (error,)).await
}
diff --git a/crates/openhuman-core/src/flows/ops/validation.rs b/crates/openhuman-core/src/flows/ops/validation.rs
index 006d372a30..c57fdbbb11 100644
--- a/crates/openhuman-core/src/flows/ops/validation.rs
+++ b/crates/openhuman-core/src/flows/ops/validation.rs
@@ -63,6 +63,15 @@ pub(crate) fn config_aware_engine_compatibility_errors(
referenced_workflow_compatibility_errors(config, graph)
}
+/// Config-aware compatibility check for a portable Copilot graph payload.
+pub(crate) fn engine_compatibility_errors_json(
+ config: &Config,
+ graph: Value,
+) -> Result<Vec<String>, String> {
+ let graph = tinyflows::migrate::deserialize_graph(graph)?;
+ Ok(config_aware_engine_compatibility_errors(config, &graph))
+}
+
/// Validates a candidate graph without persisting it — the same
/// migrate/validate path `flows_create` and `ProposeWorkflowTool` use — and
/// reports structural errors alongside non-fatal trigger warnings
diff --git a/crates/openhuman-core/src/flows/ops/wiring_warnings.rs b/crates/openhuman-core/src/flows/ops/wiring_warnings.rs
index e8cce9eeb9..8cc8bc86e9 100644
--- a/crates/openhuman-core/src/flows/ops/wiring_warnings.rs
+++ b/crates/openhuman-core/src/flows/ops/wiring_warnings.rs
@@ -55,6 +55,15 @@ pub(crate) async fn graph_wiring_warnings(config: &Config, graph: &WorkflowGraph
warnings
}
+/// Best-effort wiring diagnostics for a portable Copilot graph payload.
+pub(crate) async fn wiring_warnings_json(
+ config: &Config,
+ graph: Value,
+) -> Result<Vec<String>, String> {
+ let graph = tinyflows::migrate::deserialize_graph(graph)?;
+ Ok(graph_wiring_warnings(config, &graph).await)
+}
+
/// Author-time WARN (systemic tool-contract fix, Part 2c): any
/// `=nodes.<id>.item.json.data.<field>` binding — anywhere in the graph, not
/// just `tool_call` args — whose `<id>` names a `tool_call` node calling a