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
chore: files changed crates/openhuman-core/src/cron/README.md,crates/openhuman-embed/README.md,gitbo
Steven Enamakel7e765d5762ec
diff --git a/crates/openhuman-core/src/cron/README.md b/crates/openhuman-core/src/cron/README.mdindex 0cd20941ad..bec4fee824 100644--- a/crates/openhuman-core/src/cron/README.md+++ b/crates/openhuman-core/src/cron/README.md@@ -8,7 +8,9 @@ Scheduled-job runtime. Owns cron-expression and human-delay parsing, the persist- `pub fn add_once` / `pub fn add_once_at` / `pub fn parse_human_delay` / `pub fn pause_job` / `pub fn resume_job` / `pub fn update_cron_job`: `ops.rs` (also re-exported as `pub use ops as rpc`).- `pub fn schedule_cron_expression` / `pub fn next_run_for_schedule` / `pub fn normalize_expression` / `pub fn validate_schedule` / `pub fn validate_agent_schedule` / `pub fn runs_closer_than` / `pub struct TooFrequent` / `pub const MIN_AGENT_JOB_INTERVAL`: `schedule.rs`.- `pub fn add_job` / `pub fn add_agent_job` / `pub fn add_agent_job_with_definition` / `pub fn add_shell_job` / `pub fn add_flow_schedule_job` / `pub fn find_flow_schedule_job` / `pub fn due_jobs` / `pub fn get_job` / `pub fn list_jobs` / `pub fn list_runs` / `pub fn record_last_run` / `pub fn record_run` / `pub fn remove_job` / `pub fn reschedule_after_run` / `pub fn update_job`: `store.rs`, a thin `Config` -> `CronStoreOptions` wrapper over `tinyflows_sqlite::schedule` (schema, job CRUD and run history live upstream).-- `pub mod scheduler` (`pub async fn run(config: Config)`, `pub async fn execute_job_now` for the `cron.run` "Run Now" path): `scheduler.rs`, split into submodules `scheduler/failure_classification.rs` (failure classifiers), `scheduler/retry.rs` (`execute_job_now`, `execute_job_with_retry`), `scheduler/agent_run.rs` (`run_agent_job`, `build_agent_for_cron_job`, `run_flow_schedule_job`), `scheduler/delivery.rs` (`deliver_if_configured`), `scheduler/shell_job.rs` (`run_job_command_with_timeout`), and `scheduler/run_record.rs`; the poll loop and `run` stay in `scheduler.rs` itself.+- `pub mod scheduler` (`pub async fn run(config: Config)`, `pub async fn execute_job_now` for the `cron.run` "Run Now" path, `pub fn is_running` for the one-loop-per-process slot in `scheduler/slot.rs`; `scheduler/dispatch.rs` (`JobDispatcher`) and `scheduler/in_flight.rs` are described under [Dispatch](#dispatch)): `scheduler.rs`, split into submodules `scheduler/failure_classification.rs` (failure classifiers), `scheduler/retry.rs` (`execute_job_now`, `execute_job_with_retry`), `scheduler/agent_run.rs` (`run_agent_job`, `build_agent_for_cron_job`, `run_flow_schedule_job`), `scheduler/delivery.rs` (`deliver_if_configured`), `scheduler/shell_job.rs` (`run_job_command_with_timeout`), and `scheduler/run_record.rs`; the poll loop and `run` stay in `scheduler.rs` itself.+- `pub mod policy`: `policy.rs`: per-job `JobPolicy { retries, single_flight }` in a host-owned `cron_job_policies` table beside the store (`CronJob` itself belongs to `tinyflows-schedule`). No row is the default policy; `store::remove_job` / `clear_all_jobs` drop rows with their jobs.+- `pub mod system_job_handlers`: `system_job_handlers.rs`: in-process handlers for system jobs (`register(name, handler) -> SystemJobRegistration`, `dispatch`). The embed facade's `Runtime::on_system_job` registers here.- `pub mod scheduler_gate`: throttles *background* LLM work (memory digests, embeddings, summarisation) on host power / CPU signals via `current_policy()` / `wait_for_capacity()`. It lives here for historical reasons; the cron poll loop does not consult it, and its consumers are `modules/memory_host.rs` and `security/credentials/`. See its own [README](scheduler_gate/README.md).- `pub mod seed`: `seed.rs`: `seed_proactive_agents` installs the built-in proactive jobs when onboarding flips to completed (`config/ops/ui.rs`); `prune_retired_jobs` removes rows for removed features on boot and workspace activation.- `pub mod bus`: `bus.rs`: `CronDeliverySubscriber` (`cron::delivery`) consumes `CronDeliveryRequested` and sends through the named `tinychannels_bus::Channel`.@@ -19,13 +21,24 @@ Scheduled-job runtime. Owns cron-expression and human-delay parsing, the persist- `shell`: `run_job_command_with_timeout` refuses the command unless the `SecurityPolicy` (`SecurityPolicy::from_config`, built once in `scheduler::run` and per call in `execute_job_now`) passes `can_act`, `is_rate_limited`, and `is_command_allowed`; a `blocked by security policy:` result is never retried.- `agent`: the scheduler builds an `Agent` directly and runs a turn (see below); it does not go through `agent::triage`.-- `flow`: a `flows::Flow` schedule-trigger binding, the mechanism behind a workflow's [schedule trigger](../../../../gitbooks/features/workflows.md). `flows/ops/triggers.rs::bind_schedule_trigger` creates it via `add_flow_schedule_job` (idempotent through `find_flow_schedule_job`) from both `flows_set_enabled` and `reconcile_schedule_triggers_on_boot`. Its `command` column carries the bound flow's id; on fire `run_flow_schedule_job` publishes `DomainEvent::FlowScheduleTick { flow_id }` instead of running anything itself. `flows::bus::FlowTriggerSubscriber` does the actual dispatch. Never created via the `cron_add` agent tool, whose `job_type` enum is `shell` / `agent` only.+- `flow`: a `flows::Flow` schedule-trigger binding, the mechanism behind a workflow's [schedule trigger](../../../../gitbooks/features/workflows.md). `flows/ops/triggers.rs::bind_schedule_trigger` creates it via `add_flow_schedule_job` (idempotent through `find_flow_schedule_job`) from both `flows_set_enabled` and `reconcile_schedule_triggers_on_boot`. Its `command` column carries the bound flow's id; on fire `run_flow_schedule_job` publishes `DomainEvent::FlowScheduleTick { flow_id }` instead of running anything itself. A `system:<name>` row (`system_jobs.rs`) publishes `CronSystemJobDue` instead and, when a handler is registered for `<name>` (`system_job_handlers.rs`), awaits it and records its result; without one it is `ok` on dispatch. `flows::bus::FlowTriggerSubscriber` does the actual dispatch. Never created via the `cron_add` agent tool, whose `job_type` enum is `shell` / `agent` only.### Agent jobs`run_agent_job` prefixes the prompt (`[cron:<id> <name>] <prompt>`), applies a per-job `model` override to a cloned `Config`, and, when `job.agent_id` names a definition in `AgentDefinitionRegistry`, resolves that definition's `ModelSpec` onto the cloned config (the iteration cap is left to the session builder, see #4868). `build_agent_for_cron_job` uses `Agent::from_config_for_agent` for a recognized `agent_id`, falling back to `Agent::from_config` when it cannot build a definition or no id was supplied.-`execute_job_with_retry` wraps every job type with `config.reliability.scheduler_retries` attempts and exponential backoff. For agent jobs it classifies failures before retrying: backend session-expired, provider insufficient-credits (402), managed-backend budget-exhausted (400), API-key-unset, and local-LLM-unreachable all halt the loop immediately and suppress the retries-exhausted error report. The user-facing message is a canned string from `classify_agent_anyhow_for_user`; the raw error goes only to observability.+When `job.agent_id` names an agent a host registered (`agent::host_agents::resolve`, installed by `openhuman-embed`'s `Runtime`), `build_agent_for_cron_job` builds the session from that `HostAgent` instead: its definition, its host tools and its config (provider model and route applied, the job's `model` on top), and the turn runs inside its `CoreContext`, still under `TrustedAutomation { Cron }`. The registry model overrides above are skipped for such agents.++`execute_job_with_retry` wraps every job type with the job's retry budget (`policy::effective_retries`: the job's `retries` override, else `config.reliability.scheduler_retries`) attempts and exponential backoff. For agent jobs it classifies failures before retrying: backend session-expired, provider insufficient-credits (402), managed-backend budget-exhausted (400), API-key-unset, and local-LLM-unreachable all halt the loop immediately and suppress the retries-exhausted error report. The user-facing message is a canned string from `classify_agent_anyhow_for_user`; the raw error goes only to observability.++## Dispatch++The poll loop no longer awaits its batch. `JobDispatcher::dispatch` spawns each due job onto a task set (bounded by `scheduler.max_concurrent`) and returns, so one long agent turn cannot hold up the next poll. Two guards replace the implicit one the blocked loop gave:++- `in_flight`: a job counts as running from dispatch until its run is persisted (a counter, so a "Run now" overlapping a scheduled run of a default job is tracked correctly); the scheduler never dispatches a running job.+- Claimed slot: a recurring job's `next_run` is advanced to its next occurrence at dispatch (`update_job` with the same schedule); the usual `reschedule_after_run` recomputes it from the finish time. A crash mid-run therefore does not re-run the job at startup.++A slot that comes due while the job is still running is skipped silently by default. With `JobPolicy::single_flight` it is recorded as a `skipped` run and `ops::run_job_now` / `cron.run` refuse while the job runs. Dropping the dispatcher (the loop task aborted by `CoreRuntime::stop_services` or the runtime's drop) aborts its jobs. `ops::run_job_now` runs a job to completion with the same retry budget, run record and delivery; `cron.run` spawns the same `run_and_record`.## Event bus@@ -91,6 +104,6 @@ that evidence on each run instead (#6158).## Tests-- Unit: `ops_tests.rs`, `scheduler_tests.rs` (shared fixtures; `#[path]`-includes `scheduler_profile_and_shell_tests.rs`, `scheduler_halt_and_persist_tests.rs`, `scheduler_classifier_and_delivery_tests.rs`, `scheduler_frequency_tests.rs`), `store_tests.rs` (Config-to-options mapping; the store itself is tested in `tinyflows-sqlite`), `schedule_tests.rs`, `types_tests.rs`, `seed_tests.rs`, `bus_tests.rs`.+- Unit: `policy_tests.rs`, `system_job_handlers_tests.rs`, `scheduler/in_flight_tests.rs`, `ops_tests.rs`, `scheduler_tests.rs` (shared fixtures; `#[path]`-includes `scheduler_dispatch_tests.rs` (non-blocking dispatch, slot claim, single-flight skip, retry budgets, handler results), `scheduler_host_agent_tests.rs` (host-registered agents), `scheduler_profile_and_shell_tests.rs`, `scheduler_halt_and_persist_tests.rs`, `scheduler_classifier_and_delivery_tests.rs`, `scheduler_frequency_tests.rs`), `store_tests.rs` (Config-to-options mapping; the store itself is tested in `tinyflows-sqlite`), `schedule_tests.rs`, `types_tests.rs`, `seed_tests.rs`, `bus_tests.rs`.- Schema/parsing coverage lives in `schemas_tests.rs`.- Tool coverage: `tools/{add,list,remove,run,runs,update}_tests.rs` (announce-mode `allowed_users` checks live in `add_tests.rs`) and `tools/collapsed_tests.rs` (action enum, merged schema, per-action permission resolution).diff --git a/crates/openhuman-embed/README.md b/crates/openhuman-embed/README.mdindex 88c9597b0d..1d2f6d65f5 100644--- a/crates/openhuman-embed/README.md+++ b/crates/openhuman-embed/README.md@@ -275,6 +275,16 @@ caches (cost log, prompt templates, migration markers). The desktop app, CLIand TUI install `openhuman_rpc::session_store`, the classic on-disk layout behindthe same port. See `tests/session_store.rs`.+### Scheduling++`Runtime::cron()` upserts named jobs (`JobSpec::agent` for a turn of a+runtime agent with its host tools, `JobSpec::system` for a handler registered+with `Runtime::on_system_job`), lists, removes, runs them now and reads their+history. A `ServiceSet` with `cron: true` starts the scheduler on `build()`+and stops it with the runtime; `start_services` / `stop_services` control it+explicitly. See [`gitbooks/developing/embedding.md`](../../gitbooks/developing/embedding.md#scheduling)+and `tests/cron_agents.rs`.+### Still runtime-wideThese are read from the runtime's boot config by every agent today. They@@ -388,6 +398,9 @@ turn against a `wiremock` provider with nothing bound;`tests/runtime_agents.rs` runs three agents with different providers, accesstiers, skills, MCP servers and working directories on one runtime and showsthe API key reaching a mocked managed backend as a bearer;+`tests/cron_agents.rs` runs a cron job as a runtime agent with its host tool+under the `TrustedAutomation { Cron }` origin, records a system job handler's+error, and starts and stops the scheduler with the runtime;`tests/public_api.rs` pins the host-facing embedding contract at compiletime. Run them with `cargo test -p openhuman-embed --features inference,mcp,skills`.diff --git a/gitbooks/developing/embedding.md b/gitbooks/developing/embedding.mdindex da1dea4316..3c0b40ad84 100644--- a/gitbooks/developing/embedding.md+++ b/gitbooks/developing/embedding.md@@ -272,6 +272,61 @@ that session held, and it is meant to be paired with a session id the turnis not sharing with turns that expect their history intact. `.meter(f)`reports what a turn spent, including a turn that ran and then failed.+## Scheduling++OpenHuman's own cron can drive scheduled turns of a runtime's agents, with+their host tools, and run host code on a schedule. `runtime.cron()` is a typed+facade over the runtime's job store; jobs are named and `upsert` is idempotent+by that name, so a host can declare its schedule on every start:++```rust,no_run+# async fn demo(runtime: &openhuman_embed::Runtime) -> Result<(), Box<dyn std::error::Error>> {+use openhuman_embed::{JobSchedule, JobSpec};++let cron = runtime.cron();+// One turn of the runtime agent `teeny` every morning.+cron.upsert(+ JobSpec::agent("morning", "teeny", "Plan the day.", JobSchedule::Cron {+ expr: "0 8 * * *".into(),+ tz: Some("Europe/Berlin".into()),+ })+ .retries(0) // exactly one attempt: the turn has side effects+ .single_flight(true) // skip (and record) a slot that comes due mid-run+)?;+// Host code on a schedule; its result is the run's recorded result.+runtime.on_system_job("digest", |_ctx| async { Ok(()) })?;+cron.upsert(JobSpec::system("digest", "digest", JobSchedule::Every { ms: 15 * 60_000 }))?;++let run = cron.run_now("morning").await?; // same path as a scheduled run+println!("{} {}", run.success, run.output);+# Ok(()) }+```++- **Jobs fire only while the scheduler runs.** Build the runtime with+ `.services(ServiceSet { cron: true, ..ServiceSet::none() })`; `build()` then+ starts the selected services and dropping the runtime (and its agents) stops+ them. `Runtime::start_services` / `stop_services` give explicit control.+ Without the scheduler, jobs are stored and `run_now` still works.+- **An agent job runs as the agent.** When `agent_id` names an agent alive on+ the runtime, the turn uses its definition and system prompt, its+ `AgentSpec::tools` and attached tools, its provider and its own context+ (`agent::host_agents` resolves it for the core's cron and workflow drivers).+ Any other id resolves through the core's agent registries. The turn's origin+ is `TrustedAutomation { Cron }`, not the agent's own access origin. Agent jobs+ may not run more often than every five minutes.+- **A system job runs the host's handler.** `on_system_job(name, handler)`+ registers an async `Fn(SystemJobContext) -> Result<(), String>`; when the job+ comes due the scheduler still publishes `CronSystemJobDue` on the bus, then+ awaits the handler and records `ok` or `error` with its message.+- **Retries and overlap.** A failed run is retried `retries` times with+ backoff; unset keeps `reliability.scheduler_retries` (2), and `0` is one+ attempt. A job is never run twice at once: each due job is dispatched on its+ own task, so a long job no longer holds up the others, and a slot that comes+ due while the job is still running is skipped. With `single_flight` that+ skip is recorded as a `skipped` run and `run_now` is refused meanwhile.+- `cron.list()`, `cron.remove(name)` and `cron.runs(name, limit)` cover the+ rest. Shell jobs and workflow schedule triggers are not managed here.+## Harness: the one-agent shorthand`Harness` is a `Runtime` plus exactly one agent, built from one set of