agentic examples

The telephone game

The telephone game: a rumor passes through five villagers, each of whom hears the previous version through the orchestrator's dependency pipe and repeats it... imperfectly. No shared state, no scroll passed around - the framework itself carries the whisper.

Observability & Ops Round 3 Matz exit 0

source on github

bundle exec ruby examples/telephone_game.rb

a real captured run

the rumor: "Old Tom saw a cat chase two mice."

the miller     heard it as: Old Tom wrestled a cat chase two mice.
the baker      heard it as: Old Tom wrestled an enormous cat chase two mice.
the fisherman  heard it as: Old Tom wrestled an enormous cat chase two mice, down by the river
the innkeeper  heard it as: Old Tom wrestled an enormous cat chase twelve wolves, down by the river
the town crier heard it as: HEAR YE: OLD TOM WRESTLED AN ENORMOUS CAT CHASE TWELVE WOLVES, DOWN BY THE RIVER!!

(completed in 1ms - the whisper traveled through 5 villagers)

source

# frozen_string_literal: true

# The telephone game: a rumor passes through five villagers, each of
# whom hears the previous version through the orchestrator's dependency
# pipe and repeats it... imperfectly. No shared state, no scroll passed
# around - the framework itself carries the whisper.
#
#   bundle exec ruby examples/telephone_game.rb ["a rumor"]
#
# Runs offline. The bug is the feature.

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

QUIRKS = {
  class="s">"the miller" => ->(s) { s.sub(/\bsaw\b/, class="s">"wrestled") },
  class="s">"the baker" => ->(s) { s.sub(/\ba (\w+)/, 'an enormous \1') },
  class="s">"the fisherman" => ->(s) { class="s">"#{s.chomp(".class="s">")}, down by the river" },
  class="s">"the innkeeper" => ->(s) { s.gsub(/\btwo\b/i, class="s">"twelve").gsub(/\bmice\b/, class="s">"wolves") },
  class="s">"the town crier" => ->(s) { class="s">"HEAR YE: #{s.upcase}!!" }
}.freeze

rumor = ARGV.first || class="s">"Old Tom saw a cat chase two mice."

orchestrator = Agentic:class="y">:PlanOrchestrator.new
tasks = []
QUIRKS.each_key do |villager|
  task = Agentic:class="y">:Task.new(
    description: villager,
    agent_spec: {class="s">"name" => villager, class="s">"instructions" => class="s">"Repeat what you heard"},
    payload: rumor
  )
  orchestrator.add_task(task, tasks.empty? ? [] : [tasks.last], agent: ->(t) {
    heard = t.dependency_outputs.values.first || t.payload
    QUIRKS.fetch(t.description).call(heard)
  })
  tasks << task
end

result = orchestrator.execute_plan

puts class="s">"the rumor: \"#{rumor}\class="s">""
puts
tasks.each do |task|
  puts format(class="s">"%-14s heard it as: %s", task.description, result.results[task.id].output)
end
puts
puts class="s">"(#{result.status} in #{(result.execution_time * 1000).round}ms - " \
  class="s">"the whisper traveled through #{tasks.size} villagers)"