DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
refactor(capabilities): name the metadata keys the runtime reads back
Bingxi Zhao (Frank)3e0405a996c2
diff --git a/deeptutor/agents/chat/agentic_pipeline.py b/deeptutor/agents/chat/agentic_pipeline.pyindex 7e7f0a27c..04a3e2a08 100644--- a/deeptutor/agents/chat/agentic_pipeline.py+++ b/deeptutor/agents/chat/agentic_pipeline.py@@ -22,6 +22,7 @@ from deeptutor.capabilities import (active_loop_capabilities,any_exclusive_capability_active,)+from deeptutor.capabilities.protocol import END_LOOPfrom deeptutor.core.agentic import (DispatchOutcome,LLMClientConfig,@@ -959,7 +960,7 @@ class AgenticChatPipeline:# Neutral stop signal for loop plugins (e.g. a crisis redirect): the# outer capability owns the final message, so skip further LLM rounds.# Everything below only exists to feed the answer back to the model.- if context.metadata.get("end_loop"):+ if context.metadata.get(END_LOOP):return Falsebody_text = _format_user_reply_body(diff --git a/deeptutor/capabilities/protocol.py b/deeptutor/capabilities/protocol.pyindex f0986ebd0..a8a3cf137 100644--- a/deeptutor/capabilities/protocol.py+++ b/deeptutor/capabilities/protocol.py@@ -7,6 +7,26 @@ from typing import Any, Protocolfrom deeptutor.core.context import UnifiedContext+# ── Keys a capability may write into ``context.metadata`` for the runtime ──────+#+# Turn metadata is a shared scratchpad, so the handful of keys the runtime+# itself reads back are named here, next to the interface a capability author is+# already reading. Anything else in there is private to whoever put it.++#: Set truthy during ``on_user_resume`` to end the turn without another LLM+#: round — the capability owns the final message from that point on. The user's+#: reply still reaches the transcript; only feeding it back to the model stops.+END_LOOP = "end_loop"++#: The body to publish as ``agent_output`` on the turn's CAPABILITY_COMPLETE+#: event.+AGENT_OUTPUT = "agent_output"++#: A dict of extras to publish alongside it. Only this sub-dict is forwarded —+#: never ``context.metadata`` whole, which holds live callables and the user's+#: own answers — so a capability states exactly what may leave the turn.+EVENT_METADATA = "event_metadata"+@dataclass(frozen=True, slots=True)class PromptBlock:@@ -119,4 +139,11 @@ class KnowledgeCapability:return set()-__all__ = ["KnowledgeCapability", "LoopCapability", "PromptBlock"]+__all__ = [+ "AGENT_OUTPUT",+ "END_LOOP",+ "EVENT_METADATA",+ "KnowledgeCapability",+ "LoopCapability",+ "PromptBlock",+]diff --git a/deeptutor/runtime/orchestrator.py b/deeptutor/runtime/orchestrator.pyindex c2172f5dc..c586fbea0 100644--- a/deeptutor/runtime/orchestrator.py+++ b/deeptutor/runtime/orchestrator.py@@ -13,6 +13,7 @@ import loggingfrom typing import Any, AsyncIteratorimport uuid+from deeptutor.capabilities.protocol import AGENT_OUTPUT, EVENT_METADATAfrom deeptutor.core.context import UnifiedContextfrom deeptutor.core.stream import StreamEvent, StreamEventTypefrom deeptutor.core.stream_bus import StreamBus, register_bus, unregister_bus@@ -26,8 +27,9 @@ logger = logging.getLogger(__name__)def completion_event_fields(context: UnifiedContext, cap_name: str) -> tuple[str, dict[str, Any]]:"""Build CAPABILITY_COMPLETE ``agent_output`` + metadata.- Capabilities may stash a body on ``context.metadata["agent_output"]`` and- publishable extras under ``context.metadata["event_metadata"]``.+ Capabilities may stash a body on ``context.metadata[AGENT_OUTPUT]`` and+ publishable extras under ``context.metadata[EVENT_METADATA]`` (both named in+ ``deeptutor.capabilities.protocol``).``capability``, ``session_id`` and ``turn_id`` always win so consumers canrely on those keys.@@ -40,8 +42,8 @@ def completion_event_fields(context: UnifiedContext, cap_name: str) -> tuple[strencode. A capability that wants a value on the bus says so."""meta = context.metadata or {}- agent_output = str(meta.get("agent_output") or "")- published = meta.get("event_metadata")+ agent_output = str(meta.get(AGENT_OUTPUT) or "")+ published = meta.get(EVENT_METADATA)extras = dict(published) if isinstance(published, dict) else {}return agent_output, {**extras,