Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
refactor(loop): add turn_id for trace correlation
chengyongru728d837e4ece
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex d5673603d..ea3e50e11 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -209,6 +209,7 @@ class TurnContext:msg: InboundMessagesession_key: strstate: TurnState+ turn_id: strsession: Session | None = Nonehistory: list[dict[str, Any]] = field(default_factory=list)@@ -1267,9 +1268,10 @@ class AgentLoop:key = session_key or msg.session_keyctx = TurnContext(msg=msg,- session=self.sessions.get_or_create(key),+ session=None,session_key=key,state=TurnState.RESTORE,+ turn_id=f"{key}:{time.time_ns()}",on_progress=on_progress,on_stream=on_stream,on_stream_end=on_stream_end,@@ -1308,7 +1310,8 @@ class AgentLoop:))logger.debug(- "State {} took {:.1f}ms -> event {}",+ "[turn {}] State {} took {:.1f}ms -> event {}",+ ctx.turn_id,ctx.state.name,duration,event,@@ -1317,7 +1320,8 @@ class AgentLoop:next_state = self._TRANSITIONS.get((ctx.state, event))if next_state is None:raise RuntimeError(- f"No transition from {ctx.state} on event {event!r}"+ f"[turn {ctx.turn_id}] No transition from {ctx.state} "+ f"on event {event!r}")ctx.state = next_state