Class: SublayerAgentGenerator

Inherits:
Sublayer::Generators::Base show all
Defined in:
lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb

Instance Attribute Summary

Attributes inherited from Sublayer::Generators::Base

#results

Instance Method Summary collapse

Methods inherited from Sublayer::Generators::Base

llm_output_adapter

Constructor Details

#initialize(description:, trigger:, goal:, check_status:, step:) ⇒ SublayerAgentGenerator

Returns a new instance of SublayerAgentGenerator.



10
11
12
13
14
15
16
# File 'lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb', line 10

def initialize(description:, trigger:, goal:, check_status:, step:)
  @description = description
  @trigger_condition = trigger
  @goal = goal
  @check_status = check_status
  @step = step
end

Instance Method Details

#example_agentObject



58
59
60
# File 'lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb', line 58

def example_agent
  File.read(File.join(__dir__, "example_agent.rb"))
end

#generateObject



18
19
20
# File 'lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb', line 18

def generate
  super
end

#promptObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb', line 22

def prompt
  "  You are an expert ruby programmer and great at repurposing code examples to use for new situations.\n\n  A Sublayer agent is a DSL for defining a feedback loop for an AI agent. The agents sit running like a daemon and are triggered to run and step toward their goal checking status along the way.\n\n  One example of a Sublayer agent is this one for doing TDD with RSpec:\n  <example_tdd_agent>\n  \#{example_agent}\n  </example_tdd_agent>\n\n  Sublayer Agents take advantage of other Sublayer components to perform their tasks.\n  Sublayer::Actions are used to perform actions in the outside world, things like saving files, making external api calls, retrieving data, etc\n  Sublayer::Generators are used to make calls to LLMs based on information they receive from Sublayer::Actions or other sources and return structured data for other Sublayer::Actions to do use in the outside world\n\n  The Sublayer Agent DSL consists of 4 main parts:\n  1. trigger: What triggers the agent, currently built into the framework is the trigger_on_files_changed, but the trigger method also accepts a Sublayer::Triggers::Base subclass that defines an initialize method and a setup method that takes an agent as an argument\n              The setup method then calls activate(agent) when the trigger condition is met\n  2. goal: What the agent is trying to achieve, this is a block that returns a boolean\n  3. check_status: A method that checks the status of the agent on its way toward the goal. Usually you update the goal condition here or can perform any Sublayer::Actions to examine the state of the outside world\n  4. step: A method that encapsulates the way the agent should work toward the goal. Sublayer::Actions and Sublayer::Generators are used heavily here.\n\n  Your goal is to rely on the above information about how Sublayer Agents work to generate a new Sublayer agent based on the following information:\n\n  Agent description: \#{@description}\n  Trigger condition: \#{@trigger}\n  Goal condition: \#{@goal}\n  Status check method: \#{@check_status}\n  Step action method: \#{@step}\n\n  You can assume that any Sublayer::Actions or Sublayer::Generators you need are available to you in the Sublayer framework\n\n  Take a deep breath and think step by step before coding. You can do this!\n  PROMPT\nend\n"