Messages are how your application and an agent exchange information inside a task. This page covers sending messages, the different kinds of incoming messages, and how to handle them.Documentation Index
Fetch the complete documentation index at: https://relevanceai.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Send a message
Both agents and workforces usesendMessage. It accepts a string and returns a Task representing the conversation thread.
Continue a conversation
To send a follow-up message within the same conversation, pass the existing task as the second argument:File attachments
Attach files by passing an array ofFile objects as the second argument. The SDK handles the upload.
fileName and fileUrl fields) can be mixed in with File objects in the same array.
Workforce tasks don’t support file attachments. Only agent tasks accept files.
Handle incoming messages
Messages arrive through the"message" event on a task. Each event’s detail includes a message property. Use the type guard methods to determine the kind and access the right fields.
Agent responses
Whenmessage.isAgent() returns true, the message is an AgentMessage carrying the agent’s response text.
Tool executions
Whenmessage.isTool() returns true, the message is a ToolMessage representing a tool or subagent execution inside the agent’s pipeline.
status field tracks where the tool is in its lifecycle:
| Status | Meaning |
|---|---|
pending | Scheduled, not yet started |
running | Currently executing |
completed | Finished successfully |
error | Failed with an error |
cancelled | Execution was cancelled |
Read tool output
Once a tool completes, its output is available:Detect subagents
A tool message may represent a subagent rather than a standalone tool. UseisSubAgent to check, and subAgentTaskId to access the subagent’s task:
Tool errors
Check for errors on a tool message withhasErrors:
User messages
User messages represent input sent by the application or end user. They show up in the message history alongside agent responses.isTrigger returns true for the first message in a conversation — the one that created the task:
Error handling
Agent errors are delivered through the"error" event on the task. The event detail contains an AgentErrorMessage with one or more error strings.
"error" or "action" status depending on the nature of the failure. See Tasks for status details.
Workforce messages
Workforce tasks include two additional message types for multi-agent coordination:WorkforceAgentMessage— an agent within the workforce is executing a subtask. Includes details about which agent is running and the state of its work.WorkforceAgentHandoverMessage— work is being delegated from one agent to another within the workforce. Includes the trigger message and details about the receiving agent.
Streaming messages
Two message types represent real-time incremental output from the agent:ThinkingMessage— the agent’s intermediate reasoning as it processes.TypingMessage— the agent’s response text as it’s being generated.
isThinking and isTyping type guards shown above. For streaming behavior and live typing indicators, see Streaming.
