Skip to content

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

fix(agent): update agent prompts and sync logic

Steven Enamakelfe6d8f131d07
diff --git a/crates/openhuman-core/src/agent/registry/agents/morning_briefing/prompt.md b/crates/openhuman-core/src/agent/registry/agents/morning_briefing/prompt.md
index f307d48fab..516d1d72b1 100644
--- a/crates/openhuman-core/src/agent/registry/agents/morning_briefing/prompt.md
+++ b/crates/openhuman-core/src/agent/registry/agents/morning_briefing/prompt.md
@@ -16,9 +16,9 @@ Prepare a morning briefing that helps the user start their day with clarity. Pul
## How to gather data
-1. **Recent memory (last 24h).** Call the `memory_tree` tool with `mode: "cover_window"`, `since_ms = <now − 24h>` and `until_ms = <now>` (epoch-milliseconds — use the current date/time from the `Current Date & Time:` line provided with the message to compute these). It returns the **minimum set of nodes** covering the window: condensed summaries where a whole stretch is in-window, and raw recent messages otherwise — grouped by source, oldest→newest. This is your authoritative recent-memory context; the all-time memory blob is intentionally NOT injected, so do not rely on it. Pass a `source_id`/`source_kind` filter if you only need one source.
+1. **Recent memory.** Your session opens with the user's compiled memory context. Use the parts of it dated within the last 24 hours (compare against the `Current Date & Time:` line provided with the message) and any commitment that is now due; treat older entries as background, not news.
2. **Live data.** Use `composio_list_connections` to see connected integrations; for each relevant one (calendar, email, task manager), `composio_list_tools` then `composio_execute` to pull today's data.
-3. Reconcile the two: the 24h memory tells you what *happened*; the live calls tell you what's *scheduled / unread right now*. Don't double-report the same item.
+3. Reconcile the two: the recent memory tells you what *happened*; the live calls tell you what's *scheduled / unread right now*. Don't double-report the same item.
## Message shape
@@ -46,5 +46,5 @@ The briefing should read like a note from a personal assistant, not a raw data d
- **Never fabricate events, emails, or tasks.** Only include data you actually retrieved from tools or memory.
- **Respect time zones.** The `Current Date & Time:` line provided with the message carries the user's local date/time and IANA timezone — read it from there. Do **not** ask the user to repeat their timezone; only fall back to UTC and note it if that line is genuinely missing the field.
- **No stale data.** If a tool call fails or returns empty, say so — don't fall back to yesterday's data.
-- **Honor the timeline.** The `memory_tree` `cover_window` query already restricts recent memory to the last 24h, so treat its contents as genuinely recent. But each hit carries a real `time_range` — read it, and present things in the order they happened (oldest→newest). For anything carried over from a longer-lived note or a live tool result, compare its date against today's date on the `Current Date & Time:` line: if it predates the day you're briefing for, name the date explicitly ("from your May 25 note…") rather than presenting it as today's.
+- **Honor the timeline.** Present things in the order they happened (oldest→newest). For anything carried over from the memory context or a live tool result, compare its date against today's date on the `Current Date & Time:` line: if it predates the day you're briefing for, name the date explicitly ("from your May 25 note…") rather than presenting it as today's.
- **Privacy first.** Don't include full email bodies or message contents. Summarize senders and subjects.
diff --git a/crates/openhuman-core/src/agent/registry/agents/planner/prompt.md b/crates/openhuman-core/src/agent/registry/agents/planner/prompt.md
index cce2e154df..b68e856c65 100644
--- a/crates/openhuman-core/src/agent/registry/agents/planner/prompt.md
+++ b/crates/openhuman-core/src/agent/registry/agents/planner/prompt.md
@@ -4,11 +4,11 @@ You are the **Planner** agent. Your job is to decompose a complex user goal into
Before you plan, **gather context** so the plan is grounded in reality, not guesses:
-- Use `memory_recall` to search what we already know — past decisions, user preferences, project context, prior plans. Memory is cheap; planning blind is expensive.
+- Read the memory context your session opened with and the context the caller handed you — past decisions, user preferences, project context, prior plans. Planning blind is expensive.
- Use `web_search_tool` when the goal involves external information you don't have — API docs, library comparisons, current best practices, pricing, compatibility matrices.
- Use `file_read` to inspect relevant files when the project tree has code or config that constrains the plan.
-Only produce the plan JSON **after** you have the context you need. A plan built on assumptions the memory or a quick search could have resolved is a bad plan.
+Only produce the plan JSON **after** you have the context you need. A plan built on assumptions the provided context or a quick search could have resolved is a bad plan.
## Output Format
@@ -35,12 +35,12 @@ Return **only** valid JSON matching this schema:
You run as a worker inside a workflow run (the `parallel_research_cross_check` template), not as a chat delegate. The run hands your result to the next phase:
- In a **decompose** phase, return the plan JSON above; each node is one independent research angle, and `agent_id` names the phase worker (`planner`) or is omitted.
-- In a **research** phase, you are given one angle: gather evidence for it with `web_answer_tool` (`depth: "deep"` for multi-source research, when offered), `web_search_tool`, `web_contents_tool`, `web_fetch` and `memory_recall`, and return the findings with their sources instead of a plan.
+- In a **research** phase, you are given one angle: gather evidence for it with `web_answer_tool` (`depth: "deep"` for multi-source research, when offered), `web_search_tool`, `web_contents_tool` and `web_fetch`, and return the findings with their sources instead of a plan.
## Rules
0. **You are a read-only reasoning worker.** You never spawn other agents. Connected-service actions and writes belong to the caller, not to you.
-1. **Gather before planning** — Search memory and the web first. Don't guess what you can look up.
+1. **Gather before planning** — Use the provided context and search the web first. Don't guess what you can look up.
2. **Minimise tasks** — Use the fewest nodes needed. Don't over-decompose.
3. **Dependencies matter** — Use `depends_on` to express ordering. Independent tasks run in parallel.
4. **Be specific** — Each description should be a complete instruction, not a vague goal. Include relevant context you gathered.
diff --git a/crates/openhuman-core/src/agent/registry/agents/trigger_reactor/prompt.md b/crates/openhuman-core/src/agent/registry/agents/trigger_reactor/prompt.md
index 1dee6580dd..e8deea338a 100644
--- a/crates/openhuman-core/src/agent/registry/agents/trigger_reactor/prompt.md
+++ b/crates/openhuman-core/src/agent/registry/agents/trigger_reactor/prompt.md
@@ -1,20 +1,20 @@
# Trigger Reactor
-You are the **Trigger Reactor** — a narrow specialist the trigger triage agent hands off to when an incoming external event needs a small, reactive side effect. Think of yourself as the person who writes a one-sentence memory note, marks a notification as handled, or fires a single follow-up — not the person who plans a whole response.
+You are the **Trigger Reactor** — a narrow specialist the trigger triage agent hands off to when an incoming external event needs a small, reactive side effect. Think of yourself as the person who records a one-sentence memory note, marks a notification as handled, or fires a single follow-up — not the person who plans a whole response.
## How you were invoked
The triage classifier decided this trigger warranted a small reaction (not a drop, not a deep escalation to the orchestrator). Your task prompt — the user message above — was written by that classifier and contains everything you need to know about the trigger: its source, label, and any salient payload fields.
-The system prompt above this task message has been populated with the user's current memory / workspace context via the standard prompt builder. Use it to decide whether the trigger relates to something the user is currently working on.
+Your session opens with the user's compiled memory context. Use it, and the workspace state, to decide whether the trigger relates to something the user is currently working on.
## What you should do
One of two paths:
1. **React** — execute the reaction with **one, maybe two** tool calls and return a short confirmation. Typical shapes:
- - Persist a memory note (`memory_store`) summarising the trigger.
- - Recall prior context (`memory_recall`) before deciding whether to store anything.
+ - Store a durable memory note summarising the trigger (`memory` with `action: "learn"`).
+ - Recall prior context (`memory` with `action: "recall"`) before deciding whether to store anything.
- Read the workspace state (`read_workspace_state`) to ground your reaction.
- Chain two of the above if the first tells you the reaction should be different.
@@ -29,4 +29,4 @@ One of two paths:
## Output
-After your tool calls, return a single short paragraph (1–3 sentences) describing what you did. This text ends up in `TriggerEscalated` event payloads and ops dashboards — keep it terse and grep-friendly. Lead with the verb ("Persisted a memory note about…", "Escalated to orchestrator because…").
+After your tool calls, return a single short paragraph (1–3 sentences) describing what you did. This text ends up in `TriggerEscalated` event payloads and ops dashboards — keep it terse and grep-friendly. Lead with the verb ("Stored a memory note about…", "Escalated to orchestrator because…").
diff --git a/crates/openhuman-core/src/integrations/composio/ops/sync.rs b/crates/openhuman-core/src/integrations/composio/ops/sync.rs
new file mode 100644
index 0000000000..0e9ea4f8e6
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/ops/sync.rs
@@ -0,0 +1,295 @@
+//! Syncing a connected account into memory.
+//!
+//! Reading the account is the connector module's job — it holds the
+//! credential, the provider registry and the paging cursors. Storing what it
+//! read is memory's: each pass hands the batch to
+//! [`crate::memory::sources::composio::store_records`], which turns every
+//! record into a document on the bound engine. Neither half knows about the
+//! other: the module never reaches memory, and memory never sees a Composio
+//! credential.
+//!
+//! Two callers drive passes: `openhuman.composio_sync` (one connection, on
+//! demand, in the background — see [`composio_sync`]) and memory's own
+//! scheduled Composio sources (`memory::sources::composio::sync_toolkit`),
+//! which call [`run_sync_pass`] directly.
+
+use crate::config::Config;
+use crate::core::Outcome;
+use crate::memory::engine::BoundEngine;
+use crate::memory::sources::composio::{source_id_for_toolkit, store_records};
+
+use super::super::module_client::{self as connectors, methods};
+use super::super::providers::{SyncOutcome, SyncReason};
+use super::connections::resolve_toolkit_for_connection;
+use super::error_utils::{report_composio_op_error, OpResult};
+use super::pass_failure::{pass_failure, retry_delay};
+use tinyconnectors_bus::records::{ConnectorSyncRequest, ConnectorSyncResponse};
+
+/// Per-pass item budget handed to the connector's `Sync` member.
+///
+/// One pass is one budgeted slice of the account; [`MAX_PASSES`] bounds a
+/// `composio_sync` run at 10k items per click.
+pub const SYNC_PASS_MAX_ITEMS: usize = 200;
+
+/// Most passes one `composio_sync` run makes before it stops; the next run
+/// resumes from the module's cursor.
+const MAX_PASSES: usize = 50;
+
+/// What one [`run_sync_pass`] call did.
+#[derive(Debug, Clone, Default)]
+pub struct SyncPassOutcome {
+ /// Records the module returned in this pass.
+ pub records_read: usize,
+ /// Of those, how many memory stored (empty records are skipped).
+ pub written: u64,
+ /// Whether the module has more to read — the caller decides whether to
+ /// call again.
+ pub more_pending: bool,
+ /// What the module said about a pass that stopped short without failing
+ /// (today's request budget being spent, typically).
+ pub message: Option<String>,
+ /// Why the connector stopped this pass on an error (openhuman#6255). The
+ /// counts above still stand; the caller ends or retries the run.
+ pub failure: Option<String>,
+}
+
+/// `openhuman.composio_sync` — read one connected account into memory.
+///
+/// Returns as soon as the run is *started*: a full sync is minutes of paging,
+/// and the RPC caller is a UI button. The engine is resolved up front so
+/// memory being off is an error the caller sees, not a log line in a detached
+/// task. Items are filed under the toolkit's configured Composio source, or
+/// `composio:<toolkit>` when none is configured.
+pub async fn composio_sync(
+ config: &Config,
+ connection_id: &str,
+ reason: Option<String>,
+) -> OpResult<Outcome<SyncOutcome>> {
+ let reason = parse_sync_reason(reason.as_deref())?;
+ tracing::debug!(
+ connection_id = %connection_id,
+ reason = reason.as_str(),
+ "[composio] rpc sync (spawned)"
+ );
+ let toolkit = resolve_toolkit_for_connection(config, connection_id).await?;
+ let bound = crate::memory::engine::resolve(config)
+ .engine()
+ .map_err(String::from)?;
+ let source_id = source_id_for_toolkit(config, &toolkit);
+
+ let started_at_ms = u64::try_from(
+ std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .map(|d| d.as_millis())
+ .unwrap_or(0),
+ )
+ .unwrap_or(u64::MAX);
+
+ let run = SyncRun {
+ config: config.clone(),
+ bound,
+ toolkit: toolkit.clone(),
+ connection_id: connection_id.to_string(),
+ source_id,
+ reason: reason.as_str().to_string(),
+ };
+ tokio::spawn(run.drive());
+
+ let summary = format!("composio: {toolkit} sync started (background)");
+ let outcome = SyncOutcome {
+ toolkit,
+ connection_id: Some(connection_id.to_string()),
+ reason: reason.as_str().to_string(),
+ items_ingested: 0,
+ started_at_ms,
+ finished_at_ms: 0,
+ summary: summary.clone(),
+ details: serde_json::json!({ "status": "started" }),
+ };
+ Ok(Outcome::new(outcome, vec![summary]))
+}
+
+/// One background `composio_sync` run.
+struct SyncRun {
+ config: Config,
+ bound: BoundEngine,
+ toolkit: String,
+ connection_id: String,
+ source_id: String,
+ reason: String,
+}
+
+impl SyncRun {
+ /// Runs passes until the connector reports the end, a pass reads nothing,
+ /// or [`MAX_PASSES`] is reached. A pass the connector reports as failed is
+ /// retried on [`retry_delay`]'s schedule, then ends the run.
+ async fn drive(self) {
+ let started = std::time::Instant::now();
+ let mut total_written: u64 = 0;
+ let mut passes = 0usize;
+ let mut failed_attempts = 0u32;
+ let outcome: Result<bool, String> = loop {
+ passes += 1;
+ let pass = match run_sync_pass(
+ &self.config,
+ &self.bound,
+ &self.toolkit,
+ &self.connection_id,
+ &self.source_id,
+ &self.reason,
+ SYNC_PASS_MAX_ITEMS,
+ )
+ .await
+ {
+ Ok(pass) => pass,
+ Err(error) => break Err(error),
+ };
+ total_written = total_written.saturating_add(pass.written);
+ if let Some(reason) = pass.failure {
+ failed_attempts += 1;
+ let Some(delay) = retry_delay(failed_attempts) else {
+ break Err(reason);
+ };
+ tracing::info!(
+ toolkit = %self.toolkit,
+ connection_id = %self.connection_id,
+ attempt = failed_attempts,
+ retry_in_secs = delay.as_secs(),
+ "[composio] connector sync pass failed; retrying"
+ );
+ tokio::time::sleep(delay).await;
+ continue;
+ }
+ failed_attempts = 0;
+ tracing::debug!(
+ toolkit = %self.toolkit,
+ connection_id = %self.connection_id,
+ pass = passes,
+ records_read = pass.records_read,
+ written = pass.written,
+ more_pending = pass.more_pending,
+ "[composio] background sync pass ok"
+ );
+ if !pass.more_pending || pass.records_read == 0 || passes >= MAX_PASSES {
+ break Ok(pass.more_pending);
+ }
+ };
+ match outcome {
+ Ok(more_pending) => tracing::info!(
+ toolkit = %self.toolkit,
+ connection_id = %self.connection_id,
+ passes,
+ written = total_written,
+ more_pending,
+ elapsed_ms = u64::try_from(started.elapsed().as_millis()).unwrap_or(u64::MAX),
+ "[composio] background sync complete"
+ ),
+ Err(error) => {
+ report_composio_op_error("sync", &anyhow::anyhow!("{error}"));
+ tracing::warn!(
+ toolkit = %self.toolkit,
+ connection_id = %self.connection_id,
+ written = total_written,
+ error = %error,
+ "[composio] background sync failed"
+ );
+ }
+ }
+ }
+}
+
+/// Read one pass of a connection through the module and store what it
+/// returns under `source_id`.
+///
+/// A pass the connector reports as failed still stores the records it read
+/// and comes back as `Ok`, with [`SyncPassOutcome::failure`] set and nothing
+/// pending: whether to ask again is the caller's decision (openhuman#6255).
+///
+/// # Errors
+///
+/// The connector call fails, or memory cannot store the batch.
+pub async fn run_sync_pass(
+ config: &Config,
+ bound: &BoundEngine,
+ toolkit: &str,
+ connection_id: &str,
+ source_id: &str,
+ reason: &str,
+ pass_budget: usize,
+) -> Result<SyncPassOutcome, String> {
+ // Sync pages inside the call; the default 30s bus deadline reported
+ // failure on runs the module then finished successfully.
+ let response = connectors::call_slow::<_, ConnectorSyncResponse>(
+ config,
+ methods::SYNC,
+ ConnectorSyncRequest {
+ toolkit: toolkit.to_string(),
+ connection_id: Some(connection_id.to_string()),
+ reason: Some(reason.to_string()),
+ // One pass is one budgeted slice: complete=false at the budget →
+ // more_pending → the caller resumes from the module's cursor.
+ max_items: Some(pass_budget),
+ ..ConnectorSyncRequest::default()
+ },
+ )
+ .await?;
+
+ // A failed pass keeps what it read but is not "more pending" (#6255).
+ let failure = pass_failure(&response, toolkit, connection_id);
+ let more_pending = failure.is_none() && !response.batch.complete;
+ let message = response.message.clone().filter(|_| failure.is_none());
+
+ let records_read = response.batch.records.len();
+ let written = if records_read == 0 {
+ 0
+ } else {
+ store_records(bound, toolkit, connection_id, source_id, &response.batch.records)
+ .await
+ .map_err(|error| {
+ format!(
+ "storing {toolkit} records failed: {}",
+ String::from(error)
+ )
+ })?
+ };
+
+ if more_pending {
+ tracing::info!(
+ toolkit = %toolkit,
+ "[composio] sync pass stopped short of the end; the next run resumes"
+ );
+ }
+ tracing::debug!(
+ toolkit = %toolkit,
+ stage = ?response.stage,
+ pages_read = response.pages_read,
+ records_skipped = response.records_skipped,
+ records_read,
+ written,
+ "[composio] sync pass stored"
+ );
+ Ok(SyncPassOutcome {
+ records_read,
+ written,
+ more_pending,
+ message,
+ failure,
+ })
+}
+
+/// Parse the optional `reason` parameter into a [`SyncReason`].
+///
+/// `None` and the explicit `"manual"` value both map to
+/// [`SyncReason::Manual`]. Any other unrecognized string is rejected
+/// with a clear error so a typo in a caller surfaces at the RPC boundary.
+pub(crate) fn parse_sync_reason(raw: Option<&str>) -> OpResult<SyncReason> {
+ match raw {
+ None | Some("manual") => Ok(SyncReason::Manual),
+ Some("periodic") => Ok(SyncReason::Periodic),
+ Some("connection_created") => Ok(SyncReason::ConnectionCreated),
+ Some(other) => Err(format!(
+ "[composio] unrecognized sync reason '{other}': expected one of \
+ 'manual', 'periodic', 'connection_created'"
+ )),
+ }
+}