renamed all (#3207)

This commit is contained in:
Eduard van Valkenburg
2026-01-14 06:54:07 +01:00
committed by GitHub
Unverified
parent 1ae0b09e42
commit d8cf8361bd
125 changed files with 1024 additions and 1027 deletions
@@ -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:
@@ -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.")
@@ -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}")
@@ -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
@@ -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}")
@@ -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:
@@ -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)
@@ -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"
@@ -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.
@@ -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)
@@ -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:
@@ -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
@@ -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", "")
@@ -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}")
@@ -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", "")