Class: Foobara::Agent::DetermineNextCommandNameAndInputs
- Inherits:
-
LlmBackedCommand
- Object
- Command
- LlmBackedCommand
- Foobara::Agent::DetermineNextCommandNameAndInputs
show all
- Defined in:
- foobara-agent-0.1.0/src/foobara/agent/determine_next_command_name_and_inputs.rb
Constant Summary
LlmBackedExecuteMethod::LLM_INTEGRATION_KEYS
Instance Attribute Summary
#answer, #assistant_serializer, #computed_assistant_association_depth, #computed_user_association_depth, #final_answer, #llm_instructions, #messages, #parsed_answer, #user_serializer
Class Method Summary
collapse
Instance Method Summary
collapse
#attempt_to_recover_from_bad_format, #construct_messages, #depth_to_serializer, #determine_assistant_association_depth, #determine_assistant_serializer, #determine_user_association_depth, #determine_user_serializer, #execute, #generate_answer, #parse_answer
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Class Method Details
.build_llm_instructions(assistant_association_depth, goal, previous_goals) ⇒ Object
19
20
21
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
|
# File 'src/foobara/agent/determine_next_command_name_and_inputs.rb', line 19
def build_llm_instructions(assistant_association_depth, goal, previous_goals)
instructions = "You are the implementation of a command called #{scoped_full_name}"
instructions += if description && !description.empty?
" which has the following description:\n\n#{description}\n\n"
else
". "
end
result_schema = result_json_schema(assistant_association_depth)
if previous_goals && !previous_goals.empty?
instructions += "You have previously accomplished the following goals:\n\n"
previous_goals.each.with_index do |(previous_goal, state), index|
instructions += "previous goal #{index + 1}: #{previous_goal}\n"
instructions += "status of goal #{index + 1}: #{state}\n\n"
end
end
instructions += "You are working towards accomplishing the following goal:\n\n#{goal}\n\n"
instructions += "Your response of which command to run next should match the following JSON schema:"
instructions += "\n\n#{result_schema}\n\n"
instructions += "You can get more details about the inputs and result schemas for a specific command by " \
"choosing the DescribeCommand command. " \
"You will reply with nothing more than the JSON you've generated so that the calling code " \
"can successfully parse your answer."
instructions
end
|
.llm_instructions(assistant_association_depth, goal, previous_goals = nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'src/foobara/agent/determine_next_command_name_and_inputs.rb', line 7
def llm_instructions(assistant_association_depth, goal, previous_goals = nil)
key = [assistant_association_depth, goal, previous_goals]
@llm_instructions_cache ||= {}
if @llm_instructions_cache.key?(key)
@llm_instructions_cache[key]
else
@llm_instructions_cache[key] = build_llm_instructions(assistant_association_depth, goal, previous_goals)
end
end
|
Instance Method Details
#association_depth ⇒ Object
#build_messages ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'src/foobara/agent/determine_next_command_name_and_inputs.rb', line 90
def build_messages
p = [
{
content: llm_instructions,
role: :system
}
]
context.command_log.each do |command_log_entry|
agent_entry = {
command: command_log_entry.command_name
}
inputs = command_log_entry.inputs
if inputs && !inputs.empty?
agent_entry[:inputs] = inputs
end
outcome_entry = command_log_entry.outcome
p << {
content: agent_entry,
role: :assistant
}
p << {
content: outcome_entry,
role: :user
}
end
p
end
|
#context ⇒ Object
136
137
138
|
# File 'src/foobara/agent/determine_next_command_name_and_inputs.rb', line 136
def context
agent.context
end
|
#determine_llm_instructions ⇒ Object
74
75
76
77
78
79
80
|
# File 'src/foobara/agent/determine_next_command_name_and_inputs.rb', line 74
def determine_llm_instructions
self.llm_instructions = self.class.llm_instructions(
computed_user_association_depth,
goal,
previous_goal_and_status_pairs
)
end
|
#goal ⇒ Object
124
125
126
|
# File 'src/foobara/agent/determine_next_command_name_and_inputs.rb', line 124
def goal
context.current_goal.text
end
|
#previous_goal_and_status_pairs ⇒ Object
128
129
130
131
132
133
134
|
# File 'src/foobara/agent/determine_next_command_name_and_inputs.rb', line 128
def previous_goal_and_status_pairs
if context.previous_goals && !context.previous_goals.empty?
context.previous_goals.map do |previous_goal|
[previous_goal.text, previous_goal.state]
end
end
end
|