Skip to content

Commit 80fd3e9

Browse files
committed
Merge branch 'main' into add-dapr-session
2 parents d1b4720 + 4ba2e8a commit 80fd3e9

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

examples/basic/lifecycle_example.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import random
3-
from typing import Any, Optional
3+
from typing import Any, Optional, cast
44

55
from pydantic import BaseModel
66

@@ -15,6 +15,7 @@
1515
function_tool,
1616
)
1717
from agents.items import ModelResponse, TResponseInputItem
18+
from agents.tool_context import ToolContext
1819

1920

2021
class LoggingHooks(AgentHooks[Any]):
@@ -71,16 +72,22 @@ async def on_agent_end(self, context: RunContextWrapper, agent: Agent, output: A
7172

7273
async def on_tool_start(self, context: RunContextWrapper, agent: Agent, tool: Tool) -> None:
7374
self.event_counter += 1
75+
# While this type cast is not ideal,
76+
# we don't plan to change the context arg type in the near future for backwards compatibility.
77+
tool_context = cast(ToolContext[Any], context)
7478
print(
75-
f"### {self.event_counter}: Tool {tool.name} started. name={context.tool_name}, call_id={context.tool_call_id}, args={context.tool_arguments}. Usage: {self._usage_to_str(context.usage)}" # type: ignore[attr-defined]
79+
f"### {self.event_counter}: Tool {tool.name} started. name={tool_context.tool_name}, call_id={tool_context.tool_call_id}, args={tool_context.tool_arguments}. Usage: {self._usage_to_str(tool_context.usage)}"
7680
)
7781

7882
async def on_tool_end(
7983
self, context: RunContextWrapper, agent: Agent, tool: Tool, result: str
8084
) -> None:
8185
self.event_counter += 1
86+
# While this type cast is not ideal,
87+
# we don't plan to change the context arg type in the near future for backwards compatibility.
88+
tool_context = cast(ToolContext[Any], context)
8289
print(
83-
f"### {self.event_counter}: Tool {tool.name} finished. result={result}, name={context.tool_name}, call_id={context.tool_call_id}, args={context.tool_arguments}. Usage: {self._usage_to_str(context.usage)}" # type: ignore[attr-defined]
90+
f"### {self.event_counter}: Tool {tool.name} finished. result={result}, name={tool_context.tool_name}, call_id={tool_context.tool_call_id}, args={tool_context.tool_arguments}. Usage: {self._usage_to_str(tool_context.usage)}"
8491
)
8592

8693
async def on_handoff(

src/agents/realtime/openai_realtime.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,9 @@ async def _handle_ws_event(self, event: dict[str, Any]):
629629
)
630630
if not automatic_response_cancellation_enabled:
631631
await self._cancel_response()
632-
# Avoid sending conversation.item.truncate here; when GA is set to
633-
# interrupt on VAD start, the server will handle truncation.
632+
# Avoid sending conversation.item.truncate here. When the session's
633+
# turn_detection.interrupt_response is enabled (GA default), the server emits
634+
# conversation.item.truncated after the VAD start and takes care of history updates.
634635
elif parsed.type == "response.created":
635636
self._ongoing_response = True
636637
await self._emit_event(RealtimeModelTurnStartedEvent())

0 commit comments

Comments
 (0)