mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 07:42:40 +00:00
Merge branch 'main' into bugfix-python-3-10
This commit is contained in:
@@ -60,7 +60,7 @@ def test():
|
|||||||
"current_year": str(datetime.now().year)
|
"current_year": str(datetime.now().year)
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
{{crew_name}}().crew().test(n_iterations=int(sys.argv[1]), openai_model_name=sys.argv[2], inputs=inputs)
|
{{crew_name}}().crew().test(n_iterations=int(sys.argv[1]), eval_llm=sys.argv[2], inputs=inputs)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"An error occurred while testing the crew: {e}")
|
raise Exception(f"An error occurred while testing the crew: {e}")
|
||||||
|
|||||||
@@ -244,9 +244,13 @@ def to_langchain(
|
|||||||
return [t.to_structured_tool() if isinstance(t, BaseTool) else t for t in tools]
|
return [t.to_structured_tool() if isinstance(t, BaseTool) else t for t in tools]
|
||||||
|
|
||||||
|
|
||||||
def tool(*args):
|
def tool(*args, result_as_answer=False):
|
||||||
"""
|
"""
|
||||||
Decorator to create a tool from a function.
|
Decorator to create a tool from a function.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*args: Positional arguments, either the function to decorate or the tool name.
|
||||||
|
result_as_answer: Flag to indicate if the tool result should be used as the final agent answer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _make_with_name(tool_name: str) -> Callable:
|
def _make_with_name(tool_name: str) -> Callable:
|
||||||
@@ -272,6 +276,7 @@ def tool(*args):
|
|||||||
description=f.__doc__,
|
description=f.__doc__,
|
||||||
func=f,
|
func=f,
|
||||||
args_schema=args_schema,
|
args_schema=args_schema,
|
||||||
|
result_as_answer=result_as_answer,
|
||||||
)
|
)
|
||||||
|
|
||||||
return _make_tool
|
return _make_tool
|
||||||
|
|||||||
@@ -100,3 +100,25 @@ def test_default_cache_function_is_true():
|
|||||||
my_tool = MyCustomTool()
|
my_tool = MyCustomTool()
|
||||||
# Assert all the right attributes were defined
|
# Assert all the right attributes were defined
|
||||||
assert my_tool.cache_function()
|
assert my_tool.cache_function()
|
||||||
|
|
||||||
|
|
||||||
|
def test_result_as_answer_in_tool_decorator():
|
||||||
|
@tool("Tool with result as answer", result_as_answer=True)
|
||||||
|
def my_tool_with_result_as_answer(question: str) -> str:
|
||||||
|
"""This tool will return its result as the final answer."""
|
||||||
|
return question
|
||||||
|
|
||||||
|
assert my_tool_with_result_as_answer.result_as_answer is True
|
||||||
|
|
||||||
|
converted_tool = my_tool_with_result_as_answer.to_structured_tool()
|
||||||
|
assert converted_tool.result_as_answer is True
|
||||||
|
|
||||||
|
@tool("Tool with default result_as_answer")
|
||||||
|
def my_tool_with_default(question: str) -> str:
|
||||||
|
"""This tool uses the default result_as_answer value."""
|
||||||
|
return question
|
||||||
|
|
||||||
|
assert my_tool_with_default.result_as_answer is False
|
||||||
|
|
||||||
|
converted_tool = my_tool_with_default.to_structured_tool()
|
||||||
|
assert converted_tool.result_as_answer is False
|
||||||
|
|||||||
Reference in New Issue
Block a user