name: shift description: Agent Tools and Float Actions Best Practices
Agent Tools (packages/frontend/src/agent/tools)
Tools
- Use
ToolResulttype from@/agent/types. - Return
ToolResult.ok({ message, ...data })orToolResult.err(message, detail?). ToolResult.ok()requires amessagefield plus additional value data (e.g.,before,after).- Use
ToolResult.schema(valueSchema)to define output schemas. - The
outputpassed todisplayfunctions is the unwrappedvaluefromToolResult.ok.
Display Objects
- Every agent tool MUST export a
displayobject alongside the tool. - The
displayobject must satisfyToolDisplay<TInput, TOutput>from@/agent/types. - Signature:
streaming: ({ input, output }) => MessageResultsuccess: ({ input, output }) => MessageResulterror: ({ input, output }) => string
MessageResultis an array of parts:[{ text: "Received ", muted: false }, { text: "200 OK", muted: true }].- Register the
displayexport inpackages/frontend/src/components/agent/ChatContent/ChatMessage/Assistant/Tool/messages.ts.
Float Actions (packages/frontend/src/float/actions)
- Use
ActionResulttype from@/float/types. - Return
ActionResult.ok(message)orActionResult.err(message, detail?). - Use
ActionResult.schemaas the output schema (no arguments needed). - Get SDK via
const { sdk } = experimental_context as FloatToolContext.
User-Facing Messages
- Keep all user-facing messages brief and concise.
- Error messages should be clear but short (e.g., "No HTTP request loaded" not "The HTTP request object was not found in the current context").
- Success messages should be brief and actionable (e.g.,
Method set to "POST"notSuccessfully updated the HTTP method of the current request to POST).
Null and Undefined Checks
- Use
isPresentutility from@/utilswhen checking for null or undefined values. - Prefer
isPresent(value)overvalue !== undefined && value !== nullor similar checks.
ts-http-forge
- Use this library if you are working with requests
- HttpForge can modify request and read data from it like path, query, headers etc.
Code Structure
- Keep tool implementations focused and single-purpose.
- Extract complex logic into helper functions when needed, but prefer inline expressions for simple operations.
- Use descriptive parameter names in input schemas with
.describe()for better AI understanding. - If there's a util for it, use it.