Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions content/SDKs/python/api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ from agentuity import AgentRequest, AgentResponse, AgentContext
async def handler(request: AgentRequest, response: AgentResponse, context: AgentContext):
try:
# Get the request data
data = request.data.json
data = await request.data.json()
name = data.get("name")

# Log the request
Expand Down Expand Up @@ -265,7 +265,7 @@ Retrieves a value from the key-value storage.

##### Return Value

Returns a DataResult object that has an `exists` property to check if the value exists and a `data` property with accessors like `data.json` and `data.text`.
Returns a DataResult object that has an `exists` property to check if the value exists and a `data` property with async accessors like `data.json()` and `data.text()`.

##### Example

Expand All @@ -277,11 +277,11 @@ try:
value = await context.kv.get("user-preferences", "user-123")
if value.exists:
# Access data using the appropriate accessor
user_prefs = value.data.json
user_prefs = await value.data.json()
context.logger.info(f"User preferences: {user_prefs}")

# Or access as text if needed
# text_data = value.data.text
# text_data = await value.data.text()
# context.logger.info(f"User preferences (text): {text_data}")
else:
context.logger.info("User preferences not found, using defaults")
Expand Down Expand Up @@ -946,7 +946,7 @@ Returns the request payload as a dictionary.
##### Example

```python
data = request.data.json
data = await request.data.json()
print(f"Request data: {data}")
```

Expand Down
10 changes: 5 additions & 5 deletions content/SDKs/python/core-concepts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from agentuity import AgentRequest, AgentResponse, AgentContext
# Agent handler function
async def handler(request: AgentRequest, response: AgentResponse, context: AgentContext):
# Process the request
data = request.data.json
data = await request.data.json()

# Use the context (logging, storage, etc.)
context.logger.info('Processing request', data)
Expand All @@ -49,10 +49,10 @@ Requests contain information about the trigger event and payload data. The `Agen
- `request.get(key, defval)` - Get a value from the request metadata
- `request.data` - Get a Data object from the request
- `request.data.contentType` - The content type (or mime type) of the request
- `request.data.text` - Get the payload as a string
- `request.data.json` - Get the payload as a JSON object
- `request.data.binary` - Get the payload as a binary object
- `request.data.base64` - Get the payload as a base64 encoded string
- `request.data.text()` - Get the payload as a string (async)
- `request.data.json()` - Get the payload as a JSON object (async)
- `request.data.binary()` - Get the payload as a binary object (async)
- `request.data.base64()` - Get the payload as a base64 encoded string (async)

### Responses

Expand Down
14 changes: 7 additions & 7 deletions content/SDKs/python/examples/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ from datetime import datetime

async def run(request: AgentRequest, response: AgentResponse, context: AgentContext):
# Get the request data
data = request.data.json
data = await request.data.json()
name = data.get("name", "Guest")

# Log the request
Expand All @@ -35,7 +35,7 @@ from agentuity import AgentRequest, AgentResponse, AgentContext
import json

async def run(request: AgentRequest, response: AgentResponse, context: AgentContext):
data = request.data.json
data = await request.data.json()
action = data.get("action")
user_id = data.get("userId")
preferences = data.get("preferences")
Expand All @@ -48,7 +48,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
return response.json({"message": "No preferences found"})

# Access the data
user_prefs = result.data.json
user_prefs = await result.data.json()

return response.json({"preferences": user_prefs})

Expand Down Expand Up @@ -147,7 +147,7 @@ An agent that uses vector storage for semantic search.
from agentuity import AgentRequest, AgentResponse, AgentContext

async def run(request: AgentRequest, response: AgentResponse, context: AgentContext):
data = request.data.json
data = await request.data.json()
action = data.get("action")
query = data.get("query")
products = data.get("products")
Expand Down Expand Up @@ -239,7 +239,7 @@ from agentuity import AgentRequest, AgentResponse, AgentContext
from datetime import datetime

async def run(request: AgentRequest, response: AgentResponse, context: AgentContext):
data = request.data.json
data = await request.data.json()
action = data.get("action")
message = data.get("message")
agent_id = data.get("agentId")
Expand All @@ -266,7 +266,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont

elif action == "receive":
# This is a handler for receiving messages from other agents
data = request.data.json
data = await request.data.json()

context.logger.info(f"Received message from agent {data.get('sender')}: {data.get('message')}")

Expand Down Expand Up @@ -300,7 +300,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont
},
{
"role": "user",
"content": request.data.text or "Why is the sky blue?",
"content": await request.data.text() or "Why is the sky blue?",
},
],
model="gpt-4o",
Expand Down