summaryrefslogtreecommitdiff
path: root/Omni/Agent/Subagent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Omni/Agent/Subagent.hs')
-rw-r--r--Omni/Agent/Subagent.hs36
1 files changed, 27 insertions, 9 deletions
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...")