Git Product home page Git Product logo

actionflow's Introduction

🇨🇳中文 | 🌐English | 🇯🇵日本語


Agentica: Build AI Agents

PyPI version Downloads Contributions welcome License Apache 2.0 python_version GitHub issues Wechat Group

Agentica: A Human-Centric Framework for Large Language Model Agent Building.

Agentica: 构建你自己的Agent

Overview

LLM Agent

llm_agnet

  • 规划(Planning):任务拆解、生成计划、反思
  • 记忆(Memory):短期记忆(prompt实现)、长期记忆(RAG实现)
  • 工具使用(Tool use):function call能力,调用外部API,以获取外部信息,包括当前日期、日历、代码执行能力、对专用信息源的访问等

Agentica架构

agentica_arch

  • Planner:负责让LLM生成一个多步计划来完成复杂任务,生成相互依赖的“链式计划”,定义每一步所依赖的上一步的输出
  • Worker:接受“链式计划”,循环遍历计划中的每个子任务,并调用工具完成任务,可以自动反思纠错以完成任务
  • Solver:求解器将所有这些输出整合为最终答案

Features

Agentica是一个Agent构建工具,功能:

  • 简单代码快速编排Agent,支持 Reflection(反思)、Plan and Solve(计划并执行)、RAG、Agent、Multi-Agent、Multi-Role、Workflow等功能
  • Agent支持prompt自定义,支持多种工具调用(tool_calls)
  • 支持OpenAI/Azure/Claude/Ollama/Together API调用

Installation

pip install -U agentica

or

git clone https://github.com/shibing624/agentica.git
cd agentica
pip install .

Getting Started

  1. 复制example.env文件为.env,并粘贴OpenAI API key或者Moonshoot API key。

  2. 使用agentica构建Agent,拆解任务并执行:

自动调用google搜索工具,示例examples/web_search_demo.py

from agentica import Assistant, OpenAILLM, AzureOpenAILLM
from agentica.tools.search_serper import SearchSerperTool

m = Assistant(
  llm=AzureOpenAILLM(),
  description="You are a helpful ai assistant.",
  show_tool_calls=True,
  # Enable the assistant to search the knowledge base
  search_knowledge=False,
  tools=[SearchSerperTool()],
  # Enable the assistant to read the chat history
  read_chat_history=True,
  debug_mode=True,
)

r = m.run("一句话介绍林黛玉")
print(r, "".join(r))
r = m.run("北京最近的新闻", stream=True, print_output=True)
print(r, "".join(r))
r = m.run("总结前面的问答", stream=False, print_output=False)
print(r)

Examples

示例 描述
examples/naive_rag_demo.py 实现了基础版RAG,基于Txt文档回答问题
examples/advanced_rag_demo.py 实现了高级版RAG,基于PDF文档回答问题,新增功能:pdf文件解析、query改写,字面+语义多路召回,召回排序(rerank)
examples/python_assistant_demo.py 实现了Code Interpreter功能,自动生成python代码,并执行
examples/research_demo.py 实现了Research功能,自动调用搜索工具,汇总信息后撰写科技报告
examples/team_news_article_demo.py 实现了写新闻稿的team协作,multi-role实现,委托不用角色完成各自任务:研究员检索分析文章,撰写员根据排版写文章,汇总多角色成果输出结果
examples/workflow_news_article_demo.py 实现了写新闻稿的工作流,multi-agent的实现,定义了多个Assistant和Task,多次调用搜索工具,并生成高级排版的新闻文章
examples/workflow_investment_demo.py 实现了投资研究的工作流:股票信息收集 - 股票分析 - 撰写分析报告 - 复查报告等多个Task
examples/crawl_webpage_demo.py 实现了网页分析工作流:从Url爬取融资快讯 - 分析网页内容和格式 - 提取核心信息 - 汇总保存为md文件
examples/find_paper_from_arxiv_demo.py 实现了论文推荐工作流:自动从arxiv搜索多组论文 - 相似论文去重 - 提取核心论文信息 - 保存为csv文件
examples/remove_image_background_demo.py 实现了自动去除图片背景功能,包括自动通过pip安装库,调用库实现去除图片背景
examples/text_classification_demo.py 实现了自动训练分类模型的工作流:读取训练集文件并理解格式 - 谷歌搜索pytextclassifier库 - 爬取github页面了解pytextclassifier的调用方法 - 写代码并执行fasttext模型训练 - check训练好的模型预测结果
examples/llm_os_demo.py 实现了LLM OS的初步设计,基于LLM设计操作系统,可以通过LLM调用RAG、代码执行器、Shell等工具,并协同代码解释器、研究助手、投资助手等来解决问题。
examples/workflow_write_novel_demo.py 实现了写小说的工作流:定小说提纲 - 搜索谷歌反思提纲 - 撰写小说内容 - 保存为md文件
examples/workflow_write_tutorial_demo.py 实现了写技术教程的工作流:定教程目录 - 反思目录内容 - 撰写教程内容 - 保存为md文件

LLM OS

The LLM OS design:

LLM OS

Run the LLM OS App

cd examples
streamlit run llm_os_demo.py

llm_os

Web UI

shibing624/ChatPilot 兼容agentica,可以通过Web UI进行交互。

Web Demo: https://chat.mulanai.com

