TestCreatePrompt Class — langchain Architecture
Architecture documentation for the TestCreatePrompt class in test_structured_chat.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 742971a1_c426_ee5f_9355_f94bbb636166["TestCreatePrompt"] 9ad47010_a7a4_8c98_a464_6b696766c212["ChatPromptTemplate"] 742971a1_c426_ee5f_9355_f94bbb636166 -->|extends| 9ad47010_a7a4_8c98_a464_6b696766c212 b3f4ae4e_6bca_6b0a_6046_25b8a434cd42["SystemMessagePromptTemplate"] 742971a1_c426_ee5f_9355_f94bbb636166 -->|extends| b3f4ae4e_6bca_6b0a_6046_25b8a434cd42 e993539f_c52a_07c1_e7d4_6a7299dc1610["HumanMessagePromptTemplate"] 742971a1_c426_ee5f_9355_f94bbb636166 -->|extends| e993539f_c52a_07c1_e7d4_6a7299dc1610 a890525c_8c6f_1157_9955_6e77e67c50fd["test_structured_chat.py"] 742971a1_c426_ee5f_9355_f94bbb636166 -->|defined in| a890525c_8c6f_1157_9955_6e77e67c50fd 4e6a5d3d_ded1_b73a_b7f1_0d3c7cead611["test_create_prompt_output()"] 742971a1_c426_ee5f_9355_f94bbb636166 -->|method| 4e6a5d3d_ded1_b73a_b7f1_0d3c7cead611 01395fd5_8e3a_e32a_38ae_97a2b4d748b5["test_system_message_single_tool()"] 742971a1_c426_ee5f_9355_f94bbb636166 -->|method| 01395fd5_8e3a_e32a_38ae_97a2b4d748b5 5293a97e_53df_6e75_7ac4_469a2be9bf1a["test_system_message_multiple_tools()"] 742971a1_c426_ee5f_9355_f94bbb636166 -->|method| 5293a97e_53df_6e75_7ac4_469a2be9bf1a
Relationship Graph
Source Code
libs/langchain/tests/unit_tests/agents/test_structured_chat.py lines 122–251
class TestCreatePrompt:
# Test: Output should be a ChatPromptTemplate with sys and human messages.
def test_create_prompt_output(self) -> None:
prompt = StructuredChatAgent.create_prompt(
[Tool(name="foo", description="Test tool FOO", func=lambda x: x)],
)
assert isinstance(prompt, ChatPromptTemplate)
assert len(prompt.messages) == 2
assert isinstance(prompt.messages[0], SystemMessagePromptTemplate)
assert isinstance(prompt.messages[1], HumanMessagePromptTemplate)
# Test: Format with a single tool.
def test_system_message_single_tool(self) -> None:
prompt: Any = StructuredChatAgent.create_prompt(
[Tool(name="foo", description="Test tool FOO", func=lambda x: x)],
)
actual = prompt.messages[0].prompt.format()
expected = dedent(
"""
Respond to the human as helpfully and accurately as possible. You have access to the following tools:
foo: Test tool FOO, args: {'tool_input': {'type': 'string'}}
Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).
Valid "action" values: "Final Answer" or foo
Provide only ONE action per $JSON_BLOB, as shown:
```
{
"action": $TOOL_NAME,
"action_input": $INPUT
}
```
Follow this format:
Question: input question to answer
Thought: consider previous and subsequent steps
Action:
```
$JSON_BLOB
```
Observation: action result
... (repeat Thought/Action/Observation N times)
Thought: I know what to respond
Action:
```
{
"action": "Final Answer",
"action_input": "Final response to human"
}
```
Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation:.
Thought:
""", # noqa: E501
).strip()
assert actual == expected
# Test: Format with multiple tools.
#
# Check:
#
# You have access to the following tools:
# ...
#
# and
#
# Valid "action" values: "Final Answer" or ...
#
def test_system_message_multiple_tools(self) -> None:
prompt: Any = StructuredChatAgent.create_prompt(
[
Tool(name="foo", description="Test tool FOO", func=lambda x: x),
Tool(name="bar", description="Test tool BAR", func=lambda x: x),
],
Source
Frequently Asked Questions
What is the TestCreatePrompt class?
TestCreatePrompt is a class in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/test_structured_chat.py.
Where is TestCreatePrompt defined?
TestCreatePrompt is defined in libs/langchain/tests/unit_tests/agents/test_structured_chat.py at line 122.
What does TestCreatePrompt extend?
TestCreatePrompt extends ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free