feat: Enhance LangGraphAgentAdapter to support optional agent configuration

- Updated LangGraphAgentAdapter to conditionally apply agent configuration when creating the agent graph, allowing for more flexible initialization.
- Modified LangGraphToolAdapter to ensure only instances of BaseTool are converted, improving tool compatibility and handling.
This commit is contained in:
lorenzejay
2025-04-16 11:57:59 -07:00
parent 474d3445ef
commit fa7bd9a4ee
2 changed files with 19 additions and 8 deletions

View File

@@ -84,13 +84,21 @@ class LangGraphAgentAdapter(BaseAgentAdapter):
self._memory = MemorySaver()
converted_tools: List[Any] = self._tool_adapter.tools()
self._graph = create_react_agent(
model=self.llm,
tools=converted_tools or [],
checkpointer=self._memory,
debug=self.verbose,
)
if self._agent_config:
self._graph = create_react_agent(
model=self.llm,
tools=converted_tools or [],
checkpointer=self._memory,
debug=self.verbose,
**self._agent_config,
)
else:
self._graph = create_react_agent(
model=self.llm,
tools=converted_tools or [],
checkpointer=self._memory,
debug=self.verbose,
)
except ImportError as e:
self._logger.log(

View File

@@ -16,7 +16,7 @@ class LangGraphToolAdapter(BaseToolAdapter):
Configure and convert CrewAI tools to LangGraph-compatible format.
LangGraph expects tools in langchain_core.tools format.
"""
from langchain_core.tools import StructuredTool
from langchain_core.tools import BaseTool, StructuredTool
converted_tools = []
if self.original_tools:
@@ -24,6 +24,9 @@ class LangGraphToolAdapter(BaseToolAdapter):
else:
all_tools = tools
for tool in all_tools:
if isinstance(tool, BaseTool):
converted_tools.append(tool)
continue
def tool_wrapper(*args, tool=tool, **kwargs):
if len(args) > 0 and isinstance(args[0], str):