• 简体中文
  • v6.5.1
  • 自动压缩

    A3S Code 可以替你将长对话保持在模型的上下文预算内。启用 autoCompact 后, runtime 会持续监测上下文用量;一旦超过 autoCompactThreshold,较早的轮次就会被 压缩成一份持续更新的摘要,让 agent 在大量步骤中始终保持连贯,而无需你手动管理 token。续写则处理另一个方向:当单条回复因长度被截断时,runtime 会自动继续生成, 拼出完整回复。

    Node.js
    Python
    TypeScript
    import { Agent } from '@a3s-lab/code';
    const agent = await Agent.create('agent.acl');
    const session = agent.session('/repo', {
    // Compact older turns once context fills past the threshold.
    autoCompact: true,
    autoCompactThreshold: 0.75,
    // Auto-continue a single response that the model truncates by length.
    continuationEnabled: true,
    maxContinuationTurns: 3,
    });
    // Run a long, multi-step task. The runtime compacts older turns as needed;
    // you never touch the token math.
    for (let i = 0; i < 50; i++) {
    await session.send(`Step ${i}: continue refactoring the parser`);
    }
    // Inspect what the session is currently carrying.
    console.log('history turns:', session.history().length);
    console.log('recent memory:', await session.memoryRecent(5));
    session.close();

    长 session 若希望由 runtime 替你管理 context pressure,就使用自动压缩。 autoCompactThreshold / auto_compact_threshold 是触发压缩的上下文窗口占比 (0.0–1.0,默认 0.8);调低它可以更早触发压缩。用 history()(同步)和 memoryRecent / memory_recent 查看实时 session。