mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Add feature to override _ask_human_input function in Task (#2419)
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -14,6 +14,31 @@ This feature is especially useful in complex decision-making processes or when a
|
||||
To integrate human input into agent execution, set the `human_input` flag in the task definition. When enabled, the agent prompts the user for input before delivering its final answer.
|
||||
This input can provide extra context, clarify ambiguities, or validate the agent's output.
|
||||
|
||||
## Customizing human input sources
|
||||
|
||||
By default, human input is collected via the command line using the `input()` function. However, you can override this behavior by providing a custom function to handle human input from different sources:
|
||||
|
||||
```python
|
||||
def get_input_from_api(final_answer: str) -> str:
|
||||
"""Get human feedback from an API instead of CLI."""
|
||||
# Make an API call to get feedback
|
||||
response = requests.post("https://your-api.com/feedback", json={"answer": final_answer})
|
||||
return response.json()["feedback"]
|
||||
|
||||
task = Task(
|
||||
description="Analyze the latest market trends",
|
||||
expected_output="A detailed analysis of market trends",
|
||||
agent=analyst,
|
||||
human_input=True,
|
||||
ask_human_input=get_input_from_api # Use the custom function
|
||||
)
|
||||
```
|
||||
|
||||
The custom function should:
|
||||
- Accept a string parameter (the agent's final answer)
|
||||
- Return a string (the human feedback)
|
||||
- Return an empty string if the answer is acceptable and no further iterations are needed
|
||||
|
||||
### Example:
|
||||
|
||||
```shell
|
||||
@@ -95,4 +120,4 @@ result = crew.kickoff()
|
||||
|
||||
print("######################")
|
||||
print(result)
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user