agentic examples

The Exquisite Corpse

The Exquisite Corpse: three artists each draw one part of a creature without seeing the others' work; the assembler receives all three parts BY NAME and stacks them. The surrealists played this on folded paper; we play it on a dependency graph.

Plans & Graphs Round 4 Matz exit 0

source on github

bundle exec ruby examples/exquisite_corpse.rb

a real captured run

EXQUISITE CORPSE (seed 818)

       .---.
      ( @ @ )
       \_-_/
      /|___|\
     | (===) |
      \|___|/
       d   b
       |   |
      =$   $=

three artists, no peeking - the assembler read the parts by name:
  t.needs.head, t.needs.torso, t.needs.legs

source

# frozen_string_literal: true

# The Exquisite Corpse: three artists each draw one part of a creature
# without seeing the others' work; the assembler receives all three
# parts BY NAME and stacks them. The surrealists played this on folded
# paper; we play it on a dependency graph.
#
#   bundle exec ruby examples/exquisite_corpse.rb [seed]
#
# Runs offline. Every seed is a different creature.

require class="s">"bundler/setup"
require class="s">"agentic"

seed = (ARGV.first || rand(1000)).to_i
rng = Random.new(seed)

PARTS = {
  head: [
    [class="s">"   /\\_/\\   ", class="s">"  ( o.o )  ", class="s">"   > ^ <   "],
    [class="s">"   .---.   ", class="s">"  ( @ @ )  ", class="s">"   \\_-_/   "],
    [class="s">"   ,***,   ", class="s">"  { > < }  ", class="s">"   \"---\class="s">"   "]
  ],
  torso: [
    [class="s">"  /|___|\\  ", class="s">" | (===) | ", class="s">"  \\|___|/  "],
    [class="s">"  <#####>  ", class="s">"  |#####|  ", class="s">"  <#####>  "],
    [class="s">"   )~~~(   ", class="s">"  ( ~~~ )  ", class="s">"   )~~~(   "]
  ],
  legs: [
    [class="s">"   |   |   ", class="s">"   |   |   ", class="s">"  _|   |_  "],
    [class="s">"   d   b   ", class="s">"   |   |   ", class="s">"  =$   $=  "],
    [class="s">"   \\   /   ", class="s">"    \\ /    ", class="s">"   _/^\\_   "]
  ]
}.freeze

orchestrator = Agentic:class="y">:PlanOrchestrator.new(concurrency_limit: 3)

artists = PARTS.to_h do |part, options|
  task = Agentic:class="y">:Task.new(
    description: class="s">"draw the #{part}",
    agent_spec: {class="s">"name" => class="s">"Artist of the #{part}", class="s">"instructions" => class="s">"draw without peeking"},
    payload: options
  )
  orchestrator.add_task(task, agent: ->(t) { t.payload.sample(random: rng) })
  [part, task]
end

reveal = Agentic:class="y">:Task.new(
  description: class="s">"unfold the paper",
  agent_spec: {class="s">"name" => class="s">"Assembler", class="s">"instructions" => class="s">"stack the parts"}
)
orchestrator.add_task(reveal, needs: artists, agent: ->(t) {
  t.needs.head + t.needs.torso + t.needs.legs
})

result = orchestrator.execute_plan

puts class="s">"EXQUISITE CORPSE (seed #{seed})"
puts
result.results[reveal.id].output.each { |line| puts class="s">"    #{line}" }
puts
puts class="s">"three artists, no peeking - the assembler read the parts by name:"
puts class="s">"  t.needs.head, t.needs.torso, t.needs.legs"