File size: 1,045 Bytes
9d0fd45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Shared helpers for bus-scoped tool execution."""

from __future__ import annotations

from typing import Any

SWARM_SCOPE_KEY = "swarm_subagent_runtime"


def resolve_bus_task_id(scope: Any) -> str:
    """Return the AgentBus-scope id for tool calls.

    Heavy mode injects a synthetic per-run id via
    ``scope.metadata["bus_task_id"]``; everywhere else falls back to
    ``scope.task_id``.
    """
    metadata = getattr(scope, "metadata", None) or {}
    return str(metadata.get("bus_task_id") or scope.task_id)


def resolve_root_task_id(scope: Any) -> str:
    """Return the original root task_id (SSE / event-store scope).

    Heavy mode optionally stashes the root id under
    ``scope.metadata["root_task_id"]`` so tools that need to emit
    user-facing events can use it; absent it, ``scope.task_id`` is
    already the root.
    """
    metadata = getattr(scope, "metadata", None) or {}
    return str(metadata.get("root_task_id") or scope.task_id)


__all__ = ["SWARM_SCOPE_KEY", "resolve_bus_task_id", "resolve_root_task_id"]