Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:42 evey Hermes plugins delegate with model

From Leeroopedia
Knowledge Sources
Domains LLM_Delegation, Retry, Security
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for delegating a task to an LLM via Hermes with automatic task-type detection, sensitivity screening, and retry with exponential backoff.

Description

The delegate_with_model handler is the core LLM delegation mechanism in the evey-delegate-model plugin. It bypasses Hermes' built-in delegate_task (which has bugs and requires parent_agent context) and instead makes out-of-band completions through ctx.llm.complete(), working from any context (Telegram, cron, plugins).

Key internal components:

  • _detect_task_type(goal) — classifies the goal into one of: code, reasoning, research, creative, summary, uncensored, vision (default: research) using keyword matching
  • _is_sensitive(text) — checks against SENSITIVE_PATTERNS (password, api key, token, credential, private key, etc.); sensitive content never uses a model override
  • _call_model(model, prompt, max_tokens) — the retry wrapper that calls ctx.llm.complete with up to MAX_RETRIES_PER_MODEL = 3 retries and exponential backoff (1s, 2s). Handles PluginLlmTrustError by falling back to the active model. Returns (content, tokens, attempts, model_used, note).

Model override requires the operator to set plugins.entries.evey-delegate-model.llm.allow_model_override: true in config.yaml; without it, the call falls back to the active model with a note.

The plugin also registers delegate_parallel for running up to 6 tasks concurrently across models using contextvars.copy_context() to preserve gateway credentials in thread pools.

Usage

Import and call when you need to delegate a task to an LLM from any context (not just an active agent conversation). Also use delegate_parallel for concurrent multi-task execution. Registered as delegate_with_model and delegate_parallel on the evey_delegate toolset.

Code Reference

Source Location

  • Repository: hermes-plugins
  • File: evey-delegate-model/__init__.py
  • Lines: L44-310 (handler L157-221, _call_model L109-154, _detect_task_type L83-100, _is_sensitive L103-106, parallel L224-293)

Signature

def handler(args: dict, **kwargs) -> str:
    """
    Args:
        args: {
            model: str - optional model id (honoured only if operator grants allow_model_override),
            goal: str (required) - the task,
            context: str - extra context,
            max_tokens: number - default 2000
        }
    Returns:
        JSON: {status, model_used, model_retries, routing, sensitive, result, tokens, note?}
              or {status: "failed", error, last_error, routing}
    """

def _call_model(
    model: str | None, prompt: str, max_tokens: int = 2000
) -> tuple[str, int, int, str, str | None]:
    """One ctx.llm call with retry. Returns (content, tokens, attempts, model_used, note)."""

def _detect_task_type(goal: str) -> str:
    """Auto-detect task type from goal text. Returns: code/reasoning/research/creative/summary/uncensored/vision."""

def _is_sensitive(text: str) -> bool:
    """Check if text contains sensitive data that shouldn't go to a model override."""

def parallel_handler(args: dict, **kwargs) -> str:
    """Run up to 6 tasks in parallel across models using ThreadPoolExecutor + contextvars."""

Import

from evey_delegate_model import handler
# Or accessed via Hermes tool call: delegate_with_model / delegate_parallel

I/O Contract

Inputs

Name Type Required Description
goal str Yes The task or question for the model
model str No Model id (requires operator grant for override)
context str No Extra context included in the prompt
max_tokens number No Max response length (default 2000)

Outputs

Name Type Description
status str "success", "failed", or "error"
model_used str The model that actually handled the call
model_retries int Number of attempts before success
routing str Why the model was chosen (sensitive, user-specified, active)
sensitive bool Whether sensitive content was detected
result str The model's response text
tokens int Total tokens consumed
note str Present if model override was blocked (fell back to active)

Usage Examples

Basic Delegation

result = tool_call("delegate_with_model", {
    "goal": "Explain the difference between RAG and fine-tuning"
})
# {"status":"success","model_used":"active-model","model_retries":1,
#  "routing":"Active model (research task)","sensitive":false,
#  "result":"RAG retrieves...","tokens":450}

With Context and Model Override

result = tool_call("delegate_with_model", {
    "goal": "Write a Python function to parse CSV files",
    "context": "The CSV has headers and may contain quoted fields",
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1000
})
# If override allowed: {"status":"success","model_used":"claude-sonnet-4-20250514",...}
# If override blocked: {"status":"success","model_used":"active-model",
#   "note":"model 'claude-sonnet-4-20250514' not allowed..."}

Parallel Delegation

result = tool_call("delegate_parallel", {
    "tasks": [
        {"id": "research1", "goal": "Research latest embedding models"},
        {"id": "research2", "goal": "Research vector databases"},
        {"id": "research3", "goal": "Research reranking methods"}
    ]
})
# {"status":"complete","total":3,"succeeded":3,"failed":0,
#  "results":[{task_id, status, result, ...}, ...]}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment