Cookbook 02: Give it a goal
Give Pine Computer a train-fare research task, follow its progress and read the result. This recorded Ruby example stops before booking.
By The Pine Computer team · Updated
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.
The Ruby below is an excerpt from the October recording, not a current integration recipe. SDK setup and application helpers are omitted. Use the current agent API and file handling docs when building an integration.
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.