circuits-agent
Safe HaskellNone
LanguageGHC2024

Circuit.Agent.Tensor

Description

Seat-level tensor combinators over Ends with state carried by Body.

These are the semantic citizens that free-agent FreeSeat terms fold into. The buffer state is part of the base arrow ('Body (,) (K IO) [Post Text]') rather than a monad transformer.

Synopsis

Documentation

type AgentShard a b = Poles (Body (,) [Post Text] (K IO)) a b Source #

An effectful agent shard with a '[Post Text]' buffer threaded through the arrow.

silentShard :: AgentShard [Post Text] [Post Text] Source #

Silent shard: commit replaces the buffer; emit clears it and returns [].

awaitShard :: AgentShard [Post Text] [Post Text] -> AgentShard [Post Text] [Post Text] -> AgentShard [Post Text] [Post Text] Source #

Product / await shard: both sub-shards see the same input; emits are concatenated left-to-right.

raceShard :: AgentShard [Post Text] [Post Text] -> AgentShard [Post Text] [Post Text] -> AgentShard [Post Text] [Post Text] Source #

Coproduct / race shard: left emit wins if non-empty, otherwise right.

fanOutShard :: [AgentShard [Post Text] [Post Text]] -> AgentShard [Post Text] [Post Text] Source #

Fan-out shard: every sub-shard sees the same input; emits are concatenated in branch order.

fanInShard :: ([[Post Text]] -> [Post Text]) -> [AgentShard [Post Text] [Post Text]] -> AgentShard [Post Text] [Post Text] Source #

Fan-in shard: fan-out, then collapse the collected branch outputs with the supplied summary function.

runSubShard :: AgentShard [Post Text] [Post Text] -> [Post Text] -> IO [Post Text] Source #

Run a child shard in isolation on the given input, discarding its residual state. Branches in await race fan-out have private scratch state; only their emits rejoin the main stream.

closeShardIO :: Poles (Body (,) s (K IO)) a a -> a -> s -> IO (a, s) Source #

Close a same-type shard once, exposing both the output and the residual state. Works for any state carrier s and payload a.

ioShard :: ([Post Text] -> IO [Post Text]) -> AgentShard [Post Text] [Post Text] Source #

Build an agent shard that stores the input batch, then computes outputs from that batch in IO.

writeBatch :: Body (,) [Post Text] (K IO) [Post Text] () Source #

Helper: store the input batch as the buffer.

readBatch :: Body (,) [Post Text] (K IO) () [Post Text] Source #

Helper: return the buffer as output and clear it.

synthesisSummary :: Name -> [Name] -> [PostId] -> ([[Post Text]] -> Text) -> [[Post Text]] -> [Post Text] Source #

A fan-in summary honest by construction: the single output post is a synthesis of the supplied parent ids, so its ancestry cites every branch output by exact reference. The supplied function computes the body. No branch outputs, or an empty body -> no posts (quiet).

The caller supplies one PostId per branch output (in the order produced by concat oss). When ids are not available, pass [] and the summary falls back to a root post (no thread edge).