mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [Breaking] removed pydantic from types and workflows (#917)
* removed pydantic from types * fix test * fix test * fix tests * fix assistants client * Remove Pydantic usage from workflow code. * updated pydantic removal * updated lock and test fixes * fix mypy * updated build system * updated chat client parsing * fix broken test --------- Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
647db9635a
commit
b4ebafa9b1
@@ -113,7 +113,7 @@ class EchoingChatClient(BaseChatClient):
|
||||
contents=[TextContent(text=char)],
|
||||
role=Role.ASSISTANT,
|
||||
response_id=f"echo-stream-resp-{random.randint(1000, 9999)}",
|
||||
ai_model_id="echo-model-v1",
|
||||
model_id="echo-model-v1",
|
||||
)
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ async def non_streaming_example() -> None:
|
||||
|
||||
# Access the structured output directly from the response value
|
||||
if result.value:
|
||||
structured_data = result.value
|
||||
structured_data: OutputStruct = result.value # type: ignore
|
||||
print("Structured Output Agent (from result.value):")
|
||||
print(f"City: {structured_data.city}")
|
||||
print(f"Description: {structured_data.description}")
|
||||
@@ -62,7 +62,7 @@ async def streaming_example() -> None:
|
||||
|
||||
# Access the structured output directly from the response value
|
||||
if result.value:
|
||||
structured_data = result.value
|
||||
structured_data: OutputStruct = result.value # type: ignore
|
||||
print("Structured Output (from streaming with AgentRunResponse.from_agent_response_generator):")
|
||||
print(f"City: {structured_data.city}")
|
||||
print(f"Description: {structured_data.description}")
|
||||
|
||||
@@ -53,7 +53,7 @@ class UserInfoMemory(ContextProvider):
|
||||
)
|
||||
|
||||
# Update user info with extracted data
|
||||
if result.value:
|
||||
if result.value and isinstance(result.value, UserInfo):
|
||||
if self.user_info.name is None and result.value.name:
|
||||
self.user_info.name = result.value.name
|
||||
if self.user_info.age is None and result.value.age:
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from typing_extensions import Never
|
||||
|
||||
from agent_framework import (
|
||||
Executor,
|
||||
WorkflowBuilder,
|
||||
@@ -11,6 +9,7 @@ from agent_framework import (
|
||||
executor,
|
||||
handler,
|
||||
)
|
||||
from typing_extensions import Never
|
||||
|
||||
"""
|
||||
Step 1: Foundational patterns: Executors and edges
|
||||
|
||||
+26
-6
@@ -2,8 +2,10 @@
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from collections.abc import Mapping
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any, cast
|
||||
|
||||
# Ensure local getting_started package can be imported when running as a script.
|
||||
_SAMPLES_ROOT = Path(__file__).resolve().parents[3]
|
||||
@@ -138,15 +140,33 @@ async def main() -> None:
|
||||
# Handle the human review if required.
|
||||
if human_review_function_call:
|
||||
# Parse the human review request arguments.
|
||||
if isinstance(human_review_function_call.arguments, str):
|
||||
request = WorkflowAgent.RequestInfoFunctionArgs.model_validate_json(human_review_function_call.arguments)
|
||||
human_request_args = human_review_function_call.arguments
|
||||
if isinstance(human_request_args, str):
|
||||
request: WorkflowAgent.RequestInfoFunctionArgs = WorkflowAgent.RequestInfoFunctionArgs.from_json(
|
||||
human_request_args
|
||||
)
|
||||
elif isinstance(human_request_args, Mapping):
|
||||
request = WorkflowAgent.RequestInfoFunctionArgs.from_dict(dict(human_request_args))
|
||||
else:
|
||||
request = WorkflowAgent.RequestInfoFunctionArgs.model_validate(human_review_function_call.arguments)
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
# Mock a human response approval for demonstration purposes.
|
||||
human_response = ReviewResponse(
|
||||
request_id=request.data["agent_request"]["request_id"], feedback="Approved", approved=True
|
||||
)
|
||||
human_response = ReviewResponse(request_id=request_id_value, feedback="Approved", approved=True)
|
||||
|
||||
# Create the function call result object to send back to the agent.
|
||||
human_review_function_result = FunctionResultContent(
|
||||
|
||||
Reference in New Issue
Block a user