The Aesoperator Python SDK provides a convenient way to discover, invoke, and compose from your Python code.
Installation
Install the SDK using pip:
pip install computer-agent
The SDK requires Python 3.7 or later. It depends on the requests library for making HTTP requests to the Aesoperator API.
Authentication
To use the SDK, you first need to obtain an API key from your Aesoperator account dashboard. Then initialize the SDK client with your key:
from aesoperator import Aesoperator
aesop = Aesoperator(api_key="your_api_key_here")
This client instance will automatically authenticate with the Aesoperator service and handle token refresh. You can also specify a custom API endpoint if needed:
The input parameters are validated against the function's schema. The invocation happens synchronously and the method returns when the function completes.
For long-running functions, you can invoke them asynchronously:
This immediately returns an AesopInvocation object with metadata about the in-progress invocation. You can then poll for completion:
import time
while True:
status = aesop.get_invocation(invocation_id).status
print(f"Invocation status: {status}")
if status == "Completed":
break
time.sleep(1)
output = aesop.get_invocation(invocation_id).output
Handling Results
Operator function results are returned as Python objects deserialized from JSON. The exact structure depends on the function's output schema, but often includes the main output payload along with metadata like processing latency and logs.
output = aesop.invoke("summarize_text", text="Some long input text goes here")
summary = output.output
print(f"Summary: {summary}")
latency_ms = output.latency
print(f"Summarization took {latency_ms} milliseconds")
If the function returns an error, an AesopError exception is raised with details:
You can use the SDK to compose multiple Operator function calls into a workflow. For example, to generate questions and answers from a web page:
# Scrape the text from a web page
page_text = aesop.invoke("scrape_text", url="https://example.com")
# Generate questions based on the scraped text
questions = aesop.invoke("generate_questions", text=page_text)
# Generate answers for each question
answers = []
for question in questions:
answer = aesop.invoke("answer_question", question=question, context=page_text)
answers.append(answer)
The SDK also provides a compose method to define a sequence of function calls as a reusable pipeline:
Each step of the composition specifies the function to invoke and its parameters. You can reference the outputs of previous steps using the dot notation step_name.output.
Invoking the composed pipeline executes the steps in order and returns the final result:
This sets up a listener that triggers the process_new_record pipeline whenever a record is inserted into the new_records table. The pipeline validates the record, extracts key entities from its description field, looks up additional metadata for each entity, and updates a search index with the enriched record data.
The SDK provides convenience methods for working with and objects in your function invocations.