Module: DeepAgents::StandardTools

Defined in:
lib/deepagents/tools.rb

Overview

Standard tools that can be used by the agent

Class Method Summary collapse

Class Method Details

.file_system_tools(file_system) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/deepagents/tools.rb', line 102

def self.file_system_tools(file_system)
  [
    Tool.new("read_file", "Read a file from the file system", ["path"]) do |path|
      file_system.read(path)
    end,
    Tool.new("write_file", "Write content to a file in the file system", ["path", "content"]) do |path, content|
      file_system.write(path, content)
      "File written to #{path}"
    end,
    Tool.new("list_files", "List all files in the file system") do
      file_system.list
    end,
    Tool.new("delete_file", "Delete a file from the file system", ["path"]) do |path|
      file_system.delete(path)
      "File deleted: #{path}"
    end
  ]
end

.planning_toolObject



146
147
148
149
150
# File 'lib/deepagents/tools.rb', line 146

def self.planning_tool
  Tool.new("plan", "Create a plan for solving a task", ["task"]) do |task|
    "Plan for #{task}:\n1. Analyze the requirements\n2. Break down into subtasks\n3. Implement each subtask\n4. Test the solution\n5. Refine as needed"
  end
end

.todo_tools(state) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/deepagents/tools.rb', line 121

def self.todo_tools(state)
  [
    Tool.new("add_todo", "Add a new todo item", ["content"]) do |content|
      todo = Todo.new(content)
      state.todos << todo
      "Todo added: #{content}"
    end,
    Tool.new("list_todos", "List all todo items") do
      state.todos.map.with_index do |todo, index|
        "#{index + 1}. [#{todo.status}] #{todo.content}"
      end
    end,
    Tool.new("update_todo", "Update a todo item status", ["index", "status"]) do |index, status|
      index = index.to_i - 1
      if index < 0 || index >= state.todos.length
        raise ArgumentError, "Invalid todo index: #{index + 1}"
      end

      todo = state.todos[index]
      todo.status = status
      "Todo updated: #{todo.content} - #{status}"
    end
  ]
end