4 Commits

Author SHA1 Message Date
Victor Kyriazakos
54fba0062e fix(plugins): a session fork holds only its plugin's own tools
A name deny list cannot classify tools it has never seen: another plugin's
a2a_call or meet_join starts a remote agent task or a detached worker, and an
MCP tool can trigger server-initiated sampling, all outside the fork thread's
tool whitelist and auto-denied approvals. The fork allowlist is now built from
ownership instead: the tools whose live registration is the requesting
plugin's (newest active ledger entry per name), plus core tools marked
fork-safe in FORK_SAFE_CORE_TOOLS (empty). A name dispatch reroutes before the
registry (inline agent tools, legacy aliases, the Tool Search bridge) never
counts as the plugin's own. Naming any other tool returns None with the token
unspent, and the dispatch guard reads the allowlist again when the fork starts.

background_review extra_tools is operator-configured and goes back to its
previous behavior; the consent text says the fork uses the plugin's own tools.
2026-11-13 15:30:30 -08:00
Victor Kyriazakos
32f9c1f6b3 feat(plugins): ctx.fork_session runs a bounded background copy of the session agent
Hermes' own background review (fork the live agent after a turn, run a
bounded multi-step prompt with a narrow tool list, cancel on the next live
turn) is now open to plugins as ctx.fork_session(token, prompt, *, tools=(),
max_iterations=8, input_budget=None, task=None, timeout=None), gated by the
new consent-only capability llm.session_fork.

Reused, not copied:
- Lease: post_llm_call's side_question_token backs a side question OR a fork
  (side_question_lease.take_lease; same TTL, turn_moved_on, profile fence,
  no token for unattended turns, one redemption per turn). The payload field
  keeps its name for compatibility.
- Fork: build_cache_parity_fork(write_origin="plugin_fork:<id>") on a
  context-bound thread in the captured turn context; same-model forks replay
  the captured system prompt and tools[] byte-for-byte; routed forks get the
  history digest. Persistence stays fully detached.
- Guardrails: the thread tool whitelist is the requested names (each must
  already be in the session's tools[]); approvals auto-deny; the review's
  input budget (a plugin can only lower it) and iteration cap (<= 16);
  _BackgroundReviewRun admission so cancel_background_review_for_live_turn
  interrupts plugin forks with the review under one bounded wait;
  review_idle_queue deferral on the managed local runtime (enqueue takes a
  dispatch callable; a newer fork of the same plugin supersedes the queued
  one).
- Routing: task must be one of the plugin's register_auxiliary_task lanes,
  resolved like auxiliary.background_review.
- Usage and hooks: release_cache_parity_fork bills the parent session as
  plugin_fork:<id>; each fork loop request reports pre/post_auxiliary_call
  (aux_task="plugin_fork", plugin_id) instead of pre/post_api_request.

Tool handlers inside the fork receive turn_origin="plugin_fork:<id>"
(live calls get no new kwarg), so a plugin can refuse calls from the live
agent. The handle exposes done/cancelled/outcome/result/actions/wait/cancel,
never the fork agent. Fails closed (None) without the capability, on a bad,
expired, spent or foreign token, a tool the session does not advertise, or
a task the plugin does not own.
2026-11-13 15:30:30 -08:00
Teknium
4ea8d23cc9 fix(agent): side-question review fixes (unattended turns, profile-bound leases, billing, attribution)
- No side_question_token for cron runs (platform="cron") or delegated subagent turns
  (_delegate_depth > 0): nobody reads the answer, so it is pure unattended spend.
- A lease is bound to the profile home it was issued in; a plugin context of another profile
  gets None and leaves the lease for its owner.
- Usage bills to the session the token was issued for (capture.session_id), not the parent's
  id at release time, which can rotate between issue and redeem.
- Plugin side questions report as aux_task="plugin_side_question" with the asking plugin_id in
  pre/post_auxiliary_call, and record usage as plugin_side_question:<plugin_id>; /btw keeps
  side_question.
- Drop the new legacy key llm.allow_side_question: the capability is declare + consent only.
- The timeout starts before the fork build, so runtime resolution counts against it.
2026-10-24 19:56:21 -07:00
Cleo
a8db83446f feat(plugins): ctx.side_question asks the session's own agent after a turn
post_llm_call now carries a single-use side_question_token when a loaded
plugin holds the new llm.side_question capability. ctx.side_question(token,
prompt) redeems it: ONE text-only request on a cache-parity fork through
the turn loop's own request phases (assemble_api_request, build_api_request,
perform_api_call), never the tool loop. The parent's system prompt, tools[],
reasoning config and max_tokens are replayed verbatim, so the request reads
the warm prompt cache. Tool calls in the reply are dropped, nothing is
persisted, and usage lands on the session as side_question.

Lease rules: one attempt per turn shared by every plugin (consumed even on
failure), 60 s, invalid once the parent starts its next turn, prompt capped
at 4096 chars, timeout capped at 60 s. The lease holds its parent weakly and
runs under the turn's captured contextvars (profile and secret scope).
Refused with None: MoA, agent-as-provider runtimes, requests that carry
provider-executed tools.

has_capability moves with side_question into a PluginContext mixin
(hermes_cli/plugins_capability_ctx.py) so hermes_cli/plugins.py shrinks.

Fixes #143788
2026-10-24 19:56:21 -07:00