Principle:42 evey Hermes plugins LLM Delegation
| Knowledge Sources | |
|---|---|
| Domains | LLM_Delegation, Agent_Architecture, Autonomous_Agents |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
A pattern for making out-of-band LLM calls from any execution context (not just an active agent conversation), enabling plugins, cron jobs, and background tasks to leverage LLM capabilities.
Description
LLM Delegation is the mechanism by which an autonomous agent invokes an LLM to perform a subtask without being in a direct conversation with the user. The key challenge is that the LLM gateway credentials and context are stored in context variables tied to the active session — but delegation may originate from a cron job, a Telegram handler, or another plugin with no active conversation.
The pattern solves this by:
- Storing the LLM gateway in a module-level context (
ctx) set at plugin registration time, accessible from any code path. - Using
ctx.llm.complete()as the uniform API for all LLM calls, with parameters for messages, max_tokens, temperature, timeout, and purpose. - Handling model override trust: Model overrides require explicit operator permission (
allow_model_overridein config). Without it, the call silently falls back to the active model with a note.
Usage
Use this principle when any part of an agent system needs to make LLM calls outside of a direct user conversation. Appropriate for background processing, cron-triggered tasks, plugin-to-plugin delegation, and parallel multi-model execution.
Theoretical Basis
The delegation pattern separates the call context from the conversation context:
# Abstract pattern (NOT real implementation)
_CTX = None # set at registration, holds the LLM gateway
def delegate(goal, model=None, context=""):
prompt = build_prompt(goal, context)
result = _CTX.llm.complete(
messages=[{"role": "user", "content": prompt}],
max_tokens=2000,
temperature=0.7,
purpose="delegation",
model=model, # only honored if operator grants allow_model_override
)
return result.text
The purpose parameter tags each call for observability, enabling per-plugin cost tracking and trace attribution.
For parallel delegation, contextvars.copy_context() preserves the gateway's credential contextvars across thread pool boundaries, ensuring each parallel call has valid credentials.