中文| English
Chan-Agent
一个简洁高效的 Agent 架构,旨在为开发者提供灵活、易用的工具,支持多种 LLM 模型与任务自动化。
特点
- 轻量级:高效且快速,适合多种应用场景。
- 兼容多种 LLM 模型:支持主流的 LLM 模型,灵活配置,方便替换。
- 支持 LLM 任务执行:内置灵活的任务执行功能,可以方便地执行各种 LLM 任务。
- 支持 Agent 执行:支持 Agent 执行任务,并通过协作提升系统的智能化与自动化水平。
安装
通过 pip 安装:
pip install chan-agent
使用示例
初始化LLM
from chan_agent.llms import get_llm
llm = get_llm(
llm_type='openai',
model_name='gpt-4o-mini',
base_url='https://api.openai.com/v1',
api_key='your-api-key'
)
创建任务
from chan_agent.task_llm import TaskLLM
from chan_agent.schema import TaskOutputs, TaskInputItem
class TranslationOutput(TaskOutputs):
translation: str
task = "Translate the following text to French."
rules = ["Keep the original meaning.", "Use formal language."]
task_llm = TaskLLM(llm=llm, task=task, rules=rules, output_model=TranslationOutput)
执行任务
inputs = [
TaskInputItem(key="text", key_name="Text to translate", value="Hello, how are you?")
]
result = task_llm.call(inputs=inputs)
print(result)
使用工具
from chan_agent.llms import get_llm
from chan_agent.base_agent import BaseAgent
from chan_agent.base_tool import BaseTool, ToolResult
from chan_agent.schema import AgentMessage
llm = get_llm(
llm_type='openai',
model_name='gpt-4o-mini',
base_url='https://api.openai.com/v1',
api_key='your-api-key'
)
class WeatherTool(BaseTool):
name = "weather_tool"
description = "A tool that fetches weather information for a given city."
parameters = {
'city': {
'type': 'string',
'description': 'city name',
'required': True
},
}
def call(self, params, **kwargs) -> ToolResult:
city = params.get("city")
# Return a fixed fake weather response
return ToolResult(response=f"The weather in {city} is sunny with a high of 25°C.", use_tool_response=False)
tools = [WeatherTool()]
agent = BaseAgent(llm=llm, role="Assistant", tools=tools, rules=["Be polite."])
messages = []
messages.append(AgentMessage(role="user", content="Hello, can you tell me the weather in New York?"))
response = agent.chat(messages)
print(response)
说明
- 部分代码参考了Qwen-Agent
Metadata
Release files for chan-agent 0.0.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| chan_agent-0.0.16.tar.gz | 19.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chan_agent-0.0.16-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.4 kB
Release files / chan_agent-0.0.16.tar.gz
| Download URL | chan_agent-0.0.16.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bdd2fdb94bb4dff0c2feec0c54793a4f3f7fa76b943d53bdc92e5e83ed47864
|
|
BLAKE2b-256 checksum How to use checksums |
fe987c3cfc6ea078654e17d16862baacbdc4b5afe501803e8c55c2e1464b22d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.11
|
Release files / chan_agent-0.0.16-py3-none-any.whl
| Download URL | chan_agent-0.0.16-py3-none-any.whl |
|---|---|
| Size | 29.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd8d4561b4cd99933c7aae037301cb745a098db1f227fe2a194c18b469032d6f
|
|
BLAKE2b-256 checksum How to use checksums |
bd8fdb64cfa1bb546435dc0d024daf2747932ddb234e32d3e956fa994cb2ebda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.11
|
Security for chan-agent 0.0.16
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.