# c-agent **Repository Path**: hy19971224_admin/c-agent ## Basic Information - **Project Name**: c-agent - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-15 - **Last Updated**: 2026-03-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Based on the code map provided, I can see this is a JavaScript/Node.js project for an AI agent framework. Let me analyze the structure and create a comprehensive README. # C-Agent 一个灵活的 AI Agent 框架,支持多种 Agent 模式和工具调用能力。 ## 项目简介 C-Agent 是一个用 JavaScript/TypeScript 构建的模块化 AI Agent 框架,旨在为开发者提供构建智能代理应用的基础设施。该框架支持多种 Agent 模式,包括 ReAct、Function Call、Reflection 等,并提供灵活的工具系统和会话管理功能。 ## 核心特性 - **多种 Agent 模式**: 支持 Simple Agent、ReAct Agent、Function Call Agent、Reflection Agent 和 Plan Solve Agent - **工具系统**: 内置工具注册表,支持同步和异步工具执行 - **LLM 集成**: 统一的语言模型接口,支持多种 LLM 提供商 - **会话管理**: 灵活的状态管理和会话存储 - **流式输出**: 支持流式执行和输出 ## 项目结构 ``` c-agent/ ├── agents/ # Agent 实现 │ ├── function_call_agent.js │ ├── plan_solve_agent.js │ ├── react_agent.js │ ├── reflection_agent.js │ └── simple_agent.js ├── core/ # 核心模块 │ ├── agent.js # Agent 基类 │ ├── base_model.js # 基础模型接口 │ ├── config.js # 配置管理 │ ├── exceptions.js # 异常定义 │ ├── llm.js # LLM 提供商 │ ├── message.js # 消息处理 │ └── session_store.js # 会话存储 ├── tools/ # 工具系统 │ ├── async_executor.js │ ├── base.js │ ├── builtin/ # 内置工具 │ │ ├── calculator.js │ │ └── search.js │ ├── chain.js │ └── registry.js ├── example/ # 使用示例 │ ├── function_call.js │ └── index.js └── tests/ # 测试用例 ``` ## 安装 ```bash # 使用 pnpm pnpm install # 或使用 npm npm install # 或使用 yarn yarn install ``` ## 快速开始 ### 基本使用 ```javascript const { Agent } = require('./core/agent'); const { LLM } = require('./core/llm'); async function main() { const llm = new LLM({ provider: 'openai', model: 'gpt-4', apiKey: process.env.OPENAI_API_KEY }); const agent = new Agent({ name: 'MyAgent', llm }); const response = await agent.run('你好,请介绍一下你自己'); console.log(response); } main(); ``` ### 使用 Function Call Agent ```javascript const { FunctionCallAgent } = require('./agents/function_call_agent'); const { ToolRegistry } = require('./tools/registry'); async function main() { const registry = new ToolRegistry(); registry.register(require('./tools/builtin/calculator')); const agent = new FunctionCallAgent({ name: 'CalculatorAgent', tools: registry }); const response = await agent.run('请计算 123 + 456 的结果'); console.log(response); } main(); ``` ## Agent 类型 ### Simple Agent 最简单的 Agent 形式,直接将用户消息发送给 LLM 并返回结果。 ### ReAct Agent 支持 ReAct (Reasoning + Acting) 模式的 Agent,能够在推理过程中调用工具。 ### Function Call Agent 专门用于处理函数/工具调用的 Agent,支持自动选择和执行工具。 ### Reflection Agent 具有自我反思能力的 Agent,能够评估和改进自己的输出。 ### Plan Solve Agent 支持任务分解和规划求解的 Agent,适合复杂任务处理。 ## 工具系统 ### 内置工具 - **Calculator**: 数学表达式计算 - **Search**: 搜索功能 ### 自定义工具 ```javascript const { Tool } = require('./tools/base'); const myTool = { name: 'my_tool', description: '这是我的自定义工具', parameters: { type: 'object', properties: { input: { type: 'string', description: '输入参数' } }, required: ['input'] }, handler: async ({ input }) => { return `处理: ${input}`; } }; ``` ## 配置 框架通过 `core/config.js` 提供默认配置支持。可以通过环境变量或配置文件进行自定义: ```bash # 复制示例配置 cp .env.example .env # 编辑 .env 文件,填入你的 API Key ``` ## 测试 ```bash # 运行所有测试 npm test # 运行特定测试 npm test -- tests/agent.test.js ``` ## 依赖 - Node.js >= 18.0 - 支持 ESM 模块 ## 许可证 MIT License ## 贡献 欢迎提交 Pull Request 和 Issue!