diff --git a/content/SDKs/python/api-reference.mdx b/content/SDKs/python/api-reference.mdx index 529646b1..7b268250 100644 --- a/content/SDKs/python/api-reference.mdx +++ b/content/SDKs/python/api-reference.mdx @@ -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 @@ -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 @@ -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") @@ -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}") ``` diff --git a/content/SDKs/python/core-concepts.mdx b/content/SDKs/python/core-concepts.mdx index 1f7af7bf..05ef6621 100644 --- a/content/SDKs/python/core-concepts.mdx +++ b/content/SDKs/python/core-concepts.mdx @@ -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) @@ -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 diff --git a/content/SDKs/python/examples/index.mdx b/content/SDKs/python/examples/index.mdx index cd25a811..09689990 100644 --- a/content/SDKs/python/examples/index.mdx +++ b/content/SDKs/python/examples/index.mdx @@ -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 @@ -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") @@ -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}) @@ -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") @@ -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") @@ -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')}") @@ -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",