-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from custom tool calling methods to ToolExecutor from LangGraph (bc I didn't know how to configure callbacks in custom methods to make it render beautifully in LangSmith) Use BaseChatMessageHistory for self-reflections instead of a simple in-memory option
- Loading branch information
Showing
14 changed files
with
164 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,74 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any, Dict, List, Optional, overload | ||
from typing import List, overload, Sequence | ||
|
||
from langchain_core.agents import AgentAction, AgentFinish, AgentStep | ||
from langchain_core.callbacks import ( | ||
AsyncCallbackManagerForChainRun, | ||
CallbackManagerForChainRun, | ||
) | ||
from langchain_core.agents import AgentAction, AgentStep | ||
from langchain_core.tools import BaseTool | ||
|
||
|
||
class BaseActionExecutor(ABC): | ||
@property | ||
@abstractmethod | ||
def tools(self) -> Sequence[BaseTool]: ... | ||
|
||
@overload | ||
def execute( | ||
self, | ||
actions: List[AgentAction], | ||
name_to_tool_map: Dict[str, BaseTool], | ||
color_mapping: Dict[str, str], | ||
verbose: bool = True, | ||
tool_run_logging_kwargs: Optional[Dict[str, Any]] = None, | ||
run_manager: Optional[CallbackManagerForChainRun] = None, | ||
**kwargs, | ||
) -> List[AgentStep]: ... | ||
|
||
@overload | ||
def execute( | ||
self, | ||
actions: AgentAction, | ||
name_to_tool_map: Dict[str, BaseTool], | ||
color_mapping: Dict[str, str], | ||
verbose: bool = True, | ||
tool_run_logging_kwargs: Optional[Dict[str, Any]] = None, | ||
run_manager: Optional[CallbackManagerForChainRun] = None, | ||
**kwargs, | ||
) -> AgentStep: ... | ||
|
||
@abstractmethod | ||
def execute( | ||
self, | ||
actions: List[AgentAction] | AgentAction | AgentFinish, | ||
name_to_tool_map: Dict[str, BaseTool], | ||
color_mapping: Dict[str, str], | ||
verbose: bool = True, | ||
tool_run_logging_kwargs: Optional[Dict[str, Any]] = None, | ||
run_manager: Optional[CallbackManagerForChainRun] = None, | ||
actions: List[AgentAction] | AgentAction, | ||
**kwargs, | ||
) -> List[AgentStep] | AgentStep: | ||
"""Performs actions. | ||
Args: | ||
actions: Currently proposed actions. Can be: multi-action, single action, finishing. | ||
name_to_tool_map: Mapping from tool names to actual tools, used for calling tools based on agent's output. | ||
color_mapping: Mapping from tool names to colors, used for logging purposes when calling tools. | ||
run_manager: Callback for the current run. | ||
Returns: | ||
* List[AgentStep] - for multi-action thoughts (List[AgentAction]) | ||
* AgentStep - for single-action thoughts (AgentAction) | ||
* None - for finishing thoughts (AgentFinish) | ||
""" | ||
... | ||
|
||
@overload | ||
async def aexecute( | ||
self, | ||
actions: List[AgentAction], | ||
name_to_tool_map: Dict[str, BaseTool], | ||
color_mapping: Dict[str, str], | ||
verbose: bool = True, | ||
tool_run_logging_kwargs: Optional[Dict[str, Any]] = None, | ||
run_manager: Optional[AsyncCallbackManagerForChainRun] = None, | ||
**kwargs, | ||
) -> List[AgentStep]: ... | ||
|
||
@overload | ||
async def aexecute( | ||
self, | ||
actions: AgentAction, | ||
name_to_tool_map: Dict[str, BaseTool], | ||
color_mapping: Dict[str, str], | ||
verbose: bool = True, | ||
tool_run_logging_kwargs: Optional[Dict[str, Any]] = None, | ||
run_manager: Optional[AsyncCallbackManagerForChainRun] = None, | ||
**kwargs, | ||
) -> AgentStep: ... | ||
|
||
@abstractmethod | ||
async def aexecute( | ||
self, | ||
actions: List[AgentAction] | AgentAction, | ||
name_to_tool_map: Dict[str, BaseTool], | ||
color_mapping: Dict[str, str], | ||
verbose: bool = True, | ||
tool_run_logging_kwargs: Optional[Dict[str, Any]] = None, | ||
run_manager: Optional[AsyncCallbackManagerForChainRun] = None, | ||
**kwargs, | ||
) -> List[AgentStep] | AgentStep: | ||
"""Performs actions asynchronously. | ||
Args: | ||
actions: Currently proposed actions. Can be: multi-action, single action, finishing. | ||
name_to_tool_map: Mapping from tool names to actual tools, used for calling tools based on agent's output. | ||
color_mapping: Mapping from tool names to colors, used for logging purposes when calling tools. | ||
run_manager: Callback for the current run. | ||
Returns: | ||
* List[AgentStep] - for multi-action thoughts (List[AgentAction]) | ||
* AgentStep - for single-action thoughts (AgentAction) | ||
* None - for finishing thoughts (AgentFinish) | ||
""" | ||
... |
Oops, something went wrong.