Mirascope Frog Logo
Mirascope
DocsBlogPricingCloud
⌘K
Type to search
⌘Kto search
Escto close
mirascope
v2.0.2
1.4k
Join our
WelcomeLearnGuidesAPI Referencev1 (Legacy)
DocsGuidesAPI
Overview
Getting Started
QuickstartStructured OutputsDynamic Configuration & ChainingTools & Agents
Agents
Web Search AgentAgent Executor: Blog WritingDocumentation AgentLocal Chat with CodebaseLocalized AgentQwant Search Agent with SourcesGenerate SQL with LLM
More Advanced
Code Generation and ExecutionDocument SegmentationExtracting from PDFExtraction using VisionGenerate Captions for an ImageGenerate Synthetic DataLLM Validation With RetriesNamed Entity Recognitiono1 Style ThinkingPII ScrubbingQuery PlanRemoving Semantic DuplicatesSearch with SourcesTranscribing SpeechSupport Ticket RoutingText ClassificationText SummarizationText TranslationKnowledge Graph
Prompt Engineering
Self-Refine: Enhancing LLM Outputs Through Iterative Self-ImprovementSelf-Consistency: Enhancing LLM Reasoning with Multiple OutputsReverse Chain of ThoughtPrompt Paraphrasing: Generating Diverse Prompts for LLM Testing and EvaluationMixture of Reasoning: Enhancing LLM Performance with Multiple TechniquesDemonstration Ensembling: Enhancing LLM Responses with Aggregated ExamplesChain of Verification: Enhancing LLM Accuracy through Self-VerificationLeast to MostDiVeRSe: Enhancing LLM Reasoning with Prompt VariationsDecomposed Prompting: Enhancing LLM Problem-Solving with Tool-Based SubproblemsSystem to Attention (S2A): Enhancing LLM Focus with Query FilteringStep-back Prompting: Enhancing LLM Reasoning with High-Level QuestionsSkeleton of Thought: Enhancing LLM Response SpeedSim to M: Enhancing LLM Reasoning with Perspective-Taking
Evaluations
Evaluating Documentation AgentEvaluating Web Search Agent with LLMEvaluating Generating SQL with LLM
Langgraph Vs Mirascope
LangGraph Quickstart using Mirascope
# Sim to M: Enhancing LLM Reasoning with Perspective-Taking This recipe demonstrates how to implement the Sim to M (Simulation Theory of Mind) technique using Large Language Models (LLMs) with Mirascope. Sim to M is a prompt engineering method that enhances an LLM's ability to reason about complex situations involving multiple perspectives. <Info title="Mirascope Concepts Used" collapsible={true} defaultOpen={false}> <ul> <li><a href="/docs/v1/learn/prompts/">Prompts</a></li> <li><a href="/docs/v1/learn/calls/">Calls</a></li> </ul> </Info> <Note title="Background"> <p><a href="https://arxiv.org/pdf/2311.10227">Sim to M</a> is a prompt engineering technique for dealing with complex situations which involve multiple perspectives. First ask the LLM to establish the facts from one person's perspective, then answer the question based only on that perspective. This approach can significantly improve the LLM's ability to reason about situations involving different viewpoints or limited information.</p> </Note> ## Implementation Let's implement the Sim to M technique using Mirascope: ```python from mirascope.core import openai from mirascope.core.base.prompt import prompt_template @openai.call(model="gpt-4o-mini") @prompt_template( """ The following is a sequence of events: {story} What events does {name} know about? """ ) def get_one_perspective(story: str, name: str): """Gets one person's perspective of a story.""" @openai.call(model="gpt-4o-mini") @prompt_template( """ {story_from_perspective} Based on the above information, answer the following question: {query} """ ) def sim_to_m(story: str, query: str, name: str) -> openai.OpenAIDynamicConfig: """Executes the flow of the Sim to M technique.""" story_from_perspective = get_one_perspective(story=story, name=name) return {"computed_fields": {"story_from_perspective": story_from_perspective}} story = """Jim put the ball in the box. While Jim wasn't looking, Avi moved the \ ball to the basket.""" query = "Where does Jim think the ball is?" print(sim_to_m(story=story, query=query, name="Jim")) ``` Based on the information provided, Jim believes the ball is in the box, as he is only aware of his own action of putting the ball there. He is unaware of Avi's action of moving the ball to the basket. Therefore, Jim thinks the ball is still in the box. This implementation consists of two main functions: 1. `get_one_perspective`: This function takes a story and a person's name as input, and returns the events known to that person. 2. `sim_to_m`: This function orchestrates the Sim to M technique. It first calls `get_one_perspective` to establish the facts from one person's viewpoint, then uses this perspective to answer the given query. ## Benefits and Considerations The Sim to M implementation offers several advantages: 1. Improved reasoning about situations involving multiple perspectives or limited information. 2. Enhanced ability to model and simulate different viewpoints in complex scenarios. 3. Potential for more accurate responses in tasks involving theory of mind or perspective-taking. When implementing this technique, consider: - Carefully crafting the initial story to include relevant information about different perspectives. - Ensuring that the query is specific to a particular perspective or viewpoint. - Experimenting with different prompts for the `get_one_perspective` function to optimize perspective extraction. <Info title="Additional Real-World Applications"> <ul> <li><b>Character Analysis in Literature</b>: Use Sim to M to analyze characters' motivations and beliefs in complex narratives.</li> <li><b>Conflict Resolution</b>: Apply the technique to understand different stakeholders' viewpoints in disputes.</li> <li><b>User Experience Design</b>: Simulate how different user groups might perceive and interact with a product or service.</li> <li><b>Historical Analysis</b>: Model historical figures' decision-making based on their known information at the time.</li> <li><b>Psychological Assessments</b>: Enhance AI-assisted psychological evaluations by better modeling individual perspectives.</li> </ul> </Info> When adapting this recipe to your specific use-case, consider: - Tailoring the story and query formats to your domain for better performance. - Implementing a mechanism to handle multiple perspectives in more complex scenarios. - Combining Sim to M with other techniques like Chain of Thought for even more nuanced reasoning. - Developing a feedback loop to refine the perspective extraction process based on the accuracy of final answers. By leveraging Mirascope's `call` decorator and dynamic configuration, you can easily implement and customize the Sim to M technique to enhance your LLM's ability to reason about complex, multi-perspective situations across a wide range of applications.

Provider

On this page

Provider

On this page

© 2026 Mirascope. All rights reserved.

Mirascope® is a registered trademark of Mirascope, Inc. in the U.S.

Privacy PolicyTerms of Use