6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/omni_agent/agent.rb', line 6
def method_added(method_name)
super
return if @_omni_agent_wrapping_method
return if method_name.to_s.start_with?("__omni_agent_original_")
return unless instance_methods(false).include?(method_name)
return if OmniAgent::Agent.instance_methods(false).include?(method_name)
original_method = instance_method(method_name)
return unless original_method.arity == 0
alias_name = "__omni_agent_original_#{method_name}".to_sym
return if instance_methods(false).include?(alias_name)
@_omni_agent_wrapping_method = true
alias_method alias_name, method_name
define_method(method_name) do |input = nil, context: {}, **context_keywords|
if input.nil? && context == {} && context_keywords.empty?
run_alias_entrypoint_logic(alias_name)
else
merged_context = context.is_a?(Hash) ? context.dup : {}
merged_context.merge!(context_keywords)
run_input = run_alias_entrypoint_logic(alias_name, fallback_input: input)
run(run_input, context: merged_context, prompt_method: method_name)
end
end
ensure
@_omni_agent_wrapping_method = false
end
|