Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Python interpreter #845

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions agents-api/agents_api/activities/task_steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@

from .base_evaluate import base_evaluate
from .cozo_query_step import cozo_query_step
from .evaluate_step import evaluate_step
from .for_each_step import for_each_step
from .get_value_step import get_value_step
from .if_else_step import if_else_step
from .log_step import log_step
from .map_reduce_step import map_reduce_step
from .prompt_step import prompt_step
from .raise_complete_async import raise_complete_async
from .return_step import return_step
from .set_value_step import set_value_step
from .switch_step import switch_step
from .tool_call_step import tool_call_step
from .transition_step import transition_step
from .wait_for_input_step import wait_for_input_step
from .yield_step import yield_step
13 changes: 10 additions & 3 deletions agents-api/agents_api/activities/task_steps/base_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ def __init__(self, error, expression, values):


# Recursive evaluation helper function
def _recursive_evaluate(expr, evaluator: SimpleEval):
def _recursive_evaluate(expr, evaluator: SimpleEval, eval_prompt_prefix: str = "$ "):
if isinstance(expr, str):
try:
return evaluator.eval(expr)
result = expr
if expr.startswith(eval_prompt_prefix):
result = evaluator.eval(expr[len(eval_prompt_prefix) :].strip())

return result
except Exception as e:
if activity.in_activity():
evaluate_error = EvaluateError(e, expr, evaluator.names)
Expand Down Expand Up @@ -69,6 +73,7 @@ async def base_evaluate(
exprs: Any,
values: dict[str, Any] = {},
extra_lambda_strs: dict[str, str] | None = None,
eval_prompt_prefix: str = "$_",
) -> Any | list[Any] | dict[str, Any]:
input_len = 1 if isinstance(exprs, str) else len(exprs)
assert input_len > 0, "exprs must be a non-empty string, list or dict"
Expand Down Expand Up @@ -100,7 +105,9 @@ async def base_evaluate(
evaluator: SimpleEval = get_evaluator(names=values, extra_functions=extra_lambdas)

# Recursively evaluate the expression
result = _recursive_evaluate(exprs, evaluator)
result = _recursive_evaluate(
exprs, evaluator, eval_prompt_prefix=eval_prompt_prefix
)
return result


Expand Down
44 changes: 0 additions & 44 deletions agents-api/agents_api/activities/task_steps/evaluate_step.py

This file was deleted.

36 changes: 0 additions & 36 deletions agents-api/agents_api/activities/task_steps/for_each_step.py

This file was deleted.

40 changes: 0 additions & 40 deletions agents-api/agents_api/activities/task_steps/if_else_step.py

This file was deleted.

41 changes: 0 additions & 41 deletions agents-api/agents_api/activities/task_steps/log_step.py

This file was deleted.

39 changes: 0 additions & 39 deletions agents-api/agents_api/activities/task_steps/map_reduce_step.py

This file was deleted.

37 changes: 0 additions & 37 deletions agents-api/agents_api/activities/task_steps/return_step.py

This file was deleted.

41 changes: 0 additions & 41 deletions agents-api/agents_api/activities/task_steps/set_value_step.py

This file was deleted.

45 changes: 0 additions & 45 deletions agents-api/agents_api/activities/task_steps/switch_step.py

This file was deleted.

Loading
Loading