Class: WritersRoom::Actor

Inherits:
RobotLab::Robot
  • Object
show all
Defined in:
lib/writers_room/actor.rb

Overview

AI-powered Actor that uses RobotLab's template system, tools, and bus messaging to participate in multi-character scenes.

Follows the RobotLab example 16 Writer pattern:

  • Uses template + context instead of inline heredoc prompts
  • Equipped with tools (SpeakTool, ReadMemoryTool, etc.)
  • Reacts to bus messages via on_message handler
  • Resets chat before each message (shared memory is persistence)

Constant Summary collapse

RECENT_DIALOG_LIMIT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(character_info:, scene_info:, bus:, shared_memory: nil, display: nil, room: nil, config: nil) ⇒ Actor

Initialize an Actor with character information.

Parameters:

  • character_info (Hash)

    Character details (from .md front matter)

  • scene_info (Hash)

    Scene details (from .md front matter)

  • bus (TypedBus::MessageBus)

    Shared message bus

  • shared_memory (RobotLab::Memory) (defaults to: nil)

    Shared scene memory

  • display (Display) (defaults to: nil)

    Terminal output formatter

  • room (Room) (defaults to: nil)

    Parent room container

  • config (RobotLab::RunConfig, nil) (defaults to: nil)

    Shared LLM configuration



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/writers_room/actor.rb', line 34

def initialize(character_info:, scene_info:, bus:, shared_memory: nil, display: nil, room: nil, config: nil)
  @character_info = character_info
  @character_name = character_info[:name] || character_info["name"]
  @scene_info = scene_info
  @shared_memory = shared_memory
  @display = display
  @room = room
  @messages_processed = 0

  validate_character_info!

  @actor_context = build_template_context

  super(
    name:        @character_name.downcase.gsub(/\s+/, "_"),
    template:    :actor_system,
    context:     @actor_context,
    bus:         bus,
    config:      config,
    local_tools: build_tools
  )

  setup_message_handler
  subscribe_to_scene
end

Instance Attribute Details

#character_infoObject (readonly)

Returns the value of attribute character_info.



20
21
22
# File 'lib/writers_room/actor.rb', line 20

def character_info
  @character_info
end

#character_nameObject (readonly)

Returns the value of attribute character_name.



20
21
22
# File 'lib/writers_room/actor.rb', line 20

def character_name
  @character_name
end

#displayObject

Returns the value of attribute display.



21
22
23
# File 'lib/writers_room/actor.rb', line 21

def display
  @display
end

#roomObject

Returns the value of attribute room.



21
22
23
# File 'lib/writers_room/actor.rb', line 21

def room
  @room
end

#scene_infoObject (readonly)

Returns the value of attribute scene_info.



20
21
22
# File 'lib/writers_room/actor.rb', line 20

def scene_info
  @scene_info
end

#shared_memoryObject

Returns the value of attribute shared_memory.



21
22
23
# File 'lib/writers_room/actor.rb', line 21

def shared_memory
  @shared_memory
end

Instance Method Details

#disconnectObject

Unsubscribe from the scene channel before disconnecting.



61
62
63
64
65
66
67
# File 'lib/writers_room/actor.rb', line 61

def disconnect
  if @bus && @scene_subscriber_id
    @bus.unsubscribe(:scene, @scene_subscriber_id)
    @scene_subscriber_id = nil
  end
  super
end