Home / Class/ AgentFinish Class — langchain Architecture

AgentFinish Class — langchain Architecture

Architecture documentation for the AgentFinish class in agents.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ed938178_9a8a_e288_c89c_a0dfb4927ae8["AgentFinish"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33["Serializable"]
  ed938178_9a8a_e288_c89c_a0dfb4927ae8 -->|extends| f3658565_d05c_7f49_b7f8_622b7ef34f33
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff["agents.py"]
  ed938178_9a8a_e288_c89c_a0dfb4927ae8 -->|defined in| 81828515_0fcd_6cb4_96b8_62d4fca3e4ff
  e4aabd30_5e56_bdc6_be09_487c52a8c30a["__init__()"]
  ed938178_9a8a_e288_c89c_a0dfb4927ae8 -->|method| e4aabd30_5e56_bdc6_be09_487c52a8c30a
  23f16588_289b_53ee_d6b7_dc8f5b05d1cc["is_lc_serializable()"]
  ed938178_9a8a_e288_c89c_a0dfb4927ae8 -->|method| 23f16588_289b_53ee_d6b7_dc8f5b05d1cc
  97267826_abbd_ef67_6926_308535fdbe79["get_lc_namespace()"]
  ed938178_9a8a_e288_c89c_a0dfb4927ae8 -->|method| 97267826_abbd_ef67_6926_308535fdbe79
  121010e0_c90d_2688_909e_60e8164739ab["messages()"]
  ed938178_9a8a_e288_c89c_a0dfb4927ae8 -->|method| 121010e0_c90d_2688_909e_60e8164739ab

Relationship Graph

Source Code

libs/core/langchain_core/agents.py lines 146–188

class AgentFinish(Serializable):
    """Final return value of an `ActionAgent`.

    Agents return an `AgentFinish` when they have reached a stopping condition.
    """

    return_values: dict
    """Dictionary of return values."""

    log: str
    """Additional information to log about the return value.

    This is used to pass along the full LLM prediction, not just the parsed out
    return value.

    For example, if the full LLM prediction was `Final Answer: 2` you may want to just
    return `2` as a return value, but pass along the full string as a `log` (for
    debugging or observability purposes).
    """
    type: Literal["AgentFinish"] = "AgentFinish"

    def __init__(self, return_values: dict, log: str, **kwargs: Any):
        """Override init to support instantiation by position for backward compat."""
        super().__init__(return_values=return_values, log=log, **kwargs)

    @classmethod
    def is_lc_serializable(cls) -> bool:
        """Return `True` as this class is serializable."""
        return True

    @classmethod
    def get_lc_namespace(cls) -> list[str]:
        """Get the namespace of the LangChain object.

        Returns:
            `["langchain", "schema", "agent"]`
        """
        return ["langchain", "schema", "agent"]

    @property
    def messages(self) -> Sequence[BaseMessage]:
        """Messages that correspond to this observation."""
        return [AIMessage(content=self.log)]

Extends

Frequently Asked Questions

What is the AgentFinish class?
AgentFinish is a class in the langchain codebase, defined in libs/core/langchain_core/agents.py.
Where is AgentFinish defined?
AgentFinish is defined in libs/core/langchain_core/agents.py at line 146.
What does AgentFinish extend?
AgentFinish extends Serializable.

Analyze Your Own Codebase

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

Try Supermodel Free