Use a decorator or middleware to intercept inputs and outputs. This keeps your core “Agent Brain” code clean of infrastructure logic.
3. The Callback (Enterprise)
For complex agents like LangGraph or CrewAI, use callbacks to sync state after every node execution. This provides granular “Replayability” for every internal step of the agent.
{"docsConfig":{"$schema":"https://mintlify.com/docs.json","theme":"mint","name":"StateBase","colors":{"primary":"#2563EB","light":"#38BDF8","dark":"#0A0A0A"},"favicon":"https://mintcdn.com/statebase/cGnRcDKbxmT6bcz3/favicon.svg?fit=max\u0026auto=format\u0026n=cGnRcDKbxmT6bcz3\u0026q=85\u0026s=c2721f1aa3c5b81f7d0d340dcb0fcf66","logo":{"light":"https://mintcdn.com/statebase/cGnRcDKbxmT6bcz3/logo/light.svg?fit=max\u0026auto=format\u0026n=cGnRcDKbxmT6bcz3\u0026q=85\u0026s=49f0885ea60b083c2850f2329201383d","dark":"https://mintcdn.com/statebase/cGnRcDKbxmT6bcz3/logo/dark.svg?fit=max\u0026auto=format\u0026n=cGnRcDKbxmT6bcz3\u0026q=85\u0026s=c8c93b54cc47aa06e6f5999a079a0a01"},"background":{"decoration":null,"color":{"light":"#FFFFFF","dark":"#0A0A0A"}},"navbar":{"links":[{"label":"Dashboard","href":"https://app.statebase.org"},{"label":"Status","href":"https://status.statebase.org"}],"primary":{"type":"button","label":"Get Started","href":"https://app.statebase.org/signup"}},"search":{"prompt":"Search StateBase docs..."},"footer":{"socials":{"x":"https://x.com/statebase_ai","github":"https://github.com/StateBase","linkedin":"https://linkedin.com/company/statebase","discord":"https://discord.gg/statebase"}},"integrations":{"ga4":{"measurementId":"G-B7N0ZJYV5R"},"posthog":{"apiKey":"phc_mwpUk3r7dDsVAqjs1ogSt1jwPhlGcOG3cDz4mcJViwt"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"statebase","hasAudioNarration":false,"actualSubdomain":"statebase","customDomains":["docs.statebase.org"],"gitSource":{"type":"github","owner":"statebase","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":"","_id":"6b10d06e9ffae5051c40af7c"},"entitlements":{},"buildId":"6ae946829198b3764e82559a:success","clientVersion":"0.0.4448","searchFilterCounts":[{"language":"default","tag":"Documentation","count":85},{"language":"default","tag":"API Reference","count":6},{"language":"default","tag":"Core Concepts","count":6},{"language":"default","tag":"Integrations","count":6},{"language":"default","tag":"Agent Patterns","count":6},{"language":"default","tag":"Production Playbook","count":4},{"language":"default","tag":"SDKs","count":4},{"language":"default","tag":"Security \u0026 Compliance","count":4},{"language":"default","tag":"Live Demos","count":3},{"language":"default","tag":"Getting Started","count":3}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":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":"rbac-expansion","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":"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":"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":"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":"turbopuffer-dual-write","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":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"auth-vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"googleFontsInlined":false},"customCss":[]}
{"page":{"pagePath":"sdks/patterns","slug":"/sdks/patterns","pageMetadata":{"title":"SDK Design Patterns","description":"How to structure your code for maximum reliability.","href":"/sdks/patterns"},"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: \"How to structure your code for maximum reliability.\"\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`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock,Heading}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`The StateBase SDK is designed to be injected into your existing agent loop. Here are the three most common ways to integrate.`}),`\n`,_jsx(Heading,{level:`2`,id:`1-the-wrapper-easiest`,children:`1. The Wrapper (Easiest)`}),`\n`,_jsx(_components.p,{children:`Wrap your entire LLM call in a helper function that automatically handles context and turn logging.`}),`\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\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` ask_agent`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`session_id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`user_query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # 1. Get context`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` context `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sb.sessions.get_context(session_id, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`query`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`user_query)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # 2. Call LLM`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` answer `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` call_llm(context, user_query)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # 3. Log turn`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sb.sessions.add_turn(session_id, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`input`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`user_query, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`output`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`answer)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` answer`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`2-the-middleware-recommended`,children:`2. The Middleware (Recommended)`}),`\n`,_jsx(_components.p,{children:`Use a decorator or middleware to intercept inputs and outputs. This keeps your core “Agent Brain” code clean of infrastructure logic.`}),`\n`,_jsx(Heading,{level:`2`,id:`3-the-callback-enterprise`,children:`3. The Callback (Enterprise)`}),`\n`,_jsx(_components.p,{children:`For complex agents like LangGraph or CrewAI, use callbacks to sync state after every node execution. This provides granular “Replayability” for every internal step of the agent.`})]})}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":"SDK Design Patterns","description":"How to structure your code for maximum reliability.","href":"/sdks/patterns"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"1. The Wrapper (Easiest)","slug":"1-the-wrapper-easiest","depth":2,"children":[]},{"title":"2. The Middleware (Recommended)","slug":"2-the-middleware-recommended","depth":2,"children":[]},{"title":"3. The Callback (Enterprise)","slug":"3-the-callback-enterprise","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"statebase","siteName":"StateBase","title":"SDK Design Patterns - StateBase","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-01-30T19:05:39.203Z","originalFileLocation":"sdks/patterns.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=\"How to structure your code for maximum reliability.\">\u003cmeta data-mint-head name=\"application-name\" content=\"StateBase\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/statebase/QR0K8cPaNeiBCHC4/_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/statebase/QR0K8cPaNeiBCHC4/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/statebase/QR0K8cPaNeiBCHC4/_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/statebase/QR0K8cPaNeiBCHC4/_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/statebase/QR0K8cPaNeiBCHC4/_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/statebase/QR0K8cPaNeiBCHC4/_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/statebase/QR0K8cPaNeiBCHC4/_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/statebase/QR0K8cPaNeiBCHC4/_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/statebase/QR0K8cPaNeiBCHC4/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"SDK Design Patterns - StateBase\">\u003cmeta data-mint-head property=\"og:description\" content=\"How to structure your code for maximum reliability.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"StateBase\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.statebase.org/sdks/patterns\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://statebase.mintlify.site/_mintlify/api/og/v2?division=SDKs\u0026amp;title=SDK+Design+Patterns\u0026amp;description=How+to+structure+your+code+for+maximum+reliability.\u0026amp;theme=0f3b5ef9b1eae3f62aa9a5c9\u0026amp;signature=dada12c12b50e1704a3a212a863174a31917c4e930b4637de40c32ee0d29cf3e\">\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=\"SDK Design Patterns - StateBase\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"How to structure your code for maximum reliability.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://statebase.mintlify.site/_mintlify/api/og/v2?division=SDKs\u0026amp;title=SDK+Design+Patterns\u0026amp;description=How+to+structure+your+code+for+maximum+reliability.\u0026amp;theme=0f3b5ef9b1eae3f62aa9a5c9\u0026amp;signature=dada12c12b50e1704a3a212a863174a31917c4e930b4637de40c32ee0d29cf3e\">\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/statebase/QR0K8cPaNeiBCHC4/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"StateBase\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#2563EB\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.statebase.org/sdks/patterns\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/sdks/patterns.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.statebase.org/#organization\",\"name\":\"StateBase\",\"url\":\"https://docs.statebase.org\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/statebase/cGnRcDKbxmT6bcz3/logo/light.svg?fit=max\u0026auto=format\u0026n=cGnRcDKbxmT6bcz3\u0026q=85\u0026s=49f0885ea60b083c2850f2329201383d\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.statebase.org#website\",\"name\":\"StateBase\",\"url\":\"https://docs.statebase.org\",\"publisher\":{\"@id\":\"https://docs.statebase.org/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.statebase.org/sdks/patterns#webpage\",\"url\":\"https://docs.statebase.org/sdks/patterns\",\"name\":\"SDK Design Patterns\",\"description\":\"How to structure your code for maximum reliability.\",\"dateModified\":\"2026-01-30T19:05:39.203Z\",\"isPartOf\":{\"@id\":\"https://docs.statebase.org#website\"},\"breadcrumb\":{\"@id\":\"https://docs.statebase.org/sdks/patterns#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.statebase.org/sdks/patterns#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SDKs\",\"item\":\"https://docs.statebase.org/sdks/python\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SDK Design Patterns\",\"item\":\"https://docs.statebase.org/sdks/patterns\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.statebase.org/sdks/patterns#article\",\"headline\":\"SDK Design Patterns\",\"name\":\"SDK Design Patterns\",\"description\":\"How to structure your code for maximum reliability.\",\"url\":\"https://docs.statebase.org/sdks/patterns\",\"mainEntityOfPage\":{\"@id\":\"https://docs.statebase.org/sdks/patterns#webpage\"},\"dateModified\":\"2026-01-30T19:05:39.203Z\",\"publisher\":{\"@id\":\"https://docs.statebase.org/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.statebase.org#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"StateBase\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"StateBase\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/sdks/patterns.md","siteName":"StateBase","nav":{"global":null,"anchors":[{"anchor":"Documentation","icon":"book-open","tabs":[{"tab":"Documentation","groups":[{"group":"Getting Started","pages":[{"title":"When to use StateBase","href":"/start-here/when-to-use"},{"title":"Quickstart","href":"/quickstart"},{"title":"Copy-Paste Agent Example","href":"/start-here/copy-paste-example"}]},{"group":"Core Concepts","pages":[{"title":"The StateBase Mental Model","href":"/concepts/mental-models"},{"title":"What is State? (vs. Memory)","href":"/concepts/what-is-state"},{"title":"Sessions, Turns \u0026 Memory","href":"/concepts/sessions-turns-memory"},{"title":"Checkpoints \u0026 Rollbacks","href":"/concepts/checkpoints-rollbacks"},{"title":"Replay \u0026 Audit","href":"/concepts/replay-audit"},{"title":"Agent Failure Modes","href":"/concepts/failure-modes"}]},{"group":"Live Demos","pages":[{"title":"Agent Hallucination Recovery","href":"/demos/hallucination-recovery"},{"title":"Debugging with Replay","href":"/demos/debugging-replay"},{"title":"Multi-Tool Recovery Demo","href":"/demos/multi-tool-recovery"}]},{"group":"API Reference","pages":[{"title":"Sessions API","api":"POST https://api.statebase.org/v1/sessions","href":"/api-reference/sessions"},{"title":"Turns API","api":"POST https://api.statebase.org/v1/sessions/{session_id}/turns","href":"/api-reference/turns"},{"title":"Memory API","api":"POST https://api.statebase.org/v1/memory","href":"/api-reference/memory"},{"title":"Traces API","api":"GET https://api.statebase.org/v1/traces","href":"/api-reference/traces"}]},{"group":"Agent Patterns","pages":[{"title":"RAG Agents Pattern","href":"/patterns/rag-agents"},{"title":"Agentic RAG","href":"/patterns/agentic-rag"},{"title":"Human-in-the-Loop Pattern","href":"/patterns/human-in-the-loop"},{"title":"Long-Running Agent Pattern","href":"/patterns/long-running"},{"title":"Multi-Agent Pattern","href":"/patterns/multi-agent"}]},{"group":"Integrations","pages":[{"title":"OpenAI Integration","href":"/integrations/openai"},{"title":"Anthropic","href":"/integrations/anthropic"},{"title":"LangChain Integration","href":"/integrations/langchain"},{"title":"LangGraph Integration","href":"/integrations/langgraph"},{"title":"Vercel AI SDK","href":"/integrations/vercel-ai-sdk"},{"title":"MCP Integration","href":"/integrations/mcp"}]},{"group":"SDKs","pages":[{"title":"Python SDK","href":"/sdks/python"},{"title":"TypeScript SDK","description":"Official Node.js Client","href":"/sdks/typescript"},{"title":"SDK Design Patterns","href":"/sdks/patterns"},{"title":"Error Handling","description":"Manage API errors, retries, and timeouts across all StateBase SDKs","href":"/sdks/error-handling"}]},{"group":"Production Playbook","pages":[{"title":"When to Checkpoint","href":"/playbook/when-to-checkpoint"},{"title":"Rollback Strategies","href":"/playbook/rollback-strategies"},{"title":"Cost vs. Safety","href":"/playbook/cost-vs-safety"},{"title":"Incident Recovery","href":"/playbook/incident-recovery"}]},{"group":"Security \u0026 Compliance","pages":[{"title":"Data Handling","href":"/security/data-handling"},{"title":"Isolation Model","href":"/security/isolation-model"},{"title":"Reliability Guarantees","href":"/security/reliability-guarantees"},{"title":"Self Hosting","href":"/security/self-hosting"}]},{"group":"Templates \u0026 Examples","pages":[{"title":"Starter Agent","href":"/templates/starter-agent"},{"title":"Production Agent","href":"/templates/production-agent"},{"title":"Failure Injection","href":"/templates/failure-injection"}]}]},{"tab":"Docs","pages":[{"title":"Docs","href":"/introduction"}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api-reference/introduction"}]},{"tab":"Guides","pages":[{"title":"Guides","href":"/patterns/tool-calling"}]}]},{"anchor":"GitHub","href":"https://github.com/StateBase","icon":"github"},{"anchor":"Discord","href":"https://discord.gg/statebase","icon":"discord"}]},"basePath":"","title":"SDK Design Patterns - StateBase","deploymentId":"dpl_XLevHnGPjzxq9mbREha5Faad63Sp","buildId":"dpl_XLevHnGPjzxq9mbREha5Faad63Sp","dynamics":[],"chunks":[]}