Development
This document will help you create, deploy, and integrate AI agents seamlessly on our platform. Whether youβre building an API, chatbot, or website-based AI, this guide will walk you through the essential steps.
Here are few samples to understand & use
- https://github.com/optimalagents-ai/magic-rag-chatbot
- https://github.com/optimalagents-ai/db-query-chatbot-agent
π Interface & Routes
Design your agentβs interface routes following these guidelines:
-
Main Interface
- Create a single unified interface at β/β for all user interactions
- Keep the interface clean and intuitive
- Put clear instructions on how to use the agent
- Use a framework like FastAPI, Flask, or Node.js for building the interface
- Ensure the interface is responsive and user-friendly
- Need to use windows.href (javascript ) then add /your path name
-
API routes
- Define routes for API interactions
- Use RESTful principles for API design
- Example routes:
/run
- for executing agent logic/process
- for processing user input/status
- for checking agent status/uploads
- for uploading files/docs
- for API & Route documentation
- Use appropriate HTTP methods (GET, POST, PUT, DELETE) for each route
- Use JSON for data exchange
- Use appropriate HTTP status codes for responses
- Use appropriate HTTP headers for authentication and content type
- Please keep all your routes in one main file ( main.py or app.py )
- For client-side navigation, utilize window.location.href followed by your desired route path
- include User-Token in the request headers for all API calls to the agent
-
Documentation
- All routes and endpoints must be documented at β/docsβ
- Use built-in documentation tools:
- FastAPI: Built-in Swagger UI
- Flask: Flask-RESTPlus or Flask-Swagger
- Node.js: Swagger UI Express or similar
π Folder Structure
To keep things organized, structure your project like this:
Zip the project folder (e.g. /my-agent ) into a .zip file
. Ensure that the Dockerfile and all necessary files are included in the root folder within the zip.- Check the size of the zip file to ensure it is within the upload limits set by OptimalAgents.ai (typically 100MB).
- Make sure to remove unnecessary files or folders (like
.git
ornode_modules
orvirtual env
folders) to keep the upload size minimal. - If your project exceeds this limit, consider optimizing or splitting it into smaller components.
π Routes & API Endpoints
Your agent can expose API endpoints for users to interact with. Example setup in Flask:
Ensure your routes are well-documented and secured.
π Env Variables (Secrets)
Secrets are environment variables required by your agent to function which will be passed to the Docker container when the agent runs. Store them securely in your profileβs Secret manager. These variables will be securely managed by OptimalAgents.ai and injected into the agentβs docker runtime environment.
Please generate your CREATOR_API_KEY. This will be required to run any Agent that you have uploaded
By default, we will including AGENT_ID, CREATOR_API_KEY, Secrets as environment variables.
For testing purposes, Creator need to use their own versions of API KEYs and Secrets.
User Secrets Keys & API KEYs or OptimalAgent.ai API KEYS will be accessible to the agent only after the agent is verified & available in marketplace.
Examples include:
Never hardcode secrets! Load them in your app like this:
π Credit Check & Authorization
Before running, agents must verify user credits via the OptimalAgents API.
β Credit Check API
Make a request before executing agent logic:
Handling Responses
Response Examples Success Response
Error Response (Not Enough Credits)
Error Response (Unauthorized Agent)
π³ Docker Containerization
All agents run inside Docker containers. Your Dockerfile should look like this:
Steps to Build, Run & Test in Local
Build the container:
Run the container:
A Docker image will be automatically generated upon initial deployment and regenerated following any edits to the codebase.
For file uploads, kindly direct your bytes to the β/app/uploadsβ directory - itβs where the magic happens! OptimalAgents has cleverly bound a persistent storage space to this location, ensuring your uploads donβt pull a disappearing act.
ποΈ CORS Configuration
To enable Cross-Origin Resource Sharing (CORS) for all origins and ports in your server-side application, configure your middleware with appropriate security settings.
π Logging & Monitoring
Use logging for debugging and tracking agent performance.
Always log errors and API failures for troubleshooting!
Congratulations! π You now have everything needed to create and deploy AI agents on OptimalAgents.ai. If you need help, reach out to our support team or explore our community forums! π