Reynard人工智能工具调用系统
_原生TypeScript CodeMode实现,具有全面的AI代理工具和开发能力_
概述
Reynard AI工具调用系统为AI代理工具提供了完整的原生TypeScript CodeMode实现。该系统通过CodeMode执行提供代理命名、时间感知、位置检测、开发工具和全面的健康监控。
快速开始
代理启动顺序
使用完整的启动序列初始化您的代理身份:
cd /home/kade/runeset/reynard/packages/ai/tool-calling && pnpm startup-sequence此命令将:
- 初始化CodeMode工具系统 使用原生TypeScript实现
- 生成代理名称 使用CodeMode工具
- 建立时间上下文 当前时间和时区
- 获取位置信息 基于IP地址
- 测试工具系统 确保一切正常
替代内联命令
对于程序化访问,请使用带有异步IIFE模式的内联命令:
cd /home/kade/runeset/reynard/packages/ai/tool-calling && pnpm tsx -e "(async () => {
const { codemode } = await import('./src/codemode/codemode.js');
const cm = await codemode({ projectRoot: process.cwd() });
const result = await cm.executeCode(\`
const nameResult = await tools.agent.NamingTools.generateAgentName({
specialist: 'fox', style: 'foundation'
});
console.log('🦊 Agent name:', nameResult.data.name);
return nameResult.data;
\`);
console.log('Result:', result.returned);
cm.cleanup();
})()"可用工具
🦊 代理工具
generateAgentName-生成具有动物精神主题的代理名称assignAgentName-为具有持久性的代理分配名称getAgentName-检索当前代理名称listAgentNames-列出所有分配的代理名称rollAgentSpirit-随机选择一个动物精神(加权分布)getCurrentTime-获取当前日期和时间getCurrentLocation-根据IP地址获取位置sendDesktopNotification-使用libnotify发送桌面通知
🛠️ 开发工具
lintFrontend-用于Types/JavaScript的ESLint(带自动修复)formatFrontend-预分级格式化(仅限检查模式)lintPython-Flake8,Python版Pylint(带自动修复)formatPython-黑色+isort格式(仅限检查模式)lintMarkdown-markdownline验证(带自动修复)validateComprehensive-运行所有自定义验证脚本scanSecurity-完成安全审计(Bandit、审计ci、类型检查)runAllLinting-执行整个linting套件(带自动修复)
📊 系统工具
getVersions-获取Python、Node.js、npm、pnpm和TypeScript的版本getPythonVersion-获取Python版本信息getNodeVersion-获取Node.js版本信息getTypeScriptVersion-获取TypeScript版本信息getVscodeActiveFile-获取VS Code中当前活动的文件路径getVscodeWorkspaceInfo-获取VS Code工作区信息和设置getVscodeExtensions-获取已安装的VS代码扩展列表scanSecurityFast-运行快速安全扫描(跳过慢速Bandit检查)scanSecurityFull-运行包括Bandit在内的全面安全扫描
🧮 算法包
完整的 @entropy-tamer/reynard-algorithms 软件包(117个导出,64个类)可通过 algorithms 全局对象:
数据结构:
UnionFind,PriorityQueue,LRUCache,Trie,BloomFilterFenwickTree,IntervalTree,SegmentTree
空间结构:
SpatialHash,KdTree,Octree,BVH,Quadtree,RTree
寻路:
AStar,JPS,ThetaStar,FlowField,HPAStar,shadowcastingFOV
计算几何:
BresenhamLine,DelaunayTriangulation,VoronoiDiagram,ConvexHullOBB,MinimumBoundingBox,LineIntersection,PolygonClipping
碰撞检测:
checkCollision,SAT,SweepPrune,SpatialCollisionOptimizer
程序生成:
MarchingSquares,SimplexNoise,PoissonDisk,WaveFunctionCollapse
用途:
// Use algorithms in codemode
const result = await cm.executeCode(`
const uf = new algorithms.UnionFind(10);
uf.union(0, 1);
return uf.find(0) === uf.find(1); // true
const astar = new algorithms.AStar({ width: 10, height: 10 });
const path = astar.findPath({ x: 0, y: 0 }, { x: 9, y: 9 });
const collision = algorithms.checkCollision(aabb1, aabb2);
`);建筑
CodeMode架构
该系统使用模块化的TypeScript CodeMode架构,具有:
- 工具注册表:中央工具登记和管理
- 工具类别:按功能(代理、开发、研究、搜索、系统、可视化)组织
- 后端集成:无缝的FastAPI后端访问
- CodeMode执行:通过CodeMode执行上下文可用的所有工具
- 类型安全:对所有工具进行完整的TypeScript类型检查
健康检查系统
健康检查系统提供全面的验证:
- 工具注册表验证:确保所有工具都正确注册
- 依赖检查:验证所需的依赖关系是否可用
- 错误处理:故障组件的巧妙回退
- 性能监控:跟踪工具执行时间和成功率
位置检测
定位系统提供强大的地理定位功能:
- 主要API:使用ipapi.co进行可靠的IP地理定位
- 超时保护:5秒超时以防止挂起
- 后备系统:API不可用时的本地回退
- 综合数据:城市、国家、时区、ISP等
用法示例
基本代理初始化
import { codemode } from "./src/codemode/codemode.js";
const cm = await codemode({ projectRoot: process.cwd() });
// Generate agent name
const nameResult = await cm.executeCode(`
const nameResult = await tools.agent.NamingTools.generateAgentName({
specialist: 'fox',
style: 'foundation'
});
return nameResult.data;
`);
console.log("Agent name:", nameResult.returned.name);开发工具集成
// Run comprehensive linting
const lintResult = await cm.executeCode(`
const result = await tools.development.DevelopmentTools.runAllLinting({
fix: true
});
return result;
`);
// Security scanning
const securityResult = await cm.executeCode(`
const result = await tools.development.DevelopmentTools.scanSecurityFull();
return result;
`);位置和时间意识
// Get current time and location
const contextResult = await cm.executeCode(`
const timeResult = await tools.agent.TimeTools.getCurrentTime();
const locationResult = await tools.agent.LocationTools.getCurrentLocation();
return {
time: timeResult.data.local,
location: \`\${locationResult.data.city}, \${locationResult.data.country}\`
};
`);算法集成
// Use algorithms package in codemode
const algoResult = await cm.executeCode(`
// Data structures
const uf = new algorithms.UnionFind(10);
uf.union(0, 1);
const connected = uf.find(0) === uf.find(1);
// Pathfinding
const astar = new algorithms.AStar({ width: 10, height: 10 });
const path = astar.findPath({ x: 0, y: 0 }, { x: 9, y: 9 });
// Collision detection
const aabb1 = { minX: 0, minY: 0, maxX: 10, maxY: 10 };
const aabb2 = { minX: 5, minY: 5, maxX: 15, maxY: 15 };
const collision = algorithms.checkCollision(aabb1, aabb2);
return {
unionFind: connected,
pathLength: path ? path.length : 0,
isColliding: collision.colliding
};
`);配置
环境变量
OPENWEATHER_API_KEY-用于天气信息的可选API密钥NODE_ENV-环境模式(开发/生产)
工具配置
可以通过codemode环境配置工具:
const cm = await codemode({
projectRoot: process.cwd(),
timeoutMs: 10000, // 10 second timeout
});故障排除
常见问题
健康检查失败:
- 确保安装了所有依赖项:
pnpm install - 检查TypeScript编译:
pnpm build - 验证工具注册:
pnpm list-tools
地点API问题:
- 该系统包括自动回退到本地位置
- 检查外部API访问的网络连接
- 回退位置提供基本功能
工具执行错误:
- 检查长时间运行的操作的超时设置
- 验证开发工具的文件权限
- 确保安装了所需的系统工具(eslint、更漂亮等)
调试模式
启用调试模式以进行详细日志记录:
DEBUG=reynard:* pnpm startup-sequence性能注意事项
- 工具缓存:缓存工具以提高性能
- 并发执行:多个工具可以同时运行
- 资源管理:自动清理可防止内存泄漏
- 超时保护:防止挂在无响应的工具上
安全特性
- 输入验证:所有工具输入都经过验证和消毒
- 误差边界:始终优雅地处理故障
- 速率限制:内置防滥用保护
- 审计跟踪:所有工具执行都会记录时间戳
贡献
添加新工具
- 在适当的类别目录中创建工具类
- 实施具有适当错误处理的工具方法
- 在工具注册表中注册工具
- 添加测试和文档
- 用新的工具信息更新此README
工具开发指南
- 错误处理:始终返回结构化错误响应
- 日志记录:包括有意义的日志消息
- 类型安全:使用正确的TypeScript类型
- 文档:记录所有工具方法和参数
- 测试:包括全面的测试覆盖率
许可证
MIT许可证-有关详细信息,请参阅许可证文件。
支持
对于问题和疑问:
- 检查上面的故障排除部分
- 查阅工具文档
- 检查健康状况
pnpm startup-sequence - 报告带有详细错误消息和系统信息的问题
______________________________________________________________________
_以狐狸的狡猾精准和雷纳德生态系统的系统方法建造_ 🦊
