-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add "switch" and "for each" activities
- Loading branch information
1 parent
8263aea
commit a63fb4a
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
agents-api/agents_api/activities/task_steps/for_each_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,32 @@ | ||
import logging | ||
|
||
from beartype import beartype | ||
from simpleeval import simple_eval | ||
from temporalio import activity | ||
|
||
from ...autogen.openapi_model import ForeachStep | ||
from ...common.protocol.tasks import ( | ||
StepContext, | ||
StepOutcome, | ||
) | ||
from ...env import testing | ||
|
||
|
||
@beartype | ||
async def for_each_step(context: StepContext) -> StepOutcome: | ||
try: | ||
assert isinstance(context.current_step, ForeachStep) | ||
|
||
return StepOutcome(output=simple_eval(context.current_step.foreach.in_, names=context.model_dump())) | ||
except BaseException as e: | ||
logging.error(f"Error in for_each_step: {e}") | ||
return StepOutcome(error=str(e)) | ||
|
||
|
||
# Note: This is here just for clarity. We could have just imported if_else_step directly | ||
# They do the same thing, so we dont need to mock the if_else_step function | ||
mock_if_else_step = for_each_step | ||
|
||
for_each_step = activity.defn(name="if_else_step")( | ||
for_each_step if not testing else mock_if_else_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