mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
wip
This commit is contained in:
@@ -345,9 +345,11 @@ class Agent(BaseAgent):
|
||||
def get_delegation_tools(self, agents: Sequence[BaseAgent]) -> Sequence[BaseTool]:
|
||||
# If delegate_to is specified, use those agents instead of all agents
|
||||
if self.delegate_to is not None:
|
||||
agents_to_use = cast(List[BaseAgent], list(self.delegate_to))
|
||||
agents_to_use: Sequence[BaseAgent] = cast(
|
||||
List[BaseAgent], list(self.delegate_to)
|
||||
)
|
||||
else:
|
||||
agents_to_use = list(agents) # Convert to list to match expected type
|
||||
agents_to_use: Sequence[BaseAgent] = cast(List[BaseAgent], list(agents))
|
||||
|
||||
agent_tools = AgentTools(agents=agents_to_use)
|
||||
delegation_tools = agent_tools.tools()
|
||||
|
||||
@@ -248,13 +248,18 @@ def to_langchain(
|
||||
def tool(*args):
|
||||
"""
|
||||
Decorator to create a tool from a function.
|
||||
Ensures the decorated function is always wrapped as a BaseTool.
|
||||
"""
|
||||
|
||||
def _make_with_name(tool_name: str) -> Callable:
|
||||
def _make_with_name(tool_name: str) -> Callable[[Callable], BaseTool]:
|
||||
def _make_tool(f: Callable) -> BaseTool:
|
||||
# If f is already a BaseTool, return it
|
||||
if isinstance(f, BaseTool):
|
||||
return f
|
||||
|
||||
if f.__doc__ is None:
|
||||
raise ValueError("Function must have a docstring")
|
||||
if f.__annotations__ is None:
|
||||
if not f.__annotations__:
|
||||
raise ValueError("Function must have type annotations")
|
||||
|
||||
class_name = "".join(tool_name.split()).title()
|
||||
@@ -278,7 +283,12 @@ def tool(*args):
|
||||
return _make_tool
|
||||
|
||||
if len(args) == 1 and callable(args[0]):
|
||||
# Direct function decoration
|
||||
if isinstance(args[0], BaseTool):
|
||||
return args[0] # Already a BaseTool, return as-is
|
||||
return _make_with_name(args[0].__name__)(args[0])
|
||||
if len(args) == 1 and isinstance(args[0], str):
|
||||
elif len(args) == 1 and isinstance(args[0], str):
|
||||
# Name provided, return a decorator
|
||||
return _make_with_name(args[0])
|
||||
raise ValueError("Invalid arguments")
|
||||
else:
|
||||
raise ValueError("Invalid arguments")
|
||||
|
||||
Reference in New Issue
Block a user