Class: SmartAgent::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_agent/agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, tools: nil, mcp_servers: nil) ⇒ Agent

Returns a new instance of Agent.



5
6
7
8
9
10
11
# File 'lib/smart_agent/agent.rb', line 5

def initialize(name, tools: nil, mcp_servers: nil)
  SmartAgent.logger.info "Create agent's name is #{name}"
  @name = name
  @tools = tools
  @servers = mcp_servers
  @code = self.class.agents[name]
end

Instance Attribute Details

#serversObject

Returns the value of attribute servers.



3
4
5
# File 'lib/smart_agent/agent.rb', line 3

def servers
  @servers
end

#toolsObject

Returns the value of attribute tools.



3
4
5
# File 'lib/smart_agent/agent.rb', line 3

def tools
  @tools
end

Class Method Details

.agentsObject



53
54
55
# File 'lib/smart_agent/agent.rb', line 53

def agents
  @agents ||= {}
end

.define(name, &block) ⇒ Object



57
58
59
# File 'lib/smart_agent/agent.rb', line 57

def define(name, &block)
  agents[name] = block
end

Instance Method Details

#on_content(&block) ⇒ Object



17
18
19
# File 'lib/smart_agent/agent.rb', line 17

def on_content(&block)
  @content_event_proc = block
end

#on_eventObject



25
26
27
28
29
30
31
# File 'lib/smart_agent/agent.rb', line 25

def on_event
  if @reasoning_event_proc || @content_event_proc
    return true
  else
    return false
  end
end

#on_reasoning(&block) ⇒ Object



13
14
15
# File 'lib/smart_agent/agent.rb', line 13

def on_reasoning(&block)
  @reasoning_event_proc = block
end

#on_tool_call(&block) ⇒ Object



21
22
23
# File 'lib/smart_agent/agent.rb', line 21

def on_tool_call(&block)
  @tool_call_proc = block
end

#please(prompt) ⇒ Object



46
47
48
49
50
# File 'lib/smart_agent/agent.rb', line 46

def please(prompt)
  context = AgentContext.new(self)
  context.params[:text] = prompt
  return context.instance_eval(&@code)
end

#processor(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/smart_agent/agent.rb', line 33

def processor(name)
  case name
  when :reasoning
    return @reasoning_event_proc
  when :content
    return @content_event_proc
  when :tool
    return @tool_call_proc
  else
    return nil
  end
end