# String Interpolation Example # Demonstrates dynamic prompt construction with {variable} syntax # Basic interpolation let user_name = session "Get the user's name" let topic = session "Ask what topic they want to learn about" session "Create a personalized greeting for {user_name} about {topic}" # Multiple interpolations in one prompt let company = session "Get the company name" let industry = session "Identify the company's industry" let size = session "Determine company size (startup/mid/enterprise)" session "Write a customized proposal for {company}, a {size} company in {industry}" # Interpolation with context let research = session "Research the topic thoroughly" session "Based on the research, explain {topic} to {user_name}" context: research # Multi-line strings with interpolation let project = session "Get the project name" let deadline = session "Get the project deadline" let team_size = session "Get the team size" session """ Create a project plan for {project}. Key constraints: - Deadline: {deadline} - Team size: {team_size} Include milestones and resource allocation. """ # Interpolation in loops let languages = ["Python", "JavaScript", "Go"] for lang in languages: session "Write a hello world program in {lang}" session "Explain the syntax of {lang}" # Interpolation in parallel blocks let regions = ["North America", "Europe", "Asia Pacific"] parallel for region in regions: session "Analyze market conditions in {region}" session "Identify top competitors in {region}" # Interpolation with computed values let base_topic = session "Get the main topic" let analysis = session "Analyze {base_topic} from multiple angles" let subtopics = ["history", "current state", "future trends"] for subtopic in subtopics: session "Explore the {subtopic} of {base_topic}" context: analysis # Building dynamic workflows let workflow_type = session "What type of document should we create?" let audience = session "Who is the target audience?" let length = session "How long should the document be?" session """ Create a {workflow_type} for {audience}. Requirements: - Length: approximately {length} - Tone: appropriate for {audience} - Focus: practical and actionable Please structure with clear sections. """ # Interpolation in error messages let operation = session "Get the operation name" let target = session "Get the target resource" try: session "Perform {operation} on {target}" catch: session "Failed to {operation} on {target} - attempting recovery" throw "Operation {operation} failed for {target}" # Combining interpolation with choice blocks let task_type = session "Identify the type of task" let priority = session "Determine task priority" choice **the best approach for a {priority} priority {task_type}**: option "Immediate action": session "Execute {task_type} immediately with {priority} priority handling" option "Scheduled action": session "Schedule {task_type} based on {priority} priority queue" option "Delegate": session "Assign {task_type} to appropriate team member" # Interpolation with agent definitions agent custom_agent: model: sonnet prompt: "You specialize in helping with {topic}" session: custom_agent prompt: "Provide expert guidance on {topic} for {user_name}"