Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord level tools #878

Open
pedrofs opened this issue Nov 20, 2024 · 0 comments
Open

ActiveRecord level tools #878

pedrofs opened this issue Nov 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@pedrofs
Copy link

pedrofs commented Nov 20, 2024

Is your feature request related to a problem? Please describe.
I want to have ActiveRecord as a tool.

Imagine I have a Workflow with a sequence of Action. Workflows have name and description. I would like to have each workflow record as a possible tool to be called.

Right now, this line https://github.com/patterns-ai-core/langchainrb/blob/main/lib/langchain/assistant.rb#L359 relies directly on the class of the tool so that I can't have this record-level dynamism.

Describe the solution you'd like
We could keep the DSL approach and have a tool_name method, which could receive an arbitrary string or a block with the tool as an argument and then have this record-level dynamism.

Describe alternatives you've considered
I'm currently defining a class in run-time:

def to_langchain_tool
  workflow = self
  class_name = "WORKFLOW_#{workflow.id}"

  Object.send(:remove_const, class_name) if Object.const_defined?(class_name)

  Object.const_set(class_name, Class.new do
    extend Langchain::ToolDefinition

    define_singleton_method :name do
      class_name
    end

    define_function :call, description: workflow.description

    def initialize(triggerable)
      @triggerable = triggerable
    end

    define_method :call do
      workflow.call(@triggerable)
    end
  end)
end

Maybe I'm not seeing something? Is there an easier way of accomplishing that?

@pedrofs pedrofs added the enhancement New feature or request label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant