API Reference
Complete reference documentation for the Agentuity Python SDK, including request handling, response types, data storage, and agent communication.
This section provides detailed documentation for the Agentuity Python SDK API, including method signatures, parameters, return values, and example usage.
Table of Contents
Note: This documentation applies to Agentuity Python SDK version 1.0 and above.
Welcome Function
The Agentuity SDK allows you to customize the initial appearance of DevMode when it starts interacting with your agents by defining a welcome()
function in your agent module. This function should return a dictionary containing a welcome message and optional example prompts.
welcome()
Defines a welcome message and optional example prompts for DevMode.
Return Value
Returns a dictionary with a welcome message and optional prompts.
Example
Email Processing
The Agentuity SDK provides comprehensive email processing capabilities, including parsing incoming emails, handling attachments, and sending replies.
Email Class
The Email
class represents an incoming email with methods to access its properties and send replies.
sendReply(request, context, subject=None, text=None, html=None, attachments=None)
Send a reply to the incoming email using the Agentuity email API.
Parameters
request
(AgentRequest): The triggering agent request, used to extract metadata such as email-auth-tokencontext
(AgentContext): The agent context, used to get the base_url and agentIdsubject
(str, optional): Subject of the reply. Defaults to 'Re: <original subject>'text
(str, optional): Plain text body of the replyhtml
(str, optional): HTML body of the replyattachments
(List[OutgoingEmailAttachmentInterface], optional): List of attachments to include
Return Value
Returns None
on successful send.
Example
EmailAttachment Class
The EmailAttachment
class represents an outgoing email attachment with streaming data support.
Constructor
Parameters
filename
(str): The filename of the attachmentdata
(DataLike): The attachment data (can be string, bytes, or Data object)content_type
(str, optional): MIME type of the attachment
Properties
filename
(str): The filename of the attachmentdata()
: Returns the Data object containing the attachment content
IncomingEmailAttachment Class
The IncomingEmailAttachment
class represents an attachment from an incoming email with support for large attachments via streaming.
Properties
filename
(str): The filename of the attachmentcontent_disposition
(str): The content disposition ('attachment' or 'inline')
Methods
async data()
Asynchronously retrieves the attachment data as a Data object with streaming support for large files.
Return Value
Returns a Data
object that streams the attachment content.
Example
Agent Lifecycle
The Agentuity SDK provides a structured way to define and handle agents. An agent consists of a handler function, with its configuration managed by the Agentuity CLI.
Agent Handler
The agent handler is a function that processes requests and returns responses:
Parameters
request
: AnAgentRequest
object containing the request dataresponse
: AnAgentResponse
object for creating responsescontext
: AnAgentContext
object providing access to various capabilities
Return Value
The handler function should return an AgentResponseType
object.
Example
Storage APIs
The Agentuity SDK provides three storage APIs: Key-Value Storage, Vector Storage, and Object Storage.
Key-Value Storage
The Key-Value Storage API provides a simple way to store and retrieve data. It is accessed through the context.kv
object.
async get(name: str, key: str) -> "DataResult"
Retrieves a value from the key-value storage.
Parameters
name
: The name of the key-value storagekey
: The key to retrieve the value for
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
.
Example
async set(name: str, key: str, value: Union[str, int, float, bool, list, dict, bytes, "Data"], params: Optional[dict] = None) -> None
Stores a value in the key-value storage.
Parameters
name
: The name of the key-value storagekey
: The key to store the value undervalue
: The value to store (Union[str, int, float, bool, list, dict, bytes, "Data"])params
(optional): Can havettl
(time-to-live in seconds)
Return Value
None
Example
async delete(name: str, key: str) -> None
Deletes a value from the key-value storage.
Parameters
name
: The name of the key-value storagekey
: The key to delete
Return Value
None
Example
Vector Storage
The Vector Storage API provides a way to store and search for data using vector embeddings. It is accessed through the context.vector
object.
async upsert(name: str, *documents: VectorUpsertParams) -> list[str]
Inserts or updates vectors in the vector storage.
Parameters
name
: The name of the vector storagedocuments
: One or more documents to upsert, each with either embeddings or text
Return Value
Returns a list of string IDs for the upserted vectors.
Example
async search(name: str, params: VectorSearchParams) -> list[VectorSearchResult]
Searches for vectors in the vector storage.
Parameters
name
: The name of the vector storageparams
: Search parameters including query, limit, similarity threshold, and metadata filters
Return Value
Returns a list of search results, each containing an ID, metadata, and distance score.
Example
async delete(name: str, key: str) -> int
Deletes a vector from the vector storage.
Parameters
name
: The name of the vector storagekey
: The ID of the vector to delete
Return Value
Returns the number of vectors that were deleted (0 or 1).
Example
Object Storage
The Object Storage API provides a way to store and retrieve objects (files, documents, media) with support for public URL generation. It is accessed through the context.objectstore
object.
async get(bucket: str, key: str) -> DataResult
Retrieves an object from the object storage.
Parameters
bucket
: The bucket to get the object fromkey
: The key of the object to get
Return Value
Returns a DataResult object that has an exists
property to check if the object exists and a data
property containing the object data if found.
Example
async put(bucket: str, key: str, data: DataLike, params: Optional[ObjectStorePutParams] = None) -> None
Stores an object in the object storage.
Parameters
bucket
: The bucket to put the object intokey
: The key of the object to putdata
: The data to store (can be string, bytes, or other DataLike types)params
(optional): Additional parameters for the object. The following properties map to canonical HTTP headers:content_type
(Content-Type),content_encoding
(Content-Encoding),cache_control
(Cache-Control),content_disposition
(Content-Disposition), andcontent_language
(Content-Language). The optionalmetadata
property accepts a dictionary of arbitrary key-value pairs that will be stored as metadata with the object but not returned as part of HTTP results when the object is fetched. Thecontent_type
parameter is optional - if not provided, the content type will be automatically detected based on the data type (e.g., objects will be set toapplication/json
). If the content type cannot be determined, it defaults toapplication/octet-stream
.
Return Value
Returns None when the object has been stored successfully.
Example
async delete(bucket: str, key: str) -> bool
Deletes an object from the object storage.
Parameters
bucket
: The bucket to delete the object fromkey
: The key of the object to delete
Return Value
Returns a boolean indicating whether the object was deleted (True) or didn't exist (False).
Example
async create_public_url(bucket: str, key: str, expires_duration: Optional[int] = None) -> str
Creates a time-limited public URL for accessing an object.
Parameters
bucket
: The bucket containing the objectkey
: The key of the objectexpires_duration
(optional): Duration in milliseconds until the URL expires. Defaults to 1 hour (3600000ms) if not provided. Minimum value is 1 minute (60000ms) - values less than 1 minute will be set to 1 minute.
Return Value
Returns a public URL string that can be used to access the object.
Example
Agent Communication
The Agentuity SDK allows agents to communicate with each other through the context.get_agent()
method and agent redirection.
async get_agent(params: GetAgentRequestParams) -> RemoteAgent
Retrieves a handle to a remote agent that can be invoked.
Parameters
params
: Parameters to identify the agent, either by ID or by name and project ID
Return Value
Returns a RemoteAgent
object that can be used to invoke the agent.
Example
Agent Handoff
The response.handoff()
method allows an agent to handoff the request to another agent.
handoff(agent: GetAgentRequestParams, payload: dict | bytes | str = None, content_type: str = None, metadata: dict = None) -> AgentRedirectResponse
Redirects the current request to another agent.
Handoff
Handoff is currently only supported for handoff to other agents in the same project. However, we are working on remote agent handoff and should have that working soon.
Parameters
agent
: Parameters to identify the target agentpayload
(optional): The payload to send to the target agentcontent_type
(optional): The content type of the payloadmetadata
(optional): Additional metadata to include with the request
Return Value
Returns an AgentRedirectResponse
object.
Example
Response Types
The Agentuity SDK provides various methods for creating different types of responses through the response
object.
JSON Responses
json(data: dict, metadata: dict = None) -> AgentResponseType
Creates a JSON response.
Parameters
data
: The JSON data to include in the responsemetadata
(optional): Additional metadata to include with the response
Return Value
Returns an AgentResponseType
object with the JSON data.
Example
Text Responses
text(data: str, metadata: dict = None) -> AgentResponseType
Creates a text response.
Parameters
data
: The text to include in the responsemetadata
(optional): Additional metadata to include with the response
Return Value
Returns an AgentResponseType
object with the text data.
Example
Binary Responses
binary(data: bytes, metadata: dict = None) -> AgentResponseType
Creates a binary response.
Parameters
data
: The binary data to include in the responsemetadata
(optional): Additional metadata to include with the response
Return Value
Returns an AgentResponseType
object with the binary data.
Example
Media Type Responses
The SDK provides specialized methods for various media types:
pdf(data: bytes, metadata: dict = None) -> AgentResponseType
png(data: bytes, metadata: dict = None) -> AgentResponseType
jpeg(data: bytes, metadata: dict = None) -> AgentResponseType
gif(data: bytes, metadata: dict = None) -> AgentResponseType
webp(data: bytes, metadata: dict = None) -> AgentResponseType
mp3(data: bytes, metadata: dict = None) -> AgentResponseType
mp4(data: bytes, metadata: dict = None) -> AgentResponseType
wav(data: bytes, metadata: dict = None) -> AgentResponseType
ogg(data: bytes, metadata: dict = None) -> AgentResponseType
data(data: Any, content_type: str, metadata: dict = None) -> AgentResponseType
markdown(content: str, metadata: dict = None) -> AgentResponseType
Each method works similarly to the binary()
method but sets the appropriate content type. The data
method allows setting specific data with an exact content type, while the markdown
method provides a convenient way to return markdown content.
Example
HTML Responses
html(data: str, metadata: dict = None) -> AgentResponseType
Creates an HTML response.
Parameters
data
: The HTML content to include in the responsemetadata
(optional): Additional metadata to include with the response
Return Value
Returns an AgentResponseType
object with the HTML content.
Example
Empty Responses
empty(metadata: dict = None) -> AgentResponseType
Creates an empty response.
Parameters
metadata
(optional): Additional metadata to include with the response
Return Value
Returns an AgentResponseType
object with no payload.
Example
Request Handling
The Agentuity SDK provides various methods for accessing request data through the request
object.
Accessing Request Data
trigger() -> str
Gets the trigger type of the request.
Return Value
Returns a string representing the trigger type (webhook, cron, manual, agent, etc.).
Example
metadata(key: str, default_value = None) -> Any
Gets metadata associated with the request.
Parameters
key
: The metadata key to retrievedefault_value
(optional): A default value to return if the key does not exist
Return Value
Returns the metadata value for the specified key, or the default value if the key does not exist.
Example
json() -> dict
Gets the payload of the request as a JSON object.
Return Value
Returns the request payload as a dictionary.
Example
text() -> str
Gets the payload of the request as a string.
Return Value
Returns the request payload as a string.
Example
binary() -> bytes
Gets the payload of the request as bytes.
Return Value
Returns the request payload as bytes.
Example
Media-Specific Methods
The SDK provides specialized methods for various media types:
pdf() -> bytes
png() -> bytes
jpeg() -> bytes
gif() -> bytes
webp() -> bytes
mp3() -> bytes
wav() -> bytes
ogg() -> bytes
email() -> Email
Each method returns the request payload as bytes with the appropriate content type validation, except for email()
which returns an Email
object.
Example
email() -> Email
Gets the payload of the request as an Email object. This method validates that the content type is message/rfc822
before parsing.
Return Value
Returns an Email
object with parsed email data and accessor methods.
Example
Email Class
The Email
class provides comprehensive email parsing capabilities and is returned by the email()
method on request data.
Email Properties
All email properties are accessible as attributes on the Email object:
subject -> str
Returns the subject line of the email.
from_email -> str | None
Returns the sender's email address. Handles both simple email strings and tuple formats like ('Name', 'email@domain.com')
.
from_name -> str | None
Returns the sender's display name if available.
to -> str | None
Returns the recipient's email address. Handles both simple email strings and tuple formats.
date -> datetime | None
Returns the email date as a datetime object.
messageId -> str
Returns the unique message ID of the email.
headers -> dict
Returns all email headers as a dictionary.
text -> str
Returns the plain text content of the email.
html -> str
Returns the HTML content of the email.
attachments -> list
Returns a list of email attachments.
Email Methods
to_dict() -> dict
Converts the Email object to a dictionary containing all email data.
Return Value
Returns a dictionary with keys: subject, from_email, from_name, to, date, messageId, headers, text, html, attachments.
Example
Dictionary-Style Access
The Email object also supports dictionary-style access to its properties:
Logging
The Agentuity SDK provides logging functionality through the context.logger
object.
Logger Interface
The Logger
class defines the following methods:
Logging Methods
debug(message: str, *args, **kwargs) -> None
Logs a debug message.
Parameters
message
: The message to logargs
,kwargs
: Additional arguments to include in the log
Example
info(message: str, *args, **kwargs) -> None
Logs an informational message.
Parameters
message
: The message to logargs
,kwargs
: Additional arguments to include in the log
Example
warn(message: str, *args, **kwargs) -> None
Logs a warning message.
Parameters
message
: The message to logargs
,kwargs
: Additional arguments to include in the log
Example
error(message: str, *args, **kwargs) -> None
Logs an error message.
Parameters
message
: The message to logargs
,kwargs
: Additional arguments to include in the log
Example
Creating Child Loggers
child(**kwargs) -> Logger
Creates a child logger with additional context.
Parameters
kwargs
: Additional context to include in all logs from the child logger
Return Value
Returns a new Logger
instance with the additional context.
Example
Telemetry
The Agentuity SDK integrates with OpenTelemetry for tracing and metrics.
Tracing
The SDK provides access to OpenTelemetry tracing through the context.tracer
object.
Example
Need Help?
Join our Community for assistance or just to hang with other humans building agents.
Send us an email at hi@agentuity.com if you'd like to get in touch.
Please Follow us on
If you haven't already, please Signup for your free account now and start building your first agent!