Add runtime guidance input queue
This commit is contained in:
@@ -298,6 +298,7 @@ class LocalCodingAgent:
|
||||
team_runtime: TeamRuntime | None = None
|
||||
workflow_runtime: WorkflowRuntime | None = None
|
||||
worktree_runtime: WorktreeRuntime | None = None
|
||||
runtime_guidance_provider: Callable[[], tuple[dict[str, object], ...]] | None = None
|
||||
last_session: AgentSessionState | None = field(default=None, init=False, repr=False)
|
||||
last_run_result: AgentRunResult | None = field(default=None, init=False, repr=False)
|
||||
cumulative_usage: UsageStats = field(default_factory=UsageStats, init=False, repr=False)
|
||||
@@ -734,6 +735,11 @@ class LocalCodingAgent:
|
||||
return result
|
||||
|
||||
for turn_index in range(1, self.runtime_config.max_turns + 1):
|
||||
self._inject_runtime_guidance(
|
||||
session,
|
||||
stream_events,
|
||||
turn_index=turn_index,
|
||||
)
|
||||
self._microcompact_session_if_needed(
|
||||
session,
|
||||
stream_events,
|
||||
@@ -4274,6 +4280,69 @@ class LocalCodingAgent:
|
||||
transcript=session.transcript(),
|
||||
)
|
||||
|
||||
def _inject_runtime_guidance(
|
||||
self,
|
||||
session: AgentSessionState,
|
||||
stream_events: list[dict[str, object]],
|
||||
*,
|
||||
turn_index: int,
|
||||
) -> None:
|
||||
provider = self.runtime_guidance_provider
|
||||
if provider is None:
|
||||
return
|
||||
try:
|
||||
items = tuple(
|
||||
item
|
||||
for item in provider()
|
||||
if isinstance(item, dict)
|
||||
and str(item.get('content') or '').strip()
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
stream_events.append(
|
||||
{
|
||||
'type': 'runtime_guidance_error',
|
||||
'turn_index': turn_index,
|
||||
'error': str(exc)[:500],
|
||||
}
|
||||
)
|
||||
return
|
||||
if not items:
|
||||
return
|
||||
lines = [
|
||||
'<runtime-guidance>',
|
||||
(
|
||||
'用户在本轮任务运行过程中追加了以下引导。请在不丢弃当前进展的前提下'
|
||||
'吸收这些要求;如果它们与当前目标冲突,先说明冲突并选择最合理的继续方式。'
|
||||
),
|
||||
]
|
||||
item_ids: list[int] = []
|
||||
for index, item in enumerate(items, start=1):
|
||||
item_id = item.get('id')
|
||||
if isinstance(item_id, int) and not isinstance(item_id, bool):
|
||||
item_ids.append(item_id)
|
||||
content = str(item.get('content') or '').strip()
|
||||
lines.append(f'{index}. {content}')
|
||||
lines.append('</runtime-guidance>')
|
||||
session.append_user(
|
||||
'\n'.join(lines),
|
||||
metadata={
|
||||
'kind': 'runtime_guidance',
|
||||
'turn_index': turn_index,
|
||||
'queue_item_ids': item_ids,
|
||||
},
|
||||
message_id=f'runtime_guidance_{turn_index}_{uuid4().hex[:8]}',
|
||||
display=False,
|
||||
)
|
||||
stream_events.append(
|
||||
{
|
||||
'type': 'runtime_guidance_injected',
|
||||
'turn_index': turn_index,
|
||||
'input_ids': item_ids,
|
||||
'count': len(items),
|
||||
'message': f'已将 {len(items)} 条用户引导注入当前任务',
|
||||
}
|
||||
)
|
||||
|
||||
def render_system_prompt(self) -> str:
|
||||
prompt_context = self.build_prompt_context()
|
||||
parts = self.build_system_prompt_parts(prompt_context)
|
||||
|
||||
Reference in New Issue
Block a user