You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 25, 2026. It is now read-only.
Repository navigation
Commit f8e58bf
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: content/Guides/agent-data-handling.mdx
+20-29Lines changed: 20 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,9 @@ title: Agent Data Handling
3
3
description: How to handle data formats in your agents
4
4
---
5
5
6
-
7
6
We provide a few different ways to handle data formats in your agents to make it easier to work with different data types. Of course, your agent can always perform its own data handling by use the raw data and the content type property. However, most common data types are supported out of the box.
8
7
9
-
###How it works
8
+
## How it works
10
9
11
10
Data that is sent to your agent is transferred as raw binary data and the content type is provided to the agent. The agent can then use the content type to determine how to handle the data. The `AgentRequest` object provides a `data` property that contains the `Data` object. The `Data` object provides a `contentType` property that contains the content type of the data. The `Data` object also provides a number of helper methods to help you handle the data.
The following request data formats are supported out of the box:
57
55
58
-
####Text
56
+
### Text
59
57
60
58
You use use the `text` method on the `Data` object to get the raw text data.
61
59
@@ -77,7 +75,7 @@ You must await the `text` method to get the raw text data since the data could b
77
75
78
76
In the case the data is another content type that isn't text, the `text` method will return the raw data as a string. For example, if the content type is `application/json`, the `text` method will return the raw JSON data as a string.
79
77
80
-
####JSON
78
+
### JSON
81
79
82
80
You can use the `json` method on the `Data` object to get the raw JSON data.
83
81
@@ -99,7 +97,7 @@ You must await the `json` method to get the raw JSON data since the data could b
99
97
100
98
In the case the data is another content type that isn't JSON, the `json` method will attempt to parse the data as JSON. If the data is not valid JSON, the `json` method will throw an error.
101
99
102
-
####Object
100
+
### Object
103
101
104
102
You can use the `object` method on the `Data` object to get the JSON data as an object cast to the type you provide. This currently only works for JSON data and the JavaScript SDK.
105
103
@@ -113,8 +111,7 @@ export default async function Agent(
You must await the `base64` method to get the base64 encoded string.
186
182
187
-
####Email
183
+
### Email
188
184
189
185
If you want to get the raw binary data as an email object, you can use the `email` method on the `Data` object. This assumes that the request payload was an RFC822 encoded email.
190
186
191
-
192
187
<CodeExamplejs={`import type { AgentContext, AgentRequest, AgentResponse } from '@agentuity/sdk';
193
188
194
189
export default async function Agent(
@@ -227,12 +222,10 @@ The `Attachment` object has the following properties:
227
222
-`contentDisposition`: The content disposition of the attachment which is either `inline` or `attachment`. Defaults to `attachment`.
228
223
-`data`: The `DataType` of the attachment.
229
224
230
-
## Sending Email Replies
225
+
####Sending Email Replies
231
226
232
227
Both SDKs support sending replies to incoming emails using the `sendReply` method. This requires the email-auth-token to be present in the request metadata.
233
228
234
-
### JavaScript SDK
235
-
236
229
<CodeExamplejs={`import type { AgentContext, AgentRequest, AgentResponse } from '@agentuity/sdk';
Using a custom email address in the reply requires organizational email domain setup. Please contact us if you would like to configure for your organization.
296
289
</Callout>
297
290
298
-
### Large Attachment Support
291
+
####Large Attachment Support
299
292
300
293
Both SDKs now support large email attachments through streaming mechanisms:
301
294
302
295
-**Incoming attachments**: Use the `data()` method which returns a Promise/async Data object that streams the content
303
296
-**Outgoing attachments**: Can handle large files efficiently through the attachment data handling
304
297
-**OpenTelemetry tracing**: Automatic tracing is included for attachment operations to monitor performance
305
298
306
-
307
-
### Response Data Formats
299
+
## Response Data Formats
308
300
309
301
The following response data formats are supported out of the box. Use these methods on the `AgentResponse` object to send data in the desired format from your agent.
310
302
311
-
####Text
303
+
### Text
312
304
313
305
You can use the `text` method to send a plain text response.
The SDK provides helpers for common media types. Use the corresponding method for the type you want to return (e.g., `png`, `jpeg`, `pdf`, `mp3`, etc.).
return response.html("<h1>Hello, world!</h1><p>This is an HTML response.</p>")
424
416
`} />
425
417
426
-
####Streaming
418
+
### Streaming
427
419
428
420
For large or real-time responses, you can stream data using the `stream` method. The source can be an async iterator, a stream, or another agent's stream.
0 commit comments