Skip to content

Commit f0c2f7a

Browse files
committed
feat: Add base tool calling agent class
1 parent 6a75078 commit f0c2f7a

File tree

13 files changed

+1247
-13
lines changed

13 files changed

+1247
-13
lines changed

plugins/enthusiast-agent-re-act/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "enthusiast-agent-re-act"
3-
version = "1.3.0"
3+
version = "1.3.1"
44
description = "Base implementation of a ReAct agent for Enthusiast"
55
authors = [
66
{name = "Rafal Cymerys",email = "[email protected]"}

plugins/enthusiast-agent-re-act/src/enthusiast_agent_re_act/base_re_act_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22

3-
from enthusiast_common.agents import BaseAgent
3+
from enthusiast_common.agents import AgentType, BaseAgent
44
from langchain.agents import AgentExecutor, create_react_agent
55
from langchain_core.memory import BaseMemory
66
from langchain_core.tools import BaseTool, render_text_description_and_args
@@ -9,7 +9,7 @@
99

1010

1111
class BaseReActAgent(BaseAgent):
12-
IS_REACT = True
12+
AGENT_TYPE = AgentType.RE_ACT
1313

1414
def get_answer(self, input_text: str) -> str:
1515
agent_executor = self._build_agent_executor()

plugins/enthusiast-agent-tool-calling/README.md

Whitespace-only changes.

plugins/enthusiast-agent-tool-calling/poetry.lock

Lines changed: 1164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "enthusiast-agent-tool-calling"
3+
version = "1.0.0"
4+
description = "Base implementation of a Tool Calling agent for Enthusiast"
5+
authors = [
6+
{name = "Damian Sowiński",email = "[email protected]"}
7+
]
8+
readme = "README.md"
9+
requires-python = ">=3.10,<4"
10+
dependencies = [
11+
"enthusiast-common (>=1.4.0,<2.0.0)",
12+
"langchain (>=0.3.26,<0.4.0)"
13+
]
14+
15+
[tool.poetry]
16+
packages = [{include = "enthusiast_agent_tool_calling", from = "src"}]
17+
18+
19+
[build-system]
20+
requires = ["poetry-core>=2.0.0,<3.0.0"]
21+
build-backend = "poetry.core.masonry.api"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .base_tool_calling_agent import BaseToolCallingAgent as BaseToolCallingAgent
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Any
2+
3+
from enthusiast_common.agents import AgentType, BaseAgent
4+
from langchain.agents import AgentExecutor, create_tool_calling_agent
5+
from langchain_core.memory import BaseMemory
6+
from langchain_core.tools import BaseTool
7+
8+
9+
class BaseToolCallingAgent(BaseAgent):
10+
AGENT_TYPE = AgentType.TOOL_CALLING
11+
12+
def get_answer(self, input_text: str) -> str:
13+
agent_executor = self._build_agent_executor()
14+
response = agent_executor.invoke({"input": input_text}, config=self._build_invoke_config())
15+
return response["output"]
16+
17+
def _build_tools(self) -> list[BaseTool]:
18+
return [tool.as_tool() for tool in self._tools]
19+
20+
def _build_memory(self) -> BaseMemory:
21+
return self._injector.chat_limited_memory
22+
23+
def _build_invoke_config(self) -> dict[str, Any]:
24+
if self._callback_handler:
25+
return {"callbacks": [self._callback_handler]}
26+
27+
return {}
28+
29+
def _build_agent_executor(self) -> AgentExecutor:
30+
tools = self._build_tools()
31+
agent = create_tool_calling_agent(
32+
tools=tools,
33+
llm=self._llm,
34+
prompt=self._prompt,
35+
)
36+
return AgentExecutor(
37+
agent=agent, tools=tools, verbose=True, memory=self._build_memory(), return_intermediate_steps=True
38+
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .base import BaseAgent
1+
from .base import AgentType, BaseAgent
22

3-
__all__ = ["BaseAgent"]
3+
__all__ = ["BaseAgent", "AgentType"]

plugins/enthusiast-common/enthusiast_common/agents/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC, ABCMeta, abstractmethod
2+
from enum import Enum
23
from typing import Any
34

45
from langchain_core.callbacks import BaseCallbackHandler
@@ -13,6 +14,12 @@
1314
from ..utils import RequiredFieldsModel, validate_required_vars
1415

1516

17+
class AgentType(str, Enum):
18+
BASE = "base"
19+
RE_ACT = "re_act"
20+
TOOL_CALLING = "tool_calling"
21+
22+
1623
class ExtraArgsClassBaseMeta(ABCMeta):
1724
REQUIRED_VARS = {}
1825

@@ -42,7 +49,7 @@ class BaseAgent(ABC, ExtraArgsClassBase):
4249
PROMPT_EXTENSION = None
4350
TOOLS = []
4451

45-
IS_REACT = False
52+
AGENT_TYPE: AgentType = AgentType.BASE
4653
FILE_UPLOAD = False
4754
DEFAULT_FILE_TOOLS = [FileListTool, FileRetrievalTool]
4855

plugins/enthusiast-common/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "enthusiast-common"
3-
version = "1.4.0"
3+
version = "1.4.1"
44
description = "Core interfaces for developing custom Enthusiast plugins and integrations."
55
authors = ["Rafal Cymerys <[email protected]>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)