Overview
Theswarms.prompts module provides tools for creating, managing, and versioning prompts with comprehensive history tracking, autosaving capabilities, and integration with agent systems.
Prompt Class
A powerful class for managing prompts with version control, edit history, and autosaving features.Constructor
str
default:"uuid.uuid4().hex"
Unique identifier for the prompt
str
default:"prompt"
Name of your prompt
str
default:"Simple Prompt"
Description of the prompt
str
required
The main content of the prompt (minimum 1 character)
str
default:"current_time"
Timestamp when the prompt was created
str
default:"current_time"
Timestamp when the prompt was last modified
int
default:"0"
Number of times the prompt has been edited
List[str]
default:"[]"
History of all prompt versions
bool
default:"False"
Enable automatic saving of the prompt
str
default:"prompts"
Folder path within WORKSPACE_DIR for autosaving
bool
default:"False"
Enable auto-generation of prompts
str
default:"workspace_dir"
Parent folder for the autosave folder
Any
default:"None"
Optional LLM instance for prompt generation
Methods
edit_prompt
Edit the prompt content and update version control.str
required
The updated content of the prompt
ValueError: If the new content is identical to the current content
rollback
Roll back the prompt to a previous version.int
required
The version index to roll back to (0 is the first version)
IndexError: If the version number is out of range
get_prompt
Return the current prompt content as a string.str
The current prompt content
return_json
Return the prompt as a JSON string.str
JSON representation of the prompt with all metadata
add_tools
Add tool schemas to the prompt content.List[Callable]
required
List of callable functions to add as tools
Pre-built Prompt Templates
The module includes numerous pre-built prompt templates for common agent roles:Finance Prompts
FINANCE_AGENT_PROMPT
Comprehensive prompt for financial analysis agents.Legal Prompts
LEGAL_AGENT_PROMPT
Prompt template for legal analysis and research agents.Product & Operations
PRODUCT_AGENT_PROMPT
Prompt for product management agents.OPERATIONS_AGENT_PROMPT
Prompt for operations management agents.GROWTH_AGENT_PROMPT
Prompt for growth and marketing agents.Development Prompts
CODE_INTERPRETER
Prompt for code interpretation and execution agents.DOCUMENTATION_WRITER_SOP
Standard operating procedure for documentation writing agents.Autonomous Agent Prompts
AUTONOMOUS_AGENT_SYSTEM_PROMPT
Base system prompt for autonomous agents.get_autonomous_agent_prompt
Generate an autonomous agent prompt.get_autonomous_agent_prompt_with_context
Generate an autonomous agent prompt with additional context.Example: Complete Prompt Management
Best Practices
- Enable autosave: Always enable autosave for important prompts to prevent data loss
- Use descriptive names: Give prompts clear, descriptive names for easy identification
- Version control: Leverage the built-in version control to track prompt evolution
- Add context: Include detailed descriptions to document the prompt’s purpose
- Organize by folder: Use the
autosave_folderparameter to organize prompts by category - Regular rollbacks: Test different prompt versions using rollback functionality
- Tool integration: Use
add_tools()to seamlessly integrate function calling
Thread Safety
The Prompt class implements thread-safe operations for:- Edit operations
- Rollback operations
- Autosaving
Autosave Behavior
When autosave is enabled:- Prompts are saved to
{WORKSPACE_DIR}/{autosave_folder}/prompt-id-{id}.json - Each edit automatically triggers a save
- Rollback operations also trigger saves
- The entire prompt state (including history) is preserved