Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection
The Iterative Reflective Expansion (IRE) Algorithm is a sophisticated reasoning framework that employs iterative hypothesis generation, simulation, and refinement to solve complex problems. It leverages a multi-step approach where an AI agent generates initial solution paths, evaluates their effectiveness through simulation, reflects on errors, and dynamically revises reasoning strategies.
"A reasoning agent that can answer questions and help with tasks."
Stored on the instance; not passed to the internal agent
agent
Agent
None
Reserved for a Swarms agent instance; the constructor always builds and assigns its own internal Agent regardless of this value
max_loops
int
5
Number of simulate, reflect and select iterations in run()
system_prompt
str
GENERAL_REASONING_AGENT_SYS_PROMPT
The system prompt for the internal agent. The default tells the model not to include finance-related content, so pass your own prompt for finance tasks
model_name
str
"gpt-5.4"
The underlying language model used by the internal agent
Generates an initial set of reasoning hypotheses. Each non-empty line of the model’s reply becomes one path
simulate_path(path)
Tuple[str, float, str]
Simulates a path and returns its outcome, a score from 0.0 to 1.0, and error information, read from lines starting Outcome:, Score: and Errors:. The score is 0.0 when no score can be read
meta_reflect(error_info)
str
Performs meta-cognitive reflection on the error information
revise_path(path, feedback)
List[str]
Revises a path from the feedback. Each non-empty line becomes one revised path
select_promising_paths(paths)
List[str]
Asks the model to select the most promising paths. Each non-empty line of the reply becomes one path
synthesize_solution(paths, memory_pool)
str
Synthesizes a final solution from the promising paths and every earlier path
run(task)
Formatted per output_type
Executes the full process and returns the conversation formatted by output_type
In each of max_loops iterations, every path is simulated. A path that scores below 0.7 gets a meta-reflection and is replaced by its revised paths. A path that scores 0.7 or higher is kept.
The model selects the most promising of the resulting paths, which become the next iteration’s paths.
After the last iteration, the model synthesizes a solution from the selected paths and every path seen before.
Every step goes through one internal Agent and appends its reply to agent.conversation. The conversation holds the model’s replies but not the task. It is not cleared between calls, so a second run() returns the first run’s messages too.
The model call count grows with the number of paths: each iteration makes one simulation call per path, plus a reflection and a revision call for each path below 0.7. A reply with many lines produces many paths, so start with a small max_loops.
from swarms import IterativeReflectiveExpansionagent = IterativeReflectiveExpansion( model_name="gpt-5.4", max_loops=2, output_type="final",)solution = agent.run("What is the 40th prime number?")print(solution)
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"swarms","colors":{"primary":"#DC2626","light":"#FFFFFF","dark":"#000000"},"logo":{"light":"https://mintcdn.com/kyegomez-swarms-97/2Wfh9aBTbMWV_Lyz/logo/light.svg?fit=max\u0026auto=format\u0026n=2Wfh9aBTbMWV_Lyz\u0026q=85\u0026s=e3d664b8b8f6928c836776b54704d076","dark":"https://mintcdn.com/kyegomez-swarms-97/2Wfh9aBTbMWV_Lyz/logo/dark.svg?fit=max\u0026auto=format\u0026n=2Wfh9aBTbMWV_Lyz\u0026q=85\u0026s=d1f710292b2b40794b44a3168a6b09dc"},"favicon":"https://mintcdn.com/kyegomez-swarms-97/UEClO9jJGrigmMUe/logo.svg?fit=max\u0026auto=format\u0026n=UEClO9jJGrigmMUe\u0026q=85\u0026s=07dcb5f5b9bca5ec8fd6475dcc9b5484","navbar":{"primary":{"type":"github","href":"https://github.com/kyegomez/swarms"}},"footer":{"socials":{"twitter":"https://twitter.com/swarms_corp","github":"https://github.com/kyegomez/swarms","website":"https://swarms.ai","linkedin":"https://www.linkedin.com/company/the-swarm-corporation","discord":"https://discord.gg/EamjgSaEQf","youtube":"https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ","medium":"https://medium.com/@kyeg"}},"contextual":{"options":["copy","view","chatgpt","claude","cursor","vscode"],"display":"header"},"styling":{"latex":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"kyegomez-swarms-97","hasAudioNarration":false,"actualSubdomain":"kyegomez-swarms-97","customDomains":["docs.swarms.world"],"gitSource":{"type":"github","owner":"the-swarm-corporation","repo":"swarms-framework-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ade27d790f989adb24ebb0c","collectionId":"0cb2ea24-451d-42c5-9222-5334866254f6","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ade27d790f989adb24ebb0c"},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6ade27d790f989adb24ebb0c","clientVersion":"0.0.4044","searchFilterCounts":[{"language":"default","tag":"Examples","count":111},{"language":"default","tag":"Documentation","count":58},{"language":"default","tag":"API Reference","count":54},{"language":"default","tag":"Multi-Agent Harnesses","count":37},{"language":"default","tag":"RouteHub","count":17},{"language":"default","tag":"MCP Tool Integrations","count":15},{"language":"default","tag":"Community","count":13},{"language":"default","tag":"Model Providers","count":13},{"language":"default","tag":"Multi-Agent Architectures","count":12},{"language":"default","tag":"Integrations","count":12}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"agents/iterative-agent","slug":"/agents/iterative-agent","pageMetadata":{"title":"IRE Agent (Iterative Reflective Expansion)","description":"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection","icon":"arrows-spin","href":"/agents/iterative-agent"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{CodeBlock,Heading,Mermaid,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Mermaid)_missingMdxReference(`Mermaid`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`The Iterative Reflective Expansion (IRE) Algorithm is a sophisticated reasoning framework that employs iterative hypothesis generation, simulation, and refinement to solve complex problems. It leverages a multi-step approach where an AI agent generates initial solution paths, evaluates their effectiveness through simulation, reflects on errors, and dynamically revises reasoning strategies.`}),`\n`,_jsx(Heading,{level:`2`,id:`architecture`,children:`Architecture`}),`\n`,_jsx(Mermaid,{chart:`graph TD\n Problem_Input[\"Problem Input\"] --> Generate_Hypotheses\n Generate_Hypotheses[\"Generate Initial Hypotheses\"] --> Simulate\n subgraph Iterative Reflective Expansion Loop\n Simulate[\"Simulate Reasoning Paths\"] --> Evaluate\n Evaluate[\"Evaluate Outcomes\"] --> Reflect{Is solution satisfactory?}\n Reflect -->|No, issues found| Meta_Reflect\n Reflect -->|Yes| Promising\n Meta_Reflect[\"Meta-Cognitive Reflection\"] --> Revise_Paths\n Revise_Paths[\"Revise Paths Based on Feedback\"] --> Expand_Paths\n Expand_Paths[\"Iterative Expansion \u0026 Pruning\"] --> Simulate\n end\n Promising[\"Promising Paths Selected\"] --> Memory\n Memory[\"Memory Integration\"] --> Synthesize\n Synthesize[\"Synthesize Final Solution\"] --> Final[\"Final Solution\"]`}),`\n`,_jsx(Heading,{level:`2`,id:`workflow`,children:`Workflow`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`Generate initial hypotheses`}),`\n`,_jsx(_components.li,{children:`Simulate paths`}),`\n`,_jsx(_components.li,{children:`Reflect on errors`}),`\n`,_jsx(_components.li,{children:`Revise paths`}),`\n`,_jsx(_components.li,{children:`Select promising paths`}),`\n`,_jsx(_components.li,{children:`Synthesize solution`}),`\n`]}),`\n`,_jsxs(Heading,{level:`2`,id:`class-iterativereflectiveexpansion`,children:[`Class: `,_jsx(_components.code,{children:`IterativeReflectiveExpansion`})]}),`\n`,_jsx(Heading,{level:`3`,id:`parameters`,children:`Parameters`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Parameter`}),_jsx(_components.th,{children:`Type`}),_jsx(_components.th,{children:`Default`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`agent_name`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`str`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`\"General-Reasoning-Agent\"`})}),_jsx(_components.td,{children:`Name of the internal reasoning agent`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`description`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`str`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`\"A reasoning agent that can answer questions and help with tasks.\"`})}),_jsx(_components.td,{children:`Stored on the instance; not passed to the internal agent`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`agent`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`Agent`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`None`})}),_jsxs(_components.td,{children:[`Reserved for a Swarms agent instance; the constructor always builds and assigns its own internal `,_jsx(_components.code,{children:`Agent`}),` regardless of this value`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`max_loops`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`int`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`5`})}),_jsxs(_components.td,{children:[`Number of simulate, reflect and select iterations in `,_jsx(_components.code,{children:`run()`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`system_prompt`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`str`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`GENERAL_REASONING_AGENT_SYS_PROMPT`})}),_jsx(_components.td,{children:`The system prompt for the internal agent. The default tells the model not to include finance-related content, so pass your own prompt for finance tasks`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`model_name`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`str`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`\"gpt-5.4\"`})}),_jsx(_components.td,{children:`The underlying language model used by the internal agent`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`output_type`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`OutputType`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`\"dict\"`})}),_jsxs(_components.td,{children:[`Format of the value returned by `,_jsx(_components.code,{children:`run()`})]})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`methods`,children:`Methods`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Method`}),_jsx(_components.th,{children:`Returns`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`generate_initial_hypotheses(task)`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`List[str]`})}),_jsx(_components.td,{children:`Generates an initial set of reasoning hypotheses. Each non-empty line of the model’s reply becomes one path`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`simulate_path(path)`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`Tuple[str, float, str]`})}),_jsxs(_components.td,{children:[`Simulates a path and returns its outcome, a score from 0.0 to 1.0, and error information, read from lines starting `,_jsx(_components.code,{children:`Outcome:`}),`, `,_jsx(_components.code,{children:`Score:`}),` and `,_jsx(_components.code,{children:`Errors:`}),`. The score is 0.0 when no score can be read`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`meta_reflect(error_info)`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`str`})}),_jsx(_components.td,{children:`Performs meta-cognitive reflection on the error information`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`revise_path(path, feedback)`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`List[str]`})}),_jsx(_components.td,{children:`Revises a path from the feedback. Each non-empty line becomes one revised path`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`select_promising_paths(paths)`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`List[str]`})}),_jsx(_components.td,{children:`Asks the model to select the most promising paths. Each non-empty line of the reply becomes one path`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`synthesize_solution(paths, memory_pool)`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`str`})}),_jsx(_components.td,{children:`Synthesizes a final solution from the promising paths and every earlier path`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`run(task)`})}),_jsxs(_components.td,{children:[`Formatted per `,_jsx(_components.code,{children:`output_type`})]}),_jsxs(_components.td,{children:[`Executes the full process and returns the conversation formatted by `,_jsx(_components.code,{children:`output_type`})]})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`how-a-run-works`,children:`How a run works`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`run()`}),` generates the initial paths.`]}),`\n`,_jsxs(_components.li,{children:[`In each of `,_jsx(_components.code,{children:`max_loops`}),` iterations, every path is simulated. A path that scores below 0.7 gets a meta-reflection and is replaced by its revised paths. A path that scores 0.7 or higher is kept.`]}),`\n`,_jsx(_components.li,{children:`The model selects the most promising of the resulting paths, which become the next iteration’s paths.`}),`\n`,_jsx(_components.li,{children:`After the last iteration, the model synthesizes a solution from the selected paths and every path seen before.`}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Every step goes through one internal `,_jsx(_components.code,{children:`Agent`}),` and appends its reply to `,_jsx(_components.code,{children:`agent.conversation`}),`. The conversation holds the model’s replies but not the task. It is not cleared between calls, so a second `,_jsx(_components.code,{children:`run()`}),` returns the first run’s messages too.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`The model call count grows with the number of paths: each iteration makes one simulation call per path, plus a reflection and a revision call for each path below 0.7. A reply with many lines produces many paths, so start with a small `,_jsx(_components.code,{children:`max_loops`}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`example`,children:`Example`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`10`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` swarms `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` IterativeReflectiveExpansion`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`agent `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` IterativeReflectiveExpansion(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"gpt-5.4\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_loops`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` output_type`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"final\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`solution `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.run(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"What is the 40th prime number?\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(solution)`})]}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"IRE Agent (Iterative Reflective Expansion)","description":"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection","icon":"arrows-spin","href":"/agents/iterative-agent"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Architecture","slug":"architecture","depth":2,"children":[]},{"title":"Workflow","slug":"workflow","depth":2,"children":[]},{"title":"Class: IterativeReflectiveExpansion","slug":"class-iterativereflectiveexpansion","depth":2,"children":[{"title":"Parameters","slug":"parameters","depth":3,"children":[]},{"title":"Methods","slug":"methods","depth":3,"children":[]}]},{"title":"How a run works","slug":"how-a-run-works","depth":2,"children":[]},{"title":"Example","slug":"example","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"kyegomez-swarms-97","siteName":"swarms","title":"IRE Agent (Iterative Reflective Expansion) - swarms","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-03T00:14:50.349Z","originalFileLocation":"agents/iterative-agent.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection\">\u003cmeta data-mint-head name=\"application-name\" content=\"swarms\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"IRE Agent (Iterative Reflective Expansion) - swarms\">\u003cmeta data-mint-head property=\"og:description\" content=\"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"swarms\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.swarms.world/agents/iterative-agent\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://kyegomez-swarms-97.mintlify.app/_mintlify/api/og/v2?division=Reasoning+Agents\u0026amp;title=IRE+Agent+%28Iterative+Reflective+Expansion%29\u0026amp;description=Iterative+hypothesis+generation%2C+simulation%2C+and+refinement+through+continuous+cycles+of+testing+and+meta-cognitive+reflection\u0026amp;theme=5153e5700b995bc72eadb0da\u0026amp;signature=9938f20f3fb395fd4fff4fe057b207e363cb91d54e5aba8f643a0cde365faff3\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"IRE Agent (Iterative Reflective Expansion) - swarms\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://kyegomez-swarms-97.mintlify.app/_mintlify/api/og/v2?division=Reasoning+Agents\u0026amp;title=IRE+Agent+%28Iterative+Reflective+Expansion%29\u0026amp;description=Iterative+hypothesis+generation%2C+simulation%2C+and+refinement+through+continuous+cycles+of+testing+and+meta-cognitive+reflection\u0026amp;theme=5153e5700b995bc72eadb0da\u0026amp;signature=9938f20f3fb395fd4fff4fe057b207e363cb91d54e5aba8f643a0cde365faff3\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/kyegomez-swarms-97/Ctj8KAbEFcaygyNp/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"swarms\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#DC2626\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.swarms.world/agents/iterative-agent\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/agents/iterative-agent.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.swarms.world/#organization\",\"name\":\"swarms\",\"url\":\"https://docs.swarms.world\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/kyegomez-swarms-97/2Wfh9aBTbMWV_Lyz/logo/light.svg?fit=max\u0026auto=format\u0026n=2Wfh9aBTbMWV_Lyz\u0026q=85\u0026s=e3d664b8b8f6928c836776b54704d076\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.swarms.world#website\",\"name\":\"swarms\",\"url\":\"https://docs.swarms.world\",\"publisher\":{\"@id\":\"https://docs.swarms.world/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.swarms.world/agents/iterative-agent#webpage\",\"url\":\"https://docs.swarms.world/agents/iterative-agent\",\"name\":\"IRE Agent (Iterative Reflective Expansion)\",\"description\":\"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection\",\"dateModified\":\"2026-10-03T00:14:50.349Z\",\"isPartOf\":{\"@id\":\"https://docs.swarms.world#website\"},\"breadcrumb\":{\"@id\":\"https://docs.swarms.world/agents/iterative-agent#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.swarms.world/agents/iterative-agent#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Reasoning Agents\",\"item\":\"https://docs.swarms.world/agents/reasoning-agents-overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IRE Agent (Iterative Reflective Expansion)\",\"item\":\"https://docs.swarms.world/agents/iterative-agent\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.swarms.world/agents/iterative-agent#article\",\"headline\":\"IRE Agent (Iterative Reflective Expansion)\",\"name\":\"IRE Agent (Iterative Reflective Expansion)\",\"description\":\"Iterative hypothesis generation, simulation, and refinement through continuous cycles of testing and meta-cognitive reflection\",\"url\":\"https://docs.swarms.world/agents/iterative-agent\",\"mainEntityOfPage\":{\"@id\":\"https://docs.swarms.world/agents/iterative-agent#webpage\"},\"dateModified\":\"2026-10-03T00:14:50.349Z\",\"publisher\":{\"@id\":\"https://docs.swarms.world/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.swarms.world#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"swarms\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"swarms","nav":{"global":null,"tabs":[{"tab":"Documentation","groups":[{"group":"Getting Started","pages":[{"title":"Introduction to Swarms","href":"/introduction"},{"title":"Quickstart Guide","href":"/quickstart"},{"title":"Installation","href":"/installation"},{"title":"Environment Setup","href":"/environment-setup"}]},{"group":"Core Concepts","pages":[{"title":"Agents","href":"/concepts/agents"},{"title":"Swarms","href":"/concepts/swarms"},{"title":"Workflows","href":"/concepts/workflows"},{"title":"Tools","href":"/concepts/tools"},{"title":"Custom Multi-Agent Architectures","href":"/concepts/custom-architectures"}]},{"group":"Agent Development","pages":[{"title":"Creating Agents","icon":"robot","href":"/agents/creating-agents"},{"title":"Agent Configuration","icon":"sliders","href":"/agents/agent-configuration"},{"title":"Agent Memory","icon":"database","href":"/agents/agent-memory"},{"title":"Autonomous Mode","icon":"robot","href":"/agents/autonomous-mode"},{"title":"Agent Tools","icon":"wrench","href":"/agents/agent-tools"},{"title":"Dynamic Tool Loading","icon":"magnifying-glass-arrow-right","href":"/agents/dynamic-tools"},{"title":"Agent Skills","icon":"graduation-cap","href":"/agents/agent-skills"},{"title":"Structured Outputs","icon":"code","href":"/agents/structured-outputs"},{"title":"Prompt Caching","icon":"database","href":"/agents/prompt-caching"},{"title":"Token Usage","icon":"coins","href":"/agents/token-usage"}]},{"group":"Reasoning Agents","pages":[{"title":"Reasoning Agents Overview","icon":"brain","href":"/agents/reasoning-agents-overview"},{"title":"Self-Consistency Agent","description":"Generate multiple independent reasoning paths and aggregate them via majority voting for reliable, high-accuracy answers","icon":"check-double","href":"/agents/self-consistency-agent"},{"title":"IRE Agent (Iterative Reflective Expansion)","icon":"arrows-spin","href":"/agents/iterative-agent"},{"title":"Reasoning Duo","description":"Dual-agent collaborative system that separates reasoning and execution phases for more robust and reliable outputs","icon":"people-arrows","href":"/agents/reasoning-duo"},{"title":"Reflexion Agent","icon":"rotate","href":"/agents/reflexion-agent"},{"title":"GKP Agent (Generated Knowledge Prompting)","icon":"book-open","href":"/agents/gkp-agent"},{"title":"Tree of Thoughts","icon":"sitemap","href":"/agents/tree-of-thoughts"},{"title":"Agent Judge","icon":"gavel","href":"/agents/agent-judge"},{"title":"Reasoning Agent Router","icon":"route","href":"/agents/reasoning-agent-router"}]},{"group":"Multi-Agent Architectures","pages":[{"title":"Multi-Agent Architectures Overview","href":"/architectures/overview"},{"title":"Multi-Agent Structures Catalog","href":"/architectures/structures-catalog"},{"title":"Sequential Workflow","href":"/architectures/sequential-workflow"},{"title":"Concurrent Workflow","href":"/architectures/concurrent-workflow"},{"title":"Agent Rearrange","href":"/architectures/agent-rearrange"},{"title":"Mixture of Agents","href":"/architectures/mixture-of-agents"},{"title":"Swarm Router","href":"/architectures/swarm-router"},{"title":"Hierarchical Swarm","href":"/architectures/hierarchical-swarm"},{"title":"Heavy Swarm","href":"/architectures/heavy-swarm"},{"title":"Group Chat","href":"/architectures/group-chat"},{"title":"Graph Workflow","href":"/architectures/graph-workflow"},{"title":"Social Algorithms","href":"/architectures/social-algorithms"}]},{"group":"Deployment \u0026 Operations","pages":[{"title":"Production Best Practices","icon":"shield-check","href":"/deployment/production-best-practices"},{"title":"Scaling Swarms","icon":"chart-line","href":"/deployment/scaling"},{"title":"Monitoring \u0026 Observability","icon":"chart-mixed","href":"/deployment/monitoring"},{"title":"Telemetry","icon":"chart-line","href":"/deployment/telemetry"}]},{"group":"Integrations","pages":[{"title":"Model Providers","href":"/integrations/model-providers"},{"title":"Model Context Protocol (MCP)","href":"/integrations/mcp"},{"title":"Tools Integration","href":"/integrations/tools"},{"title":"Swarms Marketplace","href":"/integrations/marketplace"}]},{"group":"CLI Reference","pages":[{"title":"CLI Overview","icon":"terminal","href":"/cli/overview"},{"title":"Swarms CLI Tutorial","icon":"book-open","href":"/cli/tutorial"},{"title":"CLI Commands","icon":"terminal","href":"/cli/commands"},{"title":"CLI Configuration","icon":"gear","href":"/cli/configuration"},{"title":"CLI Examples","icon":"list","href":"/cli/examples"}]},{"group":"Changelog","pages":[{"title":"Changelog Overview","href":"/changelog/overview"},{"title":"Swarms v15","href":"/changelog/swarms-v15"},{"title":"Swarms v14","href":"/changelog/swarms-v14"},{"title":"Swarms v13","href":"/changelog/swarms-v13"},{"title":"Swarms v12","href":"/changelog/swarms-v12"}]}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api/agent"}]},{"tab":"RouteHub","pages":[{"title":"RouteHub","href":"/routehub/overview"}]},{"tab":"Swarms API","pages":[{"title":"Swarms API","href":"/swarms-api/overview"}]},{"tab":"Examples","pages":[{"title":"Examples","href":"/examples/overview"}]},{"tab":"Community","pages":[{"title":"Community","href":"/community/contributing"}]}]},"basePath":"","title":"IRE Agent (Iterative Reflective Expansion) - swarms","buildId":"dpl_DeHjVRGfFnhYQwHnfC2pjeXXv8h9","deploymentId":"dpl_DeHjVRGfFnhYQwHnfC2pjeXXv8h9","dynamics":[],"chunks":[]}