Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory
The ReflexionAgent implements the Reflexion framework to improve through self-reflection. It follows a process of acting on tasks, evaluating its performance, generating self-reflections, and using these reflections to improve future responses.Based on the research paper: Reflexion: Language Agents with Verbal Reinforcement Learning (Shinn et al., 2023).The agent consists of three specialized sub-agents:
Actor: Generates initial responses to tasks
Evaluator: Critically assesses responses against quality criteria
Reflector: Generates self-reflections to improve future responses
Evaluates the quality of a response to a task. Returns an evaluation string and a score between 0 and 1. The score is the last number after “final score” or “overall score” in the evaluation, divided by 10. If no such number is found, the score is 0.5.
Processes a single task through one iteration of the Reflexion process: it acts (or uses previous_response when given), evaluates, reflects, and stores the result in memory. Returns a dictionary with the keys task, response, evaluation, reflection, score and iteration.
result = agent.step(task: str, iteration: int = 0, previous_response: str = None) -> Dict[str, Any]
For each task, the first iteration acts, evaluates and reflects. Each later iteration refines the previous response with its evaluation and reflection, then evaluates and reflects again. The loop stops after max_loops iterations, or early once a score exceeds 0.9.run() returns one item per task. By default that item is the response with the highest score. With include_intermediates=True it is the list of step() dictionaries for every iteration. Each task and its best response are also added to agent.conversation.
run() takes a list of tasks, not a single string. Wrap a single task in a list.
from swarms import ReflexionAgentagent = ReflexionAgent( agent_name="reflexion-agent", model_name="gpt-5.4", max_loops=3)tasks = [ "Explain quantum computing to a beginner.", "Write a Python function to sort a list of dictionaries by a specific key."]results = agent.run(tasks)for i, result in enumerate(results): print(f"\nTask {i+1}: {tasks[i]}") print(f"Response: {result}")
The agent includes a ReflexionMemory system that maintains both short-term and long-term memories of past experiences, reflections, and feedback.
Short-term memory keeps the 10 most recent step() results.
Long-term memory receives a step’s result when its score is above 0.8 or it is the last iteration. It holds up to memory_capacity entries and drops the oldest first.
Deduplication skips a long-term entry when the words of its task and reflection have a Jaccard similarity above 0.8 with an existing entry.
Retrieval with agent.memory.get_relevant_memories(task, limit=5) ranks short-term and long-term entries by the words they share with the task.
act() adds the reflections from relevant_memories to the actor’s prompt. Inside run(), refinement works from the previous iteration’s evaluation and reflection rather than from retrieved memories.
Task Clarity: Provide clear, specific tasks to get the best results
Iteration Count: Adjust max_loops based on task complexity (more complex tasks benefit from more iterations)
Memory Management: Monitor memory usage and adjust memory_capacity as needed
Model Selection: Choose an appropriate model based on your specific use case
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/reflexion-agent","slug":"/agents/reflexion-agent","pageMetadata":{"title":"Reflexion Agent","description":"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory","icon":"rotate","href":"/agents/reflexion-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: \"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory\"\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={a:`a`,code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note,Table}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`ReflexionAgent`}),` implements the Reflexion framework to improve through self-reflection. It follows a process of acting on tasks, evaluating its performance, generating self-reflections, and using these reflections to improve future responses.`]}),`\n`,_jsxs(_components.p,{children:[`Based on the research paper: `,_jsx(_components.a,{href:`https://arxiv.org/abs/2303.11366`,children:`Reflexion: Language Agents with Verbal Reinforcement Learning`}),` (Shinn et al., 2023).`]}),`\n`,_jsx(_components.p,{children:`The agent consists of three specialized sub-agents:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Actor`}),`: Generates initial responses to tasks`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Evaluator`}),`: Critically assesses responses against quality criteria`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Reflector`}),`: Generates self-reflections to improve future responses`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,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:`\"reflexion-agent\"`})}),_jsxs(_components.td,{children:[`Name of the agent. The sub-agents are named `,_jsx(_components.code,{children:`\u003cagent_name>-actor`}),`, `,_jsx(_components.code,{children:`\u003cagent_name>-evaluator`}),` and `,_jsx(_components.code,{children:`\u003cagent_name>-reflector`})]})]}),_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:`REFLEXION_PROMPT`})}),_jsx(_components.td,{children:`System prompt for the actor. The evaluator and reflector use their own built-in prompts`})]}),_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:`\"openai/o1\"`})}),_jsx(_components.td,{children:`Model name for generating responses`})]}),_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:`3`})}),_jsx(_components.td,{children:`Maximum number of reflection iterations per task`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`memory_capacity`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`int`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`100`})}),_jsx(_components.td,{children:`Maximum capacity of long-term memory`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`methods`,children:`Methods`}),`\n`,_jsx(Heading,{level:`3`,id:`act`,children:`act`}),`\n`,_jsx(_components.p,{children:`Generates a response to the given task using the actor agent.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,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:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.act(task: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, relevant_memories: List[Dict[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, Any]] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#82071E`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#F44747`,\"--shiki-dark-font-style\":`inherit`},children:`->`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` str`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`evaluate`,children:`evaluate`}),`\n`,_jsx(_components.p,{children:`Evaluates the quality of a response to a task. Returns an evaluation string and a score between 0 and 1. The score is the last number after “final score” or “overall score” in the evaluation, divided by 10. If no such number is found, the score is 0.5.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,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:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`evaluation, score `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.evaluate(task: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, response: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#82071E`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#F44747`,\"--shiki-dark-font-style\":`inherit`},children:`->`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Tuple[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`float`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`reflect`,children:`reflect`}),`\n`,_jsx(_components.p,{children:`Generates a self-reflection based on the task, response, and evaluation.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,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:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`reflection `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.reflect(task: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, response: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, evaluation: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#82071E`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#F44747`,\"--shiki-dark-font-style\":`inherit`},children:`->`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` str`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`refine`,children:`refine`}),`\n`,_jsx(_components.p,{children:`Refines the original response based on evaluation and reflection.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,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:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`refined_response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.refine(task: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, original_response: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, evaluation: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, reflection: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#82071E`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#F44747`,\"--shiki-dark-font-style\":`inherit`},children:`->`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` str`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`step`,children:`step`}),`\n`,_jsxs(_components.p,{children:[`Processes a single task through one iteration of the Reflexion process: it acts (or uses `,_jsx(_components.code,{children:`previous_response`}),` when given), evaluates, reflects, and stores the result in memory. Returns a dictionary with the keys `,_jsx(_components.code,{children:`task`}),`, `,_jsx(_components.code,{children:`response`}),`, `,_jsx(_components.code,{children:`evaluation`}),`, `,_jsx(_components.code,{children:`reflection`}),`, `,_jsx(_components.code,{children:`score`}),` and `,_jsx(_components.code,{children:`iteration`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,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:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.step(task: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, iteration: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`int`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, previous_response: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`str`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#82071E`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#F44747`,\"--shiki-dark-font-style\":`inherit`},children:`->`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Dict[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, Any]`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`run`,children:`run`}),`\n`,_jsx(_components.p,{children:`Executes the full Reflexion process for a list of tasks, one task at a time.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,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:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`results `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.run(tasks: List[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], include_intermediates: `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#82071E`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#F44747`,\"--shiki-dark-font-style\":`inherit`},children:`->`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` List[Any]`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`For each task, the first iteration acts, evaluates and reflects. Each later iteration refines the previous response with its evaluation and reflection, then evaluates and reflects again. The loop stops after `,_jsx(_components.code,{children:`max_loops`}),` iterations, or early once a score exceeds 0.9.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`run()`}),` returns one item per task. By default that item is the response with the highest score. With `,_jsx(_components.code,{children:`include_intermediates=True`}),` it is the list of `,_jsx(_components.code,{children:`step()`}),` dictionaries for every iteration. Each task and its best response are also added to `,_jsx(_components.code,{children:`agent.conversation`}),`.`]}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`run()`}),` takes a list of tasks, not a single string. Wrap a single task in a list.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`example`,children:`Example`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`18`,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:`18`,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:` ReflexionAgent`})]}),`\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:` ReflexionAgent(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` agent_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"reflexion-agent\"`}),_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:` 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:`3`})]}),`\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:`tasks `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Explain quantum computing to a beginner.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Write a Python function to sort a list of dictionaries by a specific key.\"`})}),`\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:`results `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` agent.run(tasks)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` i, result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` enumerate`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(results):`})]}),`\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:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`Task `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`i`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`tasks[i]`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_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:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Response: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`result`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`memory-system`,children:`Memory System`}),`\n`,_jsxs(_components.p,{children:[`The agent includes a `,_jsx(_components.code,{children:`ReflexionMemory`}),` system that maintains both short-term and long-term memories of past experiences, reflections, and feedback.`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Short-term memory`}),` keeps the 10 most recent `,_jsx(_components.code,{children:`step()`}),` results.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Long-term memory`}),` receives a step’s result when its score is above 0.8 or it is the last iteration. It holds up to `,_jsx(_components.code,{children:`memory_capacity`}),` entries and drops the oldest first.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Deduplication`}),` skips a long-term entry when the words of its task and reflection have a Jaccard similarity above 0.8 with an existing entry.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Retrieval`}),` with `,_jsx(_components.code,{children:`agent.memory.get_relevant_memories(task, limit=5)`}),` ranks short-term and long-term entries by the words they share with the task.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`act()`}),` adds the reflections from `,_jsx(_components.code,{children:`relevant_memories`}),` to the actor’s prompt. Inside `,_jsx(_components.code,{children:`run()`}),`, refinement works from the previous iteration’s evaluation and reflection rather than from retrieved memories.`]}),`\n`,_jsx(Heading,{level:`2`,id:`best-practices`,children:`Best Practices`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Task Clarity`}),`: Provide clear, specific tasks to get the best results`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Iteration Count`}),`: Adjust `,_jsx(_components.code,{children:`max_loops`}),` based on task complexity (more complex tasks benefit from more iterations)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Memory Management`}),`: Monitor memory usage and adjust `,_jsx(_components.code,{children:`memory_capacity`}),` as needed`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Model Selection`}),`: Choose an appropriate model based on your specific use case`]}),`\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":"Reflexion Agent","description":"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory","icon":"rotate","href":"/agents/reflexion-agent"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Parameters","slug":"parameters","depth":2,"children":[]},{"title":"Methods","slug":"methods","depth":2,"children":[{"title":"act","slug":"act","depth":3,"children":[]},{"title":"evaluate","slug":"evaluate","depth":3,"children":[]},{"title":"reflect","slug":"reflect","depth":3,"children":[]},{"title":"refine","slug":"refine","depth":3,"children":[]},{"title":"step","slug":"step","depth":3,"children":[]},{"title":"run","slug":"run","depth":3,"children":[]}]},{"title":"Example","slug":"example","depth":2,"children":[]},{"title":"Memory System","slug":"memory-system","depth":2,"children":[]},{"title":"Best Practices","slug":"best-practices","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"kyegomez-swarms-97","siteName":"swarms","title":"Reflexion Agent - swarms","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-03T00:14:50.357Z","originalFileLocation":"agents/reflexion-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=\"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory\">\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=\"Reflexion Agent - swarms\">\u003cmeta data-mint-head property=\"og:description\" content=\"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"swarms\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.swarms.world/agents/reflexion-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=Reflexion+Agent\u0026amp;description=Self-reflective+agent+that+improves+through+iterative+acting%2C+evaluating%2C+and+reflecting+with+experience+memory\u0026amp;theme=5153e5700b995bc72eadb0da\u0026amp;signature=adaccd38cde023e79fa460967b533730901b4b9003ed18f982558393fdaab07a\">\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=\"Reflexion Agent - swarms\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://kyegomez-swarms-97.mintlify.app/_mintlify/api/og/v2?division=Reasoning+Agents\u0026amp;title=Reflexion+Agent\u0026amp;description=Self-reflective+agent+that+improves+through+iterative+acting%2C+evaluating%2C+and+reflecting+with+experience+memory\u0026amp;theme=5153e5700b995bc72eadb0da\u0026amp;signature=adaccd38cde023e79fa460967b533730901b4b9003ed18f982558393fdaab07a\">\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/reflexion-agent\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/agents/reflexion-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/reflexion-agent#webpage\",\"url\":\"https://docs.swarms.world/agents/reflexion-agent\",\"name\":\"Reflexion Agent\",\"description\":\"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory\",\"dateModified\":\"2026-10-03T00:14:50.357Z\",\"isPartOf\":{\"@id\":\"https://docs.swarms.world#website\"},\"breadcrumb\":{\"@id\":\"https://docs.swarms.world/agents/reflexion-agent#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.swarms.world/agents/reflexion-agent#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Reasoning Agents\",\"item\":\"https://docs.swarms.world/agents/reasoning-agents-overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reflexion Agent\",\"item\":\"https://docs.swarms.world/agents/reflexion-agent\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.swarms.world/agents/reflexion-agent#article\",\"headline\":\"Reflexion Agent\",\"name\":\"Reflexion Agent\",\"description\":\"Self-reflective agent that improves through iterative acting, evaluating, and reflecting with experience memory\",\"url\":\"https://docs.swarms.world/agents/reflexion-agent\",\"mainEntityOfPage\":{\"@id\":\"https://docs.swarms.world/agents/reflexion-agent#webpage\"},\"dateModified\":\"2026-10-03T00:14:50.357Z\",\"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","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)","description":"Knowledge-driven reasoning system that generates relevant information before answering queries through multi-perspective analysis","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":"Reflexion Agent - swarms","buildId":"dpl_DeHjVRGfFnhYQwHnfC2pjeXXv8h9","deploymentId":"dpl_DeHjVRGfFnhYQwHnfC2pjeXXv8h9","dynamics":[],"chunks":[]}