Wrap your own functions with wrapTool so tool executions are captured as events.
Whether an LLM wrapper captures tool executions automatically depends on the integration — see the Tool calls section on the OpenAI, Anthropic, and Vercel AI SDK pages. For tools your own code invokes directly, wrap the function with wrapTool — every execution is then captured as a tool event with input, output, duration, and status.
The wrapped function accepts one optional trailing argument carrying Carbon metadata. It is detected by the presence of a traceId, context, or additionalProperties key and is not passed to your run function:
This puts the tool event on the same trace as the LLM calls around it — see Traces.
Detection is by key presence only. If your tool’s real last argument has a
traceId, context, or additionalProperties key, it would be treated as
Carbon metadata — rename the field or wrap the value in an object.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Carbon","description":"Carbon turns every LLM and tool call into a queryable ledger — sliced by agent, model, user, and thread.","colors":{"primary":"#615fff","light":"#7c86ff","dark":"#615fff"},"logo":{"light":"https://mintcdn.com/carbon-7a946712/7iD67IuKn_mtLDOT/public/logo/light.svg?fit=max\u0026auto=format\u0026n=7iD67IuKn_mtLDOT\u0026q=85\u0026s=dd616325bfec99addef1bfcfd182e6ae","dark":"https://mintcdn.com/carbon-7a946712/7iD67IuKn_mtLDOT/public/logo/dark.svg?fit=max\u0026auto=format\u0026n=7iD67IuKn_mtLDOT\u0026q=85\u0026s=8b2c23a76e8a02b8e5fb1ae5a2ad1d83","href":"https://oncarbon.site"},"favicon":"https://mintcdn.com/carbon-7a946712/-j2qt70BSHGAC0et/favicon.ico?fit=max\u0026auto=format\u0026n=-j2qt70BSHGAC0et\u0026q=85\u0026s=86c93a6fc7610e7fa9532ec1a9cb191e","api":{"mdx":{"auth":{"method":"bearer"},"server":"https://ingest.oncarbon.site"}},"background":{"color":{"light":"#ffffff","dark":"#171717"}},"navbar":{"primary":{"type":"button","label":"Dashboard","href":"https://oncarbon.site/app"}},"footer":{"socials":{"website":"https://oncarbon.site"}},"fonts":{"family":"Be Vietnam Pro"},"icons":{"library":"lucide"},"contextual":{"options":["copy","view","claude","chatgpt"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"carbon-7a946712","hasAudioNarration":false,"actualSubdomain":"carbon-7a946712","customDomains":["docs.oncarbon.site"],"gitSource":{"type":"github","owner":"beepbop-labs","repo":"carbon-v1","deployBranch":"main","contentDirectory":"core/apps/docs/src","isPrivate":true,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6ae959aeb9c52538cea79e86:success","clientVersion":"0.0.4111","searchFilterCounts":[{"language":"default","tag":"Documentation","count":26},{"language":"default","tag":"Dashboard","count":7},{"language":"default","tag":"SDK","count":6},{"language":"default","tag":"Integrations","count":5},{"language":"default","tag":"@carbon-js/connect","count":4},{"language":"default","tag":"API Reference","count":3},{"language":"default","tag":"Concepts","count":2},{"language":"default","tag":"Get started","count":2},{"language":"default","tag":"Endpoints","count":1},{"language":"default","tag":"Overview","count":1}]},"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":"custom-rbac-roles","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":"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":"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":"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":"editor-metadata","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},{"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}],"googleFontsInlined":true},"customCss":[{"filePath":"custom.css","content":"#sidebar svg[style*=\"mask-image\"],ul.sidebar-group svg[style*=\"mask-image\"]{background-color:currentColor!important}img[src*=\"/public/icons/\"]{background-color:currentColor!important;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center;-webkit-mask-size:contain;mask-size:contain;object-fit:none;object-position:-9999px -9999px}img[src$=\"/public/icons/openai.svg\"]{-webkit-mask-image:url(\"/public/icons/openai.svg\");mask-image:url(\"/public/icons/openai.svg\")}img[src$=\"/public/icons/anthropic.svg\"]{-webkit-mask-image:url(\"/public/icons/anthropic.svg\");mask-image:url(\"/public/icons/anthropic.svg\")}img[src$=\"/public/icons/vercel.svg\"]{-webkit-mask-image:url(\"/public/icons/vercel.svg\");mask-image:url(\"/public/icons/vercel.svg\")}img[src$=\"/public/icons/claude.svg\"]{-webkit-mask-image:url(\"/public/icons/claude.svg\");mask-image:url(\"/public/icons/claude.svg\")}img[src$=\"/public/icons/codex.svg\"]{-webkit-mask-image:url(\"/public/icons/codex.svg\");mask-image:url(\"/public/icons/codex.svg\")}"}],"page":{"pagePath":"documentation/sdk/tool-calls","slug":"/documentation/sdk/tool-calls","pageMetadata":{"title":"Tool calls","description":"Wrap your own functions with wrapTool so tool executions are captured as events.","icon":"wrench","href":"/documentation/sdk/tool-calls"},"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: \"Wrap your own functions with wrapTool so tool executions are captured as events.\"\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`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Whether an LLM wrapper captures tool executions automatically depends on the integration — see the Tool calls section on the `,_jsx(_components.a,{href:`/documentation/integrations/openai#tool-calls`,children:`OpenAI`}),`, `,_jsx(_components.a,{href:`/documentation/integrations/anthropic#tool-calls`,children:`Anthropic`}),`, and `,_jsx(_components.a,{href:`/documentation/integrations/vercel-ai-sdk#tool-calls`,children:`Vercel AI SDK`}),` pages. For tools your own code invokes directly, wrap the function with `,_jsx(_components.code,{children:`wrapTool`}),` — every execution is then captured as a tool event with input, output, duration, and status.`]}),`\n`,_jsx(Heading,{level:`2`,id:`wrap-a-function`,children:`Wrap a function`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`typescript`,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:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`13`,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:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`Carbon`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@carbon-js/sdk\"`}),_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:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` carbon`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Carbon`}),_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:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` getWeather`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` carbon`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`wrapTool`}),_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\":`#9CDCFE`},children:` name:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"get_weather\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` run`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`:`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ({ `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`city`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`}),_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:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`city`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` string`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_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:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` fetch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`https://api.weather.example/v1/\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`city`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--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:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,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:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` weather`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` getWeather`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`city:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Tokyo\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The wrapped function has the same signature and return type as `,_jsx(_components.code,{children:`run`}),`. Sync and async functions both work.`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`On success, the event records the serialized input and output with `,_jsx(_components.code,{children:`status.state: \"ok\"`}),`.`]}),`\n`,_jsxs(_components.li,{children:[`On failure, the event records the error with `,_jsx(_components.code,{children:`status.state: \"error\"`}),` and the original error is rethrown — wrapping never swallows exceptions.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`attach-metadata`,children:`Attach metadata`}),`\n`,_jsxs(_components.p,{children:[`The wrapped function accepts one optional trailing argument carrying Carbon metadata. It is detected by the presence of a `,_jsx(_components.code,{children:`traceId`}),`, `,_jsx(_components.code,{children:`context`}),`, or `,_jsx(_components.code,{children:`additionalProperties`}),` key and is not passed to your `,_jsx(_components.code,{children:`run`}),` function:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`typescript`,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:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` traceId`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` carbon`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`createTraceId`}),_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:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` weather`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` getWeather`}),_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:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`city:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Tokyo\"`}),_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:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`traceId`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`context:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`agentId:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"travel-agent\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`userId:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"user-481\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } },`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`This puts the tool event on the same trace as the LLM calls around it — see `,_jsx(_components.a,{href:`/documentation/sdk/traces`,children:`Traces`}),`.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Detection is by key presence only. If your tool’s real last argument has a\n`,_jsx(_components.code,{children:`traceId`}),`, `,_jsx(_components.code,{children:`context`}),`, or `,_jsx(_components.code,{children:`additionalProperties`}),` key, it would be treated as\nCarbon metadata — rename the field or wrap the value in an object.`]})})]})}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":"Tool calls","description":"Wrap your own functions with wrapTool so tool executions are captured as events.","icon":"wrench","href":"/documentation/sdk/tool-calls"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Wrap a function","slug":"wrap-a-function","depth":2,"children":[]},{"title":"Attach metadata","slug":"attach-metadata","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"carbon-7a946712","siteName":"Carbon","title":"Tool calls - Carbon","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-06-17T02:09:07.301Z","originalFileLocation":"documentation/sdk/tool-calls.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=\"Wrap your own functions with wrapTool so tool executions are captured as events.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Carbon\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/carbon-7a946712/wXCLDvcvLaGT1c9O/_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/carbon-7a946712/wXCLDvcvLaGT1c9O/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/carbon-7a946712/wXCLDvcvLaGT1c9O/_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/carbon-7a946712/wXCLDvcvLaGT1c9O/_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/carbon-7a946712/wXCLDvcvLaGT1c9O/_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/carbon-7a946712/wXCLDvcvLaGT1c9O/_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/carbon-7a946712/wXCLDvcvLaGT1c9O/_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/carbon-7a946712/wXCLDvcvLaGT1c9O/_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/carbon-7a946712/wXCLDvcvLaGT1c9O/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Tool calls - Carbon\">\u003cmeta data-mint-head property=\"og:description\" content=\"Wrap your own functions with wrapTool so tool executions are captured as events.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Carbon\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.oncarbon.site/documentation/sdk/tool-calls\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://carbon-7a946712.mintlify.site/_mintlify/api/og/v2?division=SDK\u0026amp;title=Tool+calls\u0026amp;description=Wrap+your+own+functions+with+wrapTool+so+tool+executions+are+captured+as+events.\u0026amp;theme=e43adf45b1d878dd970f2bff\u0026amp;signature=5870a3414235a5ff64963a9de37664a81adb013cd0c4ea1fa426e5a31e320f58\">\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=\"Tool calls - Carbon\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Wrap your own functions with wrapTool so tool executions are captured as events.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://carbon-7a946712.mintlify.site/_mintlify/api/og/v2?division=SDK\u0026amp;title=Tool+calls\u0026amp;description=Wrap+your+own+functions+with+wrapTool+so+tool+executions+are+captured+as+events.\u0026amp;theme=e43adf45b1d878dd970f2bff\u0026amp;signature=5870a3414235a5ff64963a9de37664a81adb013cd0c4ea1fa426e5a31e320f58\">\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/carbon-7a946712/wXCLDvcvLaGT1c9O/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Carbon\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#615fff\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.oncarbon.site/documentation/sdk/tool-calls\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/documentation/sdk/tool-calls.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.oncarbon.site/#organization\",\"name\":\"Carbon\",\"url\":\"https://docs.oncarbon.site\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/carbon-7a946712/7iD67IuKn_mtLDOT/public/logo/light.svg?fit=max\u0026auto=format\u0026n=7iD67IuKn_mtLDOT\u0026q=85\u0026s=dd616325bfec99addef1bfcfd182e6ae\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.oncarbon.site#website\",\"name\":\"Carbon\",\"url\":\"https://docs.oncarbon.site\",\"publisher\":{\"@id\":\"https://docs.oncarbon.site/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls#webpage\",\"url\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls\",\"name\":\"Tool calls\",\"description\":\"Wrap your own functions with wrapTool so tool executions are captured as events.\",\"dateModified\":\"2026-06-17T02:09:07.301Z\",\"isPartOf\":{\"@id\":\"https://docs.oncarbon.site#website\"},\"breadcrumb\":{\"@id\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SDK\",\"item\":\"https://docs.oncarbon.site/documentation/sdk/configuration\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tool calls\",\"item\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls#article\",\"headline\":\"Tool calls\",\"name\":\"Tool calls\",\"description\":\"Wrap your own functions with wrapTool so tool executions are captured as events.\",\"url\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls\",\"mainEntityOfPage\":{\"@id\":\"https://docs.oncarbon.site/documentation/sdk/tool-calls#webpage\"},\"dateModified\":\"2026-06-17T02:09:07.301Z\",\"publisher\":{\"@id\":\"https://docs.oncarbon.site/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.oncarbon.site#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Carbon\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Carbon\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/documentation/sdk/tool-calls.md","siteName":"Carbon","nav":{"global":null,"tabs":[{"tab":"Documentation","icon":"book-open","groups":[{"group":"Get started","pages":[{"title":"What is Carbon?","icon":"house","href":"/documentation/get-started"},{"title":"Quickstart","icon":"rocket","href":"/documentation/get-started/quickstart"}]},{"group":"Integrations","pages":[{"title":"OpenAI","icon":"https://mintlify.s3.us-west-1.amazonaws.com/carbon-7a946712/public/icons/openai.svg","href":"/documentation/integrations/openai"},{"title":"Anthropic","icon":"https://mintlify.s3.us-west-1.amazonaws.com/carbon-7a946712/public/icons/anthropic.svg","href":"/documentation/integrations/anthropic"},{"title":"Vercel AI SDK","icon":"https://mintlify.s3.us-west-1.amazonaws.com/carbon-7a946712/public/icons/vercel.svg","href":"/documentation/integrations/vercel-ai-sdk"},{"title":"Claude Code","icon":"https://mintlify.s3.us-west-1.amazonaws.com/carbon-7a946712/public/icons/claude.svg","href":"/documentation/integrations/claude-code"},{"title":"Codex","icon":"https://mintlify.s3.us-west-1.amazonaws.com/carbon-7a946712/public/icons/codex.svg","href":"/documentation/integrations/codex"}]},{"group":"SDK","pages":[{"title":"Configuration","icon":"settings","href":"/documentation/sdk/configuration"},{"title":"Serverless","icon":"cloud","href":"/documentation/sdk/serverless"},{"title":"Context","icon":"tag","href":"/documentation/sdk/context"},{"title":"Traces","description":"Correlate the events of one logical operation with a shared trace ID.","icon":"route","href":"/documentation/sdk/traces"},{"title":"Tool calls","icon":"wrench","href":"/documentation/sdk/tool-calls"},{"title":"Manual capture","description":"Build and capture canonical events directly when wrappers don't fit your stack.","icon":"pencil","href":"/documentation/sdk/manual-capture"}]},{"group":"@carbon-js/connect","pages":[{"title":"CLI","icon":"terminal","href":"/documentation/connect/commands"},{"title":"API keys","icon":"key","href":"/documentation/connect/api-keys"},{"title":"How it works","icon":"settings","href":"/documentation/connect/how-it-works"},{"title":"Privacy","icon":"shield-check","href":"/documentation/connect/privacy"}]},{"group":"Concepts","pages":[{"title":"The event model","icon":"database","href":"/documentation/concepts/events"},{"title":"Delivery guarantees","icon":"shield-check","href":"/documentation/concepts/delivery"}]},{"group":"Dashboard","pages":[{"title":"Analytics pages","icon":"chart-line","href":"/documentation/dashboard/analytics"},{"title":"Alerts","icon":"bell","href":"/documentation/dashboard/alerts"},{"title":"Dashboards","icon":"layout-dashboard","href":"/documentation/dashboard/dashboards"},{"title":"Pivots","icon":"table","href":"/documentation/dashboard/pivots"},{"title":"SQL","icon":"code","href":"/documentation/dashboard/sql"},{"title":"API keys","icon":"key","href":"/documentation/dashboard/api-keys"},{"title":"Plans and limits","icon":"credit-card","href":"/documentation/dashboard/plans"}]}]},{"tab":"API Reference","icon":"square-terminal","pages":[{"title":"API Reference","href":"/api-reference/overview/introduction"}]}]},"basePath":"","title":"Tool calls - Carbon","buildId":"dpl_DqYu5MPb49gWBBbUGgpHQUmCHY3P","deploymentId":"dpl_DqYu5MPb49gWBBbUGgpHQUmCHY3P","dynamics":[],"chunks":[]}