Function tool
What shipped
A function you've written can now be attached to an agent as a tool, the same way a workflow is. The agent calls it by name, passes the inputs the function declares, and reads back whatever the function returns. There's no separate tool record to create: the function's description tells the agent when to use it, and its input schema is the tool's inputs.
Who it's for
Developers who need a small piece of custom logic, such as a calculation, a lookup, or a reshaping of data, that's simpler to write as code than to build as a workflow.
How to use
- Write the function, and give it a description and its inputs. A function with no description isn't offered to agents, because the agent has nothing to decide with.
- Attach the function to an agent from the agent's tools.
- In a conversation, the agent calls it when the description matches what the user needs.
Calls are checked against the function's inputs before the function runs. A missing required input, a value of the wrong type, or an input the function doesn't declare is refused, and the agent is told why.
Global variables
A function reads and writes global variables with variables.global.get([...]) and variables.global.set({...}).
- They only work when agentic flows (shared memory) are enabled for the agent. Otherwise
variables.global.getreturnsundefinedfor every name andvariables.global.sethas no effect. This is intended: functions follow the same rule as workflows. - Write variable names as literals, for example
variables.global.get(["tier", "locale"])orvariables.global.set({ lastOrderId: id }). The names a function uses are detected when you save it, and only those are sent when it runs. A name held in a variable, as invariables.global.get([name]), isn't detected, so it comes backundefined. - Writes are applied only when the function finishes without throwing. If it throws, none of its writes are kept.
Related
- PR: #5046
- Related docs: Workflow tool