test_sync_dynamic_prompt_on_async_invoke() — langchain Function Reference
Architecture documentation for the test_sync_dynamic_prompt_on_async_invoke() function in test_decorators.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD b3fdc43a_d871_28a8_783a_a97d97b13e03["test_sync_dynamic_prompt_on_async_invoke()"] 85a104a3_11cf_6539_d0c0_ba69a17a41d4["test_decorators.py"] b3fdc43a_d871_28a8_783a_a97d97b13e03 -->|defined in| 85a104a3_11cf_6539_d0c0_ba69a17a41d4 style b3fdc43a_d871_28a8_783a_a97d97b13e03 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_decorators.py lines 800–822
async def test_sync_dynamic_prompt_on_async_invoke() -> None:
"""Test that sync dynamic_prompt works when invoked via async path (.ainvoke).
When a sync middleware is defined with @dynamic_prompt, it automatically creates
both sync and async implementations. The async implementation delegates to the
sync function, allowing the middleware to work in both sync and async contexts.
"""
calls = []
@dynamic_prompt
def sync_prompt(request: ModelRequest) -> str:
calls.append("sync_prompt")
return "Sync prompt"
agent = create_agent(model=FakeToolCallingModel(), middleware=[sync_prompt])
# Sync dynamic_prompt now works in async path via delegation
result = await agent.ainvoke({"messages": [HumanMessage("Hello")]})
# The sync prompt function was called via async delegation
assert calls == ["sync_prompt"]
# The model executed with the custom prompt
assert result["messages"][-1].content == "Sync prompt-Hello"
Domain
Subdomains
Source
Frequently Asked Questions
What does test_sync_dynamic_prompt_on_async_invoke() do?
test_sync_dynamic_prompt_on_async_invoke() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_decorators.py.
Where is test_sync_dynamic_prompt_on_async_invoke() defined?
test_sync_dynamic_prompt_on_async_invoke() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_decorators.py at line 800.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free