act_as_agent 0.2.0 → 0.4.0
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/Gemfile.lock +3 -3
- data/lib/act_as_agent/errors/providers/anthropic/too_many_requests_error.rb +10 -0
- data/lib/act_as_agent/providers/anthropic.rb +8 -7
- data/lib/act_as_agent/tools/list_files.rb +1 -1
- data/lib/act_as_agent/tools/read_file.rb +45 -0
- data/lib/act_as_agent/tools/write_file.rb +72 -0
- data/tmp/.gitignore +23 -0
- metadata +8 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 44beb0803696e1d1a3952e52516c32d31a43e4bf362a7a442babe9c6fdd5009d
|
|
4
|
+
data.tar.gz: 29e103f42b606986355492513ee6c45d9267df75e7a7df76746d86736cd1ec60
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43d5f4ae93bf68b8ec5e3407b7033dca82efa19d9303cc141374d71aac20c49d96e1f581e4482905194ddd229087d112b7c7d1a8bd0c1c1db92db19989a94b3c
|
|
7
|
+
data.tar.gz: dea06b560a54e3139769d45d8d0b42fa3755e6521b6f8fe7581faad1c40bde07c05fe77b885ff1ac1e278df3772f698711f98699fe5039581d4bc96420fbc4d3
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
act_as_agent (0.
|
|
5
|
-
act_as_api_client (~> 1.3.
|
|
4
|
+
act_as_agent (0.4.0)
|
|
5
|
+
act_as_api_client (~> 1.3.2)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
act_as_api_client (1.3.
|
|
10
|
+
act_as_api_client (1.3.2)
|
|
11
11
|
event_stream_parser
|
|
12
12
|
addressable (2.8.7)
|
|
13
13
|
public_suffix (>= 2.0.2, < 7.0)
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
# https://docs.claude.com/en/docs/agents-and-tools/tool-use/overview#tool-use-examples
|
|
5
5
|
require "act_as_agent/api_clients/anthropic_api_client"
|
|
6
6
|
require "act_as_agent/errors/providers/anthropic/authentication_error"
|
|
7
|
+
require "act_as_agent/errors/providers/anthropic/too_many_requests_error"
|
|
7
8
|
|
|
8
9
|
module ActAsAgent
|
|
9
10
|
module Providers
|
|
@@ -34,25 +35,27 @@ module ActAsAgent
|
|
|
34
35
|
case response["error"]["type"]
|
|
35
36
|
when "authentication_error"
|
|
36
37
|
return ActAsAgent::Errors::Providers::AuthenticationError
|
|
38
|
+
when "rate_limit_error"
|
|
39
|
+
return ActAsAgent::Errors::Providers::TooManyRequestsError
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
return response if response["stop_reason"] == "end_turn"
|
|
41
44
|
|
|
42
|
-
response["content"].
|
|
43
|
-
next unless message["type"] == "tool_use"
|
|
45
|
+
tool_responses = response["content"].each_with_object([]) do |message, memo|
|
|
46
|
+
next memo unless message["type"] == "tool_use"
|
|
44
47
|
|
|
45
48
|
@tools.each do |tool|
|
|
46
49
|
next unless tool.name == message["name"]
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
memo << {
|
|
49
52
|
"role" => "assistant",
|
|
50
53
|
"content" => [
|
|
51
54
|
message
|
|
52
55
|
]
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
memo << {
|
|
56
59
|
role: "user",
|
|
57
60
|
content: [
|
|
58
61
|
{
|
|
@@ -66,8 +69,6 @@ module ActAsAgent
|
|
|
66
69
|
end
|
|
67
70
|
|
|
68
71
|
request(content: content + tool_responses) unless tool_responses.empty?
|
|
69
|
-
|
|
70
|
-
response["content"]
|
|
71
72
|
end
|
|
72
73
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
73
74
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "act_as_agent/errors/tool_incorrect_args_error"
|
|
4
|
+
|
|
5
|
+
module ActAsAgent
|
|
6
|
+
module Tools
|
|
7
|
+
class ReadFile
|
|
8
|
+
ERROR = ActAsAgent::Errors::ToolIncorrectArgsError
|
|
9
|
+
|
|
10
|
+
attr_reader :file_path
|
|
11
|
+
|
|
12
|
+
def initialize(file_path: nil)
|
|
13
|
+
@file_path = file_path
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def name
|
|
17
|
+
self.class.to_s.gsub("::", "__")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def description
|
|
21
|
+
"Read file by the given path"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def input_schema
|
|
25
|
+
{
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
file_path: { type: "string",
|
|
29
|
+
description: "File path to read" }
|
|
30
|
+
},
|
|
31
|
+
required: []
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def call(args = {})
|
|
36
|
+
path = args.fetch("file_path", nil)
|
|
37
|
+
|
|
38
|
+
return File.read(path) unless path.nil? || path.chomp == ""
|
|
39
|
+
return File.read(file_path) unless file_path.nil?
|
|
40
|
+
|
|
41
|
+
ERROR.new("Incorrect params have been given to list files tool")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "act_as_agent/errors/tool_incorrect_args_error"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
module ActAsAgent
|
|
7
|
+
module Tools
|
|
8
|
+
class WriteFile
|
|
9
|
+
ERROR = ActAsAgent::Errors::ToolIncorrectArgsError
|
|
10
|
+
|
|
11
|
+
attr_reader :file_path, :base_folder, :return_content
|
|
12
|
+
|
|
13
|
+
def initialize(file_path: nil, base_folder: nil, return_content: false)
|
|
14
|
+
@file_path = file_path
|
|
15
|
+
@base_folder = base_folder
|
|
16
|
+
@return_content = return_content
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def name
|
|
20
|
+
self.class.to_s.gsub("::", "__")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def description
|
|
24
|
+
"
|
|
25
|
+
It writes content into file. If file doesn't exist it will create a new one.
|
|
26
|
+
It accepts two parameters file_path and file_content.
|
|
27
|
+
But file_path is optional as by default it will write into the file
|
|
28
|
+
user want it to be saved.
|
|
29
|
+
"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def input_schema
|
|
33
|
+
{
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
file_path: { type: "string",
|
|
37
|
+
description: "File path to write" },
|
|
38
|
+
file_content: { type: "string", description: "File content" }
|
|
39
|
+
},
|
|
40
|
+
required: ["file_content"]
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def call(args = {})
|
|
45
|
+
path = args.fetch("file_path", "")
|
|
46
|
+
content = args.fetch("file_content", nil)
|
|
47
|
+
|
|
48
|
+
return write(base_folder, path, content) unless path.chomp == ""
|
|
49
|
+
return write(base_folder, file_path, content) unless file_path.nil?
|
|
50
|
+
return write(nil, base_folder, content) unless base_folder.nil?
|
|
51
|
+
|
|
52
|
+
ERROR.new("Incorrect params have been given to write file tool")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def write(base_folder, path, content)
|
|
58
|
+
path = File.join(base_folder, path) unless base_folder.nil? || base_folder.chomp == ""
|
|
59
|
+
path = File.expand_path(path)
|
|
60
|
+
|
|
61
|
+
dir_level = path.end_with?("/") ? 0 : 1
|
|
62
|
+
FileUtils.mkdir_p(File.dirname(path, dir_level))
|
|
63
|
+
|
|
64
|
+
return if File.directory?(path)
|
|
65
|
+
|
|
66
|
+
File.write(path, content)
|
|
67
|
+
|
|
68
|
+
File.read(path) if return_content
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/tmp/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
/.pnp
|
|
6
|
+
.pnp.js
|
|
7
|
+
|
|
8
|
+
# testing
|
|
9
|
+
/coverage
|
|
10
|
+
|
|
11
|
+
# production
|
|
12
|
+
/build
|
|
13
|
+
|
|
14
|
+
# misc
|
|
15
|
+
.DS_Store
|
|
16
|
+
.env.local
|
|
17
|
+
.env.development.local
|
|
18
|
+
.env.test.local
|
|
19
|
+
.env.production.local
|
|
20
|
+
|
|
21
|
+
npm-debug.log*
|
|
22
|
+
yarn-debug.log*
|
|
23
|
+
yarn-error.log*
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: act_as_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Max Rukomoynikov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: act_as_api_client
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.3.
|
|
19
|
+
version: 1.3.2
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.3.
|
|
26
|
+
version: 1.3.2
|
|
27
27
|
description: "\n Build and manage AI agents with ease using ActAsAgent. This gem
|
|
28
28
|
provides a robust framework for creating, configuring, and deploying intelligent
|
|
29
29
|
agents that can perform tasks autonomously. Whether you're looking to automate workflows,
|
|
@@ -50,10 +50,14 @@ files:
|
|
|
50
50
|
- lib/act_as_agent/api_clients/anthropic_api_client.rb
|
|
51
51
|
- lib/act_as_agent/base.rb
|
|
52
52
|
- lib/act_as_agent/errors/providers/anthropic/authentication_error.rb
|
|
53
|
+
- lib/act_as_agent/errors/providers/anthropic/too_many_requests_error.rb
|
|
53
54
|
- lib/act_as_agent/errors/tool_incorrect_args_error.rb
|
|
54
55
|
- lib/act_as_agent/providers/anthropic.rb
|
|
55
56
|
- lib/act_as_agent/tools/list_files.rb
|
|
57
|
+
- lib/act_as_agent/tools/read_file.rb
|
|
58
|
+
- lib/act_as_agent/tools/write_file.rb
|
|
56
59
|
- sig/act_as_agent.rbs
|
|
60
|
+
- tmp/.gitignore
|
|
57
61
|
homepage: https://github.com/Rukomoynikov/act_as_agent
|
|
58
62
|
licenses:
|
|
59
63
|
- MIT
|