foobara-agent 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ module Foobara
2
+ class Agent
3
+ class ListCommands < Foobara::Command
4
+ inputs do
5
+ command_connector :duck, :required, "Connector to end"
6
+ end
7
+
8
+ result do
9
+ user_provided_commands [:string], :required,
10
+ "List of commands the user would like you to choose from to accomplish the goal"
11
+ agent_specific_commands [:string], :required,
12
+ "Commands available to all agents to introspect or end the session"
13
+ end
14
+
15
+ def execute
16
+ construct_command_lists
17
+
18
+ command_lists
19
+ end
20
+
21
+ attr_accessor :command_lists
22
+
23
+ def construct_command_lists
24
+ user_provided_commands = []
25
+ agent_specific_commands = []
26
+
27
+ command_connector.all_transformed_command_classes.each do |command_class|
28
+ if command_class.domain == Foobara::Agent
29
+ agent_specific_commands
30
+ else
31
+ user_provided_commands
32
+ end << command_class.full_command_name
33
+ end
34
+
35
+ self.command_lists = { user_provided_commands:, agent_specific_commands: }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ module Foobara
2
+ class Agent
3
+ class ListTypes < Foobara::Command
4
+ inputs do
5
+ command_connector :duck, :required, "Connector to fetch types from"
6
+ end
7
+
8
+ result [:string]
9
+
10
+ def execute
11
+ construct_type_list
12
+
13
+ type_list
14
+ end
15
+
16
+ attr_accessor :type_list
17
+
18
+ def construct_type_list
19
+ self.type_list = command_connector.all_exposed_type_names
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Foobara
2
+ class Agent
3
+ class CommandLogEntry < Foobara::Model
4
+ attributes do
5
+ command_name :string, :required, "Name of the command that was run"
6
+ inputs :duck, :required, "Inputs to the command" # TODO: Allow :attributes to be used as a type succesfully
7
+ outcome :required do
8
+ success :boolean, :required, "Whether the command succeeded or not"
9
+ result :duck, :allow_nil, "Result of the command"
10
+ # TODO: create a type for error hash structure
11
+ errors_hash :duck, :allow_nil, "Errors that occurred during the command"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Foobara
2
+ class Agent
3
+ class Context < Foobara::Model
4
+ attributes do
5
+ # TODO: why doesn't this default of [] work as expected on newly created models?
6
+ command_log [CommandLogEntry], default: [],
7
+ description: "Log of all commands run so far and their outcomes"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ require "io/wait"
2
+
3
+ module Foobara
4
+ class Agent
5
+ attr_accessor :context, :agent_command_connector, :agent_name, :llm_model
6
+
7
+ def initialize(
8
+ context: nil,
9
+ agent_name: nil,
10
+ command_classes: nil,
11
+ agent_command_connector: nil,
12
+ llm_model: nil
13
+ )
14
+ # TODO: shouldn't have to pass command_log here since it has a default, debug that
15
+ self.context = context
16
+ self.agent_command_connector = agent_command_connector
17
+ self.agent_name = agent_name if agent_name
18
+ self.llm_model = llm_model
19
+
20
+ build_initial_context
21
+ build_agent_command_connector
22
+
23
+ command_classes&.each do |command_class|
24
+ self.agent_command_connector.connect(command_class)
25
+ end
26
+ end
27
+
28
+ def accomplish_goal(goal, result_type: nil)
29
+ inputs = {
30
+ goal:,
31
+ final_result_type: result_type,
32
+ current_context: context,
33
+ existing_command_connector: agent_command_connector,
34
+ agent_name:
35
+ }
36
+
37
+ if llm_model
38
+ inputs[:llm_model] = llm_model
39
+ end
40
+
41
+ AccomplishGoal.run(inputs)
42
+ end
43
+
44
+ def build_initial_context
45
+ # TODO: shouldn't have to pass command_log here since it has a default, debug that
46
+ self.context ||= Context.new(command_log: [])
47
+ end
48
+
49
+ def build_agent_command_connector
50
+ self.agent_command_connector ||= Connector.new(
51
+ accomplish_goal_command: self,
52
+ llm_model:,
53
+ default_serializers: [
54
+ Foobara::CommandConnectors::Serializers::ErrorsSerializer,
55
+ Foobara::CommandConnectors::Serializers::AtomicSerializer,
56
+ Foobara::CommandConnectors::Serializers::JsonSerializer
57
+ ]
58
+ )
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foobara-agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Miles Georgi
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: foobara
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.0.126
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.126
26
+ - !ruby/object:Gem::Dependency
27
+ name: foobara-llm-backed-command
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.0.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.1
40
+ email:
41
+ - azimux@gmail.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - CHANGELOG.md
47
+ - LICENSE-MPL-2.0.txt
48
+ - LICENSE.txt
49
+ - README.md
50
+ - lib/foobara/agent.rb
51
+ - src/foobara/agent.rb
52
+ - src/foobara/agent/accomplish_goal.rb
53
+ - src/foobara/agent/connector/connector.rb
54
+ - src/foobara/agent/connector/set_command_connector_inputs_transformer.rb
55
+ - src/foobara/agent/describe_command.rb
56
+ - src/foobara/agent/describe_type.rb
57
+ - src/foobara/agent/determine_inputs_for_next_command.rb
58
+ - src/foobara/agent/determine_next_command.rb
59
+ - src/foobara/agent/end_session_because_goal_has_been_accomplished.rb
60
+ - src/foobara/agent/give_up.rb
61
+ - src/foobara/agent/list_commands.rb
62
+ - src/foobara/agent/list_types.rb
63
+ - src/foobara/agent/types/command_log_entry.rb
64
+ - src/foobara/agent/types/context.rb
65
+ homepage: https://github.com/foobara/agent
66
+ licenses:
67
+ - MPL-2.0
68
+ metadata:
69
+ homepage_uri: https://github.com/foobara/agent
70
+ source_code_uri: https://github.com/foobara/agent
71
+ changelog_uri: https://github.com/foobara/agent/blob/main/CHANGELOG.md
72
+ rubygems_mfa_required: 'true'
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.4.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.6.7
88
+ specification_version: 4
89
+ summary: An agent that uses whatever Foobara commands you wish to accomplish goals
90
+ of your choosing!
91
+ test_files: []