Cookbook 02: Give it a goal
Hand the computer a goal in plain words, follow its notes while it works, and read its answer.
By The Pine Computer team
Instead of steering the browser one step at a time, the program hands the computer a goal and follows along: the cheapest day next week to take the train from London to Paris, for two adults.
It compared the days on the operator’s own site and answered with the day, the time and the price. It stopped before any passenger or payment details. The film shortens a run of about four and a half minutes.
computer = pine.create_computer
session = computer.create_session(browser: true)
session.agent.run("Find the cheapest day next week to take the train
from London to Paris for two adults. Tell me the day, time and price.")
session.agent.events do |e|
note = e.type == "step" && e.payload["phase"] == "commentary"
puts "· #{e.payload["text"]}" if note
break if e.terminal?
end
puts session.agent.result["summary"]
gets # press Enter to stop
computer.stopThe events say what it’s doing as it goes, and the result holds its answer. More in the docs.