日志调试
使用logging模块记录日志。配置日志级别:self.logger.setLevel(logging.DEBUG)。记录关键信息:self.logger.info(f'处理输入: {input}')。日志输出到logs/skills.log。
断点调试
VS Code调试配置:在launch.json中添加调试配置。设置断点后按F5启动调试。查看变量值、调用栈。适合复杂逻辑的调试。
单元测试
使用pytest编写测试:def test_hello_skill(): skill = HelloSkill(); result = skill.execute(name='test'); assert 'test' in result。运行:pytest tests/skills/。
性能分析
使用cProfile分析性能:python -m cProfile -s tottime skill.py。找出耗时操作,优化代码。常用优化:减少API调用、使用缓存、异步处理。