12
12
13
13
from opentelemetry .trace import NoOpTracer , use_span
14
14
from pydantic .json_schema import GenerateJsonSchema
15
- from typing_extensions import Literal , Never , TypeGuard , TypeVar , deprecated
15
+ from typing_extensions import Literal , Never , TypeIs , TypeVar , deprecated
16
16
17
17
from pydantic_graph import End , Graph , GraphRun , GraphRunContext
18
18
from pydantic_graph ._utils import get_event_loop
@@ -459,7 +459,7 @@ def iter(
459
459
self ,
460
460
user_prompt : str | Sequence [_messages .UserContent ] | None ,
461
461
* ,
462
- output_type : type [ RunOutputDataT ] | ToolOutput [ RunOutputDataT ] | None = None ,
462
+ output_type : None = None ,
463
463
message_history : list [_messages .ModelMessage ] | None = None ,
464
464
model : models .Model | models .KnownModelName | str | None = None ,
465
465
deps : AgentDepsT = None ,
@@ -468,7 +468,23 @@ def iter(
468
468
usage : _usage .Usage | None = None ,
469
469
infer_name : bool = True ,
470
470
** _deprecated_kwargs : Never ,
471
- ) -> AbstractAsyncContextManager [AgentRun [AgentDepsT , Any ]]: ...
471
+ ) -> AbstractAsyncContextManager [AgentRun [AgentDepsT , OutputDataT ]]: ...
472
+
473
+ @overload
474
+ def iter (
475
+ self ,
476
+ user_prompt : str | Sequence [_messages .UserContent ] | None ,
477
+ * ,
478
+ output_type : type [RunOutputDataT ] | ToolOutput [RunOutputDataT ],
479
+ message_history : list [_messages .ModelMessage ] | None = None ,
480
+ model : models .Model | models .KnownModelName | str | None = None ,
481
+ deps : AgentDepsT = None ,
482
+ model_settings : ModelSettings | None = None ,
483
+ usage_limits : _usage .UsageLimits | None = None ,
484
+ usage : _usage .Usage | None = None ,
485
+ infer_name : bool = True ,
486
+ ** _deprecated_kwargs : Never ,
487
+ ) -> AbstractAsyncContextManager [AgentRun [AgentDepsT , RunOutputDataT ]]: ...
472
488
473
489
@overload
474
490
@deprecated ('`result_type` is deprecated, use `output_type` instead.' )
@@ -1621,7 +1637,7 @@ def _prepare_output_schema(
1621
1637
@staticmethod
1622
1638
def is_model_request_node (
1623
1639
node : _agent_graph .AgentNode [T , S ] | End [result .FinalResult [S ]],
1624
- ) -> TypeGuard [_agent_graph .ModelRequestNode [T , S ]]:
1640
+ ) -> TypeIs [_agent_graph .ModelRequestNode [T , S ]]:
1625
1641
"""Check if the node is a `ModelRequestNode`, narrowing the type if it is.
1626
1642
1627
1643
This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
@@ -1631,7 +1647,7 @@ def is_model_request_node(
1631
1647
@staticmethod
1632
1648
def is_call_tools_node (
1633
1649
node : _agent_graph .AgentNode [T , S ] | End [result .FinalResult [S ]],
1634
- ) -> TypeGuard [_agent_graph .CallToolsNode [T , S ]]:
1650
+ ) -> TypeIs [_agent_graph .CallToolsNode [T , S ]]:
1635
1651
"""Check if the node is a `CallToolsNode`, narrowing the type if it is.
1636
1652
1637
1653
This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
@@ -1641,7 +1657,7 @@ def is_call_tools_node(
1641
1657
@staticmethod
1642
1658
def is_user_prompt_node (
1643
1659
node : _agent_graph .AgentNode [T , S ] | End [result .FinalResult [S ]],
1644
- ) -> TypeGuard [_agent_graph .UserPromptNode [T , S ]]:
1660
+ ) -> TypeIs [_agent_graph .UserPromptNode [T , S ]]:
1645
1661
"""Check if the node is a `UserPromptNode`, narrowing the type if it is.
1646
1662
1647
1663
This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
@@ -1651,7 +1667,7 @@ def is_user_prompt_node(
1651
1667
@staticmethod
1652
1668
def is_end_node (
1653
1669
node : _agent_graph .AgentNode [T , S ] | End [result .FinalResult [S ]],
1654
- ) -> TypeGuard [End [result .FinalResult [S ]]]:
1670
+ ) -> TypeIs [End [result .FinalResult [S ]]]:
1655
1671
"""Check if the node is a `End`, narrowing the type if it is.
1656
1672
1657
1673
This method preserves the generic parameters while narrowing the type, unlike a direct call to `isinstance`.
0 commit comments