mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-13 09:16:04 +00:00
refactor(agent-runner): tighten protocol v1 runtime boundaries
This commit is contained in:
committed by
huanghuoguoguo
parent
f9e07df539
commit
2fd2c6aadc
34
src/langbot/pkg/pipeline/msgtrun/round_policy.py
Normal file
34
src/langbot/pkg/pipeline/msgtrun/round_policy.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Shared max-round message window helpers for Pipeline behavior."""
|
||||
from __future__ import annotations
|
||||
|
||||
import typing
|
||||
|
||||
|
||||
DEFAULT_MAX_ROUND = 10
|
||||
|
||||
|
||||
def get_max_round(config: dict[str, typing.Any]) -> typing.Any:
|
||||
"""Return the configured Pipeline max-round value."""
|
||||
return config.get('max-round', DEFAULT_MAX_ROUND)
|
||||
|
||||
|
||||
def select_max_round_messages(
|
||||
messages: list[typing.Any] | None,
|
||||
max_round: typing.Any,
|
||||
) -> list[typing.Any]:
|
||||
"""Select a bounded recent message window by user-round count."""
|
||||
if not messages:
|
||||
return []
|
||||
|
||||
temp_messages: list[typing.Any] = []
|
||||
current_round = 0
|
||||
|
||||
for msg in messages[::-1]:
|
||||
if current_round < max_round:
|
||||
temp_messages.append(msg)
|
||||
if getattr(msg, 'role', None) == 'user':
|
||||
current_round += 1
|
||||
else:
|
||||
break
|
||||
|
||||
return temp_messages[::-1]
|
||||
@@ -3,7 +3,7 @@ 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 (
|
||||
from ..round_policy import (
|
||||
get_max_round,
|
||||
select_max_round_messages,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user