|
3 | 3 | Extends StandardMagenticManager to add approval gates before plan execution. |
4 | 4 | """ |
5 | 5 |
|
| 6 | +import asyncio |
6 | 7 | import re |
7 | 8 | from typing import Any, List, Optional |
8 | 9 |
|
|
13 | 14 | from semantic_kernel.agents.orchestration.prompts._magentic_prompts import \ |
14 | 15 | ORCHESTRATOR_TASK_LEDGER_FACTS_PROMPT |
15 | 16 | from semantic_kernel.contents import ChatMessageContent |
16 | | -from v3.config.settings import connection_config, current_user_id |
| 17 | +from v3.config.settings import (connection_config, current_user_id, |
| 18 | + orchestration_config) |
17 | 19 | from v3.models.models import MPlan, MStep |
18 | 20 |
|
19 | 21 |
|
@@ -104,18 +106,23 @@ async def plan(self, magentic_context: MagenticContext) -> Any: |
104 | 106 | # ) |
105 | 107 |
|
106 | 108 |
|
107 | | - async def _wait_for_user_approval(self) -> Optional[messages.PlanApprovalResponse]: |
| 109 | + async def _wait_for_user_approval(self, plan_id: Optional[str] = None) -> Optional[messages.PlanApprovalResponse]: # plan_id will not be optional in future |
108 | 110 | """Wait for user approval response.""" |
109 | | - user_id = current_user_id.get() |
110 | 111 | # Temporarily use console input for approval - will switch to WebSocket or API in future |
111 | | - response = input("\nApprove this execution plan? [y/n]: ").strip().lower() |
112 | | - if response in ['y', 'yes']: |
113 | | - return messages.PlanApprovalResponse(approved=True) |
114 | | - elif response in ['n', 'no']: |
115 | | - return messages.PlanApprovalResponse(approved=False) |
116 | | - else: |
117 | | - print("Invalid input. Please enter 'y' for yes or 'n' for no.") |
118 | | - return await self._wait_for_user_approval() |
| 112 | + # response = input("\nApprove this execution plan? [y/n]: ").strip().lower() |
| 113 | + # if response in ['y', 'yes']: |
| 114 | + # return messages.PlanApprovalResponse(approved=True, plan_id=plan_id if plan_id else "input") |
| 115 | + # elif response in ['n', 'no']: |
| 116 | + # return messages.PlanApprovalResponse(approved=False, plan_id=plan_id if plan_id else "input") |
| 117 | + # else: |
| 118 | + # print("Invalid input. Please enter 'y' for yes or 'n' for no.") |
| 119 | + # return await self._wait_for_user_approval() |
| 120 | + # In future, implement actual waiting for WebSocket or API response here |
| 121 | + if plan_id not in orchestration_config.approvals: |
| 122 | + orchestration_config.approvals[plan_id] = None |
| 123 | + while orchestration_config.approvals[plan_id] is None: |
| 124 | + await asyncio.sleep(0.2) |
| 125 | + return messages.PlanApprovalResponse(approved=orchestration_config.approvals[plan_id], plan_id=plan_id) |
119 | 126 |
|
120 | 127 |
|
121 | 128 | async def prepare_final_answer(self, magentic_context: MagenticContext) -> ChatMessageContent: |
|
0 commit comments