Class: LittleGhost::Tools::WriteTodos

Inherits:
LittleGhost::Tool show all
Defined in:
lib/little_ghost/tools/write_todos.rb

Overview

WriteTodos lets an agent share a live plan with the application and the person following its work. Add it like any other tool:

class ResearchAgent < LittleGhost::Agent
tools LittleGhost::Tools::WriteTodos
end

Each execution replaces the full plan in RunContext state. Todo IDs remain stable across updates, statuses are pending, in_progress, or completed, and no more than one todo may be in progress. When no context is available, the tool retains fallback state on its instance.

Instance Attribute Summary

Attributes inherited from LittleGhost::Tool

#context

Instance Method Summary collapse

Methods inherited from LittleGhost::Tool

#agent, define, description, #description, exclusive, #exclusive?, #initialize, input_schema, #input_schema, #model, #run, #runtime, #sandbox, specification, #specification, tool_name, #tool_name, #workspace

Methods included from Support::ClassAttributes

#class_attribute, included

Constructor Details

This class inherits a constructor from LittleGhost::Tool

Instance Method Details

#call(input) ⇒ Object

Replaces the stored plan after enforcing progress and ID invariants.

Raises:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/little_ghost/tools/write_todos.rb', line 55

def call(input)
  todos = input.fetch("todos")
  raise ToolError, "only one todo may be in progress" if todos.count { |todo| todo["status"] == "in_progress" } > 1

  ids = todos.map { |todo| todo.fetch("id") }
  raise ToolError, "todo IDs must be unique" unless ids.uniq.length == ids.length

  state = context ? (context.state["little_ghost.plan"] ||= empty_plan) : (@fallback_state ||= empty_plan)
  state.replace("plan_title" => input.fetch("plan_title"), "todos" => todos.map(&:dup))
  state.dup
end

#execute(input, context: nil) ⇒ Object

Trims user-facing titles before normal tool validation and execution.



50
51
52
# File 'lib/little_ghost/tools/write_todos.rb', line 50

def execute(input, context: nil)
  super(normalize_titles(input), context:)
end