Skip to main content
Create a Custom Code tool for calculations and data processing that do not need network access. The Python input and output models become the tool contract the agent sees.

Prerequisites

  • Permission to manage organization tools.
  • A deterministic Python task that can run without an internet connection.
  • Vault secrets for any sensitive values the code needs.
1

Create the draft

Go to Global Tools, choose New tool, then select Custom Code. Enter a precise tool name and Instructions. Instructions maps to the API description field.
The New tool page with Custom Code highlighted

Select Custom Code from the New tool page

2

Define typed input and output

Define a Pydantic Input model, an Output model, and a synchronous handler(input: Input) -> Output function. Add field descriptions so the model knows which values to supply.Return the declared output model. Keep logs useful for testing, but return the data the agent needs from the handler.
3

Add dependencies and secrets

List each dependency as an exact version such as pydantic==2.11.7. Packages with URLs, environment markers, or extras are rejected.Declare Vault secret names separately from the source. Do not place secret values in code or logs. The environment exposes only the declared secrets.
Expand Metadata, select the Vault secrets the tool can access, and enter the pinned packages in Dependencies.
The Custom Code metadata panel with the Dependencies field highlighted

Configure Vault secrets and Python dependencies

4

Build the tool

Save the draft, then choose Build tool.
The Custom Code editor with Build tool highlighted

Build the tool after defining its code and metadata

The build installs the pinned dependencies, imports the declared modules, and derives the argument schema from the Pydantic models.
5

Test and publish

Run representative input, check the structured output and logs, then publish. You must have a valid schema, available secrets and dependencies, and a successful run for the current draft.
6

Attach the published version

Attach the version to an agent and verify it in a test call. See Attach a tool to an agent.

Environment limits

Custom Code runs in an isolated environment with no internet access. Use an API Request tool or MCP server for network calls. Avoid unbounded loops, large payloads, and large output objects. A run that exceeds its time or data limit returns a failure instead of partial output. Code tools can run on call start, first user message, and tool success or failure. They cannot run on call end. See Run a tool on call events.