logo
0
0
WeChat Login
feat: 初始化 Conscious Agent — 本地运行的独立 Python Agent

Conscious Agent

🧠 本地运行的独立 AI Agent — 用 Python 写的

具备对话交互工具调用(Shell、文件操作、搜索、计算)和记忆管理能力。

特性

  • 🗣️ 多轮对话:基于 OpenAI 兼容 API 的流畅对话体验
  • 🔧 工具调用:内置 7 个实用工具,支持 Function Calling
  • 💾 持久化记忆:对话自动保存,支持恢复历史会话
  • 🛡️ 安全机制:Shell 命令黑白名单、输出截断、危险操作拦截
  • 📺 流式输出:支持实时打字效果
  • ⚙️ 灵活配置:YAML + 环境变量分层配置

快速开始

1. 安装依赖

pip install -e .

或手动安装:

pip install openai rich click pyyaml python-dotenv

2. 配置 API

cp .env.example .env # 编辑 .env,填入你的 API Key 和 Base URL

支持任何 OpenAI 兼容的 API(OpenAI / Azure / 本地 Ollama / vLLM 等)。

3. 启动

# 交互模式 agent run # 或者用 Python 直接运行 python -m agent.main run # 非交互模式(单次提问) agent ask "帮我写一个 Python 快排"

内置工具

工具说明示例
shell执行终端命令ls -la, git status
file_read读取文件内容读取源代码、配置文件
file_write写入文件创建新文件、修改代码
file_list列出目录内容查看项目结构
calculator数学计算2**32, sqrt(144)
web_search搜索互联网查询最新信息
env_info查看环境信息系统版本、Python 版本

交互命令

/clear 清空对话历史 /history 查看对话历史 /sessions 列出已保存的会话 /help 显示帮助 /quit 退出

配置说明

编辑 config.yaml 自定义行为:

# 模型 model: "${AGENT_MODEL:-gpt-4o}" # 对话参数 max_tokens: 4096 temperature: 0.7 # 记忆 memory: max_turns: 50 persist: true save_path: "./data/conversations" # 安全 safety: confirm_dangerous: true blocked_shell_commands: - "rm -rf /"

项目结构

├── agent/ │ ├── __init__.py # 包定义 │ ├── main.py # CLI 入口 │ ├── agent.py # Agent 核心(对话循环) │ ├── config.py # 配置加载 │ ├── memory.py # 对话记忆管理 │ └── tools.py # 内置工具集 ├── config.yaml # 全局配置 ├── .env.example # 环境变量模板 ├── pyproject.toml # 项目元数据 └── README.md

License

MIT