Repository navigation
v0.1.0a3 - Type-Safe Phase Workflows with Auto-Rendering
🎯 v0.1.0a3 - Type-Safe Phase Workflows with Auto-Rendering
This release brings significant DX improvements to phase-based workflows, with full Enum support and automatic phase tracking.
🚀 What's New
Auto-Rendering with Current Phase
No more manual phase tracking! Context.render() now automatically uses the current phase from state:
# Before (v0.1.0a2)
ctx.render(phase=state.phase()) # Manual phase passing
# After (v0.1.0a3)
ctx.render() # Automatic! ✨
Cleaner State Initialization
New current_phase parameter for cleaner state setup:
# Before
state = State(
initial={"session": {"phase": "intake"}},
phases=Phases
)
# After
state = State(current_phase="intake", phases=Phases) # Much cleaner!
Full Enum Support for Type Safety
Complete Enum support across the entire phase API:
class Phases(str, Enum):
INTAKE = "intake"
ASSESSMENT = "assessment"
# Now works everywhere:
ctx.phase(Phases.INTAKE).configure(
transitions_to=[Phases.ASSESSMENT] # ✅ Type-safe!
)
ctx.advance_phase(Phases.ASSESSMENT) # ✅ IDE autocomplete
✨ Key Features
✅ Auto-rendering: ctx.render() uses current phase automatically
✅ Type-safe transitions: transitions_to=[Phases.NEXT] with full Enum support
✅ Cleaner API: State(current_phase="init") instead of nested dicts
✅ Better validation: Immediate errors with actionable messages
✅ Backward compatible: Strings still work everywhere
🎨 Developer Experience
New method: ctx.current_phase() to check current phase
Enhanced validation: Clear error messages with fix suggestions
IDE support: Full autocomplete for Enum-based workflows
Token counting: ctx.token_count() respects current phase
🔧 Breaking Changes
Context.render() now auto-uses state.phase() when no phase specified:
Impact: Low - explicit phase= parameter still works
Migration: Remove manual phase=state.phase() calls (optional)
📦 What's Included
67 tests passing (14 new deep integration tests)
New examples:
multi_phase_workflow.py - Updated with Enum patterns
gemini_phase_workflow.py - Production-ready Gemini workflow
Validated formats: TEXT, OpenAI, Anthropic, Gemini (fully tested)
🧪 Production Ready
Comprehensive testing validates:
✅ All render formats (including Gemini generation_config)
✅ Phase transitions and validation
✅ Enum/string consistency
✅ Edge cases and error handling
✅ Memory integration
✅ Token counting with phases
📚 Examples
Basic Phase Workflow
from kontxt import Context, State, SystemPrompt, Format
from enum import Enum
class Phases(str, Enum):
TRIAGE = "triage"
RESOLUTION = "resolution"
# Initialize
state = State(current_phase=Phases.TRIAGE, phases=Phases)
ctx = Context(state=state)
# Configure
ctx.phase(Phases.TRIAGE).configure(
instructions="Gather information",
transitions_to=[Phases.RESOLUTION] # Type-safe!
)
# Use
ctx.add_user_message("Help!")
payload = ctx.render(format=Format.GEMINI) # Auto-uses TRIAGE phase
# Advance
ctx.advance_phase(Phases.RESOLUTION) # Validated!
🔗 Resources
Full Changelog: [CHANGELOG.md](vscode-webview://17f13ik0iikphc9stt4ur2fr0gs0tsfttlvaki3376otqmgg1vj3/CHANGELOG.md)
Examples: [examples/](vscode-webview://17f13ik0iikphc9stt4ur2fr0gs0tsfttlvaki3376otqmgg1vj3/examples/)
Documentation: Coming soon
🙏 Feedback Welcome
This is an alpha release. Please report issues or suggestions!