Class: RubyLLM::Toolbox::Tools::TodoWrite
- Defined in:
- lib/ruby_llm/toolbox/tools/todo_write.rb
Overview
SAFE. Tracks a task list for multi-step work. Each call replaces the whole list (the standard agent pattern) and renders it back. State lives on the tool instance, so it persists across calls within a single chat session (when one instance is registered with the chat).
Constant Summary collapse
- STATUSES =
%w[pending in_progress completed].freeze
- MARKS =
{ "pending" => "[ ]", "in_progress" => "[~]", "completed" => "[x]" }.freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#call, exec_tool!, exec_tool?, #initialize, #name
Constructor Details
This class inherits a constructor from RubyLLM::Toolbox::Base
Instance Method Details
#execute(todos:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_llm/toolbox/tools/todo_write.rb', line 25 def execute(todos:) return error("todos must be an array", code: :bad_todos) unless todos.is_a?(Array) normalized = todos.map { |todo| normalize(todo) } invalid = normalized.find { |todo| !STATUSES.include?(todo[:status]) } return error("invalid status: #{invalid[:status].inspect} (use #{STATUSES.join(', ')})", code: :bad_status) if invalid @todos = normalized render end |