Module: Rubyagents
- Defined in:
- lib/rubyagents.rb,
lib/rubyagents/ui.rb,
lib/rubyagents/cli.rb,
lib/rubyagents/mcp.rb,
lib/rubyagents/tool.rb,
lib/rubyagents/agent.rb,
lib/rubyagents/model.rb,
lib/rubyagents/errors.rb,
lib/rubyagents/memory.rb,
lib/rubyagents/prompt.rb,
lib/rubyagents/sandbox.rb,
lib/rubyagents/version.rb,
lib/rubyagents/callback.rb,
lib/rubyagents/code_agent.rb,
lib/rubyagents/tools/file_read.rb,
lib/rubyagents/tools/list_gems.rb,
lib/rubyagents/tools/file_write.rb,
lib/rubyagents/tools/user_input.rb,
lib/rubyagents/tools/web_search.rb,
lib/rubyagents/tool_calling_agent.rb,
lib/rubyagents/tools/visit_webpage.rb,
lib/rubyagents/models/ruby_llm_adapter.rb
Defined Under Namespace
Modules: MCP, Models, Prompt, UI Classes: ActionStep, Agent, AgentError, CLI, Callback, ChatMessage, CodeAgent, Error, ExecutionError, FileRead, FileWrite, FinalAnswerException, FinalAnswerTool, GenerationError, InterruptError, ListGems, ManagedAgentTool, MaxStepsError, Memory, Model, ParsingError, PlanningStep, PromptTemplates, RunResult, Sandbox, TokenUsage, Tool, ToolCall, ToolCallFunction, ToolCallingAgent, UserInput, UserMessage, VisitWebpage, WebSearch
Constant Summary collapse
- VERSION =
"0.2.1"
Class Method Summary collapse
-
.tool(tool_name, desc, output: :string, **inputs, &block) ⇒ Object
Block-based tool shorthand Usage: greet = Rubyagents.tool(:greet, "Greets a person", name: "The person's name") { |name:| "Hello, #name!" }.
- .tool_from_mcp(command:, tool_name:) ⇒ Object
- .tools_from_mcp(command:) ⇒ Object
Class Method Details
.tool(tool_name, desc, output: :string, **inputs, &block) ⇒ Object
Block-based tool shorthand Usage:
greet = Rubyagents.tool(:greet, "Greets a person", name: "The person's name") { |name:| "Hello, #{name}!" }
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rubyagents/tool.rb', line 103 def self.tool(tool_name, desc, output: :string, **inputs, &block) klass = Class.new(Tool) do self.tool_name(tool_name.to_s) self.description(desc) inputs.each do |param_name, param_desc| type, description = if param_desc.is_a?(Hash) [param_desc[:type] || :string, param_desc[:description] || param_desc.to_s] else [:string, param_desc.to_s] end input param_name, type: type, description: description end self.output_type(output) define_method(:call, &block) end klass.new end |
.tool_from_mcp(command:, tool_name:) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/rubyagents/mcp.rb', line 115 def self.tool_from_mcp(command:, tool_name:) transport = MCP::StdioTransport.new(command: command) response = transport.send_request(request: { method: "tools/list", params: {} }) tools = response.dig("result", "tools") || [] tool_def = tools.find { |t| t["name"] == tool_name } unless tool_def available = tools.map { |t| t["name"] }.join(", ") raise ArgumentError, "Tool #{tool_name.inspect} not found. Available: #{available}" end MCP::MCPToolWrapper.for(tool_def, transport) end |
.tools_from_mcp(command:) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/rubyagents/mcp.rb', line 108 def self.tools_from_mcp(command:) transport = MCP::StdioTransport.new(command: command) response = transport.send_request(request: { method: "tools/list", params: {} }) tools = response.dig("result", "tools") || [] tools.map { |t| MCP::MCPToolWrapper.for(t, transport) } end |