Python: Refactor RequestInfoExecutor (#1403)

* Refactor RequestInfoExecutor

* Update AI script

* Fix formatting

* Address comments

* fix unit test
This commit is contained in:
Tao Chen
2025-10-13 12:18:17 -07:00
committed by GitHub
Unverified
parent baf59ca1ed
commit fc12ab9fed
12 changed files with 705 additions and 579 deletions
@@ -5,7 +5,7 @@ import sys
from collections.abc import Mapping
from dataclasses import dataclass
from pathlib import Path
from typing import Any, cast
from typing import Any
# Ensure local getting_started package can be imported when running as a script.
_SAMPLES_ROOT = Path(__file__).resolve().parents[3]
@@ -150,23 +150,17 @@ async def main() -> None:
else:
raise TypeError("Unexpected argument type for human review function call.")
request_payload_obj: Any = request.data
if not isinstance(request_payload_obj, Mapping):
raise ValueError("Human review request payload must be a mapping.")
request_payload = cast(Mapping[str, Any], request_payload_obj)
request_payload: Any = request.data
if not isinstance(request_payload, HumanReviewRequest):
raise ValueError("Human review request payload must be a HumanReviewRequest.")
agent_request_obj = request_payload.get("agent_request")
if not isinstance(agent_request_obj, Mapping):
raise ValueError("Human review request must include agent_request mapping data.")
agent_request_data = cast(Mapping[str, Any], agent_request_obj)
request_id_obj = agent_request_data.get("request_id")
if not isinstance(request_id_obj, str):
raise ValueError("Human review request_id must be a string.")
request_id_value = request_id_obj
agent_request = request_payload.agent_request
if agent_request is None:
raise ValueError("Human review request must include agent_request.")
request_id = agent_request.request_id
# Mock a human response approval for demonstration purposes.
human_response = ReviewResponse(request_id=request_id_value, feedback="Approved", approved=True)
human_response = ReviewResponse(request_id=request_id, feedback="Approved", approved=True)
# Create the function call result object to send back to the agent.
human_review_function_result = FunctionResultContent(