Examples¶
Complete working examples demonstrating RobotLab features.
Overview¶
These examples show how to use RobotLab for common scenarios, from simple chatbots to complex multi-robot systems.
Examples¶
| Example | Description |
|---|---|
| Basic Chat | Simple conversational robot |
| Multi-Robot Network | Customer service with routing |
| Tool Usage | External API integration |
| MCP Server | Creating an MCP tool server |
| Rails Application | Full Rails integration |
Quick Links¶
Simple Examples¶
Advanced Examples¶
Hello World¶
require "robot_lab"
RobotLab.configure do |config|
config.default_model = "claude-sonnet-4"
end
robot = RobotLab.build do
name "greeter"
template "You are a friendly greeter. Say hello warmly."
end
state = RobotLab.create_state(message: "Hi there!")
result = robot.run(state: state)
puts result.output.first.content
Robot with Tools¶
robot = RobotLab.build do
name "calculator"
template "You help with calculations."
tool :calculate do
description "Perform a calculation"
parameter :expression, type: :string, required: true
handler { |expression:, **_| eval(expression).to_s }
end
end
state = RobotLab.create_state(message: "What's 25 * 4?")
result = robot.run(state: state)
Network with Routing¶
classifier = RobotLab.build do
name "classifier"
template "Classify: BILLING, TECHNICAL, or GENERAL"
end
billing = RobotLab.build do
name "billing"
template "You handle billing questions."
end
tech = RobotLab.build do
name "tech"
template "You handle technical issues."
end
network = RobotLab.create_network do
name "support"
add_robot classifier
add_robot billing
add_robot tech
router ->(args) {
case args.call_count
when 0 then :classifier
when 1
category = args.last_result&.output&.first&.content&.strip
category == "BILLING" ? :billing : :tech
end
}
end
result = network.run(state: state)
Running Examples¶
-
Install dependencies:
-
Set API key:
-
Run example: