Skip to content
Merged
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
4 changes: 2 additions & 2 deletions re_act/schedule_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ async def main():
workflow_name="ParentWorkflow",
workflow_id=workflow_id,
input={
"email": "john.doe@example.com",
"current_accepted_applicants_count": 9
"email": "admin@example.com",
"current_accepted_applicants_count": 10
}
)

Expand Down
27 changes: 21 additions & 6 deletions re_act/src/functions/decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ async def decide(input: DecideInput):

client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

tools = [
{
"type": "function",
"function": {
"name": "accept_applicant",
"description": "Accept the applicant",
"parameters": {}
}
},
{
"type": "function",
"function": {
"name": "reject_applicant",
"description": "Reject the applicant",
"parameters": {}
}
}
]

response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
Expand All @@ -38,17 +57,13 @@ async def decide(input: DecideInput):
The maximum number of accepted applicants is: 10

Decide if the applicant should be accepted or rejected.
Return only a JSON object with these exact fields:
{{
"accepted": boolean
}}
""",
}
],
response_format={"type": "json_object"},
tools=tools
)

return response.choices[0].message.content
return response.choices[0].message.tool_calls
except Exception as e:
log.error("Failed to decide", error=e)
raise FunctionFailure("Failed to decide", non_retryable=True)
Expand Down
6 changes: 3 additions & 3 deletions re_act/src/workflows/parent_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ async def run(self, input: ParentWorkflowInput):
start_to_close_timeout=timedelta(seconds=120)
)

decision = json.loads(decide_result)["accepted"]
decision = decide_result[0]['function']['name']

child_workflow_result = None
if decision:
if decision == "accept_applicant":
child_workflow_result = await workflow.child_execute(
ChildWorkflowA,
workflow_id=f"{parent_workflow_id}-child-a",
input=input.email
)
elif not decision:
elif decision == "reject_applicant":
child_workflow_result = await workflow.child_execute(
ChildWorkflowB,
workflow_id=f"{parent_workflow_id}-child-b",
Expand Down