Group multi-step work into a single trace. Advanced, most apps don’t need this.
A trajectory is one OTel span that stays open across a multi-step turn. Subsequent bento.track_ai and tool_span calls in the same task become children of it, so the whole flow shows up as one trace instead of N independent rows.This is an advanced feature. For most apps, an integration or tracking events is enough. Trajectories matter when one trace must span multiple LLM calls and tool calls within a single logical turn.When bento.instrument() is active, spans the Google ADK integration captures share the trajectory’s trace_id. One with bento.begin(...) block stitches manual and integration spans into one trace.
The context-manager form auto-finishes on exit and records exceptions on the trajectory span.
import bentolabs_sdk.analytics as bentowith bento.begin( event="user_turn", user_id="u1", input="What's the weather in Paris?", model="claude-3-5-sonnet-20241022", provider="anthropic", convo_id="conv_abc",) as interaction: with interaction.tool_span(name="web_search", input={"q": "Paris"}) as ts: results = run_search("Paris") ts.set_output(results) bento.track_ai(event="thought", input="Composing reply...") interaction.update(output="It's 18C and partly cloudy in Paris.")
The imperative form is available for code that can’t use with:
Trajectories detach from any outer OTel context, the same as a bare track_ai. So they’re root spans in their own trace even when called inside a customer’s existing FastAPI / Django / etc. instrumented stack. track_ai calls inside a begin()/finish() block parent to the trajectory.
Trajectories must be finished in reverse open order (LIFO). Finishing an outer trajectory while an inner one is still open raises RuntimeError. Use with bento.begin(...) as i: to guarantee correct nesting.
Wraps a function in bento.begin() / interaction.finish(). The function name becomes the event name; the return value becomes output.value. It does not auto-capture arguments, which are often non-trivial to serialize and frequently contain sensitive data. To record them, call interaction.update(input=...) from inside the function, or use @bento.tool, which does capture.
Wraps a function in bento.tool_span(...). The function’s bound arguments become input.value (as a JSON dict), and the return value becomes output.value. The span carries openinference.span.kind="tool" so downstream classification picks it up. Set capture_input=False or capture_output=False for sensitive args or huge return payloads.
The module-level helper opens a tool span without threading an Interaction handle through code:
with bento.tool_span("web_search", input={"q": "..."}) as ts: result = run_search(...) ts.set_output(result)
Same parenting rule as track_ai: parents to the active trajectory if begin() is open in this task, else becomes a detached root. Exceptions raised inside the block are recorded on the span (status=ERROR, exception event) and re-raised.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Bento","description":"Production infrastructure for AI agents. Monitor what runs. Improve what fails. Compound learnings.","colors":{"primary":"#FF3C00","light":"#FF7A4D","dark":"#C23D0F"},"logo":{"light":"https://mintcdn.com/bentolabs-67c07c24/UR3oVTg-dFSkd4Qv/logo/light.svg?fit=max\u0026auto=format\u0026n=UR3oVTg-dFSkd4Qv\u0026q=85\u0026s=52d59445f69fca8e14170d9f18f24489","dark":"https://mintcdn.com/bentolabs-67c07c24/UR3oVTg-dFSkd4Qv/logo/dark.svg?fit=max\u0026auto=format\u0026n=UR3oVTg-dFSkd4Qv\u0026q=85\u0026s=cb9f386a99e01805f4d0b2e6afb4eee9","href":"https://bentolabs.ai"},"favicon":"https://mintcdn.com/bentolabs-67c07c24/UR3oVTg-dFSkd4Qv/favicon.svg?fit=max\u0026auto=format\u0026n=UR3oVTg-dFSkd4Qv\u0026q=85\u0026s=7af1b6c525f2fa0a76075cfae72bdf22","appearance":{"default":"dark"},"navbar":{"links":[{"icon":"clock-rotate-left","href":"/changelog","label":"Changelog"},{"icon":"github","href":"https://github.com/BentoLabs-ai","label":"GitHub"}],"primary":{"type":"button","label":"Dashboard","href":"https://platform.bentolabs.ai"}},"footer":{"socials":{"x":"https://x.com/bentolabsai","github":"https://github.com/BentoLabs-ai","linkedin":"https://www.linkedin.com/company/bentolabs-ai"},"links":[{"header":"Product","items":[{"label":"Dashboard","href":"https://platform.bentolabs.ai"},{"label":"Website","href":"https://bentolabs.ai"}]},{"header":"Developers","items":[{"label":"GitHub","href":"https://github.com/BentoLabs-ai"},{"label":"Python SDK","href":"/python/installation"},{"label":"TypeScript SDK","href":"/typescript"},{"label":"CLI","href":"/cli/installation"}]},{"header":"Company","items":[{"label":"Support","href":"mailto:support@bentolabs.ai"}]}]},"seo":{"metatags":{"title":"Bento Documentation","description":"Production infrastructure for AI agents. SDK docs, quickstart, and reference for the Bento platform.","keywords":"Bento, BentoLabs, AI agents, AI infrastructure, agent traces, agent monitoring, agent evaluations, signals, OpenTelemetry, Python SDK, gen_ai","author":"BentoLabs","og:type":"website","og:site_name":"Bento Docs","og:title":"Bento Documentation","og:description":"Production infrastructure for AI agents. Monitor what runs. Improve what fails. Compound learnings.","og:url":"https://docs.bentolabs.ai","og:locale":"en_US","twitter:card":"summary","twitter:site":"@bentolabsai","twitter:title":"Bento Documentation","twitter:description":"Production infrastructure for AI agents. SDK docs, quickstart, and reference for the Bento platform.","robots":"index, follow","googlebot":"index, follow"},"indexing":"navigable"},"fonts":{"heading":{"family":"Inter"},"body":{"family":"Inter"}},"contextual":{"options":["copy","view","assistant","claude","chatgpt","perplexity","add-mcp","mcp","cursor","vscode"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"bentolabs-67c07c24","hasAudioNarration":false,"actualSubdomain":"bentolabs-67c07c24","customDomains":["docs.bentolabs.ai"],"gitSource":{"type":"github","owner":"bentolabs-ai","repo":"docs","deployBranch":"main","isPrivate":false,"contentDirectory":"","mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a21dd80a5fe930653fc0085","collectionId":"df42cf17-99f6-410f-a873-850ed68eb3f1","schemaVersion":"v2"},"feedback":{"thumbs":true,"edits":false},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6a21dd80a5fe930653fc0085:success","clientVersion":"0.0.3971","searchFilterCounts":[{"language":"default","tag":"Get started","count":15},{"language":"default","tag":"CLI","count":13},{"language":"default","tag":"Python SDK","count":9},{"language":"default","tag":"Resources","count":8},{"language":"default","tag":"Concepts","count":5},{"language":"default","tag":"Advanced","count":4},{"language":"default","tag":"Overview","count":3},{"language":"default","tag":"Workspace \u0026 sources","count":2},{"language":"default","tag":"Migrations","count":2},{"language":"default","tag":"Manual tracking","count":2}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"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":"editor-v7-file-tree","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":"pause-universal-search-reconcile","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":"per-site-search-delta","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":"editor-private-page-search","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":"editor-nav-generations","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":"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":"editor-agent-model-picker","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":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"isAtlas":false,"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"python/trajectories","slug":"/python/trajectories","pageMetadata":{"title":"Trajectories","description":"Group multi-step work into a single trace. Advanced, most apps don't need this.","icon":"diagram-project","href":"/python/trajectories"},"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: \"Group multi-step work into a single trace. Advanced, most apps don’t need this.\"\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`,em:`em`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`A `,_jsx(_components.strong,{children:`trajectory`}),` is one OTel span that stays open across a multi-step turn. Subsequent `,_jsx(_components.code,{children:`bento.track_ai`}),` and `,_jsx(_components.code,{children:`tool_span`}),` calls in the same task become children of it, so the whole flow shows up as one trace instead of N independent rows.`]}),`\n`,_jsxs(_components.p,{children:[`This is an advanced feature. For most apps, an `,_jsx(_components.a,{href:`/python/integrations`,children:`integration`}),` or `,_jsx(_components.a,{href:`/python/track-ai`,children:`tracking events`}),` is enough. Trajectories matter when one trace must span multiple LLM calls and tool calls within a single logical turn.`]}),`\n`,_jsxs(_components.p,{children:[`When `,_jsx(_components.a,{href:`/python/integrations`,children:_jsx(_components.code,{children:`bento.instrument()`})}),` is active, spans the Google ADK integration captures share the trajectory’s `,_jsx(_components.code,{children:`trace_id`}),`. One `,_jsx(_components.code,{children:`with bento.begin(...)`}),` block stitches manual and integration spans into one trace.`]}),`\n`,_jsx(Heading,{level:`2`,id:`bento-begin`,children:`bento.begin()`}),`\n`,_jsx(_components.p,{children:`The context-manager form auto-finishes on exit and records exceptions on the trajectory span.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`17`,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:`17`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bentolabs_sdk.analytics `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bento`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bento.begin(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` event`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user_turn\"`}),_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:` user_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"u1\"`}),_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:` input`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"What's the weather in Paris?\"`}),_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`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"claude-3-5-sonnet-20241022\"`}),_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:` provider`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"anthropic\"`}),_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:` convo_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"conv_abc\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` interaction:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` interaction.tool_span(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"web_search\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_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:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"q\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Paris\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ts:`})]}),`\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:` run_search(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Paris\"`}),_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:` ts.set_output(results)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bento.track_ai(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"thought\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_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:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Composing reply...\"`}),_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:` interaction.update(`}),_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:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"It's 18C and partly cloudy in Paris.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The imperative form is available for code that can’t use `,_jsx(_components.code,{children:`with`}),`:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,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:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`interaction `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bento.begin(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user_turn\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`user_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"u1\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_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:`#0A3069`,\"--shiki-dark\":`#CE9178`},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:`# do work, optionally call interaction.update(...) mid-flight`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`interaction.finish(`}),_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:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`parenting-and-isolation`,children:`Parenting and isolation`}),`\n`,_jsxs(_components.p,{children:[`Trajectories detach from any outer OTel context, the same as a bare `,_jsx(_components.code,{children:`track_ai`}),`. So they’re root spans in their own trace even when called inside a customer’s existing FastAPI / Django / etc. instrumented stack. `,_jsx(_components.code,{children:`track_ai`}),` calls `,_jsx(_components.em,{children:`inside`}),` a `,_jsx(_components.code,{children:`begin()/finish()`}),` block parent to the trajectory.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Trajectories must be finished in reverse open order (LIFO). Finishing an outer trajectory while an inner one is still open raises `,_jsx(_components.code,{children:`RuntimeError`}),`. Use `,_jsx(_components.code,{children:`with bento.begin(...) as i:`}),` to guarantee correct nesting.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`decorators`,children:`Decorators`}),`\n`,_jsx(_components.p,{children:`Both decorators wrap function-shaped work, and both work on sync and async functions.`}),`\n`,_jsx(Heading,{level:`3`,id:`@bento-interaction`,children:`@bento.interaction`}),`\n`,_jsxs(_components.p,{children:[`Wraps a function in `,_jsx(_components.code,{children:`bento.begin()`}),` / `,_jsx(_components.code,{children:`interaction.finish()`}),`. The function name becomes the event name; the return value becomes `,_jsx(_components.code,{children:`output.value`}),`. It does `,_jsx(_components.strong,{children:`not`}),` auto-capture arguments, which are often non-trivial to serialize and frequently contain sensitive data. To record them, call `,_jsx(_components.code,{children:`interaction.update(input=...)`}),` from inside the function, or use `,_jsx(_components.code,{children:`@bento.tool`}),`, which does capture.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,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:`7`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@bento.interaction`})}),`\n`,_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:` handle_message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`msg`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_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:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\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:` reply`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@bento.interaction`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`event`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user_turn\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`capture_output`}),_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:`)`})]}),`\n`,_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:` handle_message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`msg`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_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:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` ...`})}),`\n`]})})}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Option`}),_jsx(_components.th,{children:`Default`}),_jsx(_components.th,{children:`Effect`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`event`})}),_jsx(_components.td,{children:`function name`}),_jsx(_components.td,{children:`Override the event name.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`capture_output`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`True`})}),_jsxs(_components.td,{children:[`Set the return value as `,_jsx(_components.code,{children:`output.value`}),`. JSON-serialized if not a string.`]})]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`@bento-tool`,children:`@bento.tool`}),`\n`,_jsxs(_components.p,{children:[`Wraps a function in `,_jsx(_components.code,{children:`bento.tool_span(...)`}),`. The function’s bound arguments become `,_jsx(_components.code,{children:`input.value`}),` (as a JSON dict), and the return value becomes `,_jsx(_components.code,{children:`output.value`}),`. The span carries `,_jsx(_components.code,{children:`openinference.span.kind=\"tool\"`}),` so downstream classification picks it up. Set `,_jsx(_components.code,{children:`capture_input=False`}),` or `,_jsx(_components.code,{children:`capture_output=False`}),` for sensitive args or huge return payloads.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,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:`7`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@bento.tool`})}),`\n`,_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:` web_search`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_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:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`limit`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`int`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 10`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> list[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]:`})]}),`\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:` [`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},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:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@bento.tool`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"search\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`capture_input`}),_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:`)`})]}),`\n`,_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:` web_search`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> list[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` ...`})}),`\n`]})})}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Option`}),_jsx(_components.th,{children:`Default`}),_jsx(_components.th,{children:`Effect`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`name`})}),_jsx(_components.td,{children:`function name`}),_jsx(_components.td,{children:`Override the span name.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`capture_input`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`True`})}),_jsxs(_components.td,{children:[`Capture bound arguments as `,_jsx(_components.code,{children:`input.value`}),`. `,_jsx(_components.code,{children:`self`}),`/`,_jsx(_components.code,{children:`cls`}),` are dropped.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`capture_output`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`True`})}),_jsxs(_components.td,{children:[`Set the return value as `,_jsx(_components.code,{children:`output.value`}),`.`]})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`tool-spans`,children:`Tool spans`}),`\n`,_jsxs(_components.p,{children:[`The module-level helper opens a tool span without threading an `,_jsx(_components.code,{children:`Interaction`}),` handle through code:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,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:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bento.tool_span(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"web_search\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_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:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"q\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ts:`})]}),`\n`,_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:` run_search(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:`...`}),_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:` ts.set_output(result)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Same parenting rule as `,_jsx(_components.code,{children:`track_ai`}),`: parents to the active trajectory if `,_jsx(_components.code,{children:`begin()`}),` is open in this task, else becomes a detached root. Exceptions raised inside the block are recorded on the span (status=ERROR, exception event) and re-raised.`]}),`\n`,_jsx(Heading,{level:`3`,id:`toolspan-api`,children:`ToolSpan API`}),`\n`,_jsxs(_components.p,{children:[`A `,_jsx(_components.code,{children:`ToolSpan`}),` carries two methods:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Method`}),_jsx(_components.th,{children:`Purpose`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ts.set_output(value)`})}),_jsxs(_components.td,{children:[`Write to `,_jsx(_components.code,{children:`output.value`}),`. Strings pass through; dicts/lists are JSON-serialized.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`ts.set_attribute(key, value)`})}),_jsx(_components.td,{children:`Escape hatch for arbitrary OTel attributes.`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`interaction-api`,children:`Interaction API`}),`\n`,_jsxs(_components.p,{children:[`An `,_jsx(_components.code,{children:`Interaction`}),` is the handle `,_jsx(_components.code,{children:`begin()`}),` returns:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Method`}),_jsx(_components.th,{children:`Purpose`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`interaction.update(input=..., output=..., properties=...)`})}),_jsx(_components.td,{children:`Patch attributes on the open trajectory before finish.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`interaction.finish(output=..., properties=...)`})}),_jsx(_components.td,{children:`End the trajectory span. Idempotent.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`interaction.tool_span(name, input=..., properties=...)`})}),_jsx(_components.td,{children:`Open a child tool span under this trajectory.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`interaction.event_id`})}),_jsx(_components.td,{children:`The trajectory’s span ID (16-hex string).`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`interaction.convo_id`})}),_jsxs(_components.td,{children:[`The conversation ID passed to `,_jsx(_components.code,{children:`begin()`}),`.`]})]})]})]})]})}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":"Trajectories","description":"Group multi-step work into a single trace. Advanced, most apps don't need this.","icon":"diagram-project","href":"/python/trajectories"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"bento.begin()","slug":"bento-begin","depth":2,"children":[{"title":"Parenting and isolation","slug":"parenting-and-isolation","depth":3,"children":[]}]},{"title":"Decorators","slug":"decorators","depth":2,"children":[{"title":"@bento.interaction","slug":"@bento-interaction","depth":3,"children":[]},{"title":"@bento.tool","slug":"@bento-tool","depth":3,"children":[]}]},{"title":"Tool spans","slug":"tool-spans","depth":2,"children":[{"title":"ToolSpan API","slug":"toolspan-api","depth":3,"children":[]}]},{"title":"Interaction API","slug":"interaction-api","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"bentolabs-67c07c24","siteName":"Bento","title":"Bento Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-05-30T01:44:30.922Z","originalFileLocation":"python/trajectories.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=\"dark\"}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=\"Group multi-step work into a single trace. Advanced, most apps don\u0026#x27;t need this.\">\u003cmeta data-mint-head name=\"keywords\" content=\"Bento, BentoLabs, AI agents, AI infrastructure, agent traces, agent monitoring, agent evaluations, signals, OpenTelemetry, Python SDK, gen_ai\">\u003cmeta data-mint-head name=\"application-name\" content=\"Bento\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003cmeta data-mint-head name=\"robots\" content=\"index, follow\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Bento Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"Production infrastructure for AI agents. Monitor what runs. Improve what fails. Compound learnings.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Bento Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.bentolabs.ai/python/trajectories\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://bentolabs-67c07c24.mintlify.app/_mintlify/api/og/v2?division=Advanced\u0026amp;title=Trajectories\u0026amp;description=Group+multi-step+work+into+a+single+trace.+Advanced%2C+most+apps+don%27t+need+this.\u0026amp;theme=7e776a1e7779628f30b79d1e\u0026amp;signature=4ca63e5362df387cdfad3f67e0174fc4fb2696486f6d7da3880f5ece77ad2445\">\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=\"Bento Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Production infrastructure for AI agents. SDK docs, quickstart, and reference for the Bento platform.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://bentolabs-67c07c24.mintlify.app/_mintlify/api/og/v2?division=Advanced\u0026amp;title=Trajectories\u0026amp;description=Group+multi-step+work+into+a+single+trace.+Advanced%2C+most+apps+don%27t+need+this.\u0026amp;theme=7e776a1e7779628f30b79d1e\u0026amp;signature=4ca63e5362df387cdfad3f67e0174fc4fb2696486f6d7da3880f5ece77ad2445\">\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/bentolabs-67c07c24/5y0pyf96-lCjMzMa/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Bento\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#FF3C00\">\u003cmeta data-mint-head name=\"og:locale\" content=\"en_US\">\u003cmeta data-mint-head name=\"author\" content=\"BentoLabs\">\u003cmeta data-mint-head name=\"googlebot\" content=\"index, follow\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.bentolabs.ai/python/trajectories\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/python/trajectories.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.bentolabs.ai/#organization\",\"name\":\"Bento\",\"url\":\"https://docs.bentolabs.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/bentolabs-67c07c24/UR3oVTg-dFSkd4Qv/logo/light.svg?fit=max\u0026auto=format\u0026n=UR3oVTg-dFSkd4Qv\u0026q=85\u0026s=52d59445f69fca8e14170d9f18f24489\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.bentolabs.ai#website\",\"name\":\"Bento\",\"url\":\"https://docs.bentolabs.ai\",\"publisher\":{\"@id\":\"https://docs.bentolabs.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.bentolabs.ai/python/trajectories#webpage\",\"url\":\"https://docs.bentolabs.ai/python/trajectories\",\"name\":\"Trajectories\",\"description\":\"Group multi-step work into a single trace. Advanced, most apps don't need this.\",\"dateModified\":\"2026-05-30T01:44:30.922Z\",\"isPartOf\":{\"@id\":\"https://docs.bentolabs.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.bentolabs.ai/python/trajectories#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.bentolabs.ai/python/trajectories#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Bento\",\"item\":\"https://docs.bentolabs.ai\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Trajectories\",\"item\":\"https://docs.bentolabs.ai/python/trajectories\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.bentolabs.ai/python/trajectories#article\",\"headline\":\"Trajectories\",\"name\":\"Trajectories\",\"description\":\"Group multi-step work into a single trace. Advanced, most apps don't need this.\",\"url\":\"https://docs.bentolabs.ai/python/trajectories\",\"mainEntityOfPage\":{\"@id\":\"https://docs.bentolabs.ai/python/trajectories#webpage\"},\"dateModified\":\"2026-05-30T01:44:30.922Z\",\"publisher\":{\"@id\":\"https://docs.bentolabs.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.bentolabs.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Bento\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Bento","nav":{"global":null,"tabs":[{"tab":"Get started","icon":"rocket","pages":[{"title":"Get started","href":""}]},{"tab":"Python SDK","icon":"python","groups":[{"group":"Get started","icon":"rocket","pages":[{"title":"Installation","icon":"download","href":"/python/installation"},{"title":"Configuration","icon":"gear","href":"/python/configuration"}]},{"group":"Integrations","icon":"plug","pages":[{"title":"Google ADK","icon":"google","href":"/python/integrations"}]},{"group":"Manual tracking","icon":"paper-plane","pages":[{"title":"Tracking events","icon":"code","href":"/python/track-ai"},{"title":"Properties","description":"Pass arbitrary custom dimensions through to span attributes.","icon":"sliders","href":"/python/properties"}]},{"group":"Advanced","icon":"screwdriver-wrench","pages":[{"title":"Trajectories","icon":"diagram-project","href":"/python/trajectories"},{"title":"Identity helpers","description":"Late-bind user_id, session_id, and tags onto open spans, or scope them per-task. Advanced.","icon":"user-tag","href":"/python/identity"},{"title":"OTel transport","icon":"cube","href":"/python/otel-transport"},{"title":"Threading model","icon":"microchip","href":"/python/threading-model"}]}]},{"tab":"TypeScript SDK","icon":"js","pages":[{"title":"TypeScript SDK","href":"/typescript"}]},{"tab":"CLI","icon":"terminal","pages":[{"title":"CLI","href":"/cli/overview"}]}]},"title":"Bento Documentation","buildId":"dpl_DFJrtvUi8HS5F9nkooKuDJsuD5BM","deploymentId":"dpl_DFJrtvUi8HS5F9nkooKuDJsuD5BM","dynamics":[],"chunks":[]}