Problem
AgentRef field detection currently relies on Inline[T] and Externalized[T] being visible as the outer annotation. In the common path, get_type_hints() strips outer Annotated[...] metadata, so declarations like Annotated[Externalized[T], ...] can already work incidentally.
However, the raw annotation fallback path and any future move to get_type_hints(..., include_extras=True) would preserve Annotated as the outer type. In those cases, is_inline_annotation(), is_externalized_annotation(), and get_wrapped_type() would no longer identify AgentRef field markers correctly.
Proposal
Add an internal helper that recursively unwraps outer typing.Annotated layers before AgentRef marker detection and wrapped-type extraction.
Expected supported declarations:
from typing import Annotated
class MyState(AgentRefState):
step: Annotated[Inline[str], "metadata"]
docs: Annotated[Externalized[list[dict]], "metadata"]
nested: Annotated[Annotated[Externalized[list[str]], "a"], "b"]
Scope should stay intentionally narrow: use Annotated metadata only for marker detection compatibility, and do not interpret framework reducer metadata or other metadata values as AgentRef behavior in this change.
Implementation likely belongs in agentref/core/types.py, used by:
is_inline_annotation()
is_externalized_annotation()
get_wrapped_type()
Add focused tests covering outer and nested Annotated wrappers around both Inline and Externalized markers, including the raw-annotation fallback path if practical.
Alternatives considered
Keep relying on get_type_hints() default behavior, which strips Annotated metadata today. This is fragile because it does not cover fallback behavior and would break if AgentRef later preserves extras intentionally.
Support Externalized[Annotated[T, ...]] only. That already works for marker detection because Externalized remains the outer type, but it does not address the more idiomatic Annotated[Externalized[T], ...] form.
Related framework
All frameworks; most relevant to LangGraph because LangGraph commonly uses Annotated for reducer metadata.
Related backend
All CAS backends; this is annotation handling and should not affect storage behavior.
Expected impact
Improves type annotation compatibility and future-proofs AgentRef against preserving Annotated metadata. Runtime behavior should remain unchanged for existing Inline[T] and Externalized[T] declarations.
Problem
AgentRef field detection currently relies on
Inline[T]andExternalized[T]being visible as the outer annotation. In the common path,get_type_hints()strips outerAnnotated[...]metadata, so declarations likeAnnotated[Externalized[T], ...]can already work incidentally.However, the raw annotation fallback path and any future move to
get_type_hints(..., include_extras=True)would preserveAnnotatedas the outer type. In those cases,is_inline_annotation(),is_externalized_annotation(), andget_wrapped_type()would no longer identify AgentRef field markers correctly.Proposal
Add an internal helper that recursively unwraps outer
typing.Annotatedlayers before AgentRef marker detection and wrapped-type extraction.Expected supported declarations:
Scope should stay intentionally narrow: use
Annotatedmetadata only for marker detection compatibility, and do not interpret framework reducer metadata or other metadata values as AgentRef behavior in this change.Implementation likely belongs in
agentref/core/types.py, used by:is_inline_annotation()is_externalized_annotation()get_wrapped_type()Add focused tests covering outer and nested
Annotatedwrappers around bothInlineandExternalizedmarkers, including the raw-annotation fallback path if practical.Alternatives considered
Keep relying on
get_type_hints()default behavior, which stripsAnnotatedmetadata today. This is fragile because it does not cover fallback behavior and would break if AgentRef later preserves extras intentionally.Support
Externalized[Annotated[T, ...]]only. That already works for marker detection becauseExternalizedremains the outer type, but it does not address the more idiomaticAnnotated[Externalized[T], ...]form.Related framework
All frameworks; most relevant to LangGraph because LangGraph commonly uses
Annotatedfor reducer metadata.Related backend
All CAS backends; this is annotation handling and should not affect storage behavior.
Expected impact
Improves type annotation compatibility and future-proofs AgentRef against preserving
Annotatedmetadata. Runtime behavior should remain unchanged for existingInline[T]andExternalized[T]declarations.