praxo-core 0.6.1 → 0.7.0
raw patch · 9 files changed
+281/−39 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Praxo.Agent: Action :: String -> String -> String -> Json -> Action
+ Praxo.Agent: Interrupt :: String -> String -> ToolCall -> Interrupt
+ Praxo.Agent: InterruptDecision :: String -> Maybe Json -> String -> String -> InterruptDecision
+ Praxo.Agent: [actionArguments] :: Action -> Json
+ Praxo.Agent: [actionKind] :: Action -> String
+ Praxo.Agent: [actionSessionId] :: Action -> String
+ Praxo.Agent: [actionToolName] :: Action -> String
+ Praxo.Agent: [beforeTool] :: AgentOptions -> Maybe (ToolCall -> IO (Either AgentError ToolCall))
+ Praxo.Agent: [interruptAction] :: InterruptDecision -> String
+ Praxo.Agent: [interruptArguments] :: InterruptDecision -> Maybe Json
+ Praxo.Agent: [interruptCall] :: Interrupt -> ToolCall
+ Praxo.Agent: [interruptOn] :: AgentOptions -> [String]
+ Praxo.Agent: [interruptReason] :: InterruptDecision -> String
+ Praxo.Agent: [interruptResponse] :: InterruptDecision -> String
+ Praxo.Agent: [interruptRunId] :: Interrupt -> String
+ Praxo.Agent: [interruptSessionId] :: Interrupt -> String
+ Praxo.Agent: [onInterruptDecision] :: AgentOptions -> Maybe InterruptHandler
+ Praxo.Agent: [onInterrupt] :: AgentOptions -> Maybe InterruptApproval
+ Praxo.Agent: [runId] :: AgentOptions -> String
+ Praxo.Agent: [sessionId] :: AgentOptions -> String
+ Praxo.Agent: data Action
+ Praxo.Agent: data Interrupt
+ Praxo.Agent: data InterruptDecision
+ Praxo.Agent: instance GHC.Classes.Eq Praxo.Agent.Action
+ Praxo.Agent: instance GHC.Classes.Eq Praxo.Agent.Interrupt
+ Praxo.Agent: instance GHC.Classes.Eq Praxo.Agent.InterruptDecision
+ Praxo.Agent: instance GHC.Show.Show Praxo.Agent.Action
+ Praxo.Agent: instance GHC.Show.Show Praxo.Agent.Interrupt
+ Praxo.Agent: instance GHC.Show.Show Praxo.Agent.InterruptDecision
+ Praxo.Agent: interruptApprove :: String
+ Praxo.Agent: interruptEdit :: String
+ Praxo.Agent: interruptReject :: String
+ Praxo.Agent: interruptRespond :: String
+ Praxo.Agent: type InterruptApproval = Interrupt -> IO Bool
+ Praxo.Agent: type InterruptHandler = Interrupt -> IO InterruptDecision
- Praxo.Agent: AgentOptions :: ([Message] -> IO (Either AgentError Response)) -> (ToolCall -> IO (Either AgentError Json)) -> (String -> IO (Either AgentError ())) -> Int -> Integer -> Maybe (String -> Bool) -> [String] -> Bool -> Bool -> AgentOptions
+ Praxo.Agent: AgentOptions :: ([Message] -> IO (Either AgentError Response)) -> (ToolCall -> IO (Either AgentError Json)) -> (String -> IO (Either AgentError ())) -> Int -> Integer -> Maybe (Action -> Bool) -> [String] -> Bool -> Bool -> String -> String -> [String] -> Maybe InterruptHandler -> Maybe InterruptApproval -> Maybe (ToolCall -> IO (Either AgentError ToolCall)) -> AgentOptions
- Praxo.Agent: [policy] :: AgentOptions -> Maybe (String -> Bool)
+ Praxo.Agent: [policy] :: AgentOptions -> Maybe (Action -> Bool)
Files
- README.md +33/−2
- REGISTRY.md +6/−6
- conformance/Main.hs +1/−1
- llms.md +4/−4
- llms.txt +4/−4
- praxo-core.cabal +1/−1
- src/Praxo/Agent.hs +109/−18
- src/Praxo/Wire.hs +1/−1
- tests/Main.hs +122/−2
README.md view
@@ -7,7 +7,7 @@ middleware, JSON Schema validation, plugin manifest parsing, and runtime helpers. - Implementation type: Core.-- Package version: `0.6.0`; supported `SPEC_VERSION`: `0.2.0`.+- Package version: `0.7.0`; supported `SPEC_VERSION`: `0.2.0`. - Local gate: all eleven shared vector groups, native regression tests, and source API/parity checks. - Linux and Windows CI run the full suite. Hackage publication uses@@ -20,7 +20,7 @@ - Machine-readable entry: [llms.txt](https://github.com/axisvela/praxo-core/blob/main/language/haskell/llms.txt) and [llms.md](https://github.com/axisvela/praxo-core/blob/main/language/haskell/llms.md) - [Examples](https://github.com/axisvela/praxo-core/tree/main/language/haskell/examples): runnable language-specific examples. - Coding-agent contract: [docs/getting-started/coding-agents.md](https://github.com/axisvela/praxo-core/blob/main/docs/getting-started/coding-agents.md)-- Registry: [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.0)+- Registry: [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.1) - Community: [X](https://x.com/axisvela) · [Weibo](https://weibo.com/u/1936025761) ## Get started@@ -57,6 +57,7 @@ | Retry transient failures | [retry](https://github.com/axisvela/praxo-core/tree/main/language/haskell/examples/retry) | | Add provider fallback | [provider-fallback](https://github.com/axisvela/praxo-core/tree/main/language/haskell/examples/provider-fallback) | | Observe agent events | [event-sink](https://github.com/axisvela/praxo-core/tree/main/language/haskell/examples/event-sink) |+| Require human approval | [hitl](https://github.com/axisvela/praxo-core/tree/main/language/haskell/examples/hitl) | ## Build and Test @@ -169,6 +170,36 @@ the status and a bounded body otherwise. The sink adds no authentication, retries, buffering, ordering, or exactly-once delivery. Event data may contain sensitive content, so filter caller-side; use HTTPS for remote endpoints.++## Human-in-the-Loop Approval++`AgentOptions` accepts `interruptOn`, `onInterruptDecision`, and `onInterrupt` to+pause matching tool calls. The agent checks allowed tools, runs the initial+policy, applies `beforeTool`, and then applies the interrupt before `tool.call`+and `invoke`.++```haskell+import Praxo.Agent+import Praxo.Json++options :: AgentOptions -> AgentOptions+options base = base+ { interruptOn = ["write_note"]+ , onInterruptDecision = Just $ \interrupt ->+ pure (InterruptDecision interruptEdit+ (Just (JObject [("text", JString "hello"),+ ("visibility", JString "private")]))+ "" "")+ }+```++Decisions are `interruptApprove` (continue), `interruptEdit` (replace arguments+and reauthorize), `interruptReject` (return `AGENT_APPROVAL_DENIED` with the+reason), and `interruptRespond` (skip the tool and use the response). A matching+call with no handler returns `AGENT_INTERRUPT_UNHANDLED`; an unknown action or+an edit without arguments returns `AGENT_INTERRUPT_DECISION_INVALID`. The policy+hook receives an `Action` so edited arguments are reauthorized. See+[`examples/hitl`](examples/hitl/). ## Declared Scope and Limits
REGISTRY.md view
@@ -1,7 +1,7 @@ # PRAXO-CORE Haskell Registry Introduction -**Status:** published. Source version `0.6.1`, source-tag `haskell/v0.6.1`. Published registry version: `0.6.0`. Registry+**Status:** published. Source version `0.7.0`, source+tag `haskell/v0.7.0`. Published registry version: `0.6.1`. Registry pages are release snapshots; verify the published version before relying on a feature. @@ -14,12 +14,12 @@ | Field | Value | | --- | --- | | Package | `praxo-core` |-| Registry | [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.0) |-| Source version | `0.6.1` |-| Published registry version | `0.6.0` |+| Registry | [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.1) |+| Source version | `0.7.0` |+| Published registry version | `0.6.1` | | Install (published) | `cabal install praxo-core` | | Install (source/release prepared) | `cabal install praxo-core` |-| Source tag | `haskell/v0.6.1` |+| Source tag | `haskell/v0.7.0` | | Tier | Core | | Contract | `SPEC_VERSION` `0.2.0` | | Documentation | https://axisvela.github.io/praxo-core/languages/haskell/ |
conformance/Main.hs view
@@ -61,7 +61,7 @@ then pure (Right (A.toolCallArguments call)) else pure (Left (A.AgentError "TOOL_NOT_FOUND" "tool not found")) sink event = modifyIORef' events (++ [JString event]) >> pure (Right ())- options = A.AgentOptions model tool sink (fromInteger (number (field "maxSteps" input))) (number (field "maxTokens" input)) Nothing [] False False+ options = A.AgentOptions model tool sink (fromInteger (number (field "maxSteps" input))) (number (field "maxTokens" input)) Nothing [] False False "run-conformance" "session-conformance" [] Nothing Nothing Nothing result <- A.runAgent options [] (asString (field "prompt" input)) actualEvents <- readIORef events count <- readIORef invocations
llms.md view
@@ -7,12 +7,12 @@ ## Package - package: `praxo-core`-- registry: [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.0)-- source_version: `0.6.1`-- published_version: `0.6.0`+- registry: [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.1)+- source_version: `0.7.0`+- published_version: `0.6.1` - install_published: `cabal install praxo-core` - install_source: `cabal install praxo-core`-- source_tag: `haskell/v0.6.1`+- source_tag: `haskell/v0.7.0` - tier: Core - contract: `SPEC_VERSION` `0.2.0` - documentation: https://axisvela.github.io/praxo-core/languages/haskell/
llms.txt view
@@ -7,12 +7,12 @@ # Package - package: `praxo-core`-- registry: [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.0)-- source_version: `0.6.1`-- published_version: `0.6.0`+- registry: [Hackage](https://hackage.haskell.org/package/praxo-core-0.6.1)+- source_version: `0.7.0`+- published_version: `0.6.1` - install_published: `cabal install praxo-core` - install_source: `cabal install praxo-core`-- source_tag: `haskell/v0.6.1`+- source_tag: `haskell/v0.7.0` - tier: Core - contract: `SPEC_VERSION` `0.2.0` - documentation: https://axisvela.github.io/praxo-core/languages/haskell/
praxo-core.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: praxo-core-version: 0.6.1+version: 0.7.0 synopsis: Embeddable MIT-licensed agent framework for Haskell description: Native agent loop with tools, policy hooks, typed events, memory, checkpoints, context budgets, middleware, JSON Schema validation,
src/Praxo/Agent.hs view
@@ -1,16 +1,40 @@-module Praxo.Agent (AgentError(..), ToolCall(..), Message(..), Response(..), AgentOptions(..), RunResult(..), runAgent) where+module Praxo.Agent (AgentError(..), ToolCall(..), Action(..), Interrupt(..), InterruptDecision(..), InterruptHandler, InterruptApproval, interruptApprove, interruptEdit, interruptReject, interruptRespond, Message(..), Response(..), AgentOptions(..), RunResult(..), runAgent) where import Data.Maybe (isNothing) -import Praxo.Json (Json, encodeJson)+import Praxo.Json (Json(..), encodeJson) +interruptApprove :: String+interruptApprove = "approve"++interruptEdit :: String+interruptEdit = "edit"++interruptReject :: String+interruptReject = "reject"++interruptRespond :: String+interruptRespond = "respond"+ data AgentError = AgentError { errorCode :: String, errorMessage :: String } deriving (Eq, Show) data ToolCall = ToolCall { toolCallId :: String, toolCallName :: String, toolCallArguments :: Json } deriving (Eq, Show)+data Action = Action { actionKind :: String, actionSessionId :: String, actionToolName :: String, actionArguments :: Json } deriving (Eq, Show)+data Interrupt = Interrupt { interruptRunId :: String, interruptSessionId :: String, interruptCall :: ToolCall } deriving (Eq, Show)+data InterruptDecision = InterruptDecision { interruptAction :: String, interruptArguments :: Maybe Json, interruptResponse :: String, interruptReason :: String } deriving (Eq, Show)+type InterruptHandler = Interrupt -> IO InterruptDecision+type InterruptApproval = Interrupt -> IO Bool data Message = Message { messageRole :: String, messageContent :: String, messageToolCalls :: [ToolCall], messageToolCallId :: String } deriving (Eq, Show) data Response = Response { responseContent :: String, responseToolCalls :: [ToolCall], inputTokens :: Integer, outputTokens :: Integer } deriving (Eq, Show)-data AgentOptions = AgentOptions { generate :: [Message] -> IO (Either AgentError Response), invoke :: ToolCall -> IO (Either AgentError Json), emit :: String -> IO (Either AgentError ()), maxSteps :: Int, maxTokens :: Integer, policy :: Maybe (String -> Bool), allowedTools :: [String], requirePolicy :: Bool, requireToolScope :: Bool }+data AgentOptions = AgentOptions { generate :: [Message] -> IO (Either AgentError Response), invoke :: ToolCall -> IO (Either AgentError Json), emit :: String -> IO (Either AgentError ()), maxSteps :: Int, maxTokens :: Integer, policy :: Maybe (Action -> Bool), allowedTools :: [String], requirePolicy :: Bool, requireToolScope :: Bool, runId :: String, sessionId :: String, interruptOn :: [String], onInterruptDecision :: Maybe InterruptHandler, onInterrupt :: Maybe InterruptApproval, beforeTool :: Maybe (ToolCall -> IO (Either AgentError ToolCall)) } data RunResult = RunResult { runOutput :: String, runSteps :: Int, runInputTokens :: Integer, runOutputTokens :: Integer, runMessages :: [Message] } deriving (Eq, Show) +data InterruptOutcome = InterruptOutcome+ { outcomeSkip :: Bool+ , outcomeResponse :: String+ , outcomeCall :: ToolCall+ , outcomeEdited :: Bool+ }+ ensureAllowed :: Either AgentError () -> IO (Either AgentError a) -> IO (Either AgentError a) ensureAllowed (Left err) _ = pure (Left err) ensureAllowed (Right ()) action = action@@ -44,16 +68,19 @@ | requireToolScope opts && null (allowedTools opts) = Just (AgentError "AGENT_INVALID_OPTIONS" "agent: require tool scope: allowedTools must not be empty") | otherwise = Nothing- authorize kind = case policy options of+ authorize kind call = case policy options of Nothing -> Right ()- Just hook -> if hook kind then Right () else Left (AgentError "AGENT_POLICY_DENIED" ("agent: " ++ kind ++ " denied"))+ Just hook ->+ if hook (Action kind (sessionId options) (toolCallName call) (toolCallArguments call))+ then Right ()+ else Left (AgentError "AGENT_POLICY_DENIED" ("agent: " ++ kind ++ " denied")) checkTool call | not (null (allowedTools options)) && toolCallName call `notElem` allowedTools options = Left (AgentError "AGENT_TOOL_NOT_ALLOWED" ("agent: tool " ++ toolCallName call ++ " is not allowed"))- | otherwise = authorize "tool.invoke"+ | otherwise = authorize "tool.invoke" call loop step usedIn usedOut messages | step > limit = pure (Left (AgentError "AGENT_MAX_STEPS" "agent: maximum steps exceeded"))- | otherwise = ensureAllowed (authorize "model.generate") $ do+ | otherwise = ensureAllowed (authorize "model.generate" (ToolCall "" "" JNull)) $ do generated <- generate options messages case generated of Left err -> pure (Left err)@@ -73,14 +100,78 @@ Left err -> pure (Left err) Right updated -> loop (step + 1) totalIn totalOut updated tools messages [] = pure (Right messages)- tools messages (call:rest) = ensureAllowed (checkTool call) $ do- event <- emit options "tool.call"- case event of- Left err -> pure (Left err)- Right () -> do- result <- invoke options call- case result of- Left err -> pure (Left err)- Right value -> case encodeJson value of- Left detail -> pure (Left (AgentError "TOOL_RESULT" detail))- Right content -> tools (messages ++ [Message "tool" content [] (toolCallId call)]) rest+ tools messages (call:rest) = case checkTool call of+ Left err -> pure (Left err)+ Right () -> do+ prepared <- applyBeforeTool call+ case prepared of+ Left err -> pure (Left err)+ Right active -> do+ interrupted <- applyInterrupt active+ case interrupted of+ Left err -> pure (Left err)+ Right outcome+ | outcomeSkip outcome -> finishSkipped messages outcome rest+ | otherwise -> do+ let final = outcomeCall outcome+ recheck = if outcomeEdited outcome || final /= call+ then checkTool final+ else Right ()+ ensureAllowed recheck $ do+ event <- emit options "tool.call"+ case event of+ Left err -> pure (Left err)+ Right () -> do+ result <- invoke options final+ case result of+ Left err -> pure (Left err)+ Right value -> case encodeJson value of+ Left detail -> pure (Left (AgentError "TOOL_RESULT" detail))+ Right content -> tools (messages ++ [Message "tool" content [] (toolCallId final)]) rest+ finishSkipped messages outcome rest =+ case encodeJson (JString (outcomeResponse outcome)) of+ Left detail -> pure (Left (AgentError "TOOL_RESULT" detail))+ Right content -> tools (messages ++ [Message "tool" content [] (toolCallId (outcomeCall outcome))]) rest+ applyBeforeTool call = case beforeTool options of+ Nothing -> pure (Right call)+ Just handler -> handler call+ applyInterrupt call+ | toolCallName call `notElem` interruptOn options =+ pure (Right (InterruptOutcome False "" call False))+ | isNothing (onInterruptDecision options) && isNothing (onInterrupt options) =+ pure (Left (AgentError "AGENT_INTERRUPT_UNHANDLED"+ ("agent: approval handler not configured: " ++ toolCallName call)))+ | otherwise = do+ event <- emit options "tool.interrupt"+ case event of+ Left err -> pure (Left err)+ Right () -> do+ let pending = Interrupt (runId options) (sessionId options) call+ case onInterruptDecision options of+ Just handler -> fmap (applyDecision call) (handler pending)+ Nothing -> case onInterrupt options of+ Just approval -> do+ approved <- approval pending+ pure $ if approved+ then Right (InterruptOutcome False "" call False)+ else Left (AgentError "AGENT_APPROVAL_DENIED"+ ("agent: tool call denied by approval: " ++ toolCallName call))+ Nothing -> pure (Left (AgentError "AGENT_INTERRUPT_UNHANDLED"+ ("agent: approval handler not configured: " ++ toolCallName call)))+ applyDecision call decision+ | interruptAction decision == interruptApprove =+ Right (InterruptOutcome False "" call False)+ | interruptAction decision == interruptEdit =+ case interruptArguments decision of+ Nothing -> Left (AgentError "AGENT_INTERRUPT_DECISION_INVALID" "agent: edit requires arguments")+ Just arguments -> Right (InterruptOutcome False ""+ (call { toolCallArguments = arguments }) True)+ | interruptAction decision == interruptReject =+ Left (AgentError "AGENT_APPROVAL_DENIED"+ ("agent: tool call denied by approval: " ++ toolCallName call ++ ": "+ ++ interruptReason decision))+ | interruptAction decision == interruptRespond =+ Right (InterruptOutcome True (interruptResponse decision) call False)+ | otherwise =+ Left (AgentError "AGENT_INTERRUPT_DECISION_INVALID"+ ("agent: invalid interrupt decision: " ++ show (interruptAction decision)))
src/Praxo/Wire.hs view
@@ -4,4 +4,4 @@ specVersion = "0.2.0" sdkVersion :: String-sdkVersion = "0.6.1"+sdkVersion = "0.7.0"
tests/Main.hs view
@@ -26,6 +26,7 @@ main :: IO () main = do agentTests+ hitlTests runtimeTests middlewareTests adapterTests@@ -33,7 +34,7 @@ harmovelaTests mcpTests seamTests- assert "contract version" (specVersion == "0.2.0" && sdkVersion == "0.6.1")+ assert "contract version" (specVersion == "0.2.0" && sdkVersion == "0.7.0") forM_ ["", "01", "1.", "+1", "NaN", "1e", "[1,]", "{\"a\":1,}", "{}{}", "\"\\q\"", "\"\\ud800\"", "\"\\udc00\"", "\"\\ud800\\u0041\"", "\"line\nbreak\"", "true garbage"] $ \raw -> assert ("invalid JSON " ++ show raw) (isLeft (parseJson raw)) assert "unicode escape" (parseJson "\"\\u00e9\\ud83d\\ude00\"" == Right (JString "\x00e9\x1f600"))@@ -103,7 +104,7 @@ n <- readIORef calls pure (Right (if n == 0 then A.Response "" [call] 2 1 else A.Response "done" [] 1 1)) tool _ = modifyIORef' calls (+1) >> pure (Right JNull)- options = A.AgentOptions model tool sink 2 5 Nothing [] False False+ options = A.AgentOptions model tool sink 2 5 Nothing [] False False "run-test" "session-test" [] Nothing Nothing Nothing result <- A.runAgent options [] "hello" assert "agent success and usage" (case result of Right r -> A.runSteps r == 2 && A.runInputTokens r == 3 && A.runOutputTokens r == 2; _ -> False) history <- readIORef requests@@ -173,6 +174,125 @@ writeIORef calls 1 defaults <- A.runAgent options [] "x" assert "safe defaults preserve behavior" (case defaults of Right r -> A.runOutput r == "done"; _ -> False)++hitlTests :: IO ()+hitlTests = do+ let echoCall = A.ToolCall "call-1" "echo" (JObject [("value", JString "original")])+ model messages = pure $ Right $ case reverse messages of+ (lastMessage:_) | A.messageRole lastMessage == "tool" -> A.Response "final" [] 0 0+ _ -> A.Response "" [echoCall] 0 0+ echoModel messages = pure $ Right $ case reverse messages of+ (lastMessage:_) | A.messageRole lastMessage == "tool" -> A.Response (A.messageContent lastMessage) [] 0 0+ _ -> A.Response "" [echoCall] 0 0+ base tool = A.AgentOptions+ { A.generate = model+ , A.invoke = tool+ , A.emit = \_ -> pure (Right ())+ , A.maxSteps = 4+ , A.maxTokens = 0+ , A.policy = Nothing+ , A.allowedTools = ["echo"]+ , A.requirePolicy = False+ , A.requireToolScope = False+ , A.runId = "run-hitl"+ , A.sessionId = "session-hitl"+ , A.interruptOn = ["echo"]+ , A.onInterruptDecision = Nothing+ , A.onInterrupt = Nothing+ , A.beforeTool = Nothing+ }++ approveCalls <- newIORef []+ approveEvents <- newIORef []+ let approveTool call = modifyIORef' approveCalls (++ [A.toolCallArguments call]) >> pure (Right (A.toolCallArguments call))+ approveOptions = (base approveTool)+ { A.emit = \name -> modifyIORef' approveEvents (++ [name]) >> pure (Right ())+ , A.onInterruptDecision = Just $ \interrupt -> do+ assert "hitl interrupt run id" (A.interruptRunId interrupt == "run-hitl")+ assert "hitl interrupt session id" (A.interruptSessionId interrupt == "session-hitl")+ assert "hitl interrupt call" (A.toolCallName (A.interruptCall interrupt) == "echo")+ assert "hitl interrupt arguments" (A.toolCallArguments (A.interruptCall interrupt) == JObject [("value", JString "original")])+ pure (A.InterruptDecision A.interruptApprove Nothing "" "")+ }+ approved <- A.runAgent approveOptions [] "go"+ approveCallValues <- readIORef approveCalls+ approveEventValues <- readIORef approveEvents+ assert "hitl approve" (case approved of Right r -> A.runOutput r == "final"; _ -> False)+ assert "hitl approve effects" (approveCallValues == [JObject [("value", JString "original")]])+ assert "hitl interrupt event order" (approveEventValues == ["run.started", "tool.interrupt", "tool.call", "run.completed"])++ editCalls <- newIORef []+ editOrder <- newIORef []+ let editTool call = modifyIORef' editCalls (++ [call]) >> pure (Right JNull)+ editPolicy action+ | A.actionKind action == "model.generate" = True+ | otherwise = asString (field "value" (A.actionArguments action)) == "original"+ editOptions = (base editTool)+ { A.policy = Just editPolicy+ , A.beforeTool = Just $ \call -> do+ modifyIORef' editOrder (++ ["before"])+ pure (Right call)+ , A.onInterruptDecision = Just $ \_ -> do+ current <- readIORef editOrder+ assert "hitl before middleware precedes interrupt" (current == ["before"])+ modifyIORef' editOrder (++ ["interrupt"])+ pure (A.InterruptDecision A.interruptEdit (Just (JObject [("value", JString "edited")])) "" "")+ }+ edited <- A.runAgent editOptions [] "go"+ editCallValues <- readIORef editCalls+ editOrderValues <- readIORef editOrder+ assert "hitl edit reauthorization denied" (case edited of Left err -> A.errorCode err == "AGENT_POLICY_DENIED"; _ -> False)+ assert "hitl edit no effects" (null editCallValues)+ assert "hitl middleware before interrupt order" (editOrderValues == ["before", "interrupt"])++ rejectCalls <- newIORef []+ let rejectOptions = (base (\call -> modifyIORef' rejectCalls (++ [call]) >> pure (Right JNull)))+ { A.onInterruptDecision = Just $ \_ -> pure (A.InterruptDecision A.interruptReject Nothing "" "not allowed") }+ rejected <- A.runAgent rejectOptions [] "go"+ rejectCallValues <- readIORef rejectCalls+ assert "hitl reject code" (case rejected of Left err -> A.errorCode err == "AGENT_APPROVAL_DENIED" && "not allowed" `isInfixOf` A.errorMessage err; _ -> False)+ assert "hitl reject no effects" (null rejectCallValues)++ respondCalls <- newIORef []+ let respondOptions = (base (\call -> modifyIORef' respondCalls (++ [call]) >> pure (Right JNull)))+ { A.generate = echoModel+ , A.onInterruptDecision = Just $ \_ -> pure (A.InterruptDecision A.interruptRespond Nothing "human answer" "")+ }+ responded <- A.runAgent respondOptions [] "go"+ respondCallValues <- readIORef respondCalls+ assert "hitl respond output" (case responded of Right r -> A.runOutput r == "\"human answer\""; _ -> False)+ assert "hitl respond no effects" (null respondCallValues)++ unhandledCalls <- newIORef []+ unhandled <- A.runAgent (base (\call -> modifyIORef' unhandledCalls (++ [call]) >> pure (Right JNull))) [] "go"+ unhandledCallValues <- readIORef unhandledCalls+ assert "hitl unhandled code" (case unhandled of Left err -> A.errorCode err == "AGENT_INTERRUPT_UNHANDLED"; _ -> False)+ assert "hitl unhandled no effects" (null unhandledCallValues)++ invalidCalls <- newIORef []+ let invalidOptions = (base (\call -> modifyIORef' invalidCalls (++ [call]) >> pure (Right JNull)))+ { A.onInterruptDecision = Just $ \_ -> pure (A.InterruptDecision "invalid" Nothing "" "") }+ invalid <- A.runAgent invalidOptions [] "go"+ invalidCallValues <- readIORef invalidCalls+ assert "hitl invalid decision code" (case invalid of Left err -> A.errorCode err == "AGENT_INTERRUPT_DECISION_INVALID"; _ -> False)+ assert "hitl invalid decision no effects" (null invalidCallValues)++ missingArgumentsCalls <- newIORef []+ let missingArgumentsOptions = (base (\call -> modifyIORef' missingArgumentsCalls (++ [call]) >> pure (Right JNull)))+ { A.onInterruptDecision = Just $ \_ -> pure (A.InterruptDecision A.interruptEdit Nothing "" "") }+ missingArguments <- A.runAgent missingArgumentsOptions [] "go"+ missingArgumentsCallValues <- readIORef missingArgumentsCalls+ assert "hitl edit requires arguments" (case missingArguments of Left err -> A.errorCode err == "AGENT_INTERRUPT_DECISION_INVALID"; _ -> False)+ assert "hitl edit missing arguments no effects" (null missingArgumentsCallValues)++ approvalCalls <- newIORef []+ let approvalOptions = (base (\call -> modifyIORef' approvalCalls (++ [call]) >> pure (Right JNull)))+ { A.onInterrupt = Just $ \_ -> pure False }+ approval <- A.runAgent approvalOptions [] "go"+ approvalCallValues <- readIORef approvalCalls+ assert "hitl approval denial code" (case approval of Left err -> A.errorCode err == "AGENT_APPROVAL_DENIED"; _ -> False)+ assert "hitl approval denial no effects" (null approvalCallValues)+ runtimeTests :: IO () runtimeTests = do