DurableAgent, we typically model tools as steps. These can range from simple function calls to entire multi-day workflows.
Basic Tool Definition
Tools inDurableAgent follow the same structure as AI SDK tools:
workflows/chat/steps/tools.ts
"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
messages: The full conversation asLanguageModelV2PrompttoolCallId: Unique identifier for this tool invocationexperimental_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
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:| Capability | Step-Level ("use step") | Workflow-Level ("use workflow") |
|---|---|---|
getWritable() | ✅ | ❌ |
| Automatic retries | ✅ | ❌ |
| Side-effects (API calls) | ✅ | ❌ |
sleep() | ❌ | ✅ |
createWebhook() | ❌ | ✅ |
defineHook().create() | ❌ | ✅ |
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
Tool Result Types
Tools can return different types of results:lineNumbers
Related Documentation
- Streaming Updates from Tools - Progress updates during execution
- Sleep and Delays - Using
sleep()in tools - Workflows and Steps - Core concepts
getWritable()API Reference - Stream API details