Home / Function/ _create_function_message() — langchain Function Reference

_create_function_message() — langchain Function Reference

Architecture documentation for the _create_function_message() function in openai_functions.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  96bcf3ef_a8e1_acf7_d502_0ce5616ce84d["_create_function_message()"]
  cf5dc0eb_d579_7cc5_dd23_6777e1b3f2ae["openai_functions.py"]
  96bcf3ef_a8e1_acf7_d502_0ce5616ce84d -->|defined in| cf5dc0eb_d579_7cc5_dd23_6777e1b3f2ae
  5642b636_f847_c032_4a08_980b2117159b["_convert_agent_action_to_messages()"]
  5642b636_f847_c032_4a08_980b2117159b -->|calls| 96bcf3ef_a8e1_acf7_d502_0ce5616ce84d
  style 96bcf3ef_a8e1_acf7_d502_0ce5616ce84d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/format_scratchpad/openai_functions.py lines 36–65

def _create_function_message(
    agent_action: AgentAction,
    observation: Any,
) -> FunctionMessage:
    """Convert agent action and observation into a function message.

    Args:
        agent_action: the tool invocation request from the agent.
        observation: the result of the tool invocation.

    Returns:
        FunctionMessage that corresponds to the original tool invocation.

    Raises:
        ValueError: if the observation cannot be converted to a string.
    """
    if not isinstance(observation, str):
        try:
            content = json.dumps(observation, ensure_ascii=False)
        except TypeError:
            content = str(observation)
        except Exception:
            _logger.exception("Unexpected error converting observation to string.")
            content = str(observation)
    else:
        content = observation
    return FunctionMessage(
        name=agent_action.tool,
        content=content,
    )

Subdomains

Frequently Asked Questions

What does _create_function_message() do?
_create_function_message() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/format_scratchpad/openai_functions.py.
Where is _create_function_message() defined?
_create_function_message() is defined in libs/langchain/langchain_classic/agents/format_scratchpad/openai_functions.py at line 36.
What calls _create_function_message()?
_create_function_message() is called by 1 function(s): _convert_agent_action_to_messages.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free