Tool definition methodology
Adding a custom tool using LangGraph CodeAct requires compliance with the LangChain specification. The steps are as follows:
- surname Cong
langchain_core.toolsimport (data)tooldecorator - Defining Required Tool Functions with Python Functions
- 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.
This answer comes from the articleLangGraph CodeAct: generating code to help intelligences solve complex tasksThe
































