test_inner_command_retry_safe() — langchain Function Reference
Architecture documentation for the test_inner_command_retry_safe() function in test_wrap_model_call_state_update.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 058450ac_e67f_66fe_11a3_984dcb479882["test_inner_command_retry_safe()"] 269d8393_43ba_e665_6d86_95d75ce0c396["TestComposition"] 058450ac_e67f_66fe_11a3_984dcb479882 -->|defined in| 269d8393_43ba_e665_6d86_95d75ce0c396 style 058450ac_e67f_66fe_11a3_984dcb479882 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py lines 533–578
def test_inner_command_retry_safe(self) -> None:
"""When outer retries, only the last inner command is used."""
call_count = 0
class MyState(AgentState):
attempt: str
class OuterMiddleware(AgentMiddleware):
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelResponse:
# Call handler twice (simulating retry)
handler(request)
return handler(request)
class InnerMiddleware(AgentMiddleware):
state_schema = MyState # type: ignore[assignment]
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ExtendedModelResponse:
nonlocal call_count
call_count += 1
response = handler(request)
return ExtendedModelResponse(
model_response=response,
command=Command(update={"attempt": f"attempt_{call_count}"}),
)
model = GenericFakeChatModel(
messages=iter([AIMessage(content="First"), AIMessage(content="Second")])
)
agent = create_agent(
model=model,
middleware=[OuterMiddleware(), InnerMiddleware()],
)
result = agent.invoke({"messages": [HumanMessage("Hi")]})
# Only the last retry's inner state should survive
messages = result["messages"]
assert messages[-1].content == "Second"
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_inner_command_retry_safe() do?
test_inner_command_retry_safe() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py.
Where is test_inner_command_retry_safe() defined?
test_inner_command_retry_safe() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 533.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free