fix(agent-runner): package context for plugin execution

This commit is contained in:
huanghuoguoguo
2026-05-21 13:56:17 +08:00
parent 26923c66c0
commit 094b87e578
10 changed files with 393 additions and 47 deletions

View File

@@ -3,6 +3,10 @@ from __future__ import annotations
from .. import truncator
import langbot_plugin.api.entities.builtin.pipeline.query as pipeline_query
from ....agent.runner.config_migration import ConfigMigration
from ....agent.runner.context_packager import (
get_legacy_max_round,
select_legacy_max_round_messages,
)
@truncator.truncator_class('round')
@@ -11,25 +15,15 @@ class RoundTruncator(truncator.Truncator):
async def truncate(self, query: pipeline_query.Query) -> pipeline_query.Query:
"""截断"""
# max-round remains a pipeline-side trimming knob until token-budget
# based compaction replaces this stage.
runner_id = ConfigMigration.resolve_runner_id(query.pipeline_config)
runner_config = ConfigMigration.resolve_runner_config(query.pipeline_config, runner_id) if runner_id else {}
max_round = runner_config.get('max-round', 10)
if runner_id:
runner_config = ConfigMigration.resolve_runner_config(query.pipeline_config, runner_id)
else:
runner_config = query.pipeline_config.get('msg-truncate', {}).get('round', {})
temp_messages = []
current_round = 0
# Traverse from back to front
for msg in query.messages[::-1]:
if current_round < max_round:
temp_messages.append(msg)
if msg.role == 'user':
current_round += 1
else:
break
query.messages = temp_messages[::-1]
query.messages = select_legacy_max_round_messages(
query.messages,
get_legacy_max_round(runner_config),
)
return query