refactor(agent): unify session message admission
This commit is contained in:
1 parent
7208fb663f
commit
b669c2036c
17 files changed
+284
-257
No files matched your search
@@ -6,9 +6,8 @@ import asyncio
|
||||
import hashlib
|
||||
import time
|
||||
import uuid
|
||||
from typing import TYPE_CHECKING, Any, Protocol
|
||||
from typing import Any, Protocol
|
||||
|
||||
from nanobot.agent.tools.cron import CronTool
|
||||
from nanobot.bus.events import InboundMessage, OutboundMessage
|
||||
from nanobot.cron.session_delivery import origin_delivery_context
|
||||
from nanobot.cron.session_turns import CRON_DEFER_UNTIL_IDLE_META, CRON_TRIGGER_META
|
||||
@@ -16,13 +15,8 @@ from nanobot.cron.types import CronJob, CronRunResult
|
||||
from nanobot.cron.webui_metadata import cron_proactive_delivery_metadata
|
||||
from nanobot.utils.prompt_templates import render_template
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nanobot.agent.tools.registry import ToolRegistry
|
||||
|
||||
|
||||
class BoundCronAgent(Protocol):
|
||||
tools: ToolRegistry
|
||||
|
||||
async def submit_cron_turn(self, msg: InboundMessage) -> OutboundMessage | None:
|
||||
...
|
||||
|
||||
@@ -112,10 +106,6 @@ async def run_bound_cron_job(
|
||||
},
|
||||
)
|
||||
|
||||
cron_tool = agent.tools.get("cron")
|
||||
cron_token = None
|
||||
if isinstance(cron_tool, CronTool):
|
||||
cron_token = cron_tool.set_cron_context(True)
|
||||
try:
|
||||
resp = await agent.submit_cron_turn(
|
||||
InboundMessage(
|
||||
@@ -138,10 +128,6 @@ async def run_bound_cron_job(
|
||||
},
|
||||
)
|
||||
raise
|
||||
finally:
|
||||
if isinstance(cron_tool, CronTool) and cron_token is not None:
|
||||
cron_tool.reset_cron_context(cron_token)
|
||||
|
||||
response = resp.content if resp else ""
|
||||
cron.write_run_record(
|
||||
run_id,
|
||||
|
||||
Reference in new issue
Block a user