ragflow/agent/component
Song Fuchang a1f06a4fdc
Feat: Support tool calling in Generate component (#7572)
### What problem does this PR solve?

Hello, our use case requires LLM agent to invoke some tools, so I made a
simple implementation here.

This PR does two things:

1. A simple plugin mechanism based on `pluginlib`:

This mechanism lives in the `plugin` directory. It will only load
plugins from `plugin/embedded_plugins` for now.

A sample plugin `bad_calculator.py` is placed in
`plugin/embedded_plugins/llm_tools`, it accepts two numbers `a` and `b`,
then give a wrong result `a + b + 100`.

In the future, it can load plugins from external location with little
code change.

Plugins are divided into different types. The only plugin type supported
in this PR is `llm_tools`, which must implement the `LLMToolPlugin`
class in the `plugin/llm_tool_plugin.py`.
More plugin types can be added in the future.

2. A tool selector in the `Generate` component:

Added a tool selector to select one or more tools for LLM:


![image](https://github.com/user-attachments/assets/74a21fdf-9333-4175-991b-43df6524c5dc)

And with the `bad_calculator` tool, it results this with the `qwen-max`
model:


![image](https://github.com/user-attachments/assets/93aff9c4-8550-414a-90a2-1a15a5249d94)


### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):

Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
2025-05-16 16:32:19 +08:00
..
__init__.py Feat: add code agent component (#7672) 2025-05-16 10:27:47 +08:00
akshare.py Import akshare lazzily. (#4708) 2025-02-05 12:04:11 +08:00
answer.py Code refactor. (#4291) 2024-12-30 18:38:51 +08:00
arxiv.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
baidu.py Add iteration for agent. (#4258) 2024-12-27 11:38:33 +08:00
baidufanyi.py Fix BaiduFanyi TestRun parameter validation and debug method missing … (#4275) 2024-12-30 10:34:57 +08:00
base.py add show debug (#7390) 2025-05-12 17:15:19 +08:00
begin.py Support debug components. (#3994) 2024-12-11 19:23:59 +08:00
bing.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
categorize.py add show debug (#7390) 2025-05-12 17:15:19 +08:00
code.py Feat: add code agent component (#7672) 2025-05-16 10:27:47 +08:00
concentrator.py Format: dos2unix (#4467) 2025-01-13 18:19:01 +08:00
crawler.py Fix potential SSRF attack vulnerability (#4334) 2025-01-02 18:45:45 +08:00
deepl.py Fix errors detected by Ruff (#3918) 2024-12-08 14:21:12 +08:00
duckduckgo.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
email.py Fix: Email error. (#6701) 2025-04-01 10:37:04 +08:00
exesql.py <think> tag is missing. (#7256) 2025-04-24 11:44:10 +08:00
generate.py Feat: Support tool calling in Generate component (#7572) 2025-05-16 16:32:19 +08:00
github.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
google.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
googlescholar.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
invoke.py Feat: add data type invoke (#5126) 2025-02-27 16:15:33 +08:00
iteration.py Add iteration for agent. (#4258) 2024-12-27 11:38:33 +08:00
iterationitem.py Feat: apply LLM to optimize citations. (#5935) 2025-03-11 19:56:21 +08:00
jin10.py Format: dos2unix (#4467) 2025-01-13 18:19:01 +08:00
keyword.py add show debug (#7390) 2025-05-12 17:15:19 +08:00
message.py Add graphrag (#1793) 2024-08-02 18:51:14 +08:00
pubmed.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
qweather.py Fix component qweather (#2240) 2024-09-04 17:53:11 +08:00
relevant.py Component debugging funcionality. (#4012) 2024-12-13 08:50:32 +08:00
retrieval.py Feat: let image citation being shown. (#7624) 2025-05-13 19:30:05 +08:00
rewrite.py Refa: make Rewrite component effective to relative data expression. (#5752) 2025-03-07 13:48:13 +08:00
switch.py Fix: swich follow interact issue. (#6279) 2025-03-19 17:30:12 +08:00
template.py Fix: Preserve quotes while handling variable substitution withTemplate component. (#6410) 2025-03-21 19:44:03 +08:00
tushare.py Format: dos2unix (#4467) 2025-01-13 18:19:01 +08:00
wencai.py Format: dos2unix (#4467) 2025-01-13 18:19:01 +08:00
wikipedia.py Use consistent log file names, introduced initLogger (#3403) 2024-11-14 17:13:48 +08:00
yahoofinance.py Format: dos2unix (#4467) 2025-01-13 18:19:01 +08:00