Home / File/ agents.py — langchain Source File

agents.py — langchain Source File

Architecture documentation for agents.py, a python file in the langchain codebase. 5 imports, 0 dependents.

File python CoreAbstractions MessageSchema 5 imports 3 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff["agents.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  30d1300e_92bb_90d4_ac5e_1afe56db09d2["langchain_core.load.serializable"]
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff --> 30d1300e_92bb_90d4_ac5e_1afe56db09d2
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  81828515_0fcd_6cb4_96b8_62d4fca3e4ff --> d758344f_537f_649e_f467_b9d7442e86df
  style 81828515_0fcd_6cb4_96b8_62d4fca3e4ff fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Schema definitions for representing agent actions, observations, and return values.

!!! warning

    The schema definitions are provided for backwards compatibility.

!!! warning

    New agents should be built using the
    [`langchain` library](https://pypi.org/project/langchain/), which provides a
    simpler and more flexible way to define agents.

    See docs on [building agents](https://docs.langchain.com/oss/python/langchain/agents).

Agents use language models to choose a sequence of actions to take.

A basic agent works in the following manner:

1. Given a prompt an agent uses an LLM to request an action to take
    (e.g., a tool to run).
2. The agent executes the action (e.g., runs the tool), and receives an observation.
3. The agent returns the observation to the LLM, which can then be used to generate
    the next action.
4. When the agent reaches a stopping condition, it returns a final return value.

The schemas for the agents themselves are defined in `langchain.agents.agent`.
"""

from __future__ import annotations

import json
from collections.abc import Sequence
from typing import Any, Literal

from langchain_core.load.serializable import Serializable
from langchain_core.messages import (
    AIMessage,
    BaseMessage,
    FunctionMessage,
    HumanMessage,
)


class AgentAction(Serializable):
    """Represents a request to execute an action by an agent.

    The action consists of the name of the tool to execute and the input to pass
    to the tool. The log is used to pass along extra information about the action.
    """

    tool: str
    """The name of the `Tool` to execute."""

    tool_input: str | dict
    """The input to pass in to the `Tool`."""

    log: str
    """Additional information to log about the action.

    This log can be used in a few ways. First, it can be used to audit what exactly the
// ... (197 more lines)

Subdomains

Dependencies

  • collections.abc
  • json
  • langchain_core.load.serializable
  • langchain_core.messages
  • typing

Frequently Asked Questions

What does agents.py do?
agents.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in agents.py?
agents.py defines 3 function(s): _convert_agent_action_to_messages, _convert_agent_observation_to_messages, _create_function_message.
What does agents.py depend on?
agents.py imports 5 module(s): collections.abc, json, langchain_core.load.serializable, langchain_core.messages, typing.
Where is agents.py in the architecture?
agents.py is located at libs/core/langchain_core/agents.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/core/langchain_core).

Analyze Your Own Codebase

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

Try Supermodel Free