mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 07:16:04 +00:00
refactor(agent-runner): remove host context windowing
This commit is contained in:
@@ -156,7 +156,7 @@ class AgentRunnerDescriptor(BaseModel):
|
||||
|
||||
### 3.4 context_builder.py / pipeline_adapter.py
|
||||
|
||||
`context_builder.py` 只负责从 `AgentEventEnvelope + AgentBinding` 构造 SDK v1 `AgentRunContext`。Pipeline Query 的读取、参数过滤、prompt 提取和 `max-round` bootstrap 映射都属于 `PipelineAdapter`,不再放进 context builder。
|
||||
`context_builder.py` 只负责从 `AgentEventEnvelope + AgentBinding` 构造 SDK v1 `AgentRunContext`。Pipeline Query 的读取、参数过滤和 prompt 提取属于 `PipelineAdapter`,但 PipelineAdapter 不再做历史窗口裁剪或 bootstrap 打包。
|
||||
|
||||
当前消息 Pipeline 进入 agent runner 的路径:
|
||||
|
||||
@@ -183,7 +183,7 @@ Protocol v1 context 的稳定字段:
|
||||
- `state`: `PersistentStateStore` 读取的 host-managed scoped state snapshot
|
||||
- `runtime`: host/version/workspace/bot/query/trace/deadline
|
||||
- `config`: 当前 binding 对该 runner id 的配置,即 `runner_config`
|
||||
- `bootstrap`: 可选小窗口,不是完整历史
|
||||
- `bootstrap`: 可选扩展字段;LangBot Host 默认不填历史窗口
|
||||
- `adapter`: Pipeline 或其它入口 adapter 的元数据
|
||||
|
||||
Pipeline adapter 的 `prompt` 和公开业务变量不进入顶层协议字段:
|
||||
@@ -191,58 +191,36 @@ Pipeline adapter 的 `prompt` 和公开业务变量不进入顶层协议字段
|
||||
- filtered params -> `ctx.adapter.extra["params"]`
|
||||
- legacy/effective prompt 可以暂存到 `ctx.adapter.extra["prompt"]`,但 official
|
||||
runner 不应把它当作行为契约
|
||||
- `max-round` working window 可以保留在 Pipeline adapter 兼容层,但 official
|
||||
`local-agent` 不消费该 bootstrap/window
|
||||
- packaging 元数据 -> `ctx.runtime.metadata.context_packaging`
|
||||
- LangBot Host 不生成 `bootstrap.messages`、`adapter_messages` 或 context packaging 元数据
|
||||
|
||||
现阶段不要把新的压缩或 token-budget 裁剪塞回 Pipeline stage。Pipeline 只负责入口适配;完整历史和长期上下文由 EventLog / Transcript / pull APIs / future ContextCompressor 支撑。
|
||||
|
||||
### 3.4.1 Agentic context plan
|
||||
|
||||
本轮只在 `PipelineAdapter` 中保留 `max-round` working window,不改变 user-round 选择规则。
|
||||
EventLog / Transcript / Host pull APIs 已落地,`ContextCompressor` 仍是设计预留。
|
||||
目标是让 Pipeline 逐步退化为入口 adapter,让 AgentRunner 层拥有上下文打包职责。
|
||||
|
||||
建议最终拆成四个 host-side 服务:
|
||||
建议 Host 保持三类事实源和受限 API:
|
||||
|
||||
```text
|
||||
ConversationStore / EventLog
|
||||
-> durable append-only raw messages, events, tool results, artifact refs
|
||||
ConversationProjection
|
||||
-> converts events into agent-readable conversation history
|
||||
PipelineAdapter bootstrap policy
|
||||
-> builds the bounded working context for one run
|
||||
ContextCompressor
|
||||
-> creates and updates summaries/checkpoints when thresholds are exceeded
|
||||
-> future optional service for summaries/checkpoints, requested and consumed by runners
|
||||
```
|
||||
|
||||
关键原则:
|
||||
|
||||
- 完整历史属于 LangBot host,不属于插件实例。插件仍是 singleton/stateless。
|
||||
- `ctx.bootstrap.messages` 是 optional working context window,不是完整 conversation dump。
|
||||
- `ctx.bootstrap.messages` 不是 Host 默认下发的 working context。
|
||||
- 每轮不能全量复制/序列化完整历史给插件 runtime;否则长会话会产生 O(n) 成本和跨进程 payload 膨胀。
|
||||
- `max-round` 的 user-round 规则只属于 Pipeline adapter 的 bootstrap 策略。
|
||||
- LiteLLM 接入后,context packaging 应升级为 token budget / summary / pull API 协作策略。
|
||||
- `max-round` 或类似窗口规则不属于 LangBot Host / Pipeline 语义。
|
||||
- LiteLLM 接入后,模型窗口元信息应作为 resource/runtime metadata 暴露给 runner,由 runner 决定预算和压缩策略。
|
||||
- `ContextCompressor` 生成的是派生 summary/checkpoint,不能覆盖或删除 raw history。
|
||||
- 重启恢复依赖持久化 store 和 summary checkpoint,不依赖 `SessionManager` 里的进程内 conversation list。
|
||||
|
||||
后续 `AgentRunContext` 可增加:
|
||||
|
||||
```python
|
||||
context_request: AgentContextRequest | None
|
||||
context_packaging: ContextPackagingMetadata
|
||||
```
|
||||
|
||||
建议语义:
|
||||
|
||||
- `context_request.mode`: AgentRunner manifest / binding config 请求的 `max_round`、`token_budget`、`summary_hybrid`、`external_session`
|
||||
- `context_request.budget`: 模型窗口、预留输出 token、工具/RAG 预算等偏好
|
||||
- `context_packaging.policy`: Host 本次实际采用的打包策略
|
||||
- `context_packaging.delivered_count`: 本次下发的历史消息数
|
||||
- `context_packaging.source_total_count`: packager 可见的原始历史消息数
|
||||
- `context_packaging.messages_complete`: 本窗口是否已经包含完整历史
|
||||
- `context_packaging.cursor_before`: 未来通过 host API 读取更早历史的 cursor
|
||||
|
||||
未来需要的受限 API:
|
||||
|
||||
```python
|
||||
@@ -256,7 +234,7 @@ page size、总字节数、deadline 和可访问 conversation。
|
||||
|
||||
### 3.4.2 Large artifacts and tool collaboration
|
||||
|
||||
大文件、多模态输入和工具产物不要内联进 bootstrap messages 或 tool result。后续统一用
|
||||
大文件、多模态输入和工具产物不要内联进 prompt、bootstrap 或 tool result。后续统一用
|
||||
artifact/resource ref 协作:
|
||||
|
||||
- message/content 里只放小文本和必要摘要。
|
||||
@@ -512,7 +490,7 @@ async def run_from_query(query: pipeline_query.Query) -> AsyncGenerator[Message
|
||||
### Step 4:local-agent parity
|
||||
|
||||
- 使用静态绑定配置 `ctx.config["prompt"]`,不读取 `ctx.adapter.extra["prompt"]`。
|
||||
- 通过 Host history API 拉取 transcript,不读取 `ctx.bootstrap.messages` 或 `ctx.adapter.adapter_messages`。
|
||||
- 通过 Host history API 拉取 transcript,不读取 `ctx.bootstrap.messages` 或 adapter window 字段。
|
||||
- 当前 user message 从 `ctx.input.contents` 构造,保留多模态内容。
|
||||
- RAG 只替换/插入文本部分,不丢图片/文件。
|
||||
- streaming/non-streaming 默认跟随 `runtime.metadata.streaming_supported`。
|
||||
|
||||
Reference in New Issue
Block a user