Maplemx / Agently

[AI Agent Application Development Framework] - 🚀 Build AI agent native application in very few code 💬 Easy to interact with AI agent in code using structure data and chained-calls syntax 🧩 Enhance AI Agent using plugins instead of rebuild a whole new agent
http://agently.tech
Apache License 2.0
1.07k stars 122 forks source link

must_call 的入参格式不对 #91

Closed Lizhen0628 closed 3 months ago

Lizhen0628 commented 4 months ago

@must_call_agent.tool(tool_name="get_now") def get_current_datetime_decorated( timezone: ( "str", "[*Required] Timezone string used in pytz.timezone() in Python" ) ): """get current data and time""" tz = pytz.timezone(timezone) return datetime.now().astimezone(tz)

报错内容: 51 if node.arg != "self": 52 tool_info_kwrags["args"].update({ 53 node.arg: ---> 54 (node.annotation.dims[0].value, node.annotation.dims[1].value) 55 if isinstance(node.annotation, ast.Tuple) 56 else (type(node.annotation.value).name, node.annotation.value) 57 }) 58 # get func 59 tool_info_kwrags.update({ "func": func })

AttributeError: 'Tuple' object has no attribute 'dims'

Maplemx commented 4 months ago
import Agently

agent = (
    Agently.create_agent(is_debug=True)
        .set_settings("current_model", "ZhipuAI")
        .set_settings("model.ZhipuAI.auth", { "api_key": "" })
        .set_settings("model.ZhipuAI.options", { "model": "glm-4" })
)

from datetime import datetime
import pytz
@agent.tool(tool_name="get_now")
def get_current_datetime(timezone:("str", "[*Required] Timezone string used in pytz.timezone() in Python")):
    """get current data and time"""
    tz = pytz.timezone(timezone)
    return datetime.now().astimezone(tz)

user_input = "I'm in Foshan City, What time is it now?"

result = (
    agent
        .input(user_input)
        .must_call("get_now")
        .start()
)

This works in my env.

Lizhen0628 commented 4 months ago
import Agently

agent = (
    Agently.create_agent(is_debug=True)
        .set_settings("current_model", "ZhipuAI")
        .set_settings("model.ZhipuAI.auth", { "api_key": "" })
        .set_settings("model.ZhipuAI.options", { "model": "glm-4" })
)

from datetime import datetime
import pytz
@agent.tool(tool_name="get_now")
def get_current_datetime(timezone:("str", "[*Required] Timezone string used in pytz.timezone() in Python")):
    """get current data and time"""
    tz = pytz.timezone(timezone)
    return datetime.now().astimezone(tz)

user_input = "I'm in Foshan City, What time is it now?"

result = (
    agent
        .input(user_input)
        .must_call("get_now")
        .start()
)

This works in my env.

完全copy你的代码运行还是同样的错误。 函数参数类型可以是("str", "[*Required] Timezone string used in pytz.timezone() in Python")这样吗?

Maplemx commented 4 months ago
import Agently

agent = (
    Agently.create_agent(is_debug=True)
        .set_settings("current_model", "ZhipuAI")
        .set_settings("model.ZhipuAI.auth", { "api_key": "" })
        .set_settings("model.ZhipuAI.options", { "model": "glm-4" })
)

from datetime import datetime
import pytz
@agent.tool(tool_name="get_now")
def get_current_datetime(timezone:("str", "[*Required] Timezone string used in pytz.timezone() in Python")):
    """get current data and time"""
    tz = pytz.timezone(timezone)
    return datetime.now().astimezone(tz)

user_input = "I'm in Foshan City, What time is it now?"

result = (
    agent
        .input(user_input)
        .must_call("get_now")
        .start()
)

This works in my env.

完全copy你的代码运行还是同样的错误。 函数参数类型可以是("str", "[*Required] Timezone string used in pytz.timezone() in Python")这样吗?

我使用Python 3.9.19,3.11.8,3.12.2三个版本测试了,都是可以的

Maplemx commented 3 months ago

先关闭本issue,如果再次遇到问题或是有更明确定位,可以重新开启