Skip to content

Turn struct #634

@andreasronge

Description

@andreasronge

Summary

Create immutable Turn struct to capture each LLM interaction cycle.

Spec: message-history-optimization-requirements.md (Roadmap Issue #5)

Requirements

ARC-001: Turn struct fields

Turn struct with fields:

  • number - turn sequence number (integer)
  • raw_response - full LLM output including reasoning (string, always captured per ARC-010)
  • program - parsed PTC-Lisp program (string or nil for failures)
  • result - execution result (any term)
  • prints - captured println output (list of strings)
  • tool_calls - tool invocations made (list of %{name, args, result})
  • memory - accumulated definitions (map)
  • success? - whether turn succeeded (boolean)

ARC-002: Append-only turns list

Turns list is append-only (no mutation). Each turn is a snapshot of that cycle's execution.

ARC-010: raw_response always captured

raw_response captures full LLM output including reasoning. Always captured, no debug flag needed.

DBG-001: Full programs preserved

Full programs preserved in Step.turns. Each Turn contains complete execution data.

DBG-002: Turn contains complete execution data

Turn contains: number, raw_response, program, result, prints, tool_calls, memory, success?

Implementation

File to create

  • lib/ptc_runner/turn.ex

Struct definition

defstruct [
  :number,
  :raw_response,
  :program,
  :result,
  :prints,
  :tool_calls,
  :memory,
  :success?
]

Constructor functions

Two smart constructors for creating turns:

@doc """
Create a successful turn.
"""
def success(number, raw_response, program, result, prints, tool_calls, memory)

@doc """
Create a failed turn.
"""
def failure(number, raw_response, program, error, prints, tool_calls, memory)

The success? field is set automatically:

  • Turn.success/7 sets success?: true
  • Turn.failure/7 sets success?: false

No update functions

The struct is immutable - no update/merge functions should be provided. If a turn needs modification, create a new one.

Files to modify

None - this is a standalone struct with no integration yet. Integration happens in:

Acceptance criteria

  • Turn.success/7 constructor creates turn with success?: true
  • Turn.failure/7 constructor creates turn with success?: false
  • All 8 fields accessible via pattern matching and dot notation
  • Struct is immutable (no update functions provided)
  • Basic tests for both constructors
  • Typespec defined for Turn struct

Blocked by

Blocks

Automation State

Field Value
Status SUCCESS
PR #636
Branch claude/634-turn-struct
Attempts 1

Details: Implemented Turn struct with success/7 and failure/7 constructors. All tests passing, PR created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions