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



63
64
65
# File 'lib/smart_agent/agent.rb', line 63

def agents
  @agents ||= {}
end

.define(name, &block) ⇒ Object



67
68
69
# File 'lib/smart_agent/agent.rb', line 67

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

Instance Method Details

#nameObject



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

def name
  @name
end

#on_content(&block) ⇒ Object



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

def on_content(&block)
  @content_event_proc = block
end

#on_eventObject



33
34
35
36
37
38
39
# File 'lib/smart_agent/agent.rb', line 33

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

#on_logging(&block) ⇒ Object



29
30
31
# File 'lib/smart_agent/agent.rb', line 29

def on_logging(&block)
  @log_proc = block
end

#on_reasoning(&block) ⇒ Object



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

def on_reasoning(&block)
  @reasoning_event_proc = block
end

#on_tool_call(&block) ⇒ Object



25
26
27
# File 'lib/smart_agent/agent.rb', line 25

def on_tool_call(&block)
  @tool_call_proc = block
end

#please(prompt) ⇒ Object



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

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

#processor(name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/smart_agent/agent.rb', line 41

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