File size: 2,658 Bytes
fe0ff58 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | """Base abstractions for stateful closed-loop/fault plugins and task evaluators."""
from __future__ import annotations
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Any
@dataclass
class VerifiedCall:
"""One SHA-384 verified and fresh-recomputed engine call recovered from `call_ledger.jsonl`."""
submitted_seal: str
model_id: str
tool: str
args: dict[str, Any]
answer: dict[str, Any]
raw_text: str
answer_sha384: str
receipt_sha384: str
primary_seal: str
@dataclass
class TaskEvaluatorContext:
"""Runtime context handed to each per-task `evaluator.py:grade(submission, ctx)`."""
task_id: str
task_dir: str
task_spec: dict[str, Any]
pack_dir: str
client: Any
seal_bin: str | None = None
vault: dict[str, Any] = field(default_factory=dict)
ledger_records: list[dict[str, Any]] = field(default_factory=list)
ledger_audit: dict[str, Any] | None = None
resolved_seals: list[VerifiedCall] = field(default_factory=list)
verified_by_model: dict[str, list[VerifiedCall]] = field(default_factory=dict)
plugin_episodes: list[dict[str, Any]] = field(default_factory=list)
class StatefulPlantPlugin(ABC):
"""Base class for stateful `CLC` / `FLT` plugins executed inside root `core/daemon.py`."""
def __init__(self, task_spec: dict[str, Any], engine_client: Any, vault: dict[str, Any] | None = None):
self.task_spec = task_spec
self.client = engine_client
self.vault = vault or {}
@abstractmethod
def tool_definitions(self) -> list[dict[str, Any]]:
"""Return MCP JSON tool schemas exposed to the unprivileged agent."""
@abstractmethod
def tool_category(self, tool_name: str) -> str | None:
"""Return `'discovery'`, `'sim'`, `'exempt'`, or `None` if not handled by this plugin."""
@abstractmethod
def handle_tool(self, tool_name: str, args: dict[str, Any]) -> dict[str, Any]:
"""Execute a plugin tool call.
Returns a dict:
- `text`: JSON string returned to the agent
- `isError`: bool
- `step_call_records`: optional list of `{"tool": ..., "model_id": ..., "args": ..., "raw_text": ...}`
for daemon ledger recording & post-run cryptographic recomputation.
- `episode_record`: optional snapshot stored on finalize or step.
"""
def budget_extras(self) -> dict[str, Any]:
"""Optional status counters injected into `budget_status`."""
return {}
def close(self) -> None:
"""Optional cleanup hook called when daemon shuts down."""
return None
|