Loop Engine

AI and Automation

AI as Actor

AI as an actor, not the controller

Loop Engine treats AI the same way it treats humans and automation: as an attributed actor constrained by transitions and guards.

What AI can do

  • inspect loop state in your application layer
  • recommend transitions with evidence
  • execute transitions where allowedActors includes ai-agent

What AI cannot do

  • bypass allowedActors
  • bypass hard guards
  • modify loop definitions at runtime
  • execute indefinitely if circuit-breaker constraints block it

AIAgentActor shape

1interface AIAgentActor extends ActorRef {
2 type: "ai-agent"
3 agentId: string
4 gatewaySessionId: string
5 recommendedBy?: string
6}

AI submission flow

1import { actorId, transitionId } from '@loop-engine/core'
2import { canActorExecuteTransition, buildActorEvidence, type AIAgentActor } from '@loop-engine/actors'
3 
4const agent: AIAgentActor = {
5 type: 'ai-agent',
6 id: actorId('agent:demand-forecaster'),
7 agentId: 'claude-3-5-sonnet',
8 gatewaySessionId: session.id
9}
10 
11const auth = canActorExecuteTransition(agent, transition)
12if (auth.authorized) {
13 const evidence = buildActorEvidence(agent, {
14 ai_confidence: 0.94,
15 ai_reasoning: 'Stock level below reorder point; lead time elevated',
16 recommended_qty: 500
17 })
18 
19 await engine.transition({
20 aggregateId,
21 transitionId: transitionId('trigger_po'),
22 actor: { type: agent.type, id: String(agent.id) },
23 evidence
24 })
25}