Agent prompt templates are reusable snippets of text that can be used to generate specific types of agent dispatches in an Apiary platform. These templates allow founders to command their agents in English, and the Apiary platform generates the corresponding code based on predefined rules.
Benefits
Using agent prompt templates provides several benefits:
- Consistency: Templates ensure consistency in the generated code, reducing errors and improving maintainability.
- Reusability: Templates can be reused across multiple applications or services, saving development time and effort.
- Scalability: As the number of agents and applications grows, templates enable efficient management of complex interactions.
Template Structure
A typical agent prompt template consists of:
- Header: A brief description of the template's purpose and functionality.
- Prompt: The actual English command that will be used to trigger the agent dispatch.
- Rules: Predefined rules that govern how the generated code should behave.
- Options: Optional parameters or settings that can be customized for each application.
Example Template: Simple API Call
### Simple API Call
**Prompt**: Get user data by ID
**Rules**:
+ Use GET method
+ Pass `user_id` as query parameter
+ Return JSON response
**Options**:
+ Set timeout to 5 seconds
Example Code Generation
When a founder commands the agent with the prompt "Get user data by ID", Apiary generates the following code snippet in Python:
import requests
def get_user_data(user_id):
url = f"https://api.example.com/users/{user_id}"
response = requests.get(url, timeout=5)
return response.json()
Advanced Templates: Hard Boundaries and Conflict Avoidance
More complex templates can be created to enforce hard boundaries or conflict avoidance:
Template: Exclusive Locking
### Exclusive Locking
**Prompt**: Acquire exclusive lock on resource X
**Rules**:
+ Use `SELECT ... FOR UPDATE` SQL statement
+ Check if lock is already held by another transaction
+ Raise error if lock cannot be acquired
Example Code Generation (continued)
When a founder commands the agent with the prompt "Acquire exclusive lock on resource X", Apiary generates the following code snippet in Python:
import psycopg2
def acquire_exclusive_lock(resource_id):
conn = psycopg2.connect("dbname=mydb user=myuser host=localhost")
cur = conn.cursor()
try:
cur.execute("SELECT * FROM mytable WHERE id=%s FOR UPDATE", (resource_id,))
return True
except psycopg2.Error as e:
if e.pgcode == "40P01": # Lock already held by another transaction
raise ValueError("Lock cannot be acquired")
else:
raise
Verification and Quality Bar
To ensure the generated code meets quality standards, Apiary can integrate with third-party tools for:
- Code analysis: Static code analysis to detect potential issues or security vulnerabilities.
- Code review: Automated code review to enforce best practices and coding standards.
By using agent prompt templates in an Apiary platform, founders can streamline their development workflow, reduce errors, and improve the overall quality of their applications.