Class: AnalyticalBrain::Tools::ReadWorkflow

Inherits:
Tools::Base
  • Object
show all
Defined in:
lib/analytical_brain/tools/read_workflow.rb

Overview

Reads and activates a workflow on the main session. Returns the full workflow content so the brain can create goals from it. Also sets the workflow as active on the session, injecting its content into the main agent’s “Your Expertise” section.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tools::Base

schema

Constructor Details

#initialize(main_session:) ⇒ ReadWorkflow

Returns a new instance of ReadWorkflow.

Parameters:

  • main_session (Session)

    the session to activate the workflow on



29
30
31
# File 'lib/analytical_brain/tools/read_workflow.rb', line 29

def initialize(main_session:, **)
  @main_session = main_session
end

Class Method Details

.descriptionObject



12
13
# File 'lib/analytical_brain/tools/read_workflow.rb', line 12

def self.description = "Read a workflow's full content and activate it on the session. " \
"Use the content to create appropriate goals with set_goal."

.input_schemaObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/analytical_brain/tools/read_workflow.rb', line 15

def self.input_schema
  {
    type: "object",
    properties: {
      name: {
        type: "string",
        description: "Name of the workflow to read (from the available workflows list)"
      }
    },
    required: %w[name]
  }
end

.tool_nameObject



10
# File 'lib/analytical_brain/tools/read_workflow.rb', line 10

def self.tool_name = "read_workflow"

Instance Method Details

#execute(input) ⇒ String, Hash

Parameters:

  • input (Hash<String, Object>)

    with “name” key

Returns:

  • (String)

    workflow name, description, and full content

  • (Hash)

    with :error key on validation failure



36
37
38
39
40
41
42
43
44
# File 'lib/analytical_brain/tools/read_workflow.rb', line 36

def execute(input)
  workflow_name = input["name"].to_s.strip
  return {error: "Workflow name cannot be blank"} if workflow_name.empty?

  workflow = @main_session.activate_workflow(workflow_name)
  format_workflow(workflow)
rescue Workflows::InvalidDefinitionError => error
  {error: error.message}
end