circuits-agent
Safe HaskellNone
LanguageGHC2024

Circuit.Agent.Graph

Description

Algebraic wiring of agent meetings.

Vertices are agent names; edges are labelled with sets of channels (names in to). The algebra is borrowed from algebraic-graphs:

  • empty — no agents.
  • vertex — a single agent.
  • overlay — independent subgraphs (no new delivery edges).
  • connect — every agent on the left may post to the channel(s); every agent on the right subscribes to them.

This captures broadcast buses, stars, chains, and (via a registry that maps a name to a whole subgraph) hierarchical orchestrators.

Synopsis

Graph of agents

type AgentGraph = Graph ChannelSet Name Source #

Wiring graph: vertices are agent names, edges are sets of channels.

type ChannelSet = Set Channel Source #

A set of channels carried by one graph edge.

data AgentNode Source #

A registry entry is either an atomic pure agent or a nested subgraph.

type AgentRegistry = Map Name AgentNode Source #

Registry of agents. Names map to atomic agents or whole subgraphs.

type GraphAgent = Agent (->) ([Post Text], Maybe [Post Text]) (Post Text) [Post Text] Source #

An agent after graph routing has been applied: the carrier holds the original history plus the output associated with the current state.

Construction

channel :: Channel -> ChannelSet Source #

A single channel as an edge label.

bus :: [Name] -> Channel -> AgentGraph Source #

Every named agent posts to and subscribes to ch.

This is the public-bus configuration.

star :: Name -> [Name] -> Channel -> Channel -> AgentGraph Source #

A hub agent that posts to hubCh; leaf agents post to leafCh.

chain :: [Name] -> Channel -> AgentGraph Source #

Chain agents left-to-right on a single channel.

atomic :: Agent (->) [Post Text] (Post Text) [Post Text] -> AgentNode Source #

Smart constructor for an atomic registry entry.

nested :: AgentGraph -> AgentRegistry -> AgentNode Source #

Smart constructor for a nested registry entry.

Interpretation

channelMap :: AgentGraph -> Map Name VertexInfo Source #

Compute subscriptions and addressing for every agent in the graph.

toRoster :: AgentGraph -> AgentRegistry -> [(Name, GraphAgent)] Source #

Build a roster from the graph by routing each agent's outputs along its outgoing edges and subscribing it to its incoming edges.

runGraph :: AgentGraph -> AgentRegistry -> [Post Text] -> [Post Text] Source #

Run the wired agents against an initial log.

toAgent :: AgentGraph -> AgentRegistry -> Agent (->) [Post Text] (Post Text) [Post Text] Source #

Interpret a graph as a single agent. The carrier is the input history; each new post is fed to the graph and the freshly generated posts are emitted.

flatten :: AgentGraph -> AgentRegistry -> (AgentGraph, AgentRegistry) Source #

Flatten a graph by expanding nested vertices into their subgraphs. Returns a graph whose vertices are all atomic and a registry of those atoms. Nested names are prefixed to avoid collisions.