Home / Function/ test_agent_with_new_prefix_suffix() — langchain Function Reference

test_agent_with_new_prefix_suffix() — langchain Function Reference

Architecture documentation for the test_agent_with_new_prefix_suffix() function in test_agent.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  995f9456_7bf7_6a10_1f9b_af35b2237674["test_agent_with_new_prefix_suffix()"]
  47a7b285_8e60_f78f_282d_429958c446fa["test_agent.py"]
  995f9456_7bf7_6a10_1f9b_af35b2237674 -->|defined in| 47a7b285_8e60_f78f_282d_429958c446fa
  style 995f9456_7bf7_6a10_1f9b_af35b2237674 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/agents/test_agent.py lines 373–401

def test_agent_with_new_prefix_suffix() -> None:
    """Test agent initialization kwargs with new prefix and suffix."""
    fake_llm = FakeListLLM(
        responses=["FooBarBaz\nAction: Search\nAction Input: misalignment"],
    )
    tools = [
        Tool(
            name="Search",
            func=lambda x: x,
            description="Useful for searching",
            return_direct=True,
        ),
    ]
    prefix = "FooBarBaz"

    suffix = "Begin now!\nInput: {input}\nThought: {agent_scratchpad}"

    agent = initialize_agent(
        tools=tools,
        llm=fake_llm,
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        agent_kwargs={"prefix": prefix, "suffix": suffix},
    )

    # avoids "BasePromptTemplate" has no attribute "template" error
    assert hasattr(agent.agent.llm_chain.prompt, "template")  # type: ignore[union-attr]
    prompt_str = agent.agent.llm_chain.prompt.template  # type: ignore[union-attr]
    assert prompt_str.startswith(prefix), "Prompt does not start with prefix"
    assert prompt_str.endswith(suffix), "Prompt does not end with suffix"

Domain

Subdomains

Frequently Asked Questions

What does test_agent_with_new_prefix_suffix() do?
test_agent_with_new_prefix_suffix() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/test_agent.py.
Where is test_agent_with_new_prefix_suffix() defined?
test_agent_with_new_prefix_suffix() is defined in libs/langchain/tests/unit_tests/agents/test_agent.py at line 373.

Analyze Your Own Codebase

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

Try Supermodel Free