feat(agent-runner): align protocol adapter terminology

This commit is contained in:
huanghuoguoguo
2026-05-24 09:13:15 +08:00
parent ea6c8fba57
commit 90dffa7cd8
26 changed files with 471 additions and 342 deletions

View File

@@ -1,10 +1,10 @@
"""Tests for event-first Protocol v1 entities and Pipeline compatibility adapter.
"""Tests for event-first Protocol v1 entities and Pipeline adapter.
Tests cover:
1. Pipeline Query -> AgentEventEnvelope conversion
2. Pipeline config -> AgentBinding conversion
3. AgentRunContext not inlining full history by default
4. Legacy max-round only affecting bootstrap/compat adapter
4. Pipeline max-round only affecting bootstrap/adapter context
5. Event-first run() entry point
"""
from __future__ import annotations
@@ -49,7 +49,7 @@ from langbot.pkg.agent.runner.host_models import (
StatePolicy,
DeliveryPolicy,
)
from langbot.pkg.agent.runner.pipeline_compat_adapter import PipelineCompatAdapter
from langbot.pkg.agent.runner.pipeline_adapter import PipelineAdapter
class TestPipelineQueryToEventEnvelope:
@@ -57,24 +57,24 @@ class TestPipelineQueryToEventEnvelope:
def test_query_to_event_basic_fields(self, mock_query):
"""Test basic field conversion from Query to Event envelope."""
event = PipelineCompatAdapter.query_to_event(mock_query)
event = PipelineAdapter.query_to_event(mock_query)
assert event.event_type == "message.received"
assert event.source == "pipeline_compat"
assert event.source == "pipeline_adapter"
assert event.bot_id == mock_query.bot_uuid
assert event.actor is not None
assert event.actor.actor_type == "user"
def test_query_to_event_input(self, mock_query):
"""Test input conversion from Query."""
event = PipelineCompatAdapter.query_to_event(mock_query)
event = PipelineAdapter.query_to_event(mock_query)
assert event.input is not None
assert event.input.text == "Hello world"
def test_query_to_event_conversation(self, mock_query):
"""Test conversation context extraction."""
event = PipelineCompatAdapter.query_to_event(mock_query)
event = PipelineAdapter.query_to_event(mock_query)
# Conversation may be None if no session
if event.conversation_id:
@@ -82,7 +82,7 @@ class TestPipelineQueryToEventEnvelope:
def test_query_to_event_delivery_context(self, mock_query):
"""Test delivery context extraction."""
event = PipelineCompatAdapter.query_to_event(mock_query)
event = PipelineAdapter.query_to_event(mock_query)
assert event.delivery is not None
assert event.delivery.surface == "platform"
@@ -94,7 +94,7 @@ class TestPipelineConfigToBinding:
def test_config_to_binding_runner_id(self, mock_query):
"""Test binding runner_id extraction."""
binding = PipelineCompatAdapter.pipeline_config_to_binding(
binding = PipelineAdapter.pipeline_config_to_binding(
mock_query, "plugin:author/plugin/runner"
)
@@ -102,7 +102,7 @@ class TestPipelineConfigToBinding:
def test_config_to_binding_scope(self, mock_query):
"""Test binding scope extraction."""
binding = PipelineCompatAdapter.pipeline_config_to_binding(
binding = PipelineAdapter.pipeline_config_to_binding(
mock_query, "plugin:test/plugin/runner"
)
@@ -110,8 +110,8 @@ class TestPipelineConfigToBinding:
assert binding.scope.scope_id == mock_query.pipeline_uuid
def test_config_to_binding_max_round(self, mock_query_with_max_round):
"""Test max_round extraction for compatibility adapter."""
binding = PipelineCompatAdapter.pipeline_config_to_binding(
"""Test max_round extraction for Pipeline adapter."""
binding = PipelineAdapter.pipeline_config_to_binding(
mock_query_with_max_round, "plugin:test/plugin/runner"
)
@@ -120,7 +120,7 @@ class TestPipelineConfigToBinding:
def test_config_to_binding_no_max_round(self, mock_query):
"""Test binding without max_round."""
binding = PipelineCompatAdapter.pipeline_config_to_binding(
binding = PipelineAdapter.pipeline_config_to_binding(
mock_query, "plugin:test/plugin/runner"
)
@@ -210,8 +210,8 @@ class TestAgentRunContextProtocolV1:
assert ctx.bootstrap is None or isinstance(ctx.bootstrap.messages, list)
class TestLegacyMaxRoundNotInProtocol:
"""Test that legacy max-round only affects compat adapter, not Protocol v1."""
class TestMaxRoundNotInProtocol:
"""Test that Pipeline max-round only affects adapter context, not Protocol v1."""
def test_max_round_not_in_sdk_context(self):
"""Test max-round is not a field in SDK AgentRunContext."""
@@ -221,8 +221,8 @@ class TestLegacyMaxRoundNotInProtocol:
assert "max_round" not in ctx_fields
assert "maxRound" not in ctx_fields
def test_max_round_in_compatibility_context(self):
"""Test max_round is in compatibility context, not main context."""
def test_max_round_in_adapter_context(self):
"""Test max_round is in adapter context, not main context."""
trigger = AgentTrigger(type="message.received")
event = AgentEventContext(
event_id="evt_1",
@@ -233,9 +233,9 @@ class TestLegacyMaxRoundNotInProtocol:
from langbot_plugin.api.entities.builtin.agent_runner.resources import AgentResources
from langbot_plugin.api.entities.builtin.agent_runner.runtime import AgentRuntimeContext
from langbot_plugin.api.entities.builtin.agent_runner.delivery import DeliveryContext
from langbot_plugin.api.entities.builtin.agent_runner.context import CompatibilityContext
from langbot_plugin.api.entities.builtin.agent_runner.context import AdapterContext
compat = CompatibilityContext(max_round=10)
adapter = AdapterContext(max_round=10)
ctx = AgentRunContext(
run_id="run_1",
@@ -245,20 +245,20 @@ class TestLegacyMaxRoundNotInProtocol:
delivery=DeliveryContext(surface="platform"),
resources=AgentResources(),
runtime=AgentRuntimeContext(),
compatibility=compat,
adapter=adapter,
)
# max_round is in compatibility context, not main context
assert ctx.compatibility is not None
assert ctx.compatibility.max_round == 10
# max_round is in adapter context, not main context
assert ctx.adapter is not None
assert ctx.adapter.max_round == 10
def test_binding_max_round_for_adapter_only(self, mock_query_with_max_round):
"""Test max_round in binding is for adapter use, not Protocol v1."""
binding = PipelineCompatAdapter.pipeline_config_to_binding(
binding = PipelineAdapter.pipeline_config_to_binding(
mock_query_with_max_round, "plugin:test/plugin/runner"
)
# max_round is in binding (Host-internal) for compat adapter
# max_round is in binding (Host-internal) for Pipeline adapter
assert binding.max_round == 10
# But SDK entities don't have it