Class: Luo::AgentRunnerBase
- Inherits:
-
Object
- Object
- Luo::AgentRunnerBase
show all
- Includes:
- Configurable
- Defined in:
- lib/luo/agent_runner_base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#config, included
Constructor Details
Returns a new instance of AgentRunnerBase.
12
13
14
15
|
# File 'lib/luo/agent_runner_base.rb', line 12
def initialize(histories: nil)
context.histories = histories unless histories.nil?
on_init
end
|
Class Method Details
.agents ⇒ Object
81
82
83
|
# File 'lib/luo/agent_runner_base.rb', line 81
def agents
@agents ||= {}
end
|
.disable_history ⇒ Object
105
106
107
108
109
|
# File 'lib/luo/agent_runner_base.rb', line 105
def disable_history
define_method(:save_history?) do
false
end
end
|
.language_info ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/luo/agent_runner_base.rb', line 95
def language_info
if self.config.language == "en"
""
elsif self.config.language == "zh"
"(must be a Chinese string)"
else
""
end
end
|
.register(agent) ⇒ Object
91
92
93
|
# File 'lib/luo/agent_runner_base.rb', line 91
def register(agent)
agents[agent.agent_name] = agent
end
|
Instance Method Details
#add_agent(agent) ⇒ Object
65
66
67
|
# File 'lib/luo/agent_runner_base.rb', line 65
def add_agent(agent)
context.have_running_agents << agent
end
|
#after_run ⇒ Object
55
56
|
# File 'lib/luo/agent_runner_base.rb', line 55
def after_run
end
|
#call(user_input) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/luo/agent_runner_base.rb', line 36
def call(user_input)
context.user_input = user_input
on_request
on_result
on_run
after_run
rt = Marshal.load(Marshal.dump(context))
reset_context
rt
end
|
#client ⇒ Object
20
21
22
23
|
# File 'lib/luo/agent_runner_base.rb', line 20
def client
raise Luo::ClientNotSetError, "client not set" if self.class.config.client.nil?
self.class.config.client
end
|
#context ⇒ Object
25
26
27
|
# File 'lib/luo/agent_runner_base.rb', line 25
def context
@context ||= config.context_adapter.call
end
|
#on_init ⇒ Object
17
18
|
# File 'lib/luo/agent_runner_base.rb', line 17
def on_init
end
|
#on_request ⇒ Object
47
48
49
|
# File 'lib/luo/agent_runner_base.rb', line 47
def on_request
raise NotImplementedError, "call method must be implemented in subclass"
end
|
#on_result ⇒ Object
51
52
53
|
# File 'lib/luo/agent_runner_base.rb', line 51
def on_result
raise NotImplementedError, "call method must be implemented in subclass"
end
|
#on_run ⇒ Object
58
59
60
61
62
63
|
# File 'lib/luo/agent_runner_base.rb', line 58
def on_run
context.have_running_agents.each do |agent|
context.agent_results << { agent_name: agent.class.agent_name, agent_response: agent.call }
end
context.have_running_agents.clear
end
|
#reset_context ⇒ Object
29
30
31
32
33
34
|
# File 'lib/luo/agent_runner_base.rb', line 29
def reset_context
histories = context.histories
@context = config.context_adapter.call
@context.histories = histories
@context
end
|
#save_history ⇒ Object
69
70
71
|
# File 'lib/luo/agent_runner_base.rb', line 69
def save_history
context.histories.save(context.user_input, context.final_result) if save_history?
end
|