The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(flows): add trail-off and trigger flow operations
Steven Enamakel4c4b0bec1007
diff --git a/crates/openhuman-core/src/flows/ops/trail_off.rs b/crates/openhuman-core/src/flows/ops/trail_off.rsindex 648ddd9a1b..be72f71b62 100644--- a/crates/openhuman-core/src/flows/ops/trail_off.rs+++ b/crates/openhuman-core/src/flows/ops/trail_off.rs@@ -1,137 +1,49 @@use super::*;-// The pure text heuristics (`text_looks_like_question` and the code-span / URL /-// paragraph checks under it) live in `tinyflows-copilot`; what stays here needs-// the host's `TranscriptEntry` history and tool names.-pub(super) use tinyflows_copilot::text_looks_like_question;--/// Builder-authoring tools whose result body can explain a trail-off — the-/// authoring belt `dry_run_workflow`/`validate_workflow`/`propose_workflow`/-/// `revise_workflow`/`edit_workflow`/`save_workflow` all report either a hard-/// gate rejection (`ToolResult::error`) or a self-reported broken-graph-/// result (`"ok": false` in a successful body), so a plain-text read-only-/// tool's output is never misattributed as the blocker.-const TRAIL_OFF_BLOCKER_TOOLS: &[&str] = &[- "dry_run_workflow",- "validate_workflow",- "propose_workflow",- "revise_workflow",- "edit_workflow",- "save_workflow",-];+use tinyflows_copilot::fallback::{self, ToolResult};-/// Synthesizes a guaranteed, user-facing fallback for a trail-off turn (no-/// proposal, not capped, no run error, and the model's own text isn't a-/// question). Scans the run's tool history for the last builder-tool result-/// that looks like a blocker (a hard-gate rejection, or a `dry_run_workflow`/-/// `validate_workflow` report with `"ok": false`) and asks the user about it;-/// falls back to a generic "what should I focus on" question when no such-/// blocker is found (the model may have simply stopped with nothing to point-/// to).-pub(super) fn build_trail_off_fallback(- history: &[tinytools_agent::dialect::TranscriptEntry],-) -> String {- match last_builder_tool_blocker(history) {- Some(blocker) => format!(- "I wasn't able to finish building this workflow. Here's where I got stuck:\n\n{blocker}\n\n\- Could you tell me how you'd like me to resolve that, or share more detail about what's needed here?"- ),- None => "I wasn't able to finish building this workflow in this turn. Could you describe \- what you'd like in more detail, or tell me which part to focus on?"- .to_string(),- }-}--/// Combines the guaranteed trail-off `fallback` question with the model's own-/// `original` text instead of discarding it (#4887 follow-up, Change 2). Even-/// after loosening `text_looks_like_question`, a future false negative must-/// never destroy the model's words — it should only ever ADD the guaranteed-/// question on top. The `fallback` is prepended (so the user sees the-/// actionable question first) and the original is kept below a divider for-/// context. When `original` is empty/whitespace-only (a genuine silent-/// turn — there's nothing to preserve), returns the fallback alone rather-/// than prepending an empty divider.-pub(super) fn combine_trail_off_fallback(fallback: &str, original: &str) -> String {- let trimmed_original = original.trim();- if trimmed_original.is_empty() {- fallback.to_string()- } else {- format!("{fallback}\n\n---\n\n{trimmed_original}")- }-}+// 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::combine_trail_off_fallback;+pub(super) use tinyflows_copilot::text_looks_like_question;-/// Scans `history` in reverse for the last result from a-/// [`TRAIL_OFF_BLOCKER_TOOLS`] call that reads as a failure — a plain-text-/// error message (gate rejection), or a JSON body with `"ok": false` — and-/// returns a truncated, human-readable description of it. Tool names are-/// resolved by correlating each `ToolResults` entry's `tool_call_id` back to-/// the `AssistantToolCalls` message that issued it, so this never-/// misattributes an unrelated read-only tool's plain-text output as a-/// blocker.-fn last_builder_tool_blocker(+/// Correlates each `ToolResults` entry's `tool_call_id` back to the+/// `AssistantToolCalls` message that issued it, in chronological order.+fn correlate_tool_results(history: &[tinytools_agent::dialect::TranscriptEntry],-) -> Option<String> {+) -> Vec<ToolResult> {use tinytools_agent::dialect::TranscriptEntry;let mut call_names: std::collections::HashMap<String, String> =std::collections::HashMap::new();+ let mut out = Vec::new();for message in history {- if let TranscriptEntry::AssistantToolCalls { tool_calls, .. } = message {- for call in tool_calls {- call_names.insert(call.id.clone(), call.name.clone());+ match message {+ TranscriptEntry::AssistantToolCalls { tool_calls, .. } => {+ for call in tool_calls {+ call_names.insert(call.id.clone(), call.name.clone());+ }}- }- }-- for message in history.iter().rev() {- let TranscriptEntry::ToolResults(results) = message else {- continue;- };- for result in results.iter().rev() {- let Some(name) = call_names.get(&result.tool_call_id) else {- continue;- };- if !TRAIL_OFF_BLOCKER_TOOLS.contains(&name.as_str()) {- continue;+ TranscriptEntry::ToolResults(results) => {+ for result in results {+ out.push(ToolResult {+ tool_name: call_names.get(&result.tool_call_id).cloned(),+ content: result.content.clone(),+ });+ }}- // This is the MOST RECENT authoring-belt tool result in the- // turn (results are scanned newest-first). Whatever it reads as- // is authoritative: a success/progress result here means any- // earlier failure from the same tool was already resolved- // within this turn, so we must stop at this result rather than- // keep walking backward and surfacing a stale, already-fixed- // blocker (see review discussion on this PR).- return describe_tool_result_blocker(&result.content)- .map(|desc| crate::util::truncate_with_ellipsis(&desc, 500));+ _ => {}}}- None+ out}-/// Reads one builder tool result's content as a failure description, or-/// `None` when it reads as success/progress (a `workflow_proposal` payload,-/// or an `"ok": true` report). The whole body is the description, never one-/// hardcoded field, so this stays correct regardless of which fields a given-/// tool uses to explain its failure.-fn describe_tool_result_blocker(content: &str) -> Option<String> {- let trimmed = content.trim();- if trimmed.is_empty() {- return None;- }- if let Ok(value) = serde_json::from_str::<Value>(trimmed) {- if value.get("type").and_then(Value::as_str) == Some("workflow_proposal") {- return None; // Success: a proposal was emitted.- }- if let Some(ok) = value.get("ok").and_then(Value::as_bool) {- return if ok { None } else { Some(value.to_string()) };- }- // Some other structured payload with no `ok`/`type` marker this- // function recognises — not confidently a blocker, skip it.- return None;- }- // Non-JSON content: a hard-gate rejection (`ToolResult::error`) puts the- // plain error message straight into the content — since every builder- // tool's SUCCESS shape is JSON (a proposal or a `{ ok, ... }` report), a- // bare string here is, by elimination, an error message.- Some(trimmed.to_string())+/// 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))}diff --git a/crates/openhuman-core/src/flows/ops/triggers.rs b/crates/openhuman-core/src/flows/ops/triggers.rsindex 4acdc11eff..5d32f8a848 100644--- a/crates/openhuman-core/src/flows/ops/triggers.rs+++ b/crates/openhuman-core/src/flows/ops/triggers.rs@@ -1,75 +1,5 @@use super::*;-/// Stable snake_case label for a [`TriggerKind`], matching its serde wire-/// discriminator — used in loud author-facing warnings (not derived via serde-/// so the exact human string is unmistakable at the call site).-fn trigger_kind_label(kind: &TriggerKind) -> &'static str {- match kind {- TriggerKind::Manual => "manual",- TriggerKind::Schedule => "schedule",- TriggerKind::Webhook => "webhook",- TriggerKind::AppEvent => "app_event",- TriggerKind::Form => "form",- TriggerKind::ExecuteByWorkflow => "execute_by_workflow",- TriggerKind::ChatMessage => "chat_message",- TriggerKind::Evaluation => "evaluation",- TriggerKind::System => "system",- }-}--/// Whether a flow's trigger kind currently produces *automatic* runs in this-/// host. Only three kinds fire today:-/// - `manual` — runnable on demand via `flows_run` (no automatic dispatch, but-/// that's the whole contract of a manual trigger — never a surprise).-/// - `schedule` — a `cron` job drives `FlowScheduleTick` (see-/// [`bind_schedule_trigger`]).-/// - `app_event` — matched against `ComposioTriggerReceived` at dispatch time-/// (see `flows::bus::FlowTriggerSubscriber`).-///-/// Everything else (`webhook`, `chat_message`, `form`, `execute_by_workflow`,-/// `evaluation`, `system`) is *accepted and saved* but has no wired dispatch-/// path yet — enabling such a flow silently produces a flow that never runs-/// itself. [`graph_trigger_warnings`] turns that silence into a loud warning.-fn trigger_kind_fires(kind: &TriggerKind) -> bool {- matches!(- kind,- TriggerKind::Manual | TriggerKind::Schedule | TriggerKind::AppEvent- )-}--/// Produces host-side, **non-fatal** validation warnings for a graph — today-/// exactly one: "this trigger kind does not fire automatically yet". Returns-/// an empty vec when the trigger fires (`manual`/`schedule`/`app_event`), when-/// the graph has no single resolvable trigger node, or when the trigger has no-/// `trigger_kind` discriminator (a legacy/manual-only graph authored before-/// B2 simply never self-fires — not a warnable surprise, matching-/// `bus::extract_trigger_kind`'s "no automatic binding" treatment).-///-/// This lives host-side (NOT in `tinyflows::validate`, which is host-agnostic-/// and only does structural checks) because "which trigger kinds this host has-/// wired" is an OpenHuman fact, not a property of the portable graph.-pub(crate) fn graph_trigger_warnings(graph: &WorkflowGraph) -> Vec<String> {- let Some(trigger) = graph.trigger() else {- return Vec::new();- };- let Some(kind_value) = trigger.config.get("trigger_kind") else {- return Vec::new();- };- let kind: TriggerKind = match serde_json::from_value(kind_value.clone()) {- Ok(k) => k,- Err(_) => return Vec::new(),- };- if trigger_kind_fires(&kind) {- return Vec::new();- }- let label = trigger_kind_label(&kind);- vec![format!(- "Trigger kind '{label}' does not fire automatically yet — this flow will be saved and \- can be enabled, but nothing will run it on its own until that trigger is wired up. Run \- it manually with flows_run, or switch to a `schedule` or `app_event` trigger."- )]-}-/// Enables or disables a flow. Enable/disable now (B2) binds/tears down the/// flow's automatic trigger:/// - `schedule` — registers/removes the backing `cron` job