96SEO 2026-08-06 05:24 4
如果你只和 ChatGPT 聊过天你可能会觉得 AI Agent 就是“把 prompt 发给 API,把回复显示来”。
实际痛点:

下面通过 BoxAgnts 中一个完整的 Agent 交互流程,展示如何解决这些痛点:
使用者输入:"帮我读一下 config.toml。把 port 改成 8080"
· 使用者消息加入对话历史
· 建立 system prompt
· 调用 LLM API → 流式接收响应
· AI 决定调用工具:tool_use
· 执行 read 工具
· 工具结果注入对话历史
·
调用 API → AI 分析配置
· AI 决定调用工具:tool_use
· 执行 edit 工具
· 工具结果注入对话
·
调用 API → AI 回复:"已将端口从 8000 改为 8080"
· end_turn → 对话结束
这个过程涉及 5 次 API 调用、2 次工具执行、流式推送、上下文管理。
在开始推理循环之前,需要先定义 Agent 的“角色”。BoxAgnts 内置了三个预置 Agent:
// boxagnts-workspace/src/config.rs
pub struct AgentDefinition {
pub description: Option,// 描述
pub model: Option,// 模型覆盖
pub temperature: Option,// 温度覆盖
pub prompt: Option,// 程序提示前缀
pub access: String,// 权限:full / read-only / search-only
pub visible: bool,// 是否在 @agent 自动补全中显示
pub max_turns: Option,// 最大轮次覆盖
pub color: Option。// 终端显示颜色
}
预置的三个 Agent 角色:
| Agent | 权限 | prompt 特征 | 适用场景 |
|---|---|---|---|
| build | full | "You are build agent. Focus on implementing..." | 编码、修改文件 |
| plan | read-only | "You are plan agent. You can read files and analyze..." | 代码分析、架构设计 |
| explore | search-only | "Fast search-only agent for code exploration" | 快速搜索、文件定位 |
Agent 定义中的 prompt 字段会在查询循环启动时被注入到 system prompt 的最前面:
// boxagnts-query/src/query.rs
if let Some = config.agent_definition {
if let Some = agent.prompt {
patched.system_prompt = Some(match &config.system_prompt {
Some => format!,None => agent_prompt.clone,});}
}
Agent 可以覆盖模型和最大轮次:
let effective_model = if let Some = config.agent_definition {
agent.model.clone.unwrap_or_else)
} else {
config.model.clone
};let effective_max_turns = config.agent_definition
.as_ref
.and_n
.unwrap_or;
这代表着使用者可以在同一会话中和权限——规划阶段使用只读慢思考模型。执行阶段切换到全权限快速模型,从根本上缓解 “单一模型难兼顾所有需求” 的痛点。
run_query_loop 是 BoxAgnts 中最主要的函数,位于 boxagnts-query crate 中:
pub async fn run_query_loop(
说到client,&AnthropicClient,// API 客户端
messages: &mut Vec。// 对话历史
tools这方面,&,// 工具集合
tool_ctx: &ToolContext,// 沙箱配置
再看config,&QueryConfig,// 循环配置
cost_tracker: Arc,// 成本追踪,防止预算超支
event_tx: Option,// 实时事件推送
cancel_token: CancellationToken,// 使用者可随时中断循环
pending_messages: Option<&mut Vec,// 插入式使用者消息
) -> QueryOutcome {…}
The signature itself is a design document—each parameter solves a concrete production problem:
| 参数 | 设计意图 / 痛点对应方法 |
|---|---|
client | LLM 提供商可插拔;统一入口避免多处硬编码, |
&mut Vec 对话历史直接就地修改,避免复制开销;保持上下文完整, | |
& 动态加载任意数量工具;增加功能不改主要原因, | |
| *其他参数均对应“实时取消”“预算控制”“并发插入消息”等生产需求* | |
┌─────────────────────────────────────────────┐│ loop { ││ ││ ① 检查终止条件 ││ · turn> max_turns?→ EndTurn ││ · cancel_token?说起来,→ Cancelled ││ · budget exceeded?话说回来,→ BudgetExceeded ││ ││ ② 预处理消息 ││ · drain pending_messages queue ││ · apply_tool_result_budget ││ · auto_compact ││ ││ ③ 建立 system prompt + 调用 LLM API ││ · 注入 Agent 定义 / AGENTS.md ││ · 建立 CreateMessageRequest ││ · 流式接收 StreamEvent ││ · 累积 text / thinking / tool_use blocks││ ││ ④ 处理响应 ││ · end_turn → 返回 ││ · tool_use → 并行执行工具 → 注入结果 → 继续 ││ · max_tokens → 恢复输出 → 继续 ││ ││ ⑤ 错误恢复 ││ · overloaded → 切换 fallback model ││ · stream stall → retry │└─────────────────────────────────────────────┘
A well‑structured system prompt gives model a stable “worldview”。从而降低每轮 token 消耗并提高可靠性。
fn build_system_prompt -> SystemPrompt {
let opts = SystemPromptOptions {
custom_system_prompt: config.system_prompt.clone,append_system_prompt: config.append_system_prompt.clone。output_style: config.output_style,custom_output_style_prompt: config.output_style_prompt.clone,working_directory: config.working_directory.clone,..Default::default
};let text = boxagnts_core::system_prompt::build_system_prompt;
SystemPrompt::Text
}
The prompt is layered:
┌──────────────────────────────────────┐
│ Agent 角色定义 ← AgentDefinition.prompt
├──────────────────────────────────────┤
│ 主要能力声明 │
│ • 可用工具列表 ← 动态生成自 tools 参数 |
│ • 技能列表 ← SkillTool 自动发现 |
│ • 输出格式要求 |
│ • 安全边界 |
├──────────────────────────────────────┤
│ AGENTS.md 内容 ← 项目级行为规范 |
├──────────────────────────────────────┤
│ 动态边界标记 |
│ --- 以上缓存。以下不缓存 --- |
├──────────────────────────────────────┤
│ 会话特定信息 ← 工作目录、时间等 |
└──────────────────────────────────────┘
The “---以上缓存---” line leverages Anthropic’s prompt caching,dramatically cutting token cost for repeated calls.
If model hits its token limit,a naïve implementation would abort task entirely. BoxAgnts instead automatically resumes from cut‑off point.
// boxagnts-query/src/query.rs
const MAX_TOKENS_RECOVERY_LIMIT: u32 = /* configurable */;const MAX_TOKENS_RECOVERY_MSG: &'static str =
"Output token limit hit. Resume directly — no apology,no recap of what \
you were doing. Pick up mid-thought if that is where cut happened. \
Break remaining work into smaller pieces.";
MAXTOKENSRECOVERY_MSG.LLM context windows are finite. When conversation history grows beyond a configurable fraction of window,BoxAgnts automatically compacts it by summarizing older turns.
// boxagnts-query/src/compact.rs
const AUTOCOMPACT_TRIGGER_FRACTION: f64 = /* e.g.,0.75 */;const WARNING_PCT: f64 = /* e.g.,0.80 */;const CRITICAL_PCT: f64 = /* e.g.,0.90 */;
The summarization uses an auxiliary LLM with a strict “NO_TOOLS_PREAMBLE” to guarantee that no tool calls happen during compression:
CRITICAL:
Respond with TEXT ONLY. Do NOT call any tools.
- Do NOT use Read,Bash,Grep,Glob,Edit,Write,or ANY or tool.
- You already have all context you need in conversation above.
- Tool calls will be REJECTED and will waste your only turn.
The result replaces early messages while preserving most recent few turns verbatim.
If LLM returns "tool_use"。BoxAgnts enters tool execution phase:
┌──────────────────────────────────────────────┐
| Phase : 顺序执行 PreToolUse 预处理 |
| |
├──────────────────────────────────────────────┤
| Phase : 并行执行非阻塞工具 |
| join_all → 所有工具并发运行 |
| |
└──────────────────────────────────────────────┘
The crucial design choice is to inject tool results back into conversation as **user** messages:
// boxagnts-query/src/lib.rs
async fn execute_tool( 说到name,&str,input:&Value,tools:&,ctx:&ToolContext,) -> ToolResult { let tool = tools.iter.find == name);match tool { Some=>{ debug!,tool.execute,ctx).await } None=>{ warn!,ToolResult::error) } } }
The implementation is deliberately simple—a linear scan over a small vector is negligible compared to network latency and sandbox startup time.
If a single Agent cannot handle a complex request alone,BoxAgnts offers a managed‑agent mode that separates planning from execution.
┌───────────────────┐
│ Manager Agent │
├─ Opus 等强模型 ┤
| 只做规划和分配 |
└─────────▲─────────┘
|
┌─────────────╂─────────────╂─────────────┐
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────�╗
| Executor A | | Executor B | | Executor C |
| | | | | |
| 子任务 A | | 子任务 B | | 子任务 C |
└───────────�╝ └──────────�╝ └──────────�╝
The Manager’s system prompt contains explicit directives so it never calls tools directly—it only spawns Executors via an internal agent tool.
pub fn managedagentsystem_prompt->String{
format!(r#"
You are THE MANAGER in a manager‑executor architecture.
{executor_model} with up to {max_turns} turns.
1️⃣ Analyze user request & break into sub‑tasks.
2️⃣ Spawn executors via agent tool.
3️⃣ Review results – if insufficient spawn follow‑ups.
4️⃣ Synsize all outcomes into final response."#。...))
}
A Tool gives an Agent physical capabilities . A Skill provides domain expertise—e.g.,code‑review guidelines or CSS refactoring advice.
app/extensions/skills/
├── code-review/
│ └── SKILL.md # 静态模板 + $ARGUMENTS 占位符
├── css-refactor-advisor/
├── current-wear/
...
Each SKILL.md may contain front‑matter metadata followed by markdown content.
pub struct SkillTool;
impl Tool for SkillTool { fn name->&'static str{ "skill-tool" }
async fn execute->ToolResult{ let params :SkillInput = serdejson::fromvalue?,if params.skill=="list"{ return listskills.await;} let =findandreadskill.await?,其实,let content = strip_frontmatter;let rendered = match ¶ms.args{ Some=>content.replace。None=>content.replace,};ToolResult::success } }
async fn skillsearchdirs->Vec{
let mut dirs = vec!,// 项目级优先
dirs.push.await.join );// 全局备用
dirs
}
Thus developers can override global skills with project‑specific versions—a direct answer to “在不同项目里需要不同规则,却不想改代码”的痛点。
`markdown
至于请审查,$ARGUMENTS
至于检查要点,* 函数是否过长 * 是否存在未处理的 Result/Option * 是否有不必要的 .clone * 命名是否符合 Rust 惯例 `
When invoked as:
json
{ "skill":"code-review","args":"src/main.rs" }
$ARGUMENTS placeholder becomes src/main.rs。turning static knowledge into a dynamic advisory function.
The query loop emits granular events through an unbounded channel which can be streamed to UI dashboards or TUI clients:
pub enum QueryEvent{
Token{ text:String },// 每个 token 实时推送
ToolStart{toolname:String,toolid:u64,input:String},ToolEnd{toolname:String,toolid:u64,result:String},Status,// 状态文字,例如 “正在压缩上下文…”
}
These events enable transparent debugging—developers no longer face “AI 突然卡死,我不知道它在干什么”的困惑。
An AI Agent’s multi‑turn dialogue is essentially a robust control loop:
System Prompt ➜ API Call ➜ Stream Parse ➜ Detect Tool Use ➜ Execute Tool ➜ Inject Result ➜ Loop again ⟲ until end_turn
Each mechanism in BoxAgnts directly addresses real production pains:
| Pain Point | Solved By |
|---|---|
| Diverse roles & models needed per stage | Agent Definition System – role + model overrides |
| Prompt length growth causing cost explosion | Layered System Prompt + Caching |
| Output truncation at token limit | max_tokens Recovery logic |
| Context window overflow | auto_compact structural summary |
| Tool result accumulation bloat
| |
Implementing se mechanisms transforms an “AI 能跑” prototype into a production‑ready “AI 能可靠工作” platform.
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback