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, truncation_threshold

Constructor Details

#initialize(main_session:) ⇒ ReadWorkflow

Returns a new instance of ReadWorkflow.

Parameters:

  • main_session (Session)

    the session to activate the workflow on



25
26
27
# File 'lib/analytical_brain/tools/read_workflow.rb', line 25

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

Class Method Details

.descriptionObject



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

def self.description = "Activate a workflow and return its content for goal planning."

.input_schemaObject



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

def self.input_schema
  {
    type: "object",
    properties: {
      workflow_name: {type: "string"}
    },
    required: %w[workflow_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 “workflow_name” key

Returns:

  • (String)

    workflow name, description, and full content

  • (Hash)

    with :error key on validation failure



32
33
34
35
36
37
38
39
40
# File 'lib/analytical_brain/tools/read_workflow.rb', line 32

def execute(input)
  workflow_name = input["workflow_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