Introduction to Superagent Python SDK
Superagent Python SDK is an open framework designed to facilitate the integration of AI Assistants into various applications swiftly and efficiently. This innovative tool aims to empower developers by providing a streamlined process to deploy AI systems in production environments.
Installation
Getting started with Superagent is straightforward. Developers can install the framework using Python’s popular packaging tools. Simply include the dependency in your project's build file with either of the following commands:
pip install superagent-py
# or
poetry add superagent-py
Usage
Once installed, using Superagent involves a very intuitive process. Developers can quickly spin up AI assistants within their applications by following this basic structure:
from superagent.client import Superagent
client = Superagent(token="API_TOKEN", base_url="https://api.beta.superagent.sh")
agent = client.agent.create(request={
"name": "My Agent",
"description": "My awesome agent",
"isActive": True,
"llmModel": "GPT_4_1106_PREVIEW",
"prompt": "You are a helpful assistant"
})
output = client.agent.invoke(
agent_id=agent.data.id,
input="Hi there!",
enable_streaming=False,
session_id="123"
)
print("Received response from superagent", agent.data)
Async Client
For applications requiring asynchronous operations, Superagent provides an async client. This allows developers to handle tasks without blocking their application’s runtime.
from superagent.client import AsyncSuperagent
agent = await client.agent.create(request={
"name": "My Agent",
"description": "My awesome agent",
"isActive": True,
"llmModel": "GPT_4_1106_PREVIEW",
"prompt": "You are a helpful assistant"
})
output = await client.agent.invoke(
agent_id=agent.data.id,
input="Hi there!",
enable_streaming=False,
session_id="123"
)
print("Received response from superagent", agent.data)
Handling Exceptions
Error management is integral for any development process. Superagent ensures robustness by subclassing potential exceptions through moneykit.ApiError
. Here's an example of how to manage these exceptions:
from superagent.core import ApiError
try:
client.agents.get(agent_id="12312")
except APIError as e:
# handle any api related error
Here is a basic error code you might encounter:
- 422:
UnprocessableEntityError
Acknowledgements
Superagent extends gratitude to the Fern team for their support in developing the libraries and SDKs that make such a project possible.
Beta Status
The Superagent SDK is currently in beta. This means that while it is ready for use, there may be changes between versions that do not follow the typical major update protocol. Hence, developers are encouraged to pin a specific version in their dependency manager to avoid unexpected changes.
Contributing
Contributions from the community are valued; however, due to the programmatic nature of the library's generation, direct changes cannot be merged as-is. Contributors are encouraged to first discuss potential changes by opening an issue or submitting a proof of concept as a pull request. Improvements to documentation are always welcomed and appreciated.
By providing these guidelines and a robust set of features, Superagent ensures developers have a reliable framework for incorporating AI Assistants into their projects with ease and efficiency.