PrefixMiddleware Class — langchain Architecture
Architecture documentation for the PrefixMiddleware class in test_wrap_model_call.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD b839d145_bd7e_f8f3_8f04_82e22e52c46d["PrefixMiddleware"] 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e["AgentMiddleware"] b839d145_bd7e_f8f3_8f04_82e22e52c46d -->|extends| 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e 573473e5_eb93_a7d7_84ba_c975071c09af["test_wrap_model_call.py"] b839d145_bd7e_f8f3_8f04_82e22e52c46d -->|defined in| 573473e5_eb93_a7d7_84ba_c975071c09af e843b9ae_bd50_34f9_9423_1a9ed0e30249["__init__()"] b839d145_bd7e_f8f3_8f04_82e22e52c46d -->|method| e843b9ae_bd50_34f9_9423_1a9ed0e30249 f6e2a08e_524d_cddd_7ef8_edc56357f732["wrap_model_call()"] b839d145_bd7e_f8f3_8f04_82e22e52c46d -->|method| f6e2a08e_524d_cddd_7ef8_edc56357f732
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py lines 324–337
class PrefixMiddleware(AgentMiddleware):
def __init__(self, prefix: str):
super().__init__()
self.prefix = prefix
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelCallResult:
result = handler(request)
# result is ModelResponse, extract AIMessage from it
ai_message = result.result[0]
return AIMessage(content=f"{self.prefix}{ai_message.content}")
Extends
Source
Frequently Asked Questions
What is the PrefixMiddleware class?
PrefixMiddleware is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py.
Where is PrefixMiddleware defined?
PrefixMiddleware is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py at line 324.
What does PrefixMiddleware extend?
PrefixMiddleware extends AgentMiddleware.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free