Skip to main content
This page covers common patterns for defining tools in AI agents using Workflow DevKit. With DurableAgent, we typically model tools as steps. These can range from simple function calls to entire multi-day workflows.

Basic Tool Definition

Tools in DurableAgent follow the same structure as AI SDK tools:
workflows/chat/steps/tools.ts
The key difference from standard AI SDK tools is the "use step" directive, which makes the tool execution durable with automatic retries.

Accessing Message Context

Tools receive the full conversation context as a second argument:
workflows/chat/steps/tools.ts
The context object provides:
  • messages: The full conversation as LanguageModelV2Prompt
  • toolCallId: Unique identifier for this tool invocation
  • experimental_context: Custom context passed to the agent

Writing to Streams

As discussed in Streaming Updates from Tools, tools can write custom data to the stream for progress updates:
workflows/chat/steps/tools.ts
Create a reusable helper for stream writing:
workflows/chat/utils/stream.ts

Step-Level vs Workflow-Level Tools

Tools can be implemented at either the step level or workflow level, with different capabilities:

Step-Level Tools

Best for I/O operations that need automatic retries:
lineNumbers

Workflow-Level Tools

Best for orchestration that needs workflow primitives:
lineNumbers

Hybrid Tools

Combine both approaches for complex tools:
lineNumbers

Complex Tool Patterns

Multi-Step Tools

Break complex operations into multiple steps:
lineNumbers

Conditional Tools

Implement conditional logic at the workflow level:
lineNumbers

Error Handling

Tools can throw errors that are automatically retried (for steps) or returned to the agent:
lineNumbers
Learn more in Errors and Retries.

Tool Result Types

Tools can return different types of results:
lineNumbers