mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
renamed all (#3207)
This commit is contained in:
committed by
GitHub
Unverified
parent
1ae0b09e42
commit
d8cf8361bd
+3
-3
@@ -8,7 +8,7 @@ from agent_framework import (
|
||||
HostedFileContent,
|
||||
TextContent,
|
||||
)
|
||||
from agent_framework._agents import AgentRunResponseUpdate
|
||||
from agent_framework._agents import AgentResponseUpdate
|
||||
from agent_framework.azure import AzureAIClient
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
@@ -45,7 +45,7 @@ async def test_non_streaming() -> None:
|
||||
|
||||
# Check for annotations in the response
|
||||
annotations_found: list[str] = []
|
||||
# AgentRunResponse has messages property, which contains ChatMessage objects
|
||||
# AgentResponse has messages property, which contains ChatMessage objects
|
||||
for message in result.messages:
|
||||
for content in message.contents:
|
||||
if isinstance(content, TextContent) and content.annotations:
|
||||
@@ -78,7 +78,7 @@ async def test_streaming() -> None:
|
||||
file_ids_found: list[str] = []
|
||||
|
||||
async for update in agent.run_stream(QUERY):
|
||||
if isinstance(update, AgentRunResponseUpdate):
|
||||
if isinstance(update, AgentResponseUpdate):
|
||||
for content in update.contents:
|
||||
if isinstance(content, TextContent):
|
||||
if content.text:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from agent_framework import AgentProtocol, AgentRunResponse, AgentThread, ChatMessage, HostedMCPTool
|
||||
from agent_framework import AgentProtocol, AgentResponse, AgentThread, ChatMessage, HostedMCPTool
|
||||
from agent_framework.azure import AzureAIClient
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
@@ -14,7 +14,7 @@ This sample demonstrates integrating hosted Model Context Protocol (MCP) tools w
|
||||
"""
|
||||
|
||||
|
||||
async def handle_approvals_without_thread(query: str, agent: "AgentProtocol") -> AgentRunResponse:
|
||||
async def handle_approvals_without_thread(query: str, agent: "AgentProtocol") -> AgentResponse:
|
||||
"""When we don't have a thread, we need to ensure we return with the input, approval request and approval."""
|
||||
|
||||
result = await agent.run(query, store=False)
|
||||
@@ -35,7 +35,7 @@ async def handle_approvals_without_thread(query: str, agent: "AgentProtocol") ->
|
||||
return result
|
||||
|
||||
|
||||
async def handle_approvals_with_thread(query: str, agent: "AgentProtocol", thread: "AgentThread") -> AgentRunResponse:
|
||||
async def handle_approvals_with_thread(query: str, agent: "AgentProtocol", thread: "AgentThread") -> AgentResponse:
|
||||
"""Here we let the thread deal with the previous responses, and we just rerun with the approval."""
|
||||
|
||||
result = await agent.run(query, thread=thread)
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentRunResponse, ChatResponseUpdate, HostedCodeInterpreterTool
|
||||
from agent_framework import AgentResponse, ChatResponseUpdate, HostedCodeInterpreterTool
|
||||
from agent_framework.azure import AzureAIAgentClient
|
||||
from azure.ai.agents.models import (
|
||||
RunStepDeltaCodeInterpreterDetailItemObject,
|
||||
@@ -17,7 +17,7 @@ for Python code execution and mathematical problem solving.
|
||||
"""
|
||||
|
||||
|
||||
def print_code_interpreter_inputs(response: AgentRunResponse) -> None:
|
||||
def print_code_interpreter_inputs(response: AgentResponse) -> None:
|
||||
"""Helper method to access code interpreter data."""
|
||||
|
||||
print("\nCode Interpreter Inputs during the run:")
|
||||
@@ -48,7 +48,7 @@ async def main() -> None:
|
||||
)
|
||||
query = "Generate the factorial of 100 using python code, show the code and execute it."
|
||||
print(f"User: {query}")
|
||||
response = await AgentRunResponse.from_agent_response_generator(agent.run_stream(query))
|
||||
response = await AgentResponse.from_agent_response_generator(agent.run_stream(query))
|
||||
print(f"Agent: {response}")
|
||||
# To review the code interpreter outputs, you can access
|
||||
# them from the response raw_representations, just uncomment the next line:
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentRunResponseUpdate, ChatAgent, HostedCodeInterpreterTool, HostedFileContent
|
||||
from agent_framework import AgentResponseUpdate, ChatAgent, HostedCodeInterpreterTool, HostedFileContent
|
||||
from agent_framework.azure import AzureAIAgentClient
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
@@ -53,7 +53,7 @@ async def main() -> None:
|
||||
file_ids: list[str] = []
|
||||
|
||||
async for chunk in agent.run_stream(query):
|
||||
if not isinstance(chunk, AgentRunResponseUpdate):
|
||||
if not isinstance(chunk, AgentResponseUpdate):
|
||||
continue
|
||||
|
||||
for content in chunk.contents:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from agent_framework import AgentProtocol, AgentRunResponse, AgentThread, HostedMCPTool
|
||||
from agent_framework import AgentProtocol, AgentResponse, AgentThread, HostedMCPTool
|
||||
from agent_framework.azure import AzureAIAgentClient
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
@@ -15,7 +15,7 @@ servers, including user approval workflows for function call security.
|
||||
"""
|
||||
|
||||
|
||||
async def handle_approvals_with_thread(query: str, agent: "AgentProtocol", thread: "AgentThread") -> AgentRunResponse:
|
||||
async def handle_approvals_with_thread(query: str, agent: "AgentProtocol", thread: "AgentThread") -> AgentResponse:
|
||||
"""Here we let the thread deal with the previous responses, and we just rerun with the approval."""
|
||||
from agent_framework import ChatMessage
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentRunResponseUpdate, ChatAgent, ChatResponseUpdate, HostedCodeInterpreterTool
|
||||
from agent_framework import AgentResponseUpdate, ChatAgent, ChatResponseUpdate, HostedCodeInterpreterTool
|
||||
from agent_framework.azure import AzureOpenAIAssistantsClient
|
||||
from azure.identity import AzureCliCredential
|
||||
from openai.types.beta.threads.runs import (
|
||||
@@ -21,7 +21,7 @@ for Python code execution and mathematical problem solving.
|
||||
"""
|
||||
|
||||
|
||||
def get_code_interpreter_chunk(chunk: AgentRunResponseUpdate) -> str | None:
|
||||
def get_code_interpreter_chunk(chunk: AgentResponseUpdate) -> str | None:
|
||||
"""Helper method to access code interpreter data."""
|
||||
if (
|
||||
isinstance(chunk.raw_representation, ChatResponseUpdate)
|
||||
|
||||
@@ -5,8 +5,8 @@ from collections.abc import AsyncIterable
|
||||
from typing import Any
|
||||
|
||||
from agent_framework import (
|
||||
AgentRunResponse,
|
||||
AgentRunResponseUpdate,
|
||||
AgentResponse,
|
||||
AgentResponseUpdate,
|
||||
AgentThread,
|
||||
BaseAgent,
|
||||
ChatMessage,
|
||||
@@ -60,7 +60,7 @@ class EchoAgent(BaseAgent):
|
||||
*,
|
||||
thread: AgentThread | None = None,
|
||||
**kwargs: Any,
|
||||
) -> AgentRunResponse:
|
||||
) -> AgentResponse:
|
||||
"""Execute the agent and return a complete response.
|
||||
|
||||
Args:
|
||||
@@ -69,7 +69,7 @@ class EchoAgent(BaseAgent):
|
||||
**kwargs: Additional keyword arguments.
|
||||
|
||||
Returns:
|
||||
An AgentRunResponse containing the agent's reply.
|
||||
An AgentResponse containing the agent's reply.
|
||||
"""
|
||||
# Normalize input messages to a list
|
||||
normalized_messages = self._normalize_messages(messages)
|
||||
@@ -93,7 +93,7 @@ class EchoAgent(BaseAgent):
|
||||
if thread is not None:
|
||||
await self._notify_thread_of_new_messages(thread, normalized_messages, response_message)
|
||||
|
||||
return AgentRunResponse(messages=[response_message])
|
||||
return AgentResponse(messages=[response_message])
|
||||
|
||||
async def run_stream(
|
||||
self,
|
||||
@@ -101,7 +101,7 @@ class EchoAgent(BaseAgent):
|
||||
*,
|
||||
thread: AgentThread | None = None,
|
||||
**kwargs: Any,
|
||||
) -> AsyncIterable[AgentRunResponseUpdate]:
|
||||
) -> AsyncIterable[AgentResponseUpdate]:
|
||||
"""Execute the agent and yield streaming response updates.
|
||||
|
||||
Args:
|
||||
@@ -110,7 +110,7 @@ class EchoAgent(BaseAgent):
|
||||
**kwargs: Additional keyword arguments.
|
||||
|
||||
Yields:
|
||||
AgentRunResponseUpdate objects containing chunks of the response.
|
||||
AgentResponseUpdate objects containing chunks of the response.
|
||||
"""
|
||||
# Normalize input messages to a list
|
||||
normalized_messages = self._normalize_messages(messages)
|
||||
@@ -131,7 +131,7 @@ class EchoAgent(BaseAgent):
|
||||
# Add space before word except for the first one
|
||||
chunk_text = f" {word}" if i > 0 else word
|
||||
|
||||
yield AgentRunResponseUpdate(
|
||||
yield AgentResponseUpdate(
|
||||
contents=[TextContent(text=chunk_text)],
|
||||
role=Role.ASSISTANT,
|
||||
)
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentRunResponseUpdate, ChatAgent, ChatResponseUpdate, HostedCodeInterpreterTool
|
||||
from agent_framework import AgentResponseUpdate, ChatAgent, ChatResponseUpdate, HostedCodeInterpreterTool
|
||||
from agent_framework.openai import OpenAIAssistantsClient
|
||||
from openai.types.beta.threads.runs import (
|
||||
CodeInterpreterToolCallDelta,
|
||||
@@ -20,7 +20,7 @@ for Python code execution and mathematical problem solving.
|
||||
"""
|
||||
|
||||
|
||||
def get_code_interpreter_chunk(chunk: AgentRunResponseUpdate) -> str | None:
|
||||
def get_code_interpreter_chunk(chunk: AgentResponseUpdate) -> str | None:
|
||||
"""Helper method to access code interpreter data."""
|
||||
if (
|
||||
isinstance(chunk.raw_representation, ChatResponseUpdate)
|
||||
|
||||
+5
-5
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import AgentRunResponse
|
||||
from agent_framework import AgentResponse
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -60,9 +60,9 @@ async def streaming_example() -> None:
|
||||
query = "Tell me about Tokyo, Japan"
|
||||
print(f"User: {query}")
|
||||
|
||||
# Get structured response from streaming agent using AgentRunResponse.from_agent_response_generator
|
||||
# This method collects all streaming updates and combines them into a single AgentRunResponse
|
||||
result = await AgentRunResponse.from_agent_response_generator(
|
||||
# Get structured response from streaming agent using AgentResponse.from_agent_response_generator
|
||||
# This method collects all streaming updates and combines them into a single AgentResponse
|
||||
result = await AgentResponse.from_agent_response_generator(
|
||||
agent.run_stream(query, response_format=OutputStruct),
|
||||
output_format_type=OutputStruct,
|
||||
)
|
||||
@@ -70,7 +70,7 @@ async def streaming_example() -> None:
|
||||
# Access the structured output directly from the response value
|
||||
if result.value:
|
||||
structured_data: OutputStruct = result.value # type: ignore
|
||||
print("Structured Output (from streaming with AgentRunResponse.from_agent_response_generator):")
|
||||
print("Structured Output (from streaming with AgentResponse.from_agent_response_generator):")
|
||||
print(f"City: {structured_data.city}")
|
||||
print(f"Description: {structured_data.description}")
|
||||
else:
|
||||
|
||||
+7
-10
@@ -19,9 +19,9 @@ import logging
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
import redis.asyncio as aioredis
|
||||
from agent_framework import AgentRunResponseUpdate
|
||||
import azure.functions as func
|
||||
import redis.asyncio as aioredis
|
||||
from agent_framework import AgentResponseUpdate
|
||||
from agent_framework.azure import (
|
||||
AgentCallbackContext,
|
||||
AgentFunctionApp,
|
||||
@@ -29,7 +29,6 @@ from agent_framework.azure import (
|
||||
AzureOpenAIChatClient,
|
||||
)
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
from redis_stream_response_handler import RedisStreamResponseHandler, StreamChunk
|
||||
from tools import get_local_events, get_weather_forecast
|
||||
|
||||
@@ -39,6 +38,7 @@ logger = logging.getLogger(__name__)
|
||||
REDIS_CONNECTION_STRING = os.environ.get("REDIS_CONNECTION_STRING", "redis://localhost:6379")
|
||||
REDIS_STREAM_TTL_MINUTES = int(os.environ.get("REDIS_STREAM_TTL_MINUTES", "10"))
|
||||
|
||||
|
||||
async def get_stream_handler() -> RedisStreamResponseHandler:
|
||||
"""Create a new Redis stream handler for each request.
|
||||
|
||||
@@ -70,7 +70,7 @@ class RedisStreamCallback(AgentResponseCallbackProtocol):
|
||||
|
||||
async def on_streaming_response_update(
|
||||
self,
|
||||
update: AgentRunResponseUpdate,
|
||||
update: AgentResponseUpdate,
|
||||
context: AgentCallbackContext,
|
||||
) -> None:
|
||||
"""Write streaming update to Redis Stream.
|
||||
@@ -291,24 +291,21 @@ def _format_chunk(chunk: StreamChunk, use_sse_format: bool) -> str:
|
||||
"""Format a text chunk."""
|
||||
if use_sse_format:
|
||||
return _format_sse_event("message", chunk.text, chunk.entry_id)
|
||||
else:
|
||||
return chunk.text
|
||||
return chunk.text
|
||||
|
||||
|
||||
def _format_end_of_stream(entry_id: str, use_sse_format: bool) -> str:
|
||||
"""Format end-of-stream marker."""
|
||||
if use_sse_format:
|
||||
return _format_sse_event("done", "[DONE]", entry_id)
|
||||
else:
|
||||
return "\n"
|
||||
return "\n"
|
||||
|
||||
|
||||
def _format_error(error: str, use_sse_format: bool) -> str:
|
||||
"""Format error message."""
|
||||
if use_sse_format:
|
||||
return _format_sse_event("error", error, None)
|
||||
else:
|
||||
return f"\n[Error: {error}]\n"
|
||||
return f"\n[Error: {error}]\n"
|
||||
|
||||
|
||||
def _format_sse_event(event_type: str, data: str, event_id: str | None = None) -> str:
|
||||
|
||||
+3
-3
@@ -12,8 +12,8 @@ import json
|
||||
import logging
|
||||
from typing import Any, cast
|
||||
|
||||
from agent_framework import AgentRunResponse
|
||||
import azure.functions as func
|
||||
from agent_framework import AgentResponse
|
||||
from agent_framework.azure import AgentFunctionApp, AzureOpenAIChatClient
|
||||
from azure.durable_functions import DurableOrchestrationClient, DurableOrchestrationContext
|
||||
from azure.identity import AzureCliCredential
|
||||
@@ -71,8 +71,8 @@ def multi_agent_concurrent_orchestration(context: DurableOrchestrationContext):
|
||||
# Execute both tasks concurrently using task_all
|
||||
task_results = yield context.task_all([physicist_task, chemist_task])
|
||||
|
||||
physicist_result = cast(AgentRunResponse, task_results[0])
|
||||
chemist_result = cast(AgentRunResponse, task_results[1])
|
||||
physicist_result = cast(AgentResponse, task_results[0])
|
||||
chemist_result = cast(AgentResponse, task_results[1])
|
||||
|
||||
return {
|
||||
"physicist": physicist_result.text,
|
||||
|
||||
@@ -40,7 +40,7 @@ def needs_editing(message: Any) -> bool:
|
||||
if not isinstance(message, AgentExecutorResponse):
|
||||
return False
|
||||
try:
|
||||
review = ReviewResult.model_validate_json(message.agent_run_response.text)
|
||||
review = ReviewResult.model_validate_json(message.agent_response.text)
|
||||
return review.score < 80
|
||||
except Exception:
|
||||
return False
|
||||
@@ -52,7 +52,7 @@ def is_approved(message: Any) -> bool:
|
||||
if not isinstance(message, AgentExecutorResponse):
|
||||
return True
|
||||
try:
|
||||
review = ReviewResult.model_validate_json(message.agent_run_response.text)
|
||||
review = ReviewResult.model_validate_json(message.agent_response.text)
|
||||
return review.score >= 80
|
||||
except Exception:
|
||||
return True
|
||||
|
||||
@@ -8,8 +8,8 @@ from typing import Annotated
|
||||
|
||||
from agent_framework import (
|
||||
AgentMiddleware,
|
||||
AgentResponse,
|
||||
AgentRunContext,
|
||||
AgentRunResponse,
|
||||
FunctionInvocationContext,
|
||||
)
|
||||
from agent_framework.azure import AzureAIAgentClient
|
||||
@@ -121,7 +121,7 @@ class CachingMiddleware(AgentMiddleware):
|
||||
"""Run-level caching middleware for expensive operations."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.cache: dict[str, AgentRunResponse] = {}
|
||||
self.cache: dict[str, AgentResponse] = {}
|
||||
|
||||
async def process(self, context: AgentRunContext, next: Callable[[AgentRunContext], Awaitable[None]]) -> None:
|
||||
# Create a simple cache key from the last message
|
||||
|
||||
@@ -8,8 +8,8 @@ from typing import Annotated
|
||||
|
||||
from agent_framework import (
|
||||
AgentMiddleware,
|
||||
AgentResponse,
|
||||
AgentRunContext,
|
||||
AgentRunResponse,
|
||||
ChatMessage,
|
||||
FunctionInvocationContext,
|
||||
FunctionMiddleware,
|
||||
@@ -58,7 +58,7 @@ class SecurityAgentMiddleware(AgentMiddleware):
|
||||
if "password" in query.lower() or "secret" in query.lower():
|
||||
print("[SecurityAgentMiddleware] Security Warning: Detected sensitive information, blocking request.")
|
||||
# Override the result with warning message
|
||||
context.result = AgentRunResponse(
|
||||
context.result = AgentResponse(
|
||||
messages=[
|
||||
ChatMessage(role=Role.ASSISTANT, text="Detected sensitive information, the request is blocked.")
|
||||
]
|
||||
|
||||
@@ -7,8 +7,8 @@ from typing import Annotated
|
||||
|
||||
from agent_framework import (
|
||||
AgentMiddleware,
|
||||
AgentResponse,
|
||||
AgentRunContext,
|
||||
AgentRunResponse,
|
||||
ChatMessage,
|
||||
Role,
|
||||
)
|
||||
@@ -57,7 +57,7 @@ class PreTerminationMiddleware(AgentMiddleware):
|
||||
print(f"[PreTerminationMiddleware] Blocked word '{blocked_word}' detected. Terminating request.")
|
||||
|
||||
# Set a custom response
|
||||
context.result = AgentRunResponse(
|
||||
context.result = AgentResponse(
|
||||
messages=[
|
||||
ChatMessage(
|
||||
role=Role.ASSISTANT,
|
||||
|
||||
@@ -6,9 +6,9 @@ from random import randint
|
||||
from typing import Annotated
|
||||
|
||||
from agent_framework import (
|
||||
AgentResponse,
|
||||
AgentResponseUpdate,
|
||||
AgentRunContext,
|
||||
AgentRunResponse,
|
||||
AgentRunResponseUpdate,
|
||||
ChatMessage,
|
||||
Role,
|
||||
TextContent,
|
||||
@@ -64,15 +64,15 @@ async def weather_override_middleware(
|
||||
|
||||
if context.is_streaming:
|
||||
# For streaming: create an async generator that yields chunks
|
||||
async def override_stream() -> AsyncIterable[AgentRunResponseUpdate]:
|
||||
async def override_stream() -> AsyncIterable[AgentResponseUpdate]:
|
||||
for chunk in chunks:
|
||||
yield AgentRunResponseUpdate(contents=[TextContent(text=chunk)])
|
||||
yield AgentResponseUpdate(contents=[TextContent(text=chunk)])
|
||||
|
||||
context.result = override_stream()
|
||||
else:
|
||||
# For non-streaming: just replace with the string message
|
||||
custom_message = "".join(chunks)
|
||||
context.result = AgentRunResponse(messages=[ChatMessage(role=Role.ASSISTANT, text=custom_message)])
|
||||
context.result = AgentResponse(messages=[ChatMessage(role=Role.ASSISTANT, text=custom_message)])
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
||||
@@ -25,7 +25,7 @@ import asyncio
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from agent_framework import AgentRunResponse, ChatAgent, ChatMessage, Role
|
||||
from agent_framework import AgentResponse, ChatAgent, ChatMessage, Role
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.microsoft import (
|
||||
PurviewChatPolicyMiddleware,
|
||||
@@ -158,10 +158,16 @@ async def run_with_agent_middleware() -> None:
|
||||
)
|
||||
|
||||
print("-- Agent Middleware Path --")
|
||||
first: AgentRunResponse = await agent.run(ChatMessage(role=Role.USER, text="Tell me a joke about a pirate.", additional_properties={"user_id": user_id}))
|
||||
first: AgentResponse = await agent.run(
|
||||
ChatMessage(role=Role.USER, text="Tell me a joke about a pirate.", additional_properties={"user_id": user_id})
|
||||
)
|
||||
print("First response (agent middleware):\n", first)
|
||||
|
||||
second: AgentRunResponse = await agent.run(ChatMessage(role=Role.USER, text="That was funny. Tell me another one.", additional_properties={"user_id": user_id}))
|
||||
second: AgentResponse = await agent.run(
|
||||
ChatMessage(
|
||||
role=Role.USER, text="That was funny. Tell me another one.", additional_properties={"user_id": user_id}
|
||||
)
|
||||
)
|
||||
print("Second response (agent middleware):\n", second)
|
||||
|
||||
|
||||
@@ -195,7 +201,7 @@ async def run_with_chat_middleware() -> None:
|
||||
)
|
||||
|
||||
print("-- Chat Middleware Path --")
|
||||
first: AgentRunResponse = await agent.run(
|
||||
first: AgentResponse = await agent.run(
|
||||
ChatMessage(
|
||||
role=Role.USER,
|
||||
text="Give me a short clean joke.",
|
||||
@@ -204,7 +210,7 @@ async def run_with_chat_middleware() -> None:
|
||||
)
|
||||
print("First response (chat middleware):\n", first)
|
||||
|
||||
second: AgentRunResponse = await agent.run(
|
||||
second: AgentResponse = await agent.run(
|
||||
ChatMessage(
|
||||
role=Role.USER,
|
||||
text="One more please.",
|
||||
@@ -245,12 +251,14 @@ async def run_with_custom_cache_provider() -> None:
|
||||
print("-- Custom Cache Provider Path --")
|
||||
print("Using SimpleDictCacheProvider")
|
||||
|
||||
first: AgentRunResponse = await agent.run(
|
||||
ChatMessage(role=Role.USER, text="Tell me a joke about a programmer.", additional_properties={"user_id": user_id})
|
||||
first: AgentResponse = await agent.run(
|
||||
ChatMessage(
|
||||
role=Role.USER, text="Tell me a joke about a programmer.", additional_properties={"user_id": user_id}
|
||||
)
|
||||
)
|
||||
print("First response (custom provider):\n", first)
|
||||
|
||||
second: AgentRunResponse = await agent.run(
|
||||
second: AgentResponse = await agent.run(
|
||||
ChatMessage(role=Role.USER, text="That's hilarious! One more?", additional_properties={"user_id": user_id})
|
||||
)
|
||||
print("Second response (custom provider):\n", second)
|
||||
@@ -285,12 +293,12 @@ async def run_with_custom_cache_provider() -> None:
|
||||
print("-- Default Cache Path --")
|
||||
print("Using default InMemoryCacheProvider with settings-based configuration")
|
||||
|
||||
first: AgentRunResponse = await agent.run(
|
||||
first: AgentResponse = await agent.run(
|
||||
ChatMessage(role=Role.USER, text="Tell me a joke about AI.", additional_properties={"user_id": user_id})
|
||||
)
|
||||
print("First response (default cache):\n", first)
|
||||
|
||||
second: AgentRunResponse = await agent.run(
|
||||
second: AgentResponse = await agent.run(
|
||||
ChatMessage(role=Role.USER, text="Nice! Another AI joke please.", additional_properties={"user_id": user_id})
|
||||
)
|
||||
print("Second response (default cache):\n", second)
|
||||
|
||||
@@ -34,7 +34,7 @@ async def main():
|
||||
Expected result:
|
||||
User: What is the current time?
|
||||
Result: {
|
||||
"type": "agent_run_response",
|
||||
"type": "agent_response",
|
||||
"messages": [
|
||||
{
|
||||
"type": "chat_message",
|
||||
|
||||
@@ -4,7 +4,7 @@ import asyncio
|
||||
from random import randrange
|
||||
from typing import TYPE_CHECKING, Annotated, Any
|
||||
|
||||
from agent_framework import AgentRunResponse, ChatAgent, ChatMessage, ai_function
|
||||
from agent_framework import AgentResponse, ChatAgent, ChatMessage, ai_function
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -39,7 +39,7 @@ def get_weather_detail(location: Annotated[str, "The city and state, e.g. San Fr
|
||||
)
|
||||
|
||||
|
||||
async def handle_approvals(query: str, agent: "AgentProtocol") -> AgentRunResponse:
|
||||
async def handle_approvals(query: str, agent: "AgentProtocol") -> AgentResponse:
|
||||
"""Handle function call approvals.
|
||||
|
||||
When we don't have a thread, we need to ensure we include the original query,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
|
||||
from agent_framework import (
|
||||
AgentRunResponse,
|
||||
AgentResponse,
|
||||
ChatAgent,
|
||||
Executor,
|
||||
WorkflowBuilder,
|
||||
@@ -83,9 +83,9 @@ async def main():
|
||||
.build()
|
||||
)
|
||||
|
||||
output: AgentRunResponse | None = None
|
||||
output: AgentResponse | None = None
|
||||
async for event in workflow.run_stream("hello world"):
|
||||
if isinstance(event, WorkflowOutputEvent) and isinstance(event.data, AgentRunResponse):
|
||||
if isinstance(event, WorkflowOutputEvent) and isinstance(event.data, AgentResponse):
|
||||
output = event.data
|
||||
|
||||
if output:
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ from typing import Final
|
||||
from agent_framework import (
|
||||
AgentExecutorRequest,
|
||||
AgentExecutorResponse,
|
||||
AgentRunResponse,
|
||||
AgentResponse,
|
||||
AgentRunUpdateEvent,
|
||||
ChatMessage,
|
||||
Role,
|
||||
@@ -70,7 +70,7 @@ async def enrich_with_references(
|
||||
ctx: WorkflowContext[AgentExecutorRequest],
|
||||
) -> None:
|
||||
"""Inject a follow-up user instruction that adds an external note for the next agent."""
|
||||
conversation = list(draft.full_conversation or draft.agent_run_response.messages)
|
||||
conversation = list(draft.full_conversation or draft.agent_response.messages)
|
||||
original_prompt = next((message.text for message in conversation if message.role == Role.USER), "")
|
||||
external_note = _lookup_external_note(original_prompt) or (
|
||||
"No additional references were found. Please refine the previous assistant response for clarity."
|
||||
@@ -134,7 +134,7 @@ async def main() -> None:
|
||||
elif isinstance(event, WorkflowOutputEvent):
|
||||
print("\n\n===== Final Output =====")
|
||||
response = event.data
|
||||
if isinstance(response, AgentRunResponse):
|
||||
if isinstance(response, AgentResponse):
|
||||
print(response.text or "(empty response)")
|
||||
else:
|
||||
print(response if response is not None else "No response generated.")
|
||||
|
||||
+5
-5
@@ -8,7 +8,7 @@ from typing import Annotated
|
||||
from agent_framework import (
|
||||
AgentExecutorRequest,
|
||||
AgentExecutorResponse,
|
||||
AgentRunResponse,
|
||||
AgentResponse,
|
||||
AgentRunUpdateEvent,
|
||||
ChatAgent,
|
||||
ChatMessage,
|
||||
@@ -102,12 +102,12 @@ class Coordinator(Executor):
|
||||
async def on_writer_response(
|
||||
self,
|
||||
draft: AgentExecutorResponse,
|
||||
ctx: WorkflowContext[Never, AgentRunResponse],
|
||||
ctx: WorkflowContext[Never, AgentResponse],
|
||||
) -> None:
|
||||
"""Handle responses from the other two agents in the workflow."""
|
||||
if draft.executor_id == self.final_editor_id:
|
||||
# Final editor response; yield output directly.
|
||||
await ctx.yield_output(draft.agent_run_response)
|
||||
await ctx.yield_output(draft.agent_response)
|
||||
return
|
||||
|
||||
# Writer agent response; request human feedback.
|
||||
@@ -117,8 +117,8 @@ class Coordinator(Executor):
|
||||
if draft.full_conversation is not None:
|
||||
conversation = list(draft.full_conversation)
|
||||
else:
|
||||
conversation = list(draft.agent_run_response.messages)
|
||||
draft_text = draft.agent_run_response.text.strip()
|
||||
conversation = list(draft.agent_response.messages)
|
||||
draft_text = draft.agent_response.text.strip()
|
||||
if not draft_text:
|
||||
draft_text = "No draft text was produced."
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import asyncio
|
||||
from typing import Annotated
|
||||
|
||||
from agent_framework import (
|
||||
AgentRunResponse,
|
||||
AgentResponse,
|
||||
ChatAgent,
|
||||
ChatMessage,
|
||||
FunctionCallContent,
|
||||
@@ -101,7 +101,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
return triage_agent, refund_agent, order_agent, return_agent
|
||||
|
||||
|
||||
def handle_response_and_requests(response: AgentRunResponse) -> dict[str, HandoffAgentUserRequest]:
|
||||
def handle_response_and_requests(response: AgentResponse) -> dict[str, HandoffAgentUserRequest]:
|
||||
"""Process agent response messages and extract any user requests.
|
||||
|
||||
This function inspects the agent response and:
|
||||
@@ -109,7 +109,7 @@ def handle_response_and_requests(response: AgentRunResponse) -> dict[str, Handof
|
||||
- Collects HandoffAgentUserRequest instances for response handling
|
||||
|
||||
Args:
|
||||
response: The AgentRunResponse from the agent run call.
|
||||
response: The AgentResponse from the agent run call.
|
||||
|
||||
Returns:
|
||||
A dictionary mapping request IDs to HandoffAgentUserRequest instances.
|
||||
|
||||
@@ -66,8 +66,8 @@ class Evaluator(Executor):
|
||||
ctx: Workflow context for yielding the final output string
|
||||
"""
|
||||
target_text = "1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89"
|
||||
correctness = target_text in message.agent_run_response.text
|
||||
consumption = message.agent_run_response.usage_details
|
||||
correctness = target_text in message.agent_response.text
|
||||
consumption = message.agent_response.usage_details
|
||||
await ctx.yield_output(f"Correctness: {correctness}, Consumption: {consumption}")
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ from dataclasses import dataclass
|
||||
from uuid import uuid4
|
||||
|
||||
from agent_framework import (
|
||||
AgentRunResponseUpdate,
|
||||
AgentResponseUpdate,
|
||||
AgentRunUpdateEvent,
|
||||
ChatClientProtocol,
|
||||
ChatMessage,
|
||||
@@ -161,7 +161,7 @@ class Worker(Executor):
|
||||
|
||||
# Emit approved result to external consumer via AgentRunUpdateEvent.
|
||||
await ctx.add_event(
|
||||
AgentRunUpdateEvent(self.id, data=AgentRunResponseUpdate(contents=contents, role=Role.ASSISTANT))
|
||||
AgentRunUpdateEvent(self.id, data=AgentResponseUpdate(contents=contents, role=Role.ASSISTANT))
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ class ReviewGateway(Executor):
|
||||
await ctx.request_info(
|
||||
request_data=HumanApprovalRequest(
|
||||
prompt="Review the draft. Reply 'approve' or provide edit instructions.",
|
||||
draft=response.agent_run_response.text,
|
||||
draft=response.agent_response.text,
|
||||
iteration=self._iteration,
|
||||
),
|
||||
response_type=str,
|
||||
|
||||
@@ -85,7 +85,7 @@ def get_condition(expected_result: bool):
|
||||
try:
|
||||
# Prefer parsing a structured DetectionResult from the agent JSON text.
|
||||
# Using model_validate_json ensures type safety and raises if the shape is wrong.
|
||||
detection = DetectionResult.model_validate_json(message.agent_run_response.text)
|
||||
detection = DetectionResult.model_validate_json(message.agent_response.text)
|
||||
# Route only when the spam flag matches the expected path.
|
||||
return detection.is_spam == expected_result
|
||||
except Exception:
|
||||
@@ -99,14 +99,14 @@ def get_condition(expected_result: bool):
|
||||
@executor(id="send_email")
|
||||
async def handle_email_response(response: AgentExecutorResponse, ctx: WorkflowContext[Never, str]) -> None:
|
||||
# Downstream of the email assistant. Parse a validated EmailResponse and yield the workflow output.
|
||||
email_response = EmailResponse.model_validate_json(response.agent_run_response.text)
|
||||
email_response = EmailResponse.model_validate_json(response.agent_response.text)
|
||||
await ctx.yield_output(f"Email sent:\n{email_response.response}")
|
||||
|
||||
|
||||
@executor(id="handle_spam")
|
||||
async def handle_spam_classifier_response(response: AgentExecutorResponse, ctx: WorkflowContext[Never, str]) -> None:
|
||||
# Spam path. Confirm the DetectionResult and yield the workflow output. Guard against accidental non spam input.
|
||||
detection = DetectionResult.model_validate_json(response.agent_run_response.text)
|
||||
detection = DetectionResult.model_validate_json(response.agent_response.text)
|
||||
if detection.is_spam:
|
||||
await ctx.yield_output(f"Email marked as spam: {detection.reason}")
|
||||
else:
|
||||
@@ -123,7 +123,7 @@ async def to_email_assistant_request(
|
||||
Extracts DetectionResult.email_content and forwards it as a user message.
|
||||
"""
|
||||
# Bridge executor. Converts a structured DetectionResult into a ChatMessage and forwards it as a new request.
|
||||
detection = DetectionResult.model_validate_json(response.agent_run_response.text)
|
||||
detection = DetectionResult.model_validate_json(response.agent_response.text)
|
||||
user_msg = ChatMessage(Role.USER, text=detection.email_content)
|
||||
await ctx.send_message(AgentExecutorRequest(messages=[user_msg], should_respond=True))
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ async def store_email(email_text: str, ctx: WorkflowContext[AgentExecutorRequest
|
||||
|
||||
@executor(id="to_analysis_result")
|
||||
async def to_analysis_result(response: AgentExecutorResponse, ctx: WorkflowContext[AnalysisResult]) -> None:
|
||||
parsed = AnalysisResultAgent.model_validate_json(response.agent_run_response.text)
|
||||
parsed = AnalysisResultAgent.model_validate_json(response.agent_response.text)
|
||||
email_id: str = await ctx.get_shared_state(CURRENT_EMAIL_ID_KEY)
|
||||
email: Email = await ctx.get_shared_state(f"{EMAIL_STATE_PREFIX}{email_id}")
|
||||
await ctx.send_message(
|
||||
@@ -125,7 +125,7 @@ async def submit_to_email_assistant(analysis: AnalysisResult, ctx: WorkflowConte
|
||||
|
||||
@executor(id="finalize_and_send")
|
||||
async def finalize_and_send(response: AgentExecutorResponse, ctx: WorkflowContext[Never, str]) -> None:
|
||||
parsed = EmailResponse.model_validate_json(response.agent_run_response.text)
|
||||
parsed = EmailResponse.model_validate_json(response.agent_response.text)
|
||||
await ctx.yield_output(f"Email sent: {parsed.response}")
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ async def summarize_email(analysis: AnalysisResult, ctx: WorkflowContext[AgentEx
|
||||
|
||||
@executor(id="merge_summary")
|
||||
async def merge_summary(response: AgentExecutorResponse, ctx: WorkflowContext[AnalysisResult]) -> None:
|
||||
summary = EmailSummaryModel.model_validate_json(response.agent_run_response.text)
|
||||
summary = EmailSummaryModel.model_validate_json(response.agent_response.text)
|
||||
email_id: str = await ctx.get_shared_state(CURRENT_EMAIL_ID_KEY)
|
||||
email: Email = await ctx.get_shared_state(f"{EMAIL_STATE_PREFIX}{email_id}")
|
||||
# Build an AnalysisResult mirroring to_analysis_result but with summary
|
||||
|
||||
@@ -106,7 +106,7 @@ class ParseJudgeResponse(Executor):
|
||||
|
||||
@handler
|
||||
async def parse(self, response: AgentExecutorResponse, ctx: WorkflowContext[NumberSignal]) -> None:
|
||||
text = response.agent_run_response.text.strip().upper()
|
||||
text = response.agent_response.text.strip().upper()
|
||||
if "MATCHED" in text:
|
||||
await ctx.send_message(NumberSignal.MATCHED)
|
||||
elif "ABOVE" in text and "BELOW" not in text:
|
||||
|
||||
@@ -106,7 +106,7 @@ async def store_email(email_text: str, ctx: WorkflowContext[AgentExecutorRequest
|
||||
@executor(id="to_detection_result")
|
||||
async def to_detection_result(response: AgentExecutorResponse, ctx: WorkflowContext[DetectionResult]) -> None:
|
||||
# Parse the detector JSON into a typed model. Attach the current email id for downstream lookups.
|
||||
parsed = DetectionResultAgent.model_validate_json(response.agent_run_response.text)
|
||||
parsed = DetectionResultAgent.model_validate_json(response.agent_response.text)
|
||||
email_id: str = await ctx.get_shared_state(CURRENT_EMAIL_ID_KEY)
|
||||
await ctx.send_message(DetectionResult(spam_decision=parsed.spam_decision, reason=parsed.reason, email_id=email_id))
|
||||
|
||||
@@ -127,7 +127,7 @@ async def submit_to_email_assistant(detection: DetectionResult, ctx: WorkflowCon
|
||||
@executor(id="finalize_and_send")
|
||||
async def finalize_and_send(response: AgentExecutorResponse, ctx: WorkflowContext[Never, str]) -> None:
|
||||
# Terminal step for the drafting branch. Yield the email response as output.
|
||||
parsed = EmailResponse.model_validate_json(response.agent_run_response.text)
|
||||
parsed = EmailResponse.model_validate_json(response.agent_response.text)
|
||||
await ctx.yield_output(f"Email sent: {parsed.response}")
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -208,7 +208,7 @@ async def conclude_workflow(
|
||||
ctx: WorkflowContext[Never, str],
|
||||
) -> None:
|
||||
"""Conclude the workflow by yielding the final email response."""
|
||||
await ctx.yield_output(email_response.agent_run_response.text)
|
||||
await ctx.yield_output(email_response.agent_response.text)
|
||||
|
||||
|
||||
def create_email_writer_agent() -> ChatAgent:
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ async def aggregate_with_synthesis(results: list[AgentExecutorResponse]) -> Any:
|
||||
|
||||
for r in results:
|
||||
try:
|
||||
messages = getattr(r.agent_run_response, "messages", [])
|
||||
messages = getattr(r.agent_response, "messages", [])
|
||||
final_text = messages[-1].text if messages and hasattr(messages[-1], "text") else "(no content)"
|
||||
expert_sections.append(f"{getattr(r, 'executor_id', 'analyst')}:\n{final_text}")
|
||||
|
||||
@@ -161,7 +161,7 @@ async def main() -> None:
|
||||
print("\n" + "-" * 40)
|
||||
print("INPUT REQUESTED")
|
||||
print(
|
||||
f"Agent {event.source_executor_id} just responded with: '{event.data.agent_run_response.text}'. "
|
||||
f"Agent {event.source_executor_id} just responded with: '{event.data.agent_response.text}'. "
|
||||
"Please provide your feedback."
|
||||
)
|
||||
print("-" * 40)
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ import asyncio
|
||||
from agent_framework import (
|
||||
AgentExecutorResponse,
|
||||
AgentRequestInfoResponse,
|
||||
AgentRunResponse,
|
||||
AgentResponse,
|
||||
AgentRunUpdateEvent,
|
||||
ChatMessage,
|
||||
GroupChatBuilder,
|
||||
@@ -138,8 +138,8 @@ async def main() -> None:
|
||||
print(f"About to call agent: {event.source_executor_id}")
|
||||
print("-" * 40)
|
||||
print("Conversation context:")
|
||||
agent_run_response: AgentRunResponse = event.data.agent_run_response
|
||||
messages: list[ChatMessage] = agent_run_response.messages
|
||||
agent_response: AgentResponse = event.data.agent_response
|
||||
messages: list[ChatMessage] = agent_response.messages
|
||||
recent: list[ChatMessage] = messages[-3:] if len(messages) > 3 else messages # type: ignore
|
||||
for msg in recent:
|
||||
name = msg.author_name or "unknown"
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ class TurnManager(Executor):
|
||||
2) Request info with a HumanFeedbackRequest as the payload.
|
||||
"""
|
||||
# Parse structured model output
|
||||
text = result.agent_run_response.text
|
||||
text = result.agent_response.text
|
||||
last_guess = GuessOutput.model_validate_json(text).guess
|
||||
|
||||
# Craft a precise human prompt that defines higher and lower relative to the agent's guess.
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ async def main() -> None:
|
||||
print("\n" + "-" * 40)
|
||||
print("REQUEST INFO: INPUT REQUESTED")
|
||||
print(
|
||||
f"Agent {event.source_executor_id} just responded with: '{event.data.agent_run_response.text}'. "
|
||||
f"Agent {event.source_executor_id} just responded with: '{event.data.agent_response.text}'. "
|
||||
"Please provide your feedback."
|
||||
)
|
||||
print("-" * 40)
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ async def main() -> None:
|
||||
expert_sections: list[str] = []
|
||||
for r in results:
|
||||
try:
|
||||
messages = getattr(r.agent_run_response, "messages", [])
|
||||
messages = getattr(r.agent_response, "messages", [])
|
||||
final_text = messages[-1].text if messages and hasattr(messages[-1], "text") else "(no content)"
|
||||
expert_sections.append(f"{getattr(r, 'executor_id', 'expert')}:\n{final_text}")
|
||||
except Exception as e:
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ class SummarizationExecutor(Executor):
|
||||
expert_sections: list[str] = []
|
||||
for r in results:
|
||||
try:
|
||||
messages = getattr(r.agent_run_response, "messages", [])
|
||||
messages = getattr(r.agent_response, "messages", [])
|
||||
final_text = messages[-1].text if messages and hasattr(messages[-1], "text") else "(no content)"
|
||||
expert_sections.append(f"{getattr(r, 'executor_id', 'expert')}:\n{final_text}")
|
||||
except Exception as e:
|
||||
|
||||
@@ -5,7 +5,7 @@ import logging
|
||||
from typing import cast
|
||||
|
||||
from agent_framework import (
|
||||
AgentRunResponseUpdate,
|
||||
AgentResponseUpdate,
|
||||
AgentRunUpdateEvent,
|
||||
ChatAgent,
|
||||
ChatMessage,
|
||||
@@ -82,7 +82,7 @@ last_response_id: str | None = None
|
||||
def _display_event(event: WorkflowEvent) -> None:
|
||||
"""Print the final conversation snapshot from workflow output events."""
|
||||
if isinstance(event, AgentRunUpdateEvent) and event.data:
|
||||
update: AgentRunResponseUpdate = event.data
|
||||
update: AgentResponseUpdate = event.data
|
||||
if not update.text:
|
||||
return
|
||||
global last_response_id
|
||||
|
||||
+3
-3
@@ -5,8 +5,8 @@ import logging
|
||||
from typing import Annotated, cast
|
||||
|
||||
from agent_framework import (
|
||||
AgentResponse,
|
||||
AgentRunEvent,
|
||||
AgentRunResponse,
|
||||
ChatAgent,
|
||||
ChatMessage,
|
||||
HandoffAgentUserRequest,
|
||||
@@ -163,14 +163,14 @@ def _handle_events(events: list[WorkflowEvent]) -> list[RequestInfoEvent]:
|
||||
return requests
|
||||
|
||||
|
||||
def _print_handoff_agent_user_request(response: AgentRunResponse) -> None:
|
||||
def _print_handoff_agent_user_request(response: AgentResponse) -> None:
|
||||
"""Display the agent's response messages when requesting user input.
|
||||
|
||||
This will happen when an agent generates a response that doesn't trigger
|
||||
a handoff, i.e., the agent is asking the user for more information.
|
||||
|
||||
Args:
|
||||
response: The AgentRunResponse from the agent requesting user input
|
||||
response: The AgentResponse from the agent requesting user input
|
||||
"""
|
||||
if not response.messages:
|
||||
raise RuntimeError("Cannot print agent responses: response has no messages.")
|
||||
|
||||
@@ -4,8 +4,8 @@ import asyncio
|
||||
from typing import Annotated, cast
|
||||
|
||||
from agent_framework import (
|
||||
AgentResponse,
|
||||
AgentRunEvent,
|
||||
AgentRunResponse,
|
||||
ChatAgent,
|
||||
ChatMessage,
|
||||
HandoffAgentUserRequest,
|
||||
@@ -158,14 +158,14 @@ def _handle_events(events: list[WorkflowEvent]) -> list[RequestInfoEvent]:
|
||||
return requests
|
||||
|
||||
|
||||
def _print_handoff_agent_user_request(response: AgentRunResponse) -> None:
|
||||
def _print_handoff_agent_user_request(response: AgentResponse) -> None:
|
||||
"""Display the agent's response messages when requesting user input.
|
||||
|
||||
This will happen when an agent generates a response that doesn't trigger
|
||||
a handoff, i.e., the agent is asking the user for more information.
|
||||
|
||||
Args:
|
||||
response: The AgentRunResponse from the agent requesting user input
|
||||
response: The AgentResponse from the agent requesting user input
|
||||
"""
|
||||
if not response.messages:
|
||||
raise RuntimeError("Cannot print agent responses: response has no messages.")
|
||||
|
||||
@@ -36,7 +36,7 @@ Show how to construct a parallel branch pattern in workflows. Demonstrate:
|
||||
Prerequisites:
|
||||
- Familiarity with WorkflowBuilder, executors, edges, events, and streaming runs.
|
||||
- Azure OpenAI access configured for AzureOpenAIChatClient. Log in with Azure CLI and set any required environment variables.
|
||||
- Comfort reading AgentExecutorResponse.agent_run_response.text for assistant output aggregation.
|
||||
- Comfort reading AgentExecutorResponse.agent_response.text for assistant output aggregation.
|
||||
"""
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ class AggregateInsights(Executor):
|
||||
# Map responses to text by executor id for a simple, predictable demo.
|
||||
by_id: dict[str, str] = {}
|
||||
for r in results:
|
||||
# AgentExecutorResponse.agent_run_response.text is the assistant text produced by the agent.
|
||||
by_id[r.executor_id] = r.agent_run_response.text
|
||||
# AgentExecutorResponse.agent_response.text is the assistant text produced by the agent.
|
||||
by_id[r.executor_id] = r.agent_response.text
|
||||
|
||||
research_text = by_id.get("researcher", "")
|
||||
marketing_text = by_id.get("marketer", "")
|
||||
|
||||
+2
-2
@@ -117,7 +117,7 @@ async def to_detection_result(response: AgentExecutorResponse, ctx: WorkflowCont
|
||||
2) Retrieve the current email_id from shared state.
|
||||
3) Send a typed DetectionResult for conditional routing.
|
||||
"""
|
||||
parsed = DetectionResultAgent.model_validate_json(response.agent_run_response.text)
|
||||
parsed = DetectionResultAgent.model_validate_json(response.agent_response.text)
|
||||
email_id: str = await ctx.get_shared_state(CURRENT_EMAIL_ID_KEY)
|
||||
await ctx.send_message(DetectionResult(is_spam=parsed.is_spam, reason=parsed.reason, email_id=email_id))
|
||||
|
||||
@@ -142,7 +142,7 @@ async def submit_to_email_assistant(detection: DetectionResult, ctx: WorkflowCon
|
||||
@executor(id="finalize_and_send")
|
||||
async def finalize_and_send(response: AgentExecutorResponse, ctx: WorkflowContext[Never, str]) -> None:
|
||||
"""Validate the drafted reply and yield the final output."""
|
||||
parsed = EmailResponse.model_validate_json(response.agent_run_response.text)
|
||||
parsed = EmailResponse.model_validate_json(response.agent_response.text)
|
||||
await ctx.yield_output(f"Email sent: {parsed.response}")
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -61,8 +61,8 @@ class AggregateInsights(Executor):
|
||||
# Map responses to text by executor id for a simple, predictable demo.
|
||||
by_id: dict[str, str] = {}
|
||||
for r in results:
|
||||
# AgentExecutorResponse.agent_run_response.text contains concatenated assistant text
|
||||
by_id[r.executor_id] = r.agent_run_response.text
|
||||
# AgentExecutorResponse.agent_response.text contains concatenated assistant text
|
||||
by_id[r.executor_id] = r.agent_response.text
|
||||
|
||||
research_text = by_id.get("researcher", "")
|
||||
marketing_text = by_id.get("marketer", "")
|
||||
|
||||
Reference in New Issue
Block a user