Agently Versions Save

[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

v3.2.2.3

1 month ago

New Features

  • [Agent.load_yaml_prompt()]:

    We provide developers a new way to manage your request prompt template in YAML file!

    • HOW TO USE:

      • YAML file:
      input: ${user_input}
      use_public_tools:
        - browse
      set_tool_proxy: http://127.0.0.1:7890
      instruct:
        output language: English
      output:
        page_topic:
          $type: str
          $desc: ""
        summary:
          $type: str
          $desc: ""
      
      • Python file:
      import Agently
      
      agent_factory = (
          Agently.AgentFactory()
              .set_settings("model.Google.auth.api_key", "")
              .set_settings("current_model", "Google")
      )
      
      agent = agent_factory.create_agent()
      
      print(
          agent
              .load_yaml_prompt(
                  path="./yaml_prompt.yaml",
                  # or just pass YAML string like this:
                  #yaml=yaml_str
                  variables = {
                      "user_input": "http://Agently.tech",
                  }
              )
              .start()
      )
      
      • Result:
      {'page_topic': 'Agently - Artificial Intelligence for the Enterprise', 'summary': 'Agently is a leading provider of AI-powered solutions for the enterprise. Our platform enables businesses to automate tasks, improve efficiency, and gain insights from their data. We offer a range of services, including:\n\n* **AI-powered automation:** Automate repetitive tasks, such as data entry and customer service, to free up your team to focus on more strategic initiatives.\n* **Machine learning:** Use machine learning to improve the accuracy of your predictions and decisions. We can help you identify trends and patterns in your data, and develop models that can predict future outcomes.\n* **Natural language processing:** Use natural language processing to understand and generate human language. This can be used for a variety of applications, such as chatbots, text analysis, and sentiment analysis.\n\nAgently is committed to helping businesses succeed in the digital age. We believe that AI is a powerful tool that can be used to improve efficiency, innovation, and customer satisfaction. We are excited to partner with you to explore the possibilities of AI for your business.'}
      
  • [Agently Workflow: YAML Flow]:[🧪beta] This feature may change in the future

    We try to provide a simple way to help developers to manage workflow easier with YAML files, so we publish a beta feature YAML Flow to present the idea.

    With this new feature, you can use YAML files to state chunks and manage the connections between chunks.

    Also, we preset some basic chunks(Start, UserInput and Print) to help you build your own workflow quicker.

    • BASIC USE:

      • YAML file:
      chunks:
        start:
          type: Start
        user_input:
          type: UserInput
          placeholder: '[User Input]:'
        print:
          type: Print
      connections:
        - start->user_input->print
      
      • Python file:
      import Agently
      workflow = Agently.Workflow()
      # You can use draw=True to output workflow Mermaid code instead of running it
      #print(workflow.start_yaml(path="./yaml_file.yaml", draw=True))
      workflow.start_yaml(path="./yaml_file.yaml")
      
      • Result:
      [User Input]: 1+2
      >>> 1+2
      
    • ADD YOUR OWN EXECUTORS:

      • YAML file:
      chunks:
        start:
          type: Start
        user_input:
          type: UserInput
          placeholder: '[User Input]:'
        # We state a new chunk named 'calculate'
        calculate:
          # We add a calculate executor to calculate user input
          # with executor_id = 'calculate'
          executor: calculate
        print:
          type: Print
      connections:
        # Then add the 'calculate' chunk into the workflow
        - start->user_input->calculate->print
      
      • Python file:
      import Agently
      
      # use decorator `@workflow.executor_func(<executor_id>)`
      # to state executor function
      @workflow.executor_func("calculate")
      def calculate_executor(inputs, storage):
          result = eval(inputs["input"])
          return str(result)
      
      workflow = Agently.Workflow()
      #print(workflow.start_yaml(path="./yaml_file.yaml", draw=True))
      workflow.start_yaml(path="./yaml_file.yaml")
      
      • Result:
      [User Input]: 1+2
      >>> 3
      
  • [Basic Prompt Management Methods]:

    Add a series prompt management methods to help developers directly manage the prompt information in agent instants or request with different information life cycles.

    These methods below will manage prompt information in agent instant and the prompt information will be pass to model when requesting every time** until this agent instant is dropped**.

    • agent.set_agent_prompt(<slot_name>, <value>)
    • agent.get_agent_prompt(<slot_name>)
    • agent.remove_agent_prompt(<slot_name>)

    These methods below will manage prompt information in single request which will only use the prompt information once! When the request is finished, all the prompt information will be erased.

    • agent.set_request_prompt(<slot_name>, <value>)
    • agent.get_request_prompt(<slot_name>)
    • agent.remove_request_prompt(<slot_name>)

Read Development Handbook - Standard Request Slots to learn more

Updates:

Bug Fixed:


新功能

通过YAML格式数据管理单次Agent请求模板

[Agent.load_yaml_prompt()]

我们提供了一种全新的YAML语法表达方式,来帮助您更好地管理单次Agent请求,除了方便开发人员将不同模块进行解耦外,我们也希望通过这种方式,将Agently提供的能力用一种标准化配置的方式进行跨语种表达,或是将这种表达方式提供给非开发人员使用。

如何使用

  • YAML文件/YAML文本内容:
input: ${user_input}
use_public_tools:
  - browse
set_tool_proxy: http://127.0.0.1:7890
instruct:
  输出语言: 中文
output:
  page_topic:
    $type: str
    $desc: ""
  summary:
    $type: str
    $desc: ""
  • Python文件:
import Agently

agent_factory = (
    Agently.AgentFactory()
        .set_settings("model.Google.auth.api_key", "")
        .set_settings("current_model", "Google")
)

agent = agent_factory.create_agent()

print(
    agent
        .load_yaml_prompt(
            path="./yaml_prompt.yaml",
            # 你也可以用下面方式直接传递YAML格式的字符串
            #yaml=yaml_str
            variables = {
                "user_input": "http://Agently.tech",
            }
        )
        .start()
)
  • 运行结果:
{
    "page_topic": "易用、灵活、高效的开源大模型应用开发框架",
    "summary": "Agently是一个开源的大模型应用开发框架,它可以让开发者轻松地使用大模型来构建应用程序。Agently的特点包括:\n\n* 语法简单易学,5分钟开始使用\n* 安装简单,使用pip install -U Agently即可\n* 使用灵活,可以通过几行代码指定大模型、鉴权信息等信息\n* 支持链式调用,像调用函数一样和Agent实例交互\n* 为工程开发者设计,应用开发灵活性高\n* 支持传递结构化数据灵活表达请求,管理Agent实例设定信息,提供自定义函数\n* 支持监听流式输出,使用Agently Workflow将复杂任务切分成块\n* 架构设计深度,解构了大模型驱动的Agent结构,维护了模型请求前后置信息流处理工作流等基础原子要件\n* 提供能力插件、工作流管理方案等增强开发者在应用层的表达丰富度"
}

使用YAML格式数据管理你的工作流

[Agently Workflow: YAML Flow]

[🧪测试] 这个功能后续可能会调整用法或者语法

我们向您提供一种实验性的通过YAML格式数据管理工作流的方法,通过这种管理方法,您可以对工作流中的工作块定义,以及工作块间的连接关系进行更加方便直观的管理。这个功能将为您呈现我们的初步想法,我们还会持续完善这个能力,强化这种表达方法的表达能力。

同时,我们也在这项新能力中预置了开始(Start)用户输入(UserInput)打印结果(Print)这三个基本工作块,帮助您更快速的构建自己的工作流。通过阅读这三个工作块的定义方法,也能够对您创建自定义工作块提供思路参考。

基本用法

  • YAML文件/YAML文本内容:
chunks:
  start:
    type: Start
  user_input:
    type: UserInput
    placeholder: '[用户输入]: '
  print:
    type: Print
connections:
  - start->user_input->print
  • Python文件:
import Agently
workflow = Agently.Workflow()
# 你可以通过设置draw=True来输出工作流的Mermaid代码,而不是运行它
#print(workflow.start_yaml(path="./yaml_file.yaml", draw=True))
workflow.start_yaml(path="./yaml_file.yaml")
  • 运行结果:
[用户输入]: 1+2
>>> 1+2

自定义你自己的工作块执行器

  • YAML文件/YAML文本内容:
chunks:
  start:
    type: Start
  user_input:
    type: UserInput
    placeholder: '[User Input]:'
  # 我们在这里声明一个新的calculate工作块
  calculate:
    # 然后在这里添加一个calculate执行器来计算用户输入结果
    # 在executor里指定执行器id为calc
    executor: calc
  print:
    type: Print
connections:
  # 然后把calculate工作块放入工作流中
  - start->user_input->calculate->print
  • Python file:
import Agently

# 使用函数装饰器`@workflow.executor_func(<executor_id>)`
# 来声明一个执行器id为calc的执行器函数
@workflow.executor_func("calc")
def calculate_executor(inputs, storage):
    result = eval(inputs["input"])
    return str(result)

workflow = Agently.Workflow()
#print(workflow.start_yaml(path="./yaml_file.yaml", draw=True))
workflow.start_yaml(path="./yaml_file.yaml")
  • Result:
[用户输入]: 1+2
>>> 3

通过基础Prompt管理方法理解不同的Prompt生命周期

我们添加了一系列的Prompt管理方法,来帮助开发者直接管理设定给Agent实例或是单次请求的Prompt信息,设定对象不同,这些Prompt信息的生命周期也是有差别的。

当我们使用agent.set_agent_prompt()方法向Agent实例设定Prompt信息的时候,这些信息将被传递并存储到Agent实例的结构体内,并在这个Agent实例每次请求模型时,都携带这些信息,直到这个Agent实例被销毁或者回收。

- `agent.set_agent_prompt(<基础指令名>, <value>)`
- `agent.get_agent_prompt(<基础指令名>)`
- `agent.remove_agent_prompt(<基础指令名>)`

当我们使用agent.set_request_prompt()方法向Agent实例内部的单次请求实例设定Prompt信息的时候,这些信息将只会在下一次请求时传递给模型,当请求完成后,这些信息就会被清除掉,不再保留。

- `agent.set_request_prompt(<基础指令名>, <value>)`
- `agent.get_request_prompt(<基础指令名>)`
- `agent.remove_request_prompt(<基础指令名>)`

在我们之前提供的Agent指令中,通过Agent能力插件提供的方法,例如Role插件提供的.set_role()方法,就使用了类似.set_agent_prompt()的设定方法。因此,通过.set_role()方法设定的信息将在多次请求间保留。

而基础指令如.input().instruct().output()则使用了类似.set_request_prompt()的设定方法。因此,通过.input()这些方法设定的信息,在当次请求(以.start()命令为标志)结束后,这些信息就被清理了,下次请求时需要重新设定。

阅读框架开发教程 - 基础指令列表了解我们支持的基础指令

功能升级

  • [Agently Workflow]: 做了大量让复杂工作流更加稳定可靠的优化。查看详情
  • [框架核心]: 重命名了基础Prompt槽位,让它们能和基础指令名保持一致。查看详情
  • [Facility]: 使用Agently.lib作为Agently.facility的别名,方便使用。
  • [工具: 网页浏览browse]: 移除了对newspaper3k包的依赖,并使用BeautifulSoup4包作为浏览工具替代 查看详情

问题修复

  • [请求插件: OpenAI]: 修复了会导致在使用代理Proxy的时候报await can not use on response的错误的问题 查看详情
  • [请求插件: OAIClient]: 修复了代理Proxy无法生效的问题 查看详情
  • [请求插件: OAIClient]: 修复了一个导致system prompt无法正常工作的问题 查看详情
  • [Agent能力插件: Tool]: 修复了一个因为重命名Prompt槽位导致的工具调用无法生效的问题 查看详情

v3.2.1.3

1 month ago

New Features

  • [Request: OAIClient] Add a new request plugins for those models which API format is alike OpenAI but have some additional rules like can not support multi system messages or must have strict user-assistant message orders. It's very useful for those local servering models started by local model servering library like Xinference.

HOW TO USE:

import Agently

agent_factory = (
    Agently.AgentFactory(is_debug=True)
        .set_settings("current_model", "OAIClient")
        # Mixtral for example
        .set_settings("model.OAIClient.url" , "https://api.mistral.ai/v1")
        # if you want to use Moonshot Kimi:
        #.set_settings("model.OAIClient.url", "https://api.moonshot.cn/v1")
        # set model name
        # Mixtral model list: https://docs.mistral.ai/platform/endpoints/
        .set_settings("model.OAIClient.options", { "model": "open-mistral-7b" })
        # Moonshot mode list: https://platform.moonshot.cn/docs/pricing#文本生成模型-moonshot-v1
        # set API-KEY if needed
        .set_settings("model.OAIClient.auth.api_key", "")
        # set proxy if needed
        #.set_proxy("http://127.0.0.1:7890")
        # you can also change message rules
        #.set_settings("model.OAIClient.message_rules", {
        #    "no_multi_system_messages": True, # True by default, will combine multi system messages into one
        #    "strict_orders": True, # True by default, will transform messages' order into "User-Assistant-User-Assitant" strictly
        #    "no_multi_type_messages": True, # True by default, will only allow text messages
        #})
)

agent = agent_factory.create_agent()

(
    agent
        .set_role("You love EMOJI very much and try to use EMOJI in every sentence.")
        .chat_history([
            { "role": "user", "content": "It's a beautiful day, isn't it?" },
            { "role": "assistant", "content": "Right, shine and bright!☀️" }
        ])
        .input("What do you suggest us to do today?")
        # use .start("completions") if your model is a completion model
        .start("chat")
)

Update

Bug Fixed


新功能

  • [模型请求插件: OAIClient] 新增新的模型请求插件OAIClient,用于支持开发者请求那些看起来很像OpenAI API格式的模型(但通常会有些和OpenAI API不一致的潜在规则)。这个请求插件也可以用于请求通过类似Xinference这样的本地模型服务化库启动的本地模型服务。

如何使用:

import Agently

agent_factory = (
    Agently.AgentFactory(is_debug=True)
        .set_settings("current_model", "OAIClient")
        # 这里用Mixtral举例
        .set_settings("model.OAIClient.url" , "https://api.mistral.ai/v1")
        # 如果你希望使用月之暗面的Kimi可以参考下面这个url
        #.set_settings("model.OAIClient.url", "https://api.moonshot.cn/v1")
        # 设置你要使用的具体模型
        # Mixtral支持的模型列表: https://docs.mistral.ai/platform/endpoints/
        .set_settings("model.OAIClient.options", { "model": "open-mistral-7b" })
        # 月之暗面支持的模型列表: https://platform.moonshot.cn/docs/pricing#文本生成模型-moonshot-v1
        # 设置API-KEY(如果需要的话,本地模型可能不需要)
        .set_settings("model.OAIClient.auth.api_key", "")
        # 设置代理(如果需要的话)
        #.set_proxy("http://127.0.0.1:7890")
        # 你也可以通过设置变更消息处理的规则
        #.set_settings("model.OAIClient.message_rules", {
        #    "no_multi_system_messages": True, # 默认开,如果有多条system消息,将会被合并成一条
        #    "strict_orders": True, # 默认开,将会强制将消息列转换成“用户-助理-用户-助理”顺序
        #    "no_multi_type_messages": True, # 默认开,将只保留文本类消息,并且直接将文本值放到content里
        #})
)

agent = agent_factory.create_agent()

(
    agent
        .set_role("You love EMOJI very much and try to use EMOJI in every sentence.")
        .chat_history([
            { "role": "user", "content": "It's a beautiful day, isn't it?" },
            { "role": "assistant", "content": "Right, shine and bright!☀️" }
        ])
        .input("What do you suggest us to do today?")
        # 使用.start("completions")可以支持补全模型!
        .start("chat")
)

更新

  • [模型请求插件: ERNIE] 添加了在新的API规范中,对system参数的直接支持。现在传递给文心一言的system prompt将会直接传递给API接口的system参数,而不再转换成用户对话消息了;
  • [请求优化] 优化了list中可以包含多个item的prompt提示方法。

问题修复

  • [请求指令] 修复了导致.general().abstract()不能正常工作的问题;
  • [Agent能力插件: Segment] 修复了导致流式输出过程中,处理器(handler)无法工作的问题;
  • [模型请求插件: ERNIE] 修复了一些引号冲突的问题。

v3.2.1.0

2 months ago

New Features:

  1. [Request] New models are supported!

    新增了两个模型的支持!

    • Claude:
    import Agently
    agent_factory = Agently.AgentFactory()
    
    (
        agent_factory
            .set_settings("current_model", "Claude")
            .set_settings("model.Claude.auth", { "api_key": "" })
            # switch model
            # model list: https://docs.anthropic.com/claude/docs/models-overview
            # default: claude-3-sonnet-20240229
            .set_settings("model.Claude.options", { "model": "claude-3-opus-20240229" })
    )
    
    # Test
    agent = agent_factory.create_agent()
    agent.input("Print 'It works'.").start()
    
    • MiniMax:
    import Agently
    agent_factory = Agently.AgentFactory()
    
    (
        agent_factory
            .set_settings("current_model", "MiniMax")
            .set_settings("model.MiniMax.auth", {
                "group_id": "",
                "api_key": ""
            })
            # switch model
            # model list:https://www.minimaxi.com/document/guides/chat-model/V2?id=65e0736ab2845de20908e2dd
            # default: abab5.5-chat
            .set_settings("model.MiniMax.options", { "model": "abab6-chat" })
    )
    
    # Test
    agent = agent_factory.create_agent()
    agent.input("Print 'It works'.").start()
    
  2. [Agent Workflow] add new feature .draw() to generate mermaid code to present current workflow graph!

    添加了可以根据workflow连接情况生成流程图代码(mermaid格式)的方法。

    # after connect all chunks
    mermaid_code = workflow.draw()
    
    # you can use mermaid-python package to draw the graph in colab
    # !pip install -q -U mermaid-python
    from mermaid import Mermaid
    Mermaid(mermaid_code)
    

Bug Fixed:

  1. [Framework]: https://github.com/Maplemx/Agently/issues/49
    Added try except when request event loop is not in debug mode to avoid error Event loop is closed.
    添加了try except逻辑,来减少在非debug模式下Event loop is closed的报错;
  2. [Agently Workflow]: https://github.com/Maplemx/Agently/issues/48
    Removed unnecessary print when workflow start running.
    移除了workflow启动时会出现的一个不必要的print。

v3.2.0.1

2 months ago

New Feature:

  1. [Agently Workflow] We're glad to introduce a brand new feature of Agently v3.2 to you all: Agently Workflow!

    With this new feature, you can arrange and manage your LLMs based application workflow in just 3 steps, simple and easy:

    1. Define and program your application logic into different workflow chunks;
    2. Connect chunks using chunk.connect_to() in orders; (Loop and condition judugment supported)
    3. Start the workflow using workflow.startup().

    Visit Agently Workflow Showcase Page to Explore More

  2. [Agent Component: Decorator]: @agent.tool(tool_info:dict={})

    Now you can use @agent.tool() to decorate a function to register it as an agent's tool:

    @agent.tool()
    def get_current_date():
        """Get current date"""
        return datetime.now().date().strftime("%Y-%B-%d")
    

    You can also pass other parameters to @agent.tool() in the same way when using agent.register_tool().

Update:

  1. [Framework] Updated inherit logic of settings and add is_debug parameter to .create_agent();
  2. [Agent Component: Role] Change .set_role_name() to .set_role_id() and the role id will not be passed to agent request now;
  3. [Facility: RoleManager] Change .set_name() to .set_id();
  4. [Agent Component: Tool] Update tool using prompt;

Bug Fix:

  1. [Agent Component: Segment] Clean segments' prompt cache at an earlier time and add try except logic to avoid unclean runtime cause error;

全新功能:

  1. [Agently Workflow]

    我们非常高兴能够向您介绍Agently v3.2版本推出的全新功能:Agently Workflow!

    使用这项全新的功能,只需要一二三步走,您就能够轻松惬意地编排管理您的语言模型应用工作流了:

    1. 在workflow chunks切块中编写您的应用工作流中的单块工作逻辑(如输入、判断、请求执行、数据存取等);
    2. 使用chunk.connect_to()方法将切块按您想要的工作顺序进行连接(支持环状连接、条件分支等复杂连接关系);
    3. 通过workflow.startup()开始运行工作流。

    功能案例:点击查看案例,了解新功能的用法

  2. [Agent Component: Decorator]: @agent.tool(tool_info:dict={})

    现在,您可以使用@agent.tool()装饰器来将一个函数注册给Agent使用了,具体用法如下:

    @agent.tool()
    def get_current_date():
        """Get current date"""
        return datetime.now().date().strftime("%Y-%B-%d")
    

    您可以向@agent.tool()传递其他参数,参数要求和agent.register_tool()方法保持一致。

重要更新

  1. [框架核心] 改善了一些框架内的settings设置项的继承逻辑,并且支持向.create_agent()传递is_debug参数了;
  2. [Agent能力组件:Role].set_role_name()方法更改为.set_role_id()方法,使其和业务表达解耦,同时,设置的role id将不会在agent请求模型时被传递过去,只作为代码编写时的agent身份标识;
  3. [公共设施插件: RoleManager] 与上条相同,将.set_name()方法更改为.set_id()
  4. [Agent能力组件:Tool] 更新了部分工具调用的提示词,优化Tool插件的工作质量;

问题修复

  1. [Agent能力组件:Segment] 在更早的时机清除Segments的提示词设置缓存,并添加了一段错误监听逻辑,以在运行出错时能够将当前的Segments设置清除,避免干扰下一次运行(尤其是在Colab环境中)。

v3.1.5.5

3 months ago

New Feature:

  1. [Agent Component: Session] Added chat history manual management methods and settings:

    Methods:

    • .add_chat_history(role: str, cotnent: str)
    • .get_chat_history(*, is_shorten: bool=False)
    • .rewrite_chat_history(new_chat_history: list)

    Settings:

    • strict_orders: Setting value is set as True by default. If this setting is True, component will ensure chat history append in "User-Assistant-User-Assistant" orders and when the order is incorrect, manual management methods above will automatically help developers combining chat history content. You can use .toggle_strict_orders(False) to avoid strict_orders mode.
    • manual_chat_history: Setting value is set as False by default. You can use .toggle_manual_chat_history(True) to active manual chat history management mode. If this setting is True, component will stop automatically fetch and append chat history from agent request's response to allow developers to add chat history manually using methods above. Turn on this setting when .active_session() is on will ensure manual managed chat history be passed to next agent request to enable manual managed multi-round chat.

Update:

  1. [Tool]Improved tool using prompt and improved the adaptation when timelimit argument is not in options dict when using search tool;
  2. [Framework] Updated agent alias info printer, now you can use agent.alias_manager.print_alias_info(group_by="agent_component") to print alias group by component names;
  3. [Framework] Updated JSON find and decode methods, import json5 lib and improved error report detail in debug mode;
  4. [Request: ERNIE] Updated default model name to "ernie-4.0" to follow Baidu official model name updating.

Bug Fix:

  1. [Framework] Fixed event loop closed error when using tools or fixing json decode error;
  2. [Agent Component: Segment] Fixed a bug that will cause segment main thread close too early before all async handlers finish their works;
  3. [Agent Component: Segment] Fixed a bug that will cause segment can not overwrite prompt_output.

v3.1.5

4 months ago

New Feature:

  1. Support ZhipuAI GLM-4 and GLM-3-turbo Read here to see how to set settings
  2. Agent Component: Decorator:
    • Move @agent.auto_func into Decorator Component
    • New decorator @agent.on_event(<event_name>) to help developers to add event listener easier Read Example

Update:

  1. Update reply getter to avoid unnecessary error queue.empty to make developers easier to locate error
  2. Update tool using logic and update search result data structure to make response with search better.

Bug Fixed:

  1. Fixed unexpected error when using Gemini and proxy is not set when using old version of httpx

新功能:

  1. 支持智谱GLM-4和GLM-3-turbo在线模型 阅读此案例了解如何配置使用
  2. 新增Agent组件:Decorator函数装饰器
    • 将3.1.4版本的@agent.auto_func函数装饰器从Agent类中移动到Decorator组件里
    • 新增函数装饰器@agent.on_event(<event_name>),帮助开发者为Agent请求回复内容添加事件监听器 阅读此案例了解事件监听器的作用

功能升级:

  1. 优化了请求线程中获取最终返回值的逻辑,以避免不必要的queue.empty报错,让开发者更方便地定位错误
  2. 升级了工具调用逻辑和搜索结果数据结构,现在使用搜索工具能够获得更好的回复结果了

问题修复:

  1. 修复了一个在使用旧版httpx时,请求Gemini但未设置proxy会报错的问题

v3.1.4

4 months ago

New Feature: Summon a Genie 🧞‍♂️ (Function Decorator) to Generate Agent Powered Function in Runtime

As a developer, have you ever dreamed about writing some definitions and annotation in code then "boom!" all in a sudden, some genies 🧞‍♂️ come out and make all your wishes happen? Notice that: the genies do not write the code for you, instead they just finish the work for you!

Now Agently framework present a brand new feature "agent auto function decorator" for you in version 3.1.4! Use @<agent instance>.auto_func to decorate your function and feel the magic!

Combining the tools-using abilities we enhanced the Agently agents recently in version 3.1.2, just open your mind and let's see how fantasy work you can let the agents help you to do.

Demo Code:

# create a search agent
search_agent = (
    Agently.create_agent()
        .set_settings("model.OpenAI.auth", { "api_key": "" })
)

# equip search agent with tool "search_definition"
search_agent.use_public_tools("search_definition")

# define your function: input arguments, output data structure requirement, function purpose
# then use decorator to call search agent to help
@search_agent.auto_func
def find_definition(concept_keyword:str) -> {"source": ("String", ), "definition": ("String", )}:
    """Search your knowledge or the internet to find out the definition of {concept_keyword}."""
    return

# do not need to complete the function coding
# just call it and get your result
result = find_definition("OpenAI")

Result Example:

{'source': 'Wikipedia', 'definition': "OpenAI is a U.S. artificial intelligence (AI) research organization founded in December 2015, researching artificial intelligence with the declared intention of developing 'safe and beneficial' artificial general intelligence."}

Visit Show Case Page to Explore What it Can Do More!


新功能:召唤🧞‍♂️(代码装饰器)完成只给了定义和注释的函数指向的工作

作为程序员,你是否曾经梦想着有一天,在编写代码的时候,你只需要写下一些定义和注释,然后就有某个神奇的精灵🧞‍♂️跳出来帮你把剩下的工作都完成了?注意哦,这里我们说的,并不是帮你把那些代码写完,而是直接帮你把你定义的工作做完哦!

现在,Agently框架在圆周率版本(3.1.4)为您推出了这样的全新功能:"agent智能函数装饰器",你只需要在写好定义和注释的空函数上方,使用@<agent instance>.auto_func这样一个函数装饰器,就可以感受到魔法一般的效果啦!

结合Agently最近为agent添加的工具使用能力,思路打开🫴,看看我们能让agent帮助我们做哪些神奇的事情吧。

样例代码:

# 创建一个search_agent
search_agent = (
    Agently.create_agent()
        .set_settings("model.OpenAI.auth", { "api_key": "" })
)

# 给你的search_agent装备搜索工具
search_agent.use_public_tools("search_definition")

# 定义你的函数(输入参数、输出格式、函数的工作目标)
# 然后通过装饰器召唤你的search_agent来帮忙
@search_agent.auto_func
def find_definition(concept_keyword:str) -> {"source": ("String", ), "definition": ("String", )}:
    """Search your knowledge or the internet to find out the definition of {concept_keyword}."""
    return

# 直接运行就可以获得你想要的结果
result = find_definition("OpenAI")

点击查看相关Show Case案例页面,了解还有哪些场景可以使用

v3.1.3

4 months ago

Agently v3.1.3 - Embedding Facility

New Feature:

Add embedding plugin to facility

Now You can use Agently.facility.embedding.<ProviderName> to use, provider including OpenAI, Google, ERNIE, ZhipuAI:

import Agently
# OpenAI
(
    Agently.facility
    .set_settings("embedding.OpenAI.auth", { "api_key": "" })
)
# Baidu ERNIE
(
    Agently.facility
    .set_settings("embedding.ERNIE.auth", { "aistudio": "" })
)
# ZhipuAI
(
    Agently.facility
    .set_settings("embedding.ZhipuAI.auth", { "api_key": "" })
)
# Google
(
    Agently.facility
    .set_settings("embedding.Google.auth", { "api_key": "" })
)

print(
    Agently.facility.embedding.OpenAI("I'm a yellow duck.")
)

Upgrade:

  1. Add agent.stop_tools() to remove tools those already register to agent;
  2. Add Agently.set_settings() to make developers easier to set global settings;
  3. FileStorage plugin storage path now is a variable to make it easier for developers to edit;

Bug Fix:

  1. When output contain strings like '[OUTPUT]' will no longer mislead JSON clean process.

新功能:

Facility新增Embedding插件 现在开发者可以通过Agently.facility.embedding使用,可用厂商包括OpenAI,Google,百度文心(ERNIE),智谱,用法代码样例:

import Agently
# OpenAI
(
    Agently.facility
    .set_settings("embedding.OpenAI.auth", { "api_key": "" })
)
# Baidu ERNIE
(
    Agently.facility
    .set_settings("embedding.ERNIE.auth", { "aistudio": "" })
)
# ZhipuAI
(
    Agently.facility
    .set_settings("embedding.ZhipuAI.auth", { "api_key": "" })
)
# Google
(
    Agently.facility
    .set_settings("embedding.Google.auth", { "api_key": "" })
)

print(
    Agently.facility.embedding.OpenAI("我是一只小鸭子")
)

升级优化:

  1. 增加agent.stop_tools()方法,让开发者可以移除已经赋予给agent的工具;
  2. 增加Agently.set_settings()方法,方便开发者进行全局设置;
  3. FileStorage插件已经将存储路径调整为一个变量,可以在插件内进行设置;

Bug Fix:

  1. 修复了当输出时携带'[OUTPUT]'字符串时,会导致JSON清洗出错的问题。

v3.1.2

4 months ago

Using Tools is the new feature in Agently v3.1.

You can register your function as tools to agent instance or to global tool manager.

You can also use default tools plugins in /plugins/tool/ dir or create more tool package plugins. Go to/plugins/tool/ to see how simple it is to create your own tool package plugins.

Then you can let agent instance plan whether or not to use tools and in what order to use those toolsYou can also use .must call() alias to tell agent instance to generate a dict type result to help you calling a tool.

Visit this document to see demonstration of the new feature


使用工具是Agently v3.1版本的重大功能性升级。

你可以把自己编写的函数作为工具注册给Agent实例,或者注册到全局的工具管理器(toolmanager)上。

你也可以使用框架在 /plugins/tool/ 文件夹中内置的工具集(tool package)插件,或者根据这些插件文件的格式,创建自己的工具集插件。访问 /plugins/tool/ 文件夹你就会发现创建自己的工具集插件是一件多么简单的事情。

然后,向Agent实例以,register tool()注册工具,或是通过,use all public tools()等指令告知Agent启用全部或者某些工具,你就可以让Agent实例自行决定是否在处理请求时使用工具了。

当然,你也可以通过.must call()指令让Agent实例生成一个字典类型的结果,帮助你来调用某个指定的工具。

访问这个文档查看使用新能力的案例演示

v3.0.6

4 months ago

New Feature: You can use Gemini Pro now!

How to use:

(
agent_factory
    .set_settings("model.Google.auth.api_key", "<Your-Google-API-Key-Here>")
    .set_settings("current_model", "Google")
    .set_settings("proxy", "http://127.0.0.1:7890") # You can set proxy if needed
)