Skip to content
This repository was archived by the owner on Mar 25, 2026. It is now read-only.

Commit f8e58bf

Browse files
authored
Update agent-data-handling.mdx
Signed-off-by: Matthew Congrove <mcongrove@agentuity.com>
1 parent d6c0ddf commit f8e58bf

1 file changed

Lines changed: 20 additions & 29 deletions

File tree

‎content/Guides/agent-data-handling.mdx‎

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ title: Agent Data Handling
33
description: How to handle data formats in your agents
44
---
55

6-
76
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.
87

9-
### How it works
8+
## How it works
109

1110
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.
1211

@@ -50,12 +49,11 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
5049
pass
5150
`} />
5251

53-
54-
### Request Data Formats
52+
## Request Data Formats
5553

5654
The following request data formats are supported out of the box:
5755

58-
#### Text
56+
### Text
5957

6058
You use use the `text` method on the `Data` object to get the raw text data.
6159

@@ -77,7 +75,7 @@ You must await the `text` method to get the raw text data since the data could b
7775

7876
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.
7977

80-
#### JSON
78+
### JSON
8179

8280
You can use the `json` method on the `Data` object to get the raw JSON data.
8381

@@ -99,7 +97,7 @@ You must await the `json` method to get the raw JSON data since the data could b
9997

10098
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.
10199

102-
#### Object
100+
### Object
103101

104102
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.
105103

@@ -113,8 +111,7 @@ export default async function Agent(
113111
const obj = await req.data.object<{ name: string }>();
114112
}`} />
115113

116-
117-
#### Binary
114+
### Binary
118115

119116
If you want to get the raw binary data, you can use the `binary` method on the `Data` object.
120117

@@ -136,7 +133,7 @@ You must await the `binary` method to get the raw binary data since the data cou
136133

137134
For JavaScript, the `binary` method returns a `Uint8Array` object. For Python, the `binary` method returns a `bytes` object.
138135

139-
#### Stream
136+
### Stream
140137

141138
If you want to get the raw binary data as a stream, you can use the `stream` method on the `Data` object.
142139

@@ -163,8 +160,7 @@ You must await the `stream` method to get a stream of the raw binary data. The
163160

164161
See the [Streaming](/Guides/agent-streaming) guide for more information on how Agent Streaming works.
165162

166-
167-
#### Base64
163+
### Base64
168164

169165
If you want to get the raw binary data as a base64 encoded string, you can use the `base64` method on the `Data` object.
170166

@@ -184,11 +180,10 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
184180

185181
You must await the `base64` method to get the base64 encoded string.
186182

187-
#### Email
183+
### Email
188184

189185
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.
190186

191-
192187
<CodeExample js={`import type { AgentContext, AgentRequest, AgentResponse } from '@agentuity/sdk';
193188
194189
export default async function Agent(
@@ -227,12 +222,10 @@ The `Attachment` object has the following properties:
227222
- `contentDisposition`: The content disposition of the attachment which is either `inline` or `attachment`. Defaults to `attachment`.
228223
- `data`: The `DataType` of the attachment.
229224

230-
## Sending Email Replies
225+
#### Sending Email Replies
231226

232227
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.
233228

234-
### JavaScript SDK
235-
236229
<CodeExample js={`import type { AgentContext, AgentRequest, AgentResponse } from '@agentuity/sdk';
237230
238231
export default async function Agent(
@@ -295,20 +288,19 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
295288
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.
296289
</Callout>
297290

298-
### Large Attachment Support
291+
#### Large Attachment Support
299292

300293
Both SDKs now support large email attachments through streaming mechanisms:
301294

302295
- **Incoming attachments**: Use the `data()` method which returns a Promise/async Data object that streams the content
303296
- **Outgoing attachments**: Can handle large files efficiently through the attachment data handling
304297
- **OpenTelemetry tracing**: Automatic tracing is included for attachment operations to monitor performance
305298

306-
307-
### Response Data Formats
299+
## Response Data Formats
308300

309301
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.
310302

311-
#### Text
303+
### Text
312304

313305
You can use the `text` method to send a plain text response.
314306

@@ -326,7 +318,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
326318
return response.text("Hello, world!")
327319
`} />
328320

329-
#### JSON
321+
### JSON
330322

331323
You can use the `json` method to send a JSON response.
332324

@@ -347,7 +339,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
347339
})
348340
`} />
349341

350-
#### Binary
342+
### Binary
351343

352344
You can use the `binary` method to send raw binary data.
353345

@@ -367,7 +359,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
367359
return response.binary(binary_data)
368360
`} />
369361

370-
#### Media Types (Images, Audio, Video, PDF, etc.)
362+
### Media Types (Images, Audio, Video, PDF, etc.)
371363

372364
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.).
373365

@@ -387,7 +379,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
387379
return response.png(image_data)
388380
`} />
389381

390-
#### Markdown
382+
### Markdown
391383

392384
You can use the `markdown` method to return markdown content.
393385

@@ -405,7 +397,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
405397
return response.markdown("# Hello, world!\\nThis is a markdown response.")
406398
`} />
407399

408-
#### HTML
400+
### HTML
409401

410402
You can use the `html` method to return HTML content.
411403

@@ -423,7 +415,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
423415
return response.html("<h1>Hello, world!</h1><p>This is an HTML response.</p>")
424416
`} />
425417

426-
#### Streaming
418+
### Streaming
427419

428420
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.
429421

@@ -458,8 +450,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
458450
return response.stream(chat_completion, lambda chunk: chunk.choices[0].delta.content)
459451
`} />
460452

461-
462-
#### Custom Response
453+
### Custom Response
463454

464455
For advanced use cases, you can return a native Response object from your agent.
465456

0 commit comments

Comments
 (0)