mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-06 01:32: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()
|
self._memory = MemorySaver()
|
||||||
|
|
||||||
converted_tools: List[Any] = self._tool_adapter.tools()
|
converted_tools: List[Any] = self._tool_adapter.tools()
|
||||||
|
if self._agent_config:
|
||||||
self._graph = create_react_agent(
|
self._graph = create_react_agent(
|
||||||
model=self.llm,
|
model=self.llm,
|
||||||
tools=converted_tools or [],
|
tools=converted_tools or [],
|
||||||
checkpointer=self._memory,
|
checkpointer=self._memory,
|
||||||
debug=self.verbose,
|
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:
|
except ImportError as e:
|
||||||
self._logger.log(
|
self._logger.log(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class LangGraphToolAdapter(BaseToolAdapter):
|
|||||||
Configure and convert CrewAI tools to LangGraph-compatible format.
|
Configure and convert CrewAI tools to LangGraph-compatible format.
|
||||||
LangGraph expects tools in langchain_core.tools format.
|
LangGraph expects tools in langchain_core.tools format.
|
||||||
"""
|
"""
|
||||||
from langchain_core.tools import StructuredTool
|
from langchain_core.tools import BaseTool, StructuredTool
|
||||||
|
|
||||||
converted_tools = []
|
converted_tools = []
|
||||||
if self.original_tools:
|
if self.original_tools:
|
||||||
@@ -24,6 +24,9 @@ class LangGraphToolAdapter(BaseToolAdapter):
|
|||||||
else:
|
else:
|
||||||
all_tools = tools
|
all_tools = tools
|
||||||
for tool in all_tools:
|
for tool in all_tools:
|
||||||
|
if isinstance(tool, BaseTool):
|
||||||
|
converted_tools.append(tool)
|
||||||
|
continue
|
||||||
|
|
||||||
def tool_wrapper(*args, tool=tool, **kwargs):
|
def tool_wrapper(*args, tool=tool, **kwargs):
|
||||||
if len(args) > 0 and isinstance(args[0], str):
|
if len(args) > 0 and isinstance(args[0], str):
|
||||||
|
|||||||
Reference in New Issue
Block a user