_build_final_ai_message_content() — langchain Function Reference
Architecture documentation for the _build_final_ai_message_content() function in tool_call_limit.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5ac56516_2d78_c12c_204e_15f599bbc7f4["_build_final_ai_message_content()"] 4eaf9f24_fce9_0af1_80e1_f2e4f9935aeb["tool_call_limit.py"] 5ac56516_2d78_c12c_204e_15f599bbc7f4 -->|defined in| 4eaf9f24_fce9_0af1_80e1_f2e4f9935aeb 700c6d44_38e2_8aac_1a33_3a6737757799["__init__()"] 700c6d44_38e2_8aac_1a33_3a6737757799 -->|calls| 5ac56516_2d78_c12c_204e_15f599bbc7f4 2d4474df_60a6_0dd0_a7de_afbe664f4896["after_model()"] 2d4474df_60a6_0dd0_a7de_afbe664f4896 -->|calls| 5ac56516_2d78_c12c_204e_15f599bbc7f4 style 5ac56516_2d78_c12c_204e_15f599bbc7f4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/tool_call_limit.py lines 70–101
def _build_final_ai_message_content(
thread_count: int,
run_count: int,
thread_limit: int | None,
run_limit: int | None,
tool_name: str | None,
) -> str:
"""Build the final AI message content for `'end'` behavior.
This message is displayed to the user, so it should include detailed information
about which limits were exceeded.
Args:
thread_count: Current thread tool call count.
run_count: Current run tool call count.
thread_limit: Thread tool call limit (if set).
run_limit: Run tool call limit (if set).
tool_name: Tool name being limited (if specific tool), or `None` for all tools.
Returns:
A formatted message describing which limits were exceeded.
"""
tool_desc = f"'{tool_name}' tool" if tool_name else "Tool"
exceeded_limits = []
if thread_limit is not None and thread_count > thread_limit:
exceeded_limits.append(f"thread limit exceeded ({thread_count}/{thread_limit} calls)")
if run_limit is not None and run_count > run_limit:
exceeded_limits.append(f"run limit exceeded ({run_count}/{run_limit} calls)")
limits_text = " and ".join(exceeded_limits)
return f"{tool_desc} call limit reached: {limits_text}."
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _build_final_ai_message_content() do?
_build_final_ai_message_content() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/tool_call_limit.py.
Where is _build_final_ai_message_content() defined?
_build_final_ai_message_content() is defined in libs/langchain_v1/langchain/agents/middleware/tool_call_limit.py at line 70.
What calls _build_final_ai_message_content()?
_build_final_ai_message_content() is called by 2 function(s): __init__, after_model.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free