test_openai_agent_tools_agent() — langchain Function Reference
Architecture documentation for the test_openai_agent_tools_agent() function in test_agent.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ea08f4fd_9d27_8cd9_90d0_31c9bf4bafd2["test_openai_agent_tools_agent()"] 47a7b285_8e60_f78f_282d_429958c446fa["test_agent.py"] ea08f4fd_9d27_8cd9_90d0_31c9bf4bafd2 -->|defined in| 47a7b285_8e60_f78f_282d_429958c446fa 64bbfaac_3c41_2db9_52b6_6979f090cc37["_make_tools_invocation()"] ea08f4fd_9d27_8cd9_90d0_31c9bf4bafd2 -->|calls| 64bbfaac_3c41_2db9_52b6_6979f090cc37 style ea08f4fd_9d27_8cd9_90d0_31c9bf4bafd2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/tests/unit_tests/agents/test_agent.py lines 1021–1329
async def test_openai_agent_tools_agent() -> None:
"""Test OpenAI tools agent."""
infinite_cycle = cycle(
[
_make_tools_invocation(
{
"find_pet": {"pet": "cat"},
"check_time": {},
},
),
AIMessage(content="The cat is spying from under the bed."),
],
)
GenericFakeChatModel.bind_tools = lambda self, _: self # type: ignore[assignment,misc]
model = GenericFakeChatModel(messages=infinite_cycle)
@tool
def find_pet(pet: str) -> str:
"""Find the given pet."""
if pet != "cat":
msg = "Only cats allowed"
raise ValueError(msg)
return "Spying from under the bed."
@tool
def check_time() -> str:
"""Find the given pet."""
return "It's time to pet the cat."
template = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful AI bot. Your name is kitty power meow."),
("human", "{question}"),
MessagesPlaceholder(
variable_name="agent_scratchpad",
),
],
)
# type error due to base tool type below -- would need to be adjusted on tool
# decorator.
openai_agent = create_openai_tools_agent(
model,
[find_pet],
template,
)
tool_calling_agent = create_tool_calling_agent(
model,
[find_pet],
template,
)
for agent in [openai_agent, tool_calling_agent]:
executor = AgentExecutor(agent=agent, tools=[find_pet])
# Invoke
result = await asyncio.to_thread(executor.invoke, {"question": "hello"})
assert result == {
"output": "The cat is spying from under the bed.",
"question": "hello",
}
# astream
chunks = [chunk async for chunk in executor.astream({"question": "hello"})]
assert chunks == [
{
"actions": [
OpenAIToolAgentAction(
tool="find_pet",
tool_input={"pet": "cat"},
log="\nInvoking: `find_pet` with `{'pet': 'cat'}`\n\n\n",
message_log=[
_AnyIdAIMessageChunk(
content="",
additional_kwargs={
"tool_calls": [
{
"function": {
"name": "find_pet",
"arguments": '{"pet": "cat"}',
},
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does test_openai_agent_tools_agent() do?
test_openai_agent_tools_agent() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/test_agent.py.
Where is test_openai_agent_tools_agent() defined?
test_openai_agent_tools_agent() is defined in libs/langchain/tests/unit_tests/agents/test_agent.py at line 1021.
What does test_openai_agent_tools_agent() call?
test_openai_agent_tools_agent() calls 1 function(s): _make_tools_invocation.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free