mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Add type annotations for AgentRunEvent and AgentRunUpdateEvent data attributes (#2589)
* Add type annotations for AgentRunEvent and AgentRunUpdateEvent data attributes * Fix unnecessary cast after typing improvement * Mcp pkg update introduced type change. Fix it. * update opentelemetry deps to 1.39.0 and use LogRecordExporter for type compatibility
This commit is contained in:
committed by
GitHub
Unverified
parent
9c2e800189
commit
a597a925cb
@@ -0,0 +1,43 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
"""Tests for AgentRunEvent and AgentRunUpdateEvent type annotations."""
|
||||
|
||||
from agent_framework import AgentRunResponse, AgentRunResponseUpdate, ChatMessage, Role
|
||||
from agent_framework._workflows._events import AgentRunEvent, AgentRunUpdateEvent
|
||||
|
||||
|
||||
def test_agent_run_event_data_type() -> None:
|
||||
"""Verify AgentRunEvent.data is typed as AgentRunResponse | None."""
|
||||
response = AgentRunResponse(messages=[ChatMessage(role=Role.ASSISTANT, text="Hello")])
|
||||
event = AgentRunEvent(executor_id="test", data=response)
|
||||
|
||||
# This assignment should pass type checking without a cast
|
||||
data: AgentRunResponse | None = event.data
|
||||
assert data is not None
|
||||
assert data.text == "Hello"
|
||||
|
||||
|
||||
def test_agent_run_event_data_none() -> None:
|
||||
"""Verify AgentRunEvent.data can be None."""
|
||||
event = AgentRunEvent(executor_id="test")
|
||||
|
||||
data: AgentRunResponse | None = event.data
|
||||
assert data is None
|
||||
|
||||
|
||||
def test_agent_run_update_event_data_type() -> None:
|
||||
"""Verify AgentRunUpdateEvent.data is typed as AgentRunResponseUpdate | None."""
|
||||
update = AgentRunResponseUpdate()
|
||||
event = AgentRunUpdateEvent(executor_id="test", data=update)
|
||||
|
||||
# This assignment should pass type checking without a cast
|
||||
data: AgentRunResponseUpdate | None = event.data
|
||||
assert data is not None
|
||||
|
||||
|
||||
def test_agent_run_update_event_data_none() -> None:
|
||||
"""Verify AgentRunUpdateEvent.data can be None."""
|
||||
event = AgentRunUpdateEvent(executor_id="test")
|
||||
|
||||
data: AgentRunResponseUpdate | None = event.data
|
||||
assert data is None
|
||||
Reference in New Issue
Block a user