From e856c766584ed933bed0b79c7ef47b6d98b0fb7e Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 19 Dec 2025 16:41:01 -0500 Subject: Omni/Agent: wire prompt templating system to agents - Telegram.hs: add loadTelegramSystemPrompt with fallback - Subagent.hs: add loadSystemPromptForRole with fallback - Coder.hs: add loadCoderSystemPrompt with fallback - Ava.nix: add tmpfiles rules for /home/ava/prompts/ - Prompts.hs: fix test to expect .mustache extension Templates loaded at runtime from $AVA_DATA_ROOT/prompts/. Falls back to hardcoded prompts if templates not found. Amp-Thread-ID: https://ampcode.com/threads/T-019b3878-73be-77ec-97cc-d092a28d211e Co-authored-by: Amp --- Omni/Agent/Subagent.hs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'Omni/Agent/Subagent.hs') diff --git a/Omni/Agent/Subagent.hs b/Omni/Agent/Subagent.hs index f5e04b0..9f3052d 100644 --- a/Omni/Agent/Subagent.hs +++ b/Omni/Agent/Subagent.hs @@ -18,6 +18,8 @@ -- : out omni-agent-subagent -- : dep aeson -- : dep async +-- : dep directory +-- : dep mustache -- : dep stm -- : dep uuid module Omni.Agent.Subagent @@ -92,6 +94,7 @@ import qualified Data.UUID import qualified Data.UUID.V4 import qualified Omni.Agent.AuditLog as AuditLog import qualified Omni.Agent.Engine as Engine +import qualified Omni.Agent.Prompts as Prompts import qualified Omni.Agent.Provider as Provider import qualified Omni.Agent.Subagent.Coder as Coder import qualified Omni.Agent.Tools as Tools @@ -611,6 +614,21 @@ toolsForRole Researcher keys = toolsForRole Coder _keys = Coder.coderTools toolsForRole (CustomRole _) keys = toolsForRole Researcher keys +-- | Load system prompt from template, falling back to hardcoded if unavailable +loadSystemPromptForRole :: SubagentRole -> Text -> Maybe Text -> IO Text +loadSystemPromptForRole role task maybeContext = do + let ctx = + Aeson.object + [ "role_description" .= roleDescription role, + "task" .= task, + "context" .= maybeContext + ] + result <- Prompts.renderPrompt "subagents/generic/system" ctx + case result of + Right prompt -> pure prompt + Left _err -> pure (systemPromptForRole role task maybeContext) + +-- | Hardcoded fallback prompt for subagents systemPromptForRole :: SubagentRole -> Text -> Maybe Text -> Text systemPromptForRole role task maybeContext = Text.unlines @@ -647,14 +665,14 @@ systemPromptForRole role task maybeContext = "}", "```" ] - where - roleDescription :: SubagentRole -> Text - roleDescription WebCrawler = "web research" - roleDescription CodeReviewer = "code review" - roleDescription DataExtractor = "data extraction" - roleDescription Researcher = "research" - roleDescription Coder = "coding" - roleDescription (CustomRole name) = name + +roleDescription :: SubagentRole -> Text +roleDescription WebCrawler = "web research" +roleDescription CodeReviewer = "code review" +roleDescription DataExtractor = "data extraction" +roleDescription Researcher = "research" +roleDescription Coder = "coding" +roleDescription (CustomRole name) = name runSubagent :: SubagentApiKeys -> SubagentConfig -> IO SubagentResult runSubagent keys config = runSubagentWithCallbacks keys config defaultCallbacks @@ -778,7 +796,7 @@ runGenericSubagent keys config callbacks = do let role = subagentRole config let model = fromMaybe (modelForRole role) (subagentModel config) let tools = toolsForRole role keys - let systemPrompt = systemPromptForRole role (subagentTask config) (subagentContext config) + systemPrompt <- loadSystemPromptForRole role (subagentTask config) (subagentContext config) onSubagentStart callbacks ("Starting " <> tshow role <> " subagent...") -- cgit v1.2.3