format_to_tool_messages() — langchain Function Reference
Architecture documentation for the format_to_tool_messages() function in tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a9286f07_f4e9_b9c2_3f3a_a1cea3c4479e["format_to_tool_messages()"] fe1bd3fc_e601_3b60_c724_5a81dc3b1d29["tools.py"] a9286f07_f4e9_b9c2_3f3a_a1cea3c4479e -->|defined in| fe1bd3fc_e601_3b60_c724_5a81dc3b1d29 beaefb47_cd61_4401_ac33_e9afb4d4b58f["_create_tool_message()"] a9286f07_f4e9_b9c2_3f3a_a1cea3c4479e -->|calls| beaefb47_cd61_4401_ac33_e9afb4d4b58f style a9286f07_f4e9_b9c2_3f3a_a1cea3c4479e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/format_scratchpad/tools.py lines 51–73
def format_to_tool_messages(
intermediate_steps: Sequence[tuple[AgentAction, str]],
) -> list[BaseMessage]:
"""Convert (AgentAction, tool output) tuples into `ToolMessage` objects.
Args:
intermediate_steps: Steps the LLM has taken to date, along with observations.
Returns:
list of messages to send to the LLM for the next prediction.
"""
messages = []
for agent_action, observation in intermediate_steps:
if isinstance(agent_action, ToolAgentAction):
new_messages = [
*list(agent_action.message_log),
_create_tool_message(agent_action, observation),
]
messages.extend([new for new in new_messages if new not in messages])
else:
messages.append(AIMessage(content=agent_action.log))
return messages
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does format_to_tool_messages() do?
format_to_tool_messages() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/format_scratchpad/tools.py.
Where is format_to_tool_messages() defined?
format_to_tool_messages() is defined in libs/langchain/langchain_classic/agents/format_scratchpad/tools.py at line 51.
What does format_to_tool_messages() call?
format_to_tool_messages() calls 1 function(s): _create_tool_message.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free