Skip to content

PreparedTurnContext (runtime plan before run_attempt) #1940

@MervinPraison

Description

@MervinPraison

Problem

Each runtime path prepares tools, transcript slices, and delivery channels differently, causing duplication and drift between the native loop and plugin harnesses before run_attempt.

Current state

  • Tool assembly and message building scattered across praisonaiagents/agent/chat_mixin.py, praisonaiagents/agent/chat_handler.py, and CLI backend execution branches in praisonaiagents/agent/agent.py.
  • Handoff context policies in praisonaiagents/agent/handoff.py mutate context ad hoc.
  • No shared immutable turn plan object passed into runtime run_turn.

Proposed design

  • Add PreparedTurnContext dataclass in praisonaiagents/runtime/turn_context.py capturing: resolved model_ref, AgentRuntimeProtocol instance, normalised tool schemas, transcript window, streaming/delivery handles, and session correlation ids.
  • Build PreparedTurnContext in one preflight step immediately before run_attempt (shared by all runtimes).
  • Runtimes consume the plan read-only; mutations go through defined hooks only.
  • Enables consistent metrics and tracing across harness types.

Acceptance criteria

  • Native praisonai runtime refactored to accept PreparedTurnContext without behaviour regression in tests.
  • At least one external harness uses the same plan object.
  • Multi-agent safe: plan is per-turn, not stored on shared agent globals.

Layer

Primary: core (praisonaiagents/runtime/turn_context.py)

Secondary: wrapper (CLI streaming delivery adapters)

3-way parity (Python / YAML / CLI)

Surface Supported
Python yes — internal API
YAML no — internal normalisation only
CLI no — transparent to users

Priority

P2

Related modules

praisonaiagents/agent/chat_mixin.py, praisonaiagents/agent/chat_handler.py, praisonaiagents/agent/unified_execution_mixin.py, praisonaiagents/streaming/

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    claudeAuto-trigger Claude analysis

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions