Home / Function/ test_prefix_response() — langchain Function Reference

test_prefix_response() — langchain Function Reference

Architecture documentation for the test_prefix_response() function in test_wrap_model_call.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  e16c3121_3e84_a4cf_782b_28247d9332dc["test_prefix_response()"]
  cb947a63_4e84_45da_09d8_177d819abead["TestResponseRewriting"]
  e16c3121_3e84_a4cf_782b_28247d9332dc -->|defined in| cb947a63_4e84_45da_09d8_177d819abead
  style e16c3121_3e84_a4cf_782b_28247d9332dc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py lines 321–344

    def test_prefix_response(self) -> None:
        """Test middleware that adds prefix to response."""

        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}")

        model = GenericFakeChatModel(messages=iter([AIMessage(content="Response")]))
        agent = create_agent(model=model, middleware=[PrefixMiddleware(prefix="[BOT]: ")])

        result = agent.invoke({"messages": [HumanMessage("Test")]})

        assert result["messages"][1].content == "[BOT]: Response"

Domain

Subdomains

Frequently Asked Questions

What does test_prefix_response() do?
test_prefix_response() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py.
Where is test_prefix_response() defined?
test_prefix_response() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py at line 321.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free