patterns-ai-core / langchainrb

Build LLM-powered applications in Ruby
https://rubydoc.info/gems/langchainrb
MIT License
1.45k stars 195 forks source link

Namespace conflict with Agent class/module in application due to langchainrb's Agent module #812

Closed quovai closed 1 month ago

quovai commented 1 month ago

Description
There is a namespace collision between the Agent class/module defined in my application and the Agent module in LangChain.rb. When LangChain.rb is loaded, it overrides my application's Agent class, causing a TypeError. I suspect other modules (as for example Tool) could lead to the same problem.

To Reproduce
Steps to reproduce the behavior:

  1. Define an Agent class or module in the application.
  2. Install and load the LangChain gem in the application.
  3. Launch the application
  4. LangChain's Agent module conflicts with the application's Agent class, raising an error.

Expected behavior
I expect LangChain's Agent module to be scoped under the Langchain namespace (e.g., Langchain::Agent) to avoid any conflicts with an Agent class or module in the global namespace.

Terminal commands & output
Here is the terminal output showing the conflict:

app_1         | /app1-app/app/models/agent.rb:7:in `<main>': Agent is not a class (TypeError)
app_1         | /usr/local/bundle/gems/langchainrb-0.3.14/lib/langchain.rb:34: previous definition of Agent was here

Desktop (please complete the following information):

Additional context
The issue could be solved by namespacing the Agent module inside the Langchain module (e.g., Langchain::Agent) to avoid polluting the global namespace.

As certain names (e.g. Agent, Tool) are quite common it could be useful to namespace them inside langchainrb.

quovai commented 1 month ago

Sorry the issue was probably related to an old version.

andreibondarev commented 1 month ago

@quovai Oh yeah, that's a very old version.

quovai commented 1 month ago

Very sorry... it was my ruby 2.7.6 that picked up that and I didn't notice. Again sorry.