Prompts¶
Sikka Agent's Prompts module provides a structured approach to creating, managing, and optimizing prompts for language models, ensuring consistent and effective AI behavior.
Overview¶
Prompts are critical instructions that shape AI model behavior. This module provides: - Templating for reusable prompt structures - Specialized templates for different use cases - Pre-built prompt libraries for common scenarios - Evaluation tools for prompt optimization
Well-designed prompts are essential for defining agent personality, providing task context, ensuring consistent outputs, and optimizing response quality while managing token usage.
Core Components¶
PromptTemplate¶
Basic templating system with variable substitution for creating dynamic prompts.
Parameters¶
Parameter | Type | Description | Default |
---|---|---|---|
template |
str |
Template string with placeholders in {variable} format |
Required |
Returns¶
format()
: Returns string with placeholders replaced by provided values
Code Example¶
from sikkaagent.prompts import PromptTemplate
# Create a template with placeholders
greeting_template = PromptTemplate(
template="Hello {name}, I'm specialized in {domain}. How can I help you today?"
)
# Render the template with specific values
prompt = greeting_template.format(
name="Alex",
domain="machine learning"
)
print(prompt)
# Output: "Hello Alex, I'm specialized in machine learning. How can I help you today?"
TaskPromptTemplateDict¶
A dictionary of task prompt templates keyed by task type (e.g., CODE, DEFAULT) that centralizes prompt management.
Parameters¶
Parameter | Type | Description | Default |
---|---|---|---|
*args |
Any |
Positional arguments passed to dict constructor | None |
**kwargs |
Any |
Keyword arguments passed to dict constructor | None |
Returns¶
- Dictionary mapping from task types to their corresponding prompt template dictionaries
Implementation¶
# Internal structure
{
TaskType.CODE: CodePromptTemplateDict(), # Code-specific templates
TaskType.DEFAULT: DefaultPromptTemplateDict() # Default templates
}
Code Example¶
# Access task-specific templates through PromptLibrary
from sikkaagent.prompts import PromptLibrary
from sikkaagent.utils.enums import TaskType, RoleType
# Create a prompt library
prompt_lib = PromptLibrary()
# Access the CODE task templates dictionary
code_templates = prompt_lib.task_prompts[TaskType.CODE]
# Get the assistant prompt template
assistant_template = code_templates[RoleType.ASSISTANT]
# Format the template with specific variables
prompt = assistant_template.format(
language="python",
domain="data science",
task="Create a data visualization dashboard"
)
CodePromptTemplateDict¶
Dictionary of prompt templates specifically designed for code-related tasks.
Parameters¶
Parameter | Type | Description | Default |
---|---|---|---|
*args |
Any |
Positional arguments passed to dict constructor | None |
**kwargs |
Any |
Keyword arguments passed to dict constructor | None |
Returns¶
- Dictionary of prompt templates for various coding tasks, including:
generate_languages
: For generating programming language listsgenerate_domains
: For generating programming application domainsgenerate_tasks
: For generating coding taskstask_specify_prompt
: For making coding tasks more specificRoleType.ASSISTANT
: For coding assistant promptsRoleType.USER
: For user prompts in coding tasks
Code Example¶
from sikkaagent.prompts import PromptLibrary
from sikkaagent.utils.enums import TaskType, RoleType
# Create a prompt library
prompt_lib = PromptLibrary()
# Get the code-specific prompt dictionary
code_prompts = prompt_lib.task_prompts[TaskType.CODE]
# Access a specific template for code tasks
task_specify_template = code_prompts["task_specify_prompt"]
# Format the template with specific parameters
formatted_prompt = task_specify_template.format(
language="python",
domain="web development",
task="Create a REST API",
word_limit=100
)
print(formatted_prompt)
PromptLibrary¶
Sikka Agent includes a centralized PromptLibrary
for managing and accessing prompt templates.
Parameters¶
Parameter | Type | Description | Default |
---|---|---|---|
task_prompts |
Dict[TaskType, Dict[str, Any]] |
Prompts organized by task type | {} |
prompts |
Dict[str, Dict[str, Dict[str, str]]] |
Domain-based prompt organization | {} |
Methods¶
get_system_prompt()¶
Retrieves a system prompt for a specific task type and role.
Parameters¶
Parameter | Type | Description | Default |
---|---|---|---|
task_type |
TaskType |
Type of task (CODE, DEFAULT, etc.) | Required |
role_type |
RoleType |
Role type (ASSISTANT, USER, etc.) | Required |
Returns¶
TextPrompt
: The system prompt template (defaults to "You are a helpful assistant." if not found)
get_task_specify_prompt()¶
Retrieves a task specification prompt for a task type.
Parameters¶
Parameter | Type | Description | Default |
---|---|---|---|
task_type |
TaskType |
Type of task | Required |
Returns¶
TextPrompt
: The task specification prompt template
get_generate_tasks_prompt()¶
Retrieves a task generation prompt for a task type.
Parameters¶
Parameter | Type | Description | Default |
---|---|---|---|
task_type |
TaskType |
Type of task | Required |
Returns¶
TextPrompt
: The task generation prompt template
Default Prompts¶
The library comes with pre-configured default prompts:
DEFAULT_PROMPTS = {
"default_system": PromptTemplate("You are a helpful assistant."),
"default_task": PromptTemplate("Complete the following task: {task}"),
"default_specification": PromptTemplate("Please make the task more specific: {task}"),
"default_generation": PromptTemplate("Generate content for: {task}"),
"default_evaluation": PromptTemplate("Evaluate the following: {content}"),
"default_data": PromptTemplate("Process the following data: {data}"),
}
Code Example¶
from sikkaagent.prompts import PromptLibrary
from sikkaagent.utils.enums import TaskType, RoleType
from sikkaagent.agents import ChatAgent
# Create a prompt library
prompt_lib = PromptLibrary()
# Get a system prompt for a coding task
system_prompt = prompt_lib.get_system_prompt(
task_type=TaskType.CODE,
role_type=RoleType.ASSISTANT
)
# Create an agent with the system prompt
agent = ChatAgent(
model=model,
system_prompt=system_prompt.format(
language="python",
domain="data science"
)
)
Domain-Based Organization¶
For more complex applications, prompts can be organized by domain:
from sikkaagent.prompts import PromptLibrary, PromptTemplate, PromptCategory
# Create a prompt library
prompt_lib = PromptLibrary()
# Add a domain-specific prompt
prompt_lib.add_domain_prompt(
domain="customer_support",
category=PromptCategory.SYSTEM,
name="greeting",
template="Hello, I'm a customer support assistant for {company_name}. How can I help you today?"
)
# Get and use the prompt
greeting = prompt_lib.format_domain_prompt(
domain="customer_support",
category=PromptCategory.SYSTEM,
name="greeting",
company_name="TechCorp"
)
Creating Custom Templates¶
Extend the base classes to create specialized prompt templates.
from sikkaagent.prompts.base import BasePromptTemplate
class MultiStagePromptTemplate(BasePromptTemplate):
def __init__(self, introduction, analysis_steps, conclusion, **kwargs):
super().__init__(**kwargs)
self.introduction = introduction
self.analysis_steps = analysis_steps
self.conclusion = conclusion
def format(self, **kwargs):
intro = self.introduction.format(**kwargs)
steps = [step.format(**kwargs) for step in self.analysis_steps]
concl = self.conclusion.format(**kwargs)
return f"{intro}\n\n" + "\n".join(steps) + f"\n\n{concl}"
Best Practices¶
- Be Specific: Clearly define the agent's role and expected behavior
- Include Examples: Provide few-shot examples to demonstrate desired output format
- Break It Down: Chunk complex prompts into logical sections
- Set Boundaries: Define constraints and limitations explicitly
- Test Thoroughly: Regularly evaluate prompts with diverse inputs
- Version Control: Track prompt versions and performance metrics