Class: RCrewAI::Tools::CodeExecutor
- Defined in:
- lib/rcrewai/tools/code_executor.rb
Constant Summary
Constants included from RCrewAI::ToolSchema
Instance Method Summary collapse
- #execute(**params) ⇒ Object
-
#initialize(**options) ⇒ CodeExecutor
constructor
A new instance of CodeExecutor.
Methods inherited from Base
available_tools, create_tool, #description, #execute_with_validation, #json_schema, list_available_tools, #name, #validate_params!
Methods included from RCrewAI::ToolSchema
#description, extended, #json_schema, #param, #params, #tool_name
Constructor Details
#initialize(**options) ⇒ CodeExecutor
Returns a new instance of CodeExecutor.
22 23 24 25 26 27 28 29 30 |
# File 'lib/rcrewai/tools/code_executor.rb', line 22 def initialize(**) super() @timeout = .fetch(:timeout, 30) @max_output_size = .fetch(:max_output_size, 100_000) # 100KB @allowed_languages = .fetch(:allowed_languages, %w[python ruby javascript bash]) @working_directory = [:working_directory] || Dir.mktmpdir('rcrewai_code_') @enable_file_operations = .fetch(:enable_file_operations, false) setup_security_restrictions end |
Instance Method Details
#execute(**params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rcrewai/tools/code_executor.rb', line 32 def execute(**params) validate_params!(params, required: %i[code language], optional: %i[args stdin]) language = params[:language].to_s.downcase code = params[:code] args = params[:args] || [] stdin_input = params[:stdin] begin validate_execution_params!(language, code) result = execute_code(language, code, args, stdin_input) format_execution_result(language, code, result) rescue StandardError => e "Code execution failed: #{e.}" end end |