How to access inputs in Task callbacks #1082
Unanswered
carvalhorafael
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I found a solution, but I don't know if it's the best approach. I'll share it with you: In ...
# Callback function receiving my_hash as parameter
def my_callback(output: TaskOutput, my_hash: str):
content = output.raw_output
print(f"Task output: {content}")
print(f"My Hash: {my_hash}")
@CrewBase
class MyCrew():
# saving the inputs in Class init
def __init__(self, inputs):
self.inputs = inputs
....
@task
def my_task(self) -> Task:
my_hash = self.inputs['my_hash']
return Task(
config=self.tasks_config['my_task'],
agent=self.my_agent(),
callback=self.create_callback(my_callback, my_hash)
)
# Wraps the callback to pass my_hash as parameter
def create_callback(self, my_callback, my_hash):
def wrapper(output: TaskOutput):
return my_callback(output, my_hash)
return wrapper
.... And in the my_crew = MyCrew(inputs={'my_hash': 'my hash here'}) # to inputs to be saved at class init
my_crew.crew().kickoff(inputs={'my_hash': 'my hash here'}) As I said, with this approach I was able to pass the hash in input to a callback function. Any feedback would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to access the value of an input inside a task's callback function.
Let me explain a little better.
Here is my
main.py
starting the crew and passing a hash (my_hash
) as an input:My crew has several agents and several tasks. Here I will only bring one of them:
As you can see in the code, I would like to access the value of
my_hash
passed as input from the crew inside the task callback function.How can I do this?
Here is another issue that could benefit from an answer #986
Beta Was this translation helpful? Give feedback.
All reactions