Home / Function/ _convert_agent_observation_to_messages() — langchain Function Reference

_convert_agent_observation_to_messages() — langchain Function Reference

Architecture documentation for the _convert_agent_observation_to_messages() function in agents.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  0d0b2a68_5fb9_b032_2c8a_7cfb43c20f43["_convert_agent_observation_to_messages()"]
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff["agents.py"]
  0d0b2a68_5fb9_b032_2c8a_7cfb43c20f43 -->|defined in| 81828515_0fcd_6cb4_96b8_62d4fca3e4ff
  a2344a29_310c_4291_2dbb_16e6df48d673["messages()"]
  a2344a29_310c_4291_2dbb_16e6df48d673 -->|calls| 0d0b2a68_5fb9_b032_2c8a_7cfb43c20f43
  593439c1_f9b5_edba_6209_abdef7d391c0["_create_function_message()"]
  0d0b2a68_5fb9_b032_2c8a_7cfb43c20f43 -->|calls| 593439c1_f9b5_edba_6209_abdef7d391c0
  style 0d0b2a68_5fb9_b032_2c8a_7cfb43c20f43 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/agents.py lines 209–231

def _convert_agent_observation_to_messages(
    agent_action: AgentAction, observation: Any
) -> Sequence[BaseMessage]:
    """Convert an agent action to a message.

    This code is used to reconstruct the original AI message from the agent action.

    Args:
        agent_action: Agent action to convert.
        observation: Observation to convert to a message.

    Returns:
        `AIMessage` that corresponds to the original tool invocation.
    """
    if isinstance(agent_action, AgentActionMessageLog):
        return [_create_function_message(agent_action, observation)]
    content = observation
    if not isinstance(observation, str):
        try:
            content = json.dumps(observation, ensure_ascii=False)
        except Exception:
            content = str(observation)
    return [HumanMessage(content=content)]

Subdomains

Called By

Frequently Asked Questions

What does _convert_agent_observation_to_messages() do?
_convert_agent_observation_to_messages() is a function in the langchain codebase, defined in libs/core/langchain_core/agents.py.
Where is _convert_agent_observation_to_messages() defined?
_convert_agent_observation_to_messages() is defined in libs/core/langchain_core/agents.py at line 209.
What does _convert_agent_observation_to_messages() call?
_convert_agent_observation_to_messages() calls 1 function(s): _create_function_message.
What calls _convert_agent_observation_to_messages()?
_convert_agent_observation_to_messages() is called by 1 function(s): messages.

Analyze Your Own Codebase

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

Try Supermodel Free