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

@@ -48,6 +48,18 @@ def get_round_truncator_module():
def make_truncate_config(max_round: int = 5):
"""Create a pipeline config with max-round setting."""
return {
'msg-truncate': {
'method': 'round',
'round': {
'max-round': max_round,
},
},
}
def make_agent_runner_config(max_round: int = 5):
"""Create an AgentRunner pipeline config with max-round binding config."""
return {
'ai': {
'runner': {'id': RUNNER_ID},
@@ -137,6 +149,36 @@ class TestRoundTruncatorProcess:
# All messages should be preserved
assert len(result.new_query.messages) == 5
@pytest.mark.asyncio
async def test_agent_runner_path_skips_pipeline_truncation(self):
"""AgentRunner path should leave query.messages intact at pipeline stage."""
msgtrun = get_msgtrun_module()
entities = get_entities_module()
app = FakeApp()
stage = msgtrun.ConversationMessageTruncator(app)
pipeline_config = make_agent_runner_config(max_round=1)
await stage.initialize(pipeline_config)
query = text_query("current")
query.pipeline_config = pipeline_config
query.messages = [
provider_message.Message(role='user', content='old1'),
provider_message.Message(role='assistant', content='old1_resp'),
provider_message.Message(role='user', content='current'),
]
result = await stage.process(query, 'ConversationMessageTruncator')
assert result.result_type == entities.ResultType.CONTINUE
assert [(msg.role, msg.content) for msg in result.new_query.messages] == [
('user', 'old1'),
('assistant', 'old1_resp'),
('user', 'current'),
]
@pytest.mark.asyncio
async def test_truncate_exceeds_limit(self):
"""Messages exceeding max-round should be truncated precisely.