Module: XAeonAgents::AgentDefaults

Overview

Mixin setting up default settings for agents. This mixin is meant to be the last prepended mixin in all Agent classes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object

Hook called when this mixin is prepended in a class

Parameters:

  • base (Class)

    The base class prepending this mixin



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
57
58
# File 'lib/x_aeon_agents/agent_defaults.rb', line 27

def self.prepended(base)
  base.prepend ComposableAgents::Mixins::ArtifactContract unless base.ancestors.include?(ComposableAgents::Mixins::ArtifactContract)
  base.prepend ComposableAgents::Mixins::Resumable unless base.ancestors.include?(ComposableAgents::Mixins::Resumable)
  # Make sure we always prepend at the top our initializer that sets all defaults
  base.prepend(
    Module.new do
      # Constructor
      #
      # @param args [Array] Agent's constructor arguments
      # @param session_id [String, nil] Specific X-Aeon session id to be used, or nil if none
      # @param kwargs [Array] Agent's constructor kwargs
      def initialize(*args, session_id: nil, **kwargs)
        # If we inherit from some frameworks initialize them now.
        Config.setup_composable_agents
        case self
        when ComposableAgents::AiAgents::Agent
          Config.setup_ai_agents
        when ComposableAgents::Cline::Agent
          Config.setup_cline
        end
        @session_id = session_id || AgentDefaults.singleton_session_id
        @session_dir = "#{Config.data_dir}/sessions/#{@session_id}"
        super(
          *args,
          composable_agents_dir: "#{@session_dir}/composable_agents",
          run_id: "#{@session_id}-#{kwargs[:name] || self.class.name.split('::').last}",
          **kwargs
        )
      end
    end
  )
end

.singleton_session_idObject

Get the singleton session ID. If it is the first time it is invoked, use a default session ID.



8
9
10
# File 'lib/x_aeon_agents/agent_defaults.rb', line 8

def singleton_session_id
  @singleton_session_id ||= Time.now.utc.strftime('%Y-%m-%d-%H-%M-%S-%N')
end

Instance Method Details

#new_agent(agent_class, *args, **kwargs) ⇒ ComposableAgents::Agent

Instantiate a new agent. Transfer the same session to the new agent.

Parameters:

  • agent_class (Class)

    The agent class to be instantiated

  • args (Array)

    Constructor parameters

  • kwargs (Hash)

    Constructor kwargs

Returns:

  • (ComposableAgents::Agent)

    The new agent



20
21
22
# File 'lib/x_aeon_agents/agent_defaults.rb', line 20

def new_agent(agent_class, *args, **kwargs)
  agent_class.new(*args, session_id: @session_id, **kwargs)
end