crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
20.8k stars 2.87k forks source link

Usage human_tools #221

Closed PavelAgurov closed 9 months ago

PavelAgurov commented 9 months ago

Hi! I have create agent and tool to ask user for input.

Agent:

user_manager = Agent(
    role='Communication Manager',
    goal='Ask user for input when information from user is required',
    verbose=True,
    backstory="""You are polite public relations manager.""",
    allow_delegation=False,
    max_iter=2,
    max_rpm=20,
    llm = llm
)

And task:

from langchain.agents import load_tools

human_tools = load_tools(["human"])

ask_user = Task(
    description= "This task is about to ask user for input when user input is required.",
    expected_output="User input.",
    tools= human_tools,  
    agent=user_manager,
    async_execution=False
)

When I run it I got error:

.........................

These ideas can serve as a starting point for further research and exploration based on the specific topic provided by the user.Do I need to use a tool? Yes Action: Ask question to co-worker Action Input: Communication Manager|How should we ask the user for the specific topic they want us to research?|We need to ask for user input when it is required.

Entering new CrewAgentExecutor chain... Exception in thread Thread-36 (_execute): Traceback (most recent call last): File "D:\Anaconda3\Lib\threading.py", line 1038, in _bootstrap_inner self.run() File "D:\Anaconda3\Lib\threading.py", line 975, in run self._target(*self._args, self._kwargs) File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\task.py", line 112, in _execute result = agent.execute_task(task=task_prompt, context=context, tools=tools) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\agent.py", line 151, in execute_task result = self.agent_executor.invoke( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\chains\base.py", line 162, in invoke raise e File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\chains\base.py", line 156, in invoke self._call(inputs, run_manager=run_manager) File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\agents\executor.py", line 59, in _call next_step_output = self._take_next_step( ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\agents\agent.py", line 1097, in _take_next_step [ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\agents\agent.py", line 1097, in [ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\agents\executor.py", line 195, in _iter_next_step observation = tool.run( ^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain_core\tools.py", line 373, in run raise e File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain_core\tools.py", line 345, in run self._run(*tool_args, run_manager=run_manager, *tool_kwargs) File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain_core\tools.py", line 523, in _run else self.func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\tools\agent_tools.py", line 40, in ask_question return self._execute(command) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\tools\agent_tools.py", line 64, in _execute return agent.execute_task(task, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\agent.py", line 151, in execute_task result = self.agent_executor.invoke( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\chains\base.py", line 162, in invoke raise e File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\chains\base.py", line 156, in invoke self._call(inputs, run_manager=run_manager) File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\agents\executor.py", line 59, in _call next_step_output = self._take_next_step( ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\agents\agent.py", line 1097, in _take_next_step [ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\langchain\agents\agent.py", line 1097, in [ File "C:\Users\pavel\AppData\Roaming\Python\Python311\site-packages\crewai\agents\executor.py", line 114, in _iter_next_step raise ValueError( ValueError: Unexpected output type from agent: <class 'langchain_core.agents.AgentFinish'>

joaomdmoura commented 9 months ago

Fixed on v0.5.5 πŸ˜ŽπŸ‘‰πŸ‘‰ let me know if it works now. Also you might not need a specific agents just to ask human input but you could give that tool to another agent, both should work, just a matter of experimentation