mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-05 17:22:36 +00:00
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:
@@ -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(
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user