Commit d699e05
Changed files (2)
lib
elelem
lib/elelem/agent.rb
@@ -11,6 +11,7 @@ module Elelem
@toolbox = toolbox
@terminal = terminal || Terminal.new(commands: COMMANDS)
@history = history || [{ role: "system", content: system_prompt }]
+ @toolbox.add("task", task_tool)
end
def repl
@@ -69,6 +70,21 @@ module Elelem
end
end
+ def task_tool
+ {
+ desc: "Delegate subtask to focused agent (complex searches, multi-file analysis)",
+ params: { prompt: { type: "string" } },
+ required: ["prompt"],
+ fn: ->(a) {
+ sub = Agent.new(client, toolbox, terminal: terminal, history: [
+ { role: "system", content: "Research agent. Search, analyze, report. Be concise." }
+ ])
+ sub.turn(a["prompt"])
+ { result: sub.history.last[:content] }
+ }
+ }
+ end
+
def fetch_response(ctx)
content, tool_calls = "", []
client.fetch(history + ctx, toolbox.to_h) do |chunk|
lib/elelem/toolbox.rb
@@ -31,6 +31,10 @@ module Elelem
@tools = tools
end
+ def add(name, tool)
+ @tools[name] = tool
+ end
+
def header(name, args)
"\n+ #{name.to_s.then { _1.empty? ? "?" : _1 }}(#{args})"
end