Skip to content

Commit

Permalink
Merge pull request #27 from ShoggothAI/runnable_interface
Browse files Browse the repository at this point in the history
Inherit agents and tools from Runnable interface
  • Loading branch information
whimo authored May 20, 2024
2 parents 3abd1e4 + 23a9cbb commit 13ed727
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion motleycrew/agents/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import TYPE_CHECKING, Optional, Sequence

from langchain_core.tools import Tool
from langchain_core.runnables import Runnable
from pydantic import BaseModel

from motleycrew.agents.abstract_parent import MotleyAgentAbstractParent
Expand All @@ -13,7 +14,7 @@
from motleycrew import MotleyCrew


class MotleyAgentParent(MotleyAgentAbstractParent):
class MotleyAgentParent(MotleyAgentAbstractParent, Runnable):
def __init__(
self,
goal: str,
Expand Down
5 changes: 3 additions & 2 deletions motleycrew/tools/tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Union

from langchain.tools import BaseTool
from langchain_core.runnables import Runnable

try:
from llama_index.core.tools import BaseTool as LlamaIndex__BaseTool
Expand All @@ -19,14 +20,13 @@ def normalize_input(args, kwargs):
return args[0]


class MotleyTool:
class MotleyTool(Runnable):
"""
Base tool class compatible with MotleyAgents.
It is a wrapper for LangChain's BaseTool, containing all necessary adapters and converters.
"""

def __init__(self, tool: BaseTool):
ensure_module_is_installed("llama_index")
self.tool = tool

@property
Expand Down Expand Up @@ -66,6 +66,7 @@ def to_langchain_tool(self) -> BaseTool:
return self.tool

def to_llama_index_tool(self) -> LlamaIndex__BaseTool:
ensure_module_is_installed("llama_index")
llama_index_tool = LlamaIndex__FunctionTool.from_defaults(
fn=self.tool._run,
name=self.tool.name,
Expand Down

0 comments on commit 13ed727

Please sign in to comment.