git clone https://github.com/shibing624/ChatPilot.git
cd ChatPilot
pip install -r requirements.txt

cp .env.example .env

bash start.sh

Contact

  • Issue(建议) :GitHub issues
  • 邮件我:xuming: [email protected]
  • 微信我: 加我微信号:xuming624, 备注:姓名-公司-NLP 进NLP交流群。

Citation

如果你在研究中使用了agentica,请按如下格式引用:

APA:

Xu, M. agentica: A Human-Centric Framework for Large Language Model Agent Workflows (Version 0.0.2) [Computer software]. https://github.com/shibing624/agentica

BibTeX:

@misc{Xu_agentica,
  title={agentica: A Human-Centric Framework for Large Language Model Agent Workflows},
  author={Xu Ming},
  year={2024},
  howpublished={\url{https://github.com/shibing624/agentica}},
}

License

授权协议为 The Apache License 2.0,可免费用做商业用途。请在产品说明中附加agentica的链接和授权协议。

Contribute

项目代码还很粗糙,如果大家对代码有所改进,欢迎提交回本项目,在提交之前,注意以下两点:

  • tests添加相应的单元测试
  • 使用python -m pytest来运行所有单元测试,确保所有单测都是通过的

之后即可提交PR。

Acknowledgements

Thanks for their great work!

actionflow's People

Contributors

shibing624 avatar eltociear avatar guanyixuan avatar

Stargazers

sice avatar  avatar 周南 avatar Alberto Ferrer avatar ac.zzz avatar Li Chunxia avatar Antony avatar  avatar flyonok avatar illuz avatar  avatar  avatar HeisenBerg? avatar  avatar  avatar godIsAProgrammer avatar 雨渐渐 avatar brunowang avatar  avatar LoganLan 兰浩 avatar Meta42 avatar Flipped avatar Littlefish avatar  avatar  avatar  avatar thundax avatar Stupid-Ai avatar 超级小小鱼 avatar cwyalpha avatar  avatar Aaron avatar  avatar  avatar bigbrother666 avatar Kerwin Wilson avatar Laurie avatar Xialie Zhuang avatar suc16 avatar  avatar  avatar Wu Maojia avatar  avatar  avatar  avatar  avatar

Watchers

HeisenBerg? avatar  avatar Kostas Georgiou avatar thundax avatar

actionflow's Issues

数据库示例问题

您好,能够为初学者提供一个数据库连接的参数示例供参考。感谢!

requirements中没有streamlit,直接运行示例程序会报错

Describe the bug

直接运行streamlit run llm_os_demo.py会提示没有streamlit

按照llm_os_demo.py中的提示安装完额外所需依赖后再运行, 报如下错误

Traceback (most recent call last):
  File "/miniconda3/lib/python3.12/site-packages/agentica/emb/text2vec_emb.py", line 9, in <module>
    from text2vec import SentenceModel
  File "/miniconda3/lib/python3.12/site-packages/text2vec/__init__.py", line 8, in <module>
    from text2vec.bertmatching_model import BertMatchModel
  File "/miniconda3/lib/python3.12/site-packages/text2vec/bertmatching_model.py", line 11, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/miniconda3/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 589, in _run_script
    exec(code, module.__dict__)
  File "/agentica/examples/llm_os_demo.py", line 22, in <module>
    from agentica.emb.text2vec_emb import Text2VecEmb
  File "/miniconda3/lib/python3.12/site-packages/agentica/emb/text2vec_emb.py", line 11, in <module>
    raise ImportError(
ImportError: `text2vec` not installed. Please install it with `pip install text2vec`
2024-07-04 09:23:40.786 Uncaught app exception
Traceback (most recent call last):
  File "/miniconda3/lib/python3.12/site-packages/agentica/emb/text2vec_emb.py", line 9, in <module>
    from text2vec import SentenceModel
  File "/miniconda3/lib/python3.12/site-packages/text2vec/__init__.py", line 8, in <module>
    from text2vec.bertmatching_model import BertMatchModel
  File "/miniconda3/lib/python3.12/site-packages/text2vec/bertmatching_model.py", line 11, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/miniconda3/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 589, in _run_script
    exec(code, module.__dict__)
  File "/agentica/examples/llm_os_demo.py", line 22, in <module>
    from agentica.emb.text2vec_emb import Text2VecEmb
  File "/miniconda3/lib/python3.12/site-packages/agentica/emb/text2vec_emb.py", line 11, in <module>
    raise ImportError(
ImportError: `text2vec` not installed. Please install it with `pip install text2vec`

To Reproduce

git clone https://github.com/shibing624/agentica.git
cd agentica
pip install .
cd examples
pip install streamlit agentica text2vec sqlalchemy lancedb pyarrow yfinance
streamlit run llm_os_demo.py

Describe your attempts

  • [ √ ] I checked the documentation and found no answer
  • [ √ ] I checked to make sure that this is not a duplicate issue

You should also provide code snippets you tried as a workaround, StackOverflow solution that you have walked through, or your best guess of the cause that you can't locate (e.g. cosmic radiation).

Context

  • OS [e.g. Windows 10, macOS 10.14]: Ubuntu 22.04.4 LTS
  • Hardware [e.g. CPU only, GTX 1080 Ti]: RTX 4090

Additional Information

Other things you want the developers to know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.