Overseas access: www.kdjingpai.com
Bookmark Us
Current Position:fig. beginning " AI Answers

How do I add custom tools to LangGraph CodeAct to extend the capabilities of intelligences?

2025-08-27 1.8 K

Tool definition methodology

Adding a custom tool using LangGraph CodeAct requires compliance with the LangChain specification. The steps are as follows:

  1. surname Cong langchain_core.tools import (data) tool decorator
  2. Defining Required Tool Functions with Python Functions
  3. Ensure that the parameter type is clear and has a documentation string description

Demonstration

Below is an example of the addition of a math tool:

from langchain_core.tools import tool
import math
@tool
def add(a: float, b: float) -> float:
    """加法工具"""
    return a + b
@tool
def sqrt(a: float) -> float:
    """平方根工具"""
    return math.sqrt(a)
tools = [add, sqrt]

tool integration

Pass the list of tools in when initializing the smartbody:code_act = create_codeact(model, tools=tools, eval=None). Once integrated, the intelligentsia will be able to use the defined tools in the generated code.

caveat

Tool functions need to have clear parameter type labeling and documentation, which helps the model to properly understand and use the tools.

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

Top

en_USEnglish