-
Notifications
You must be signed in to change notification settings - Fork 6
Add a human in the loop recipe. #8
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
base: main
Are you sure you want to change the base?
Conversation
jssmith
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good. See various small comments.
| - Slack/Teams messages | ||
| - Push notifications to mobile apps | ||
| - Updates to approval queue UI | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add that this implementation instead is logging.
| from typing import Optional | ||
| import asyncio | ||
|
|
||
| with workflow.unsafe.imports_passed_through(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is unsafe.imports_passed_through required here?
| ) | ||
|
|
||
| @workflow.run | ||
| async def run(self, user_request: str, approval_timeout_seconds: int = 300) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: put @workflow.run at the top of the class because it is the entrypoint.
| # Step 1: AI analyzes the request and proposes an action | ||
| proposed_action = await self._analyze_and_propose_action(user_request) | ||
|
|
||
| workflow.logger.info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this logging valuable or is it clutter? How much logging do we want to put in the recipes?
| ) | ||
|
|
||
| # Step 2: Request human approval | ||
| approval_result = await self._request_approval( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add logic where the approval is required for transactions above a threshold amount.
| reviewer_notes = self.current_decision.reviewer_notes or 'None provided' | ||
| return f"Action rejected. Reviewer notes: {reviewer_notes}" | ||
|
|
||
| else: # timeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check timeout + add final else: with Exception for invalid result.
| return timeout_msg | ||
|
|
||
| async def _analyze_and_propose_action(self, user_request: str) -> ProposedAction: | ||
| """Use LLM to analyze request and propose an action.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving prompts to a separate file
| @@ -0,0 +1 @@ | |||
| # Activities for human-in-the-loop workflow | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need __init__.py in Python 3.3+. If the file has content it can be ok to put it, but empty ones don't serve a purpose.
| @workflow.signal | ||
| async def approval_decision(self, decision: ApprovalDecision): | ||
| if decision.request_id == self.pending_request_id: | ||
| self.approval_decision = decision |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else...
At a minimum, log.
What was changed
Adds a recipe for a human in the loop workflow.