openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Orchestrator: optional dedicated worker thread for complex tasks (1 level deep)

Open senamakel opened this issue 7 months ago • 1 comments

Summary

Let the orchestrator agent open a separate conversation thread to run a long or complex delegated task when it judges that is appropriate, instead of only using in-thread spawn_subagent (which collapses sub-agent work into a single tool result on the current thread). That new thread should be labeled worker (or worker in the thread-label system) and the feature must be one level deep only: a worker thread must not spawn another worker thread.

Current behavior

  • spawn_subagent (src/openhuman/tools/impl/agent/spawn_subagent.rs) runs a sub-agent in the same user-facing turn, in process, and returns one tool_result string to the parent — no persistent dedicated chat thread in the UI for the sub-run.
  • The main user thread list is flat; thread labels are not implemented yet (see product direction in related issues / thread model in src/openhuman/memory/conversations/types.rs).

Problem

  • For large tasks, users want visibility: a running sub-task in its own thread (status, partial output, cancel) without flooding the main orchestration thread.
  • The orchestrator should decide when complexity warrants isolation (“IFF … complex” — heuristics or explicit model choice + guardrails).
  • Nesting worker threads would explode list noise and complicate cancellation; one level is enough (orchestrator → worker, stop).

Proposed design (for implementation to refine)

  1. New capability (name TBD) — e.g. spawn_worker_thread or an extension to spawn_subagent with dedicated_thread: true + task title/summary.

    • Creates a new persisted thread via existing thread_create_new / ensure_thread paths (src/openhuman/threads/ops.rs), with metadata: label: worker, parent_thread_id: <orchestrator thread> (or root_thread_id) for depth checks.
    • Runs the delegated agent loop in that thread’s context (message history isolated to the worker), with a clear link from the parent thread (system message or compact card: “Worker thread: …”).
  2. Depth = 1

    • If current_thread (or run context) is already labeled worker (or has parent_thread_id set), disallow spawning another worker thread (tool returns a clear error the model can read).
    • Orchestrator on a non-worker thread may spawn at most one worker per decision or per user message (product choice — document default).
  3. UI

    • New worker threads appear in the list under the worker label (depends on thread labels feature) and show status (queued / running / done / failed) if we add lightweight state.
    • Optional: auto-select or badge the parent when a child worker completes.
  4. Non-goals (v1)

    • Arbitrary n-level task trees, multiple parallel workers in one user message (unless we explicitly add later).

Acceptance criteria

  • [ ] Orchestrator (only from a parent / non-worker thread) can start a worker-labeled thread and run a delegated task there, with end-to-end persistence in the workspace.
  • [ ] Worker threads cannot spawn another worker (enforced in core + tool guard).
  • [ ] Complexity gating — Product-defined: model opt-in, token threshold, and/or requires_worker_thread in tool args; “IFF complex” is not unbounded spam.
  • [ ] User-visible — Parent thread shows a reference to the worker thread; user can open it from the list.
  • [ ] Tests — Unit tests for depth guard; integration for thread creation metadata.
  • [ ] Docs — Orchestrator prompt / delegation guide updated so the model knows when to use spawn_subagent inline vs worker thread.

Related

  • src/openhuman/tools/impl/agent/spawn_subagent.rs — current in-thread delegation.
  • src/openhuman/agent/harness/subagent_runner.rs — inner loop (may be reused for the worker’s execution path).
  • src/openhuman/threads/ops.rs, src/openhuman/memory/conversations/* — thread create/list persistence.
  • Thread labels (e.g. #929) — worker label for list organization.
  • app/src/providers/ChatRuntimeProvider.tsx, threadSlice — new thread from core events if we push worker creation to the UI over RPC/socket.

Note: Issue numbers for cross-refs in GitHub should point to the actual “thread labels” issue on the repo if different from above.

senamakel avatar Apr 26 '26 04:04 senamakel

Taking this. Going to extend spawn_subagent with a dedicated_thread flag so the orchestrator can opt into a fresh worker-labeled thread when the task is heavy, with a depth guard in threads/ops.rs plus a tool-side check so a worker thread cannot spawn another. On the UI side I will add the parent-thread reference card linking to the worker so users can open it from the list (the worker label itself should be free now that thread labels shipped via #929). Status badges (queued/running/done) are marked optional in the issue, so I will leave that for a follow-up if the diff grows.

obchain avatar Apr 30 '26 11:04 obchain