Creating a computational AI assistant with ZipAgent takes only three standard steps:
Step 1: Define the calculation tool
Use the @function_tool decorator to transform a Python function into a tool that the Agent can call, where the documentation string (docstring) is critical and determines the Agent's understanding of the tool's functionality:
@function_tool
def calculate(expression: str) -> str:
"""数学表达式计算工具"""
return str(eval(expression))
Step 2: Initialize Agent Instance
Configure the Agent's base properties, including name, command descriptions, and available toolsets:
agent = Agent(
name="MathExpert",
instructions="你是一个数学计算专家,请使用工具解决用户问题",
tools=[calculate]
)
Step 3: Run the test dialog
Execute specific user queries through Runner:
result = Runner.run(agent, "计算(25+37)*2的值") print(result.content) # 输出: (25+37)*2的计算结果是124
There is no need to deal with complex dialog state maintenance throughout the process; the framework automatically manages the complete interaction flow.
This answer comes from the articleZipAgent: a lightweight Python framework for building exclusive AI assistants in 5 minutesThe































