Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/interleaved-thinking/examples/01_basic_capture.py
1"""2Example 1: Basic Trace Capture34Demonstrates capturing reasoning traces from M2.1 for a simple task.5This shows how interleaved thinking provides visibility into agent decisions.6"""78import os9from pathlib import Path10from dotenv import load_dotenv1112from reasoning_trace_optimizer import TraceCapture13from reasoning_trace_optimizer.capture import format_trace_for_display1415# Load environment variables from the project root16env_path = Path(__file__).parent.parent / ".env"17load_dotenv(env_path)181920def main():21"""Run a simple task and capture the reasoning trace."""2223# Initialize capture with M2.124capture = TraceCapture(25api_key=os.getenv("ANTHROPIC_API_KEY"),26base_url="https://api.minimax.io/anthropic",27model="MiniMax-M2.1",28)2930# Define a simple task31task = "Explain what interleaved thinking is and why it matters for AI agents."32system_prompt = "You are an AI researcher explaining concepts clearly."3334print("=" * 60)35print("BASIC TRACE CAPTURE EXAMPLE")36print("=" * 60)37print(f"\nTask: {task}")38print(f"System Prompt: {system_prompt}")39print("\nCapturing reasoning trace...\n")4041# Capture the trace42trace = capture.run(43task=task,44system_prompt=system_prompt,45max_turns=5,46)4748# Display the trace49print(format_trace_for_display(trace))5051# Summary statistics52print("\n" + "=" * 60)53print("TRACE STATISTICS")54print("=" * 60)55print(f"Session ID: {trace.session_id}")56print(f"Model: {trace.model}")57print(f"Success: {trace.success}")58print(f"Total Turns: {trace.total_turns}")59print(f"Thinking Blocks: {len(trace.thinking_blocks)}")60print(f"Tool Calls: {len(trace.tool_calls)}")61print(f"Total Tokens: {trace.total_tokens}")6263# Show each thinking block summary64if trace.thinking_blocks:65print("\n" + "=" * 60)66print("THINKING BLOCK SUMMARIES")67print("=" * 60)68for i, thinking in enumerate(trace.thinking_blocks):69print(f"\n[Turn {thinking.turn_index}] ({len(thinking.content)} chars)")70# Show first 200 chars71preview = thinking.content[:200].replace("\n", " ")72print(f" Preview: {preview}...")737475if __name__ == "__main__":76main()77