fix(webui): retain system context graph after compaction (#6608)
This commit is contained in:
1 parent
d789e1bfc7
commit
4212ad726d
25 files changed
+748
-102
No files matched your search
@@ -10,7 +10,7 @@ from nanobot.agent.skills import SkillsLoader
|
||||
from nanobot.agent.tools import mcp as mcp_tools
|
||||
from nanobot.agent.tools import sessions as session_tools
|
||||
from nanobot.apps.cli import utils as cli_app_utils
|
||||
from nanobot.context_sources import record_source
|
||||
from nanobot.context_sources import record_source, system_source_scope
|
||||
from nanobot.runtime_context import (
|
||||
RUNTIME_CONTEXT_MESSAGE_META,
|
||||
RuntimeContextBlock,
|
||||
@@ -275,16 +275,15 @@ class ContextBuilder:
|
||||
"""Build a model transcript while preserving the fresh-turn boundary."""
|
||||
root = workspace or self.workspace
|
||||
with self.skills.snapshot():
|
||||
with system_source_scope():
|
||||
system_prompt = self.build_system_prompt(
|
||||
channel=channel,
|
||||
session_summary=transcript.session_summary,
|
||||
workspace=root,
|
||||
include_memory=include_memory,
|
||||
)
|
||||
messages: list[dict[str, Any]] = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": self.build_system_prompt(
|
||||
channel=channel,
|
||||
session_summary=transcript.session_summary,
|
||||
workspace=root,
|
||||
include_memory=include_memory,
|
||||
),
|
||||
},
|
||||
{"role": "system", "content": system_prompt},
|
||||
*transcript.history,
|
||||
]
|
||||
if transcript.current_message is None:
|
||||
|
||||
@@ -21,6 +21,7 @@ from uuid import uuid4
|
||||
from loguru import logger
|
||||
|
||||
from nanobot.agent.context import TranscriptInput
|
||||
from nanobot.context_sources import drain_system_sources
|
||||
from nanobot.events import NO_EVENTS, ContextCompactionEvent, EventSink
|
||||
from nanobot.providers.base import (
|
||||
CONTEXT_SAFETY_BUFFER,
|
||||
@@ -706,13 +707,18 @@ class ContextGovernor:
|
||||
),
|
||||
)
|
||||
raise
|
||||
await state.events.emit(
|
||||
ContextCompactionEvent(
|
||||
compaction_id=compaction_id,
|
||||
phase="succeeded",
|
||||
reason="context_pressure",
|
||||
),
|
||||
)
|
||||
async def publish_success() -> None:
|
||||
if (sources := drain_system_sources()) is not None:
|
||||
await state.events.emit(sources)
|
||||
await state.events.emit(
|
||||
ContextCompactionEvent(
|
||||
compaction_id=compaction_id,
|
||||
phase="succeeded",
|
||||
reason="context_pressure",
|
||||
),
|
||||
)
|
||||
|
||||
await shield_and_drain(publish_success())
|
||||
return prepared
|
||||
|
||||
async def prepare_request(
|
||||
|
||||
@@ -38,6 +38,7 @@ from nanobot.bus.queue import MessageBus
|
||||
from nanobot.bus.runtime_events import RuntimeEventContext, SubagentTaskChanged
|
||||
from nanobot.config.network import NetworkConfig
|
||||
from nanobot.config.schema import AgentDefaults, ToolsConfig
|
||||
from nanobot.context_sources import without_source_capture
|
||||
from nanobot.events import AgentEvent, EventSink
|
||||
from nanobot.llm_usage.context import LLMUsageSource, current_llm_usage_source
|
||||
from nanobot.providers.base import LLMProvider, ToolCallRequest
|
||||
@@ -597,7 +598,8 @@ class SubagentManager:
|
||||
)
|
||||
self._tasks[task_id] = record
|
||||
self._publish_status(status)
|
||||
execution = asyncio.create_task(self._run_subagent(record))
|
||||
with without_source_capture():
|
||||
execution = asyncio.create_task(self._run_subagent(record))
|
||||
self._running_tasks[task_id] = execution
|
||||
execution.add_done_callback(partial(self._task_done, record))
|
||||
logger.info("Started subagent [{}]: {}", task_id,
|
||||
|
||||
Reference in new issue
Block a user