-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agents-api): Add wait_for_input step
Signed-off-by: Diwank Tomer <[email protected]>
- Loading branch information
Diwank Tomer
committed
Aug 18, 2024
1 parent
d954077
commit 6cd98ae
Showing
20 changed files
with
174 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
agents-api/agents_api/activities/task_steps/evaluate_step.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import logging | ||
|
||
from temporalio import activity | ||
|
||
from ...activities.task_steps.utils import simple_eval_dict | ||
|
34 changes: 34 additions & 0 deletions
34
agents-api/agents_api/activities/task_steps/wait_for_input_step.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
|
||
from temporalio import activity | ||
|
||
from ...activities.task_steps.utils import simple_eval_dict | ||
from ...autogen.openapi_model import WaitForInputStep | ||
from ...common.protocol.tasks import StepContext, StepOutcome | ||
from ...env import testing | ||
|
||
|
||
async def wait_for_input_step(context: StepContext) -> StepOutcome: | ||
# NOTE: This activity is only for returning immediately, so we just evaluate the expression | ||
# Hence, it's a local activity and SHOULD NOT fail | ||
try: | ||
assert isinstance(context.current_step, WaitForInputStep) | ||
|
||
exprs = context.current_step.wait_for_input | ||
output = simple_eval_dict(exprs, values=context.model_dump()) | ||
|
||
result = StepOutcome(output=output) | ||
return result | ||
|
||
except Exception as e: | ||
logging.error(f"Error in log_step: {e}") | ||
return StepOutcome(output=None) | ||
|
||
|
||
# Note: This is here just for clarity. We could have just imported wait_for_input_step directly | ||
# They do the same thing, so we dont need to mock the wait_for_input_step function | ||
mock_wait_for_input_step = wait_for_input_step | ||
|
||
wait_for_input_step = activity.defn(name="wait_for_input_step")( | ||
wait_for_input_step if not testing else mock_wait_for_input_step | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.