test_structured_chat.py — langchain Source File
Architecture documentation for test_structured_chat.py, a python file in the langchain codebase. 7 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 02389751_e51c_28ed_a9fd_a1ef680a6802["test_structured_chat.py"] 243100a0_4629_4394_a66b_1f67b00ce784["textwrap"] 02389751_e51c_28ed_a9fd_a1ef680a6802 --> 243100a0_4629_4394_a66b_1f67b00ce784 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 02389751_e51c_28ed_a9fd_a1ef680a6802 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b["langchain_core.agents"] 02389751_e51c_28ed_a9fd_a1ef680a6802 --> 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b e45722a2_0136_a972_1f58_7b5987500404["langchain_core.prompts.chat"] 02389751_e51c_28ed_a9fd_a1ef680a6802 --> e45722a2_0136_a972_1f58_7b5987500404 43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"] 02389751_e51c_28ed_a9fd_a1ef680a6802 --> 43d88577_548b_2248_b01b_7987bae85dcc 9ec1c031_a746_799f_fa5a_a2ace4414231["langchain_classic.agents.structured_chat.base"] 02389751_e51c_28ed_a9fd_a1ef680a6802 --> 9ec1c031_a746_799f_fa5a_a2ace4414231 e124eb33_5025_9013_4f30_bf32756622d2["langchain_classic.agents.structured_chat.output_parser"] 02389751_e51c_28ed_a9fd_a1ef680a6802 --> e124eb33_5025_9013_4f30_bf32756622d2 style 02389751_e51c_28ed_a9fd_a1ef680a6802 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Unittests for langchain.agents.chat package."""
from textwrap import dedent
from typing import Any
from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.prompts.chat import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
SystemMessagePromptTemplate,
)
from langchain_core.tools import Tool
from langchain_classic.agents.structured_chat.base import StructuredChatAgent
from langchain_classic.agents.structured_chat.output_parser import (
StructuredChatOutputParser,
)
output_parser = StructuredChatOutputParser()
def get_action_and_input(text: str) -> tuple[str, str]:
output = output_parser.parse(text)
if isinstance(output, AgentAction):
return output.tool, str(output.tool_input)
if isinstance(output, AgentFinish):
return output.return_values["output"], output.log
msg = "Unexpected output type" # type: ignore[unreachable]
raise ValueError(msg)
def test_parse_with_language() -> None:
llm_output = """I can use the `foo` tool to achieve the goal.
Action:
```json
{
"action": "foo",
"action_input": "bar"
}
```
"""
action, action_input = get_action_and_input(llm_output)
assert action == "foo"
assert action_input == "bar"
def test_parse_without_language() -> None:
llm_output = """I can use the `foo` tool to achieve the goal.
Action:
```
{
"action": "foo",
"action_input": "bar"
}
```
"""
action, action_input = get_action_and_input(llm_output)
assert action == "foo"
// ... (192 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- langchain_classic.agents.structured_chat.base
- langchain_classic.agents.structured_chat.output_parser
- langchain_core.agents
- langchain_core.prompts.chat
- langchain_core.tools
- textwrap
- typing
Source
Frequently Asked Questions
What does test_structured_chat.py do?
test_structured_chat.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_structured_chat.py?
test_structured_chat.py defines 7 function(s): get_action_and_input, test_parse_case_matched_and_final_answer, test_parse_with_language, test_parse_with_language_and_spaces, test_parse_with_language_without_a_new_line, test_parse_without_language, test_parse_without_language_without_a_new_line.
What does test_structured_chat.py depend on?
test_structured_chat.py imports 7 module(s): langchain_classic.agents.structured_chat.base, langchain_classic.agents.structured_chat.output_parser, langchain_core.agents, langchain_core.prompts.chat, langchain_core.tools, textwrap, typing.
Where is test_structured_chat.py in the architecture?
test_structured_chat.py is located at libs/langchain/tests/unit_tests/agents/test_structured_chat.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain/tests/unit_tests/agents).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free