Files
tracer-cloud--opensre/core/agent_harness/turns/turn_plan.py
T
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

61 lines
2.4 KiB
Python

"""Turn-wide assembly: the decisions one turn runs on.
Assembled once at the top of ``run_turn`` and read by the action, gather, and
answer phases so they cannot disagree about what this turn knows. It composes the
frozen :class:`TurnSnapshot` (the read view of session state at turn start) with
the turn's resolved-integration decision.
The snapshot answers "what did the session look like at turn start?"; the plan
answers "what is this turn running on?". ``build_turn_plan`` owns the assembly:
it resolves integrations once and composes them into the snapshot. Tool lists and
prompts stay built by their phases (action tools need surface context; gather
tools depend on message-time GitHub scope), each reading ``resolved_integrations``
here so there is one source.
"""
from __future__ import annotations
from dataclasses import dataclass, replace
from typing import Any
from core.agent_harness.ports import SessionStore
from core.agent_harness.session.integration_resolution import resolve_and_cache_integrations
from core.agent_harness.turns.turn_snapshot import TurnSnapshot
@dataclass(frozen=True)
class TurnPlan:
"""Everything one turn runs on, assembled once at ``run_turn``."""
snapshot: TurnSnapshot
@property
def text(self) -> str:
"""Raw user input text for this turn."""
return self.snapshot.text
@property
def resolved_integrations(self) -> dict[str, Any]:
"""The turn's single resolved-integration view (frozen on the snapshot)."""
return self.snapshot.resolved_integrations
def build_turn_plan(snapshot: TurnSnapshot, session: SessionStore) -> TurnPlan:
"""Assemble the turn plan: resolve integrations once, then compose the snapshot.
Resolution runs only when the snapshot has not already been populated (a
runtime-request source can pre-fill it), so the plan is the single place that
decides what this turn knows about connected integrations.
An empty result (``{}`` — no integrations configured) is a valid resolved
view; downstream phases read it from the plan rather than re-checking, so the
resolve-once contract holds even in that case (``resolve_and_cache`` also
caches, so a repeat call would be a no-op regardless).
"""
if not snapshot.resolved_integrations:
snapshot = replace(snapshot, resolved_integrations=resolve_and_cache_integrations(session))
return TurnPlan(snapshot=snapshot)
__all__ = ["TurnPlan", "build_turn_plan"]