fix: clarify @listen decorator method vs output behavior (#2666)

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-22 18:56:27 +00:00
parent 16eb4df556
commit d5f23c439a
3 changed files with 249 additions and 17 deletions

View File

@@ -106,7 +106,23 @@ The `@listen()` decorator is used to mark a method as a listener for the output
The `@listen()` decorator can be used in several ways:
1. **Listening to a Method by Name**: You can pass the name of the method you want to listen to as a string. When that method completes, the listener method will be triggered.
1. **Listening to a Method by Name Explicitly**: You can explicitly specify that you're listening for a method by name, which removes any ambiguity.
```python Code
@listen(method="generate_city")
def generate_fun_fact(self, random_city):
# Implementation
```
2. **Listening to an Output Value Explicitly**: You can explicitly specify that you're listening for an output value, which removes any ambiguity.
```python Code
@listen(output="success")
def handle_success(self):
# Implementation
```
3. **Legacy Usage - Listening to a Method by Name**: You can pass the name of the method you want to listen to as a string. When that method completes, the listener method will be triggered.
```python Code
@listen("generate_city")
@@ -114,7 +130,7 @@ The `@listen()` decorator can be used in several ways:
# Implementation
```
2. **Listening to a Method Directly**: You can pass the method itself. When that method completes, the listener method will be triggered.
4. **Legacy Usage - Listening to a Method Directly**: You can pass the method itself. When that method completes, the listener method will be triggered.
```python Code
@listen(generate_city)
def generate_fun_fact(self, random_city):