langgraph-prebuilt


Namelanggraph-prebuilt JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://www.github.com/langchain-ai/langgraph
SummaryLibrary with high-level APIs for creating and executing LangGraph agents and tools.
upload_time2025-02-27 00:03:15
maintainerNone
docs_urlNone
authorNone
requires_python<4.0.0,>=3.9.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LangGraph Prebuilt

This library defines high-level APIs for creating and executing LangGraph agents and tools.

## Installation

```bash
pip install langgraph-prebuilt
```

## Agents

`langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent) of a tool-calling [ReAct-style](https://langchain-ai.github.io/langgraph/concepts/agentic_concepts/#react-implementation) agent - `create_react_agent`:

```bash
pip install langchain-anthropic
```

```python
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent

# Define the tools for the agent to use
def search(query: str):
    """Call to surf the web."""
    # This is a placeholder, but don't tell the LLM that...
    if "sf" in query.lower() or "san francisco" in query.lower():
        return "It's 60 degrees and foggy."
    return "It's 90 degrees and sunny."

tools = [search]
model = ChatAnthropic(model="claude-3-7-sonnet-latest")

app = create_react_agent(model, tools)
# run the agent
app.invoke(
    {"messages": [{"role": "user", "content": "what is the weather in sf"}]},
)
```

## Tools

### ToolNode

`langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_node.ToolNode) of a node that executes tool calls - `ToolNode`:

```python
from langgraph.prebuilt import ToolNode
from langchain_core.messages import AIMessage

def search(query: str):
    """Call to surf the web."""
    # This is a placeholder, but don't tell the LLM that...
    if "sf" in query.lower() or "san francisco" in query.lower():
        return "It's 60 degrees and foggy."
    return "It's 90 degrees and sunny."

tool_node = ToolNode([search])
tool_calls = [{"name": "search", "args": {"query": "what is the weather in sf"}, "id": "1"}]
ai_message = AIMessage(content="", tool_calls=tool_calls)
# execute tool call
tool_node.invoke({"messages": [ai_message]})
```

### ValidationNode

`langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_validator.ValidationNode) of a node that validates tool calls against a pydantic schema - `ValidationNode`:

```python
from pydantic import BaseModel, field_validator
from langgraph.prebuilt import ValidationNode
from langchain_core.messages import AIMessage


class SelectNumber(BaseModel):
    a: int

    @field_validator("a")
    def a_must_be_meaningful(cls, v):
        if v != 37:
            raise ValueError("Only 37 is allowed")
        return v

validation_node = ValidationNode([SelectNumber])
validation_node.invoke({
    "messages": [AIMessage("", tool_calls=[{"name": "SelectNumber", "args": {"a": 42}, "id": "1"}])]
})
```

## Agent Inbox

The library contains schemas for using the [Agent Inbox](https://github.com/langchain-ai/agent-inbox) with LangGraph agents. Learn more about how to use Agent Inbox [here](https://github.com/langchain-ai/agent-inbox#interrupts).

```python
from langgraph.types import interrupt
from langgraph.prebuilt.interrupt import HumanInterrupt, HumanResponse

def my_graph_function():
    # Extract the last tool call from the `messages` field in the state
    tool_call = state["messages"][-1].tool_calls[0]
    # Create an interrupt
    request: HumanInterrupt = {
        "action_request": {
            "action": tool_call['name'],
            "args": tool_call['args']
        },
        "config": {
            "allow_ignore": True,
            "allow_respond": True,
            "allow_edit": False,
            "allow_accept": False
        },
        "description": _generate_email_markdown(state) # Generate a detailed markdown description.
    }
    # Send the interrupt request inside a list, and extract the first response
    response = interrupt([request])[0]
    if response['type'] == "response":
        # Do something with the response
    ...
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.github.com/langchain-ai/langgraph",
    "name": "langgraph-prebuilt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.9.0",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/9d/f0/5ac07b25d58a0a5bd126f4afc1a75ce4546f0e08fb4c3432154d904198d2/langgraph_prebuilt-0.1.0.tar.gz",
    "platform": null,
    "description": "# LangGraph Prebuilt\n\nThis library defines high-level APIs for creating and executing LangGraph agents and tools.\n\n## Installation\n\n```bash\npip install langgraph-prebuilt\n```\n\n## Agents\n\n`langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent) of a tool-calling [ReAct-style](https://langchain-ai.github.io/langgraph/concepts/agentic_concepts/#react-implementation) agent - `create_react_agent`:\n\n```bash\npip install langchain-anthropic\n```\n\n```python\nfrom langchain_anthropic import ChatAnthropic\nfrom langgraph.prebuilt import create_react_agent\n\n# Define the tools for the agent to use\ndef search(query: str):\n    \"\"\"Call to surf the web.\"\"\"\n    # This is a placeholder, but don't tell the LLM that...\n    if \"sf\" in query.lower() or \"san francisco\" in query.lower():\n        return \"It's 60 degrees and foggy.\"\n    return \"It's 90 degrees and sunny.\"\n\ntools = [search]\nmodel = ChatAnthropic(model=\"claude-3-7-sonnet-latest\")\n\napp = create_react_agent(model, tools)\n# run the agent\napp.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"what is the weather in sf\"}]},\n)\n```\n\n## Tools\n\n### ToolNode\n\n`langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_node.ToolNode) of a node that executes tool calls - `ToolNode`:\n\n```python\nfrom langgraph.prebuilt import ToolNode\nfrom langchain_core.messages import AIMessage\n\ndef search(query: str):\n    \"\"\"Call to surf the web.\"\"\"\n    # This is a placeholder, but don't tell the LLM that...\n    if \"sf\" in query.lower() or \"san francisco\" in query.lower():\n        return \"It's 60 degrees and foggy.\"\n    return \"It's 90 degrees and sunny.\"\n\ntool_node = ToolNode([search])\ntool_calls = [{\"name\": \"search\", \"args\": {\"query\": \"what is the weather in sf\"}, \"id\": \"1\"}]\nai_message = AIMessage(content=\"\", tool_calls=tool_calls)\n# execute tool call\ntool_node.invoke({\"messages\": [ai_message]})\n```\n\n### ValidationNode\n\n`langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_validator.ValidationNode) of a node that validates tool calls against a pydantic schema - `ValidationNode`:\n\n```python\nfrom pydantic import BaseModel, field_validator\nfrom langgraph.prebuilt import ValidationNode\nfrom langchain_core.messages import AIMessage\n\n\nclass SelectNumber(BaseModel):\n    a: int\n\n    @field_validator(\"a\")\n    def a_must_be_meaningful(cls, v):\n        if v != 37:\n            raise ValueError(\"Only 37 is allowed\")\n        return v\n\nvalidation_node = ValidationNode([SelectNumber])\nvalidation_node.invoke({\n    \"messages\": [AIMessage(\"\", tool_calls=[{\"name\": \"SelectNumber\", \"args\": {\"a\": 42}, \"id\": \"1\"}])]\n})\n```\n\n## Agent Inbox\n\nThe library contains schemas for using the [Agent Inbox](https://github.com/langchain-ai/agent-inbox) with LangGraph agents. Learn more about how to use Agent Inbox [here](https://github.com/langchain-ai/agent-inbox#interrupts).\n\n```python\nfrom langgraph.types import interrupt\nfrom langgraph.prebuilt.interrupt import HumanInterrupt, HumanResponse\n\ndef my_graph_function():\n    # Extract the last tool call from the `messages` field in the state\n    tool_call = state[\"messages\"][-1].tool_calls[0]\n    # Create an interrupt\n    request: HumanInterrupt = {\n        \"action_request\": {\n            \"action\": tool_call['name'],\n            \"args\": tool_call['args']\n        },\n        \"config\": {\n            \"allow_ignore\": True,\n            \"allow_respond\": True,\n            \"allow_edit\": False,\n            \"allow_accept\": False\n        },\n        \"description\": _generate_email_markdown(state) # Generate a detailed markdown description.\n    }\n    # Send the interrupt request inside a list, and extract the first response\n    response = interrupt([request])[0]\n    if response['type'] == \"response\":\n        # Do something with the response\n    ...\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Library with high-level APIs for creating and executing LangGraph agents and tools.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://www.github.com/langchain-ai/langgraph",
        "Repository": "https://www.github.com/langchain-ai/langgraph"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "255d8da7b0d22304ba128d57e6f691ab6c4c56b7a79f34c84a2f43a704539c70",
                "md5": "b5c5789fd4698e1767c967f2bd08d802",
                "sha256": "06ee27fd5ab6b860f2c44747ae81a1c814c5162ef8c4de6e4729d7b57ead788c"
            },
            "downloads": -1,
            "filename": "langgraph_prebuilt-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b5c5789fd4698e1767c967f2bd08d802",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.9.0",
            "size": 24587,
            "upload_time": "2025-02-27T00:03:13",
            "upload_time_iso_8601": "2025-02-27T00:03:13.615390Z",
            "url": "https://files.pythonhosted.org/packages/25/5d/8da7b0d22304ba128d57e6f691ab6c4c56b7a79f34c84a2f43a704539c70/langgraph_prebuilt-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9df05ac07b25d58a0a5bd126f4afc1a75ce4546f0e08fb4c3432154d904198d2",
                "md5": "38507b1eecbd90289a1412069a9109da",
                "sha256": "b5acc0bd9dbebf66d738e1b31bbf75297f911de00de80a9b23f667342cd83988"
            },
            "downloads": -1,
            "filename": "langgraph_prebuilt-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "38507b1eecbd90289a1412069a9109da",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.9.0",
            "size": 23201,
            "upload_time": "2025-02-27T00:03:15",
            "upload_time_iso_8601": "2025-02-27T00:03:15.350645Z",
            "url": "https://files.pythonhosted.org/packages/9d/f0/5ac07b25d58a0a5bd126f4afc1a75ce4546f0e08fb4c3432154d904198d2/langgraph_prebuilt-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-27 00:03:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "langchain-ai",
    "github_project": "langgraph",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "langgraph-prebuilt"
}
        
Elapsed time: 1.34726s