foobara-agent-cli 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +46 -7
- data/src/foobara/agent.rb +1 -44
- data/src/foobara/cli_runner.rb +59 -0
- data/src/foobara/util.rb +56 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c3d2e1a47200eb3a55ed6b80634f30dbaf04c7f5b9e0927098bf3866f9d841
|
4
|
+
data.tar.gz: 467d2fe2e191095ae57685faf1ea3bf5cd0edd39412d2731ee8876bac991f89f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80609b7d266e727fb9ce1b70e267bae1c14d423ab6ffb898db5704f5e401457458ef829bc554c286b4d867583c15b59a9ded0caee96b10e46c80e7dfc01740ed
|
7
|
+
data.tar.gz: 6fea8df456f11fbbdc48c4d45c695c0a671a5460165a9bbc9149c6f4a4e364c4c1984ff09a640bb9ae77193414c3936d605dd06b6cb9a29f370954958c8de24d
|
data/README.md
CHANGED
@@ -3,6 +3,15 @@
|
|
3
3
|
Allows you to run a Foobara::Agent in a loop giving it new goals to accomplish in a REPL-style
|
4
4
|
CLI experience. Currently works with Ollama, OpenAI, or Anthropic.
|
5
5
|
|
6
|
+
## WARNING!!
|
7
|
+
|
8
|
+
This is experimental at the moment! It will not ask you permission before running commands. So do
|
9
|
+
not connect any commands to it that you don't want the risk of it being called when or in a manner
|
10
|
+
that is should not be.
|
11
|
+
|
12
|
+
If you would like to add that safety feature that would be awesome/fun! A good idea to let me know in advance
|
13
|
+
so I can help or coordinate.
|
14
|
+
|
6
15
|
## Contributing
|
7
16
|
|
8
17
|
I would love help with this and other Foobara gems! Feel free to hit me up at miles@foobara.com if you
|
@@ -74,34 +83,64 @@ Let's run this program on the commandline and ask our agent to find and fix the
|
|
74
83
|
|
75
84
|
```
|
76
85
|
$ example_scripts/capybaras-agent
|
77
|
-
> There is a capybara with a bad year of birth. Can you find and fix the bad record? Thanks!
|
78
86
|
|
79
|
-
|
87
|
+
Welcome to the Foobara Agent CLI! Type your goal and press enter to get started.
|
80
88
|
|
81
|
-
>
|
89
|
+
> There is a capybara with a bad year of birth. Can you find and fix the bad record? Thanks!
|
82
90
|
|
83
|
-
I
|
91
|
+
I found and fixed the Capybara record with the bad year of birth. Barbara's year of birth was
|
92
|
+
incorrectly listed as 19, which is unlikely for a capybara. I've updated it to 2019, which is
|
93
|
+
a more reasonable birth year.
|
84
94
|
|
85
95
|
>
|
86
96
|
```
|
87
97
|
|
88
98
|
We can check with FindAllCapybaras that it actually fixed the record!
|
89
99
|
|
100
|
+
```
|
101
|
+
$ ./capybaras-cli FindAllCapybaras
|
102
|
+
{
|
103
|
+
name: "Fumiko",
|
104
|
+
year_of_birth: 2020,
|
105
|
+
id: 19
|
106
|
+
},
|
107
|
+
{
|
108
|
+
name: "Barbara",
|
109
|
+
year_of_birth: 2019,
|
110
|
+
id: 20
|
111
|
+
},
|
112
|
+
{
|
113
|
+
name: "Basil",
|
114
|
+
year_of_birth: 2021,
|
115
|
+
id: 21
|
116
|
+
}
|
117
|
+
```
|
118
|
+
|
119
|
+
We can see that she was now born 2000 years later than before!
|
120
|
+
|
90
121
|
Let's tell our agent to set it back (in the same session):
|
91
122
|
|
92
123
|
```
|
93
|
-
$ example_scripts/capybaras-agent
|
124
|
+
$ example_scripts/capybaras-agent
|
125
|
+
|
126
|
+
Welcome to the Foobara Agent CLI! Type your goal and press enter to get started.
|
127
|
+
|
94
128
|
> There is a capybara with a bad year of birth. Can you find and fix the bad record? Thanks!
|
95
129
|
|
96
|
-
I found and fixed the Capybara record with the bad year of birth. Barbara's year of birth was
|
130
|
+
I found and fixed the Capybara record with the bad year of birth. Barbara's year of birth was
|
131
|
+
incorrectly listed as 19, which is unlikely for a capybara. I've updated it to 2019, which is
|
132
|
+
a more reasonable birth year.
|
97
133
|
|
98
134
|
> Thank you so much! Can you set it back so that I can do the demo over again? Thanks!
|
99
135
|
|
100
|
-
I've reset Barbara's year of birth back to 19, so you can run the demo again. The system is
|
136
|
+
I've reset Barbara's year of birth back to 19, so you can run the demo again. The system is
|
137
|
+
now ready for you to demonstrate the capybara data correction process.
|
101
138
|
|
102
139
|
>
|
103
140
|
```
|
104
141
|
|
142
|
+
And we can check that it's back to where it was as before and it's 19 again instead of 2019!
|
143
|
+
|
105
144
|
Please see example_scripts/capybaras-agent for a working script that contains this code
|
106
145
|
|
107
146
|
## License
|
data/src/foobara/agent.rb
CHANGED
@@ -3,50 +3,7 @@ require "io/wait"
|
|
3
3
|
module Foobara
|
4
4
|
class Agent
|
5
5
|
def run_cli(io_in: $stdin, io_out: $stdout, io_err: $stderr)
|
6
|
-
|
7
|
-
io_out.flush
|
8
|
-
|
9
|
-
loop do
|
10
|
-
input_is_available = io_in.wait_readable(1)
|
11
|
-
|
12
|
-
if input_is_available
|
13
|
-
line = io_in.gets
|
14
|
-
if line.nil?
|
15
|
-
break
|
16
|
-
end
|
17
|
-
|
18
|
-
goal = line.chomp
|
19
|
-
|
20
|
-
begin
|
21
|
-
outcome = accomplish_goal(goal)
|
22
|
-
|
23
|
-
if outcome.success?
|
24
|
-
result = outcome.result
|
25
|
-
io_out.puts
|
26
|
-
io_out.puts result[:message_to_user]
|
27
|
-
io_out.puts
|
28
|
-
io_out.flush
|
29
|
-
else
|
30
|
-
# :nocov:
|
31
|
-
io_out.puts
|
32
|
-
io_err.puts outcome.errors_hash
|
33
|
-
io_err.puts
|
34
|
-
io_err.flush
|
35
|
-
# :nocov:
|
36
|
-
end
|
37
|
-
|
38
|
-
io_out.write "> "
|
39
|
-
io_out.flush
|
40
|
-
rescue => e
|
41
|
-
# :nocov:
|
42
|
-
io_out.puts e.message
|
43
|
-
io_err.puts e.message
|
44
|
-
io_err.puts e.backtrace
|
45
|
-
io_err.flush
|
46
|
-
# :nocov:
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
6
|
+
CliRunner.new(self, io_in:, io_out:, io_err:).run
|
50
7
|
end
|
51
8
|
end
|
52
9
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Foobara
|
2
|
+
class Agent
|
3
|
+
class CliRunner
|
4
|
+
attr_accessor :io_in, :io_out, :io_err, :agent
|
5
|
+
|
6
|
+
def initialize(agent, io_in: $stdin, io_out: $stdout, io_err: $stderr)
|
7
|
+
self.agent = agent
|
8
|
+
self.io_in = io_in
|
9
|
+
self.io_out = io_out
|
10
|
+
self.io_err = io_err
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
Util.pipe_write_with_flush(
|
15
|
+
io_out,
|
16
|
+
"\nWelcome to the Foobara Agent CLI! Type your goal and press enter to get started.\n\n> "
|
17
|
+
)
|
18
|
+
|
19
|
+
loop do
|
20
|
+
ready = Util.pipe_wait_readable(io_in, 1)
|
21
|
+
|
22
|
+
break if agent.killed?
|
23
|
+
break if io_in.closed?
|
24
|
+
|
25
|
+
next unless ready
|
26
|
+
|
27
|
+
line = Util.pipe_readline(io_in)
|
28
|
+
|
29
|
+
break if line.nil? || io_in.closed? || agent.killed?
|
30
|
+
|
31
|
+
goal = line.strip
|
32
|
+
|
33
|
+
break if goal =~ /\A(exit|quit|bye)\z/i
|
34
|
+
next if goal.empty?
|
35
|
+
|
36
|
+
begin
|
37
|
+
outcome = agent.accomplish_goal(goal)
|
38
|
+
|
39
|
+
if outcome.success?
|
40
|
+
result = outcome.result
|
41
|
+
Util.pipe_writeline(io_out, "\nAgent says: #{result[:message_to_user]}\n")
|
42
|
+
else
|
43
|
+
# :nocov:
|
44
|
+
Util.pipe_writeline(io_err, "\nError: #{outcome.errors_hash}\n")
|
45
|
+
# :nocov:
|
46
|
+
end
|
47
|
+
|
48
|
+
Util.pipe_write_with_flush(io_out, "\n> ")
|
49
|
+
rescue => e
|
50
|
+
# :nocov:
|
51
|
+
Util.pipe_writeline(io_err, e.message)
|
52
|
+
Util.pipe_writeline(io_err, e.backtrace)
|
53
|
+
# :nocov:
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/src/foobara/util.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Util
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def pipe_writeline(io, line = "")
|
6
|
+
pipe_io_operation(io) do
|
7
|
+
io.puts line
|
8
|
+
io.flush
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def pipe_write_with_flush(io, text = "")
|
13
|
+
pipe_io_operation(io) do
|
14
|
+
io.write text
|
15
|
+
io.flush
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def pipe_readline(io)
|
20
|
+
pipe_io_operation(io) do
|
21
|
+
io.readline.strip
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def pipe_wait_readable(io, timeout = nil)
|
26
|
+
pipe_io_operation(io) do
|
27
|
+
io.wait_readable(timeout)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def pipe_io_operation(_io)
|
32
|
+
yield
|
33
|
+
rescue EOFError
|
34
|
+
nil
|
35
|
+
rescue IOError => e
|
36
|
+
# :nocov:
|
37
|
+
message = e.message
|
38
|
+
|
39
|
+
if message.include?("closed") && message.include?("stream")
|
40
|
+
nil
|
41
|
+
else
|
42
|
+
raise
|
43
|
+
end
|
44
|
+
# :nocov:
|
45
|
+
end
|
46
|
+
|
47
|
+
def close(io)
|
48
|
+
io.close
|
49
|
+
nil
|
50
|
+
rescue IOError
|
51
|
+
# :nocov:
|
52
|
+
nil
|
53
|
+
# :nocov:
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara-agent-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
@@ -35,6 +35,8 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- lib/foobara/agent_cli.rb
|
37
37
|
- src/foobara/agent.rb
|
38
|
+
- src/foobara/cli_runner.rb
|
39
|
+
- src/foobara/util.rb
|
38
40
|
homepage: https://github.com/foobara/agent-cli
|
39
41
|
licenses:
|
40
42
|
- MPL-2.0
|