Prompt Expander Agent
Expand short prompts into detailed, actionable prompts for better task execution.
Turn a one-line request into a rich, actionable prompt with the PromptExpanderAgent.
from praisonaiagents import PromptExpanderAgent
agent = PromptExpanderAgent()
result = agent.expand("write a movie script in 3 lines")
print(result.expanded_prompt)The Prompt Expander Agent transforms short, brief prompts into detailed, comprehensive prompts for better task execution. Unlike the Query Rewriter (which optimizes for search/retrieval), the Prompt Expander focuses on enriching prompts for task execution.
Agents: 1 — Specialized agent for prompt enhancement.
Quick Start
- Simple Usage
Expand a short prompt with the default strategy.
python from praisonaiagents import PromptExpanderAgent agent = PromptExpanderAgent() result = agent.expand("write a movie script in 3 lines") print(result.expanded_prompt) - With a Strategy
Choose how aggressively to expand.
python from praisonaiagents import PromptExpanderAgent, ExpandStrategy agent = PromptExpanderAgent() result = agent.expand("AI blog", strategy=ExpandStrategy.STRUCTURED) print(result.expanded_prompt)
How It Works
Workflow
- Receive short prompt
- Optionally gather context via tools
- Apply expansion strategy
- Return detailed, actionable prompt
Setup
pip install praisonaiagents praisonai
export OPENAI_API_KEY="your-key"Run — Python
from praisonaiagents import PromptExpanderAgent
agent = PromptExpanderAgent()
result = agent.expand("write a movie script in 3 lines")
print(result.expanded_prompt)Run — CLI
# Expand a short prompt
praisonai "write a movie script in 3 lines" --expand-prompt
# With verbose output
praisonai "blog about AI" --expand-prompt -v
# With tools for context gathering
praisonai "latest AI trends" --expand-prompt --expand-tools tools.pyRun — agents.yaml
framework: praisonai
topic: Prompt Expansion
roles:
expander:
role: Prompt Expander
goal: Transform short prompts into detailed prompts
backstory: You are an expert at prompt engineering
tasks:
expand:
description: Expand "write a movie script" into a detailed prompt
expected_output: Detailed, actionable promptpraisonai agents.yamlServe API
from praisonaiagents import PromptExpanderAgent
agent = PromptExpanderAgent()
# Note: PromptExpanderAgent uses .expand() method
# For API serving, integrate with standard agentExpansion Strategies
Simple expansion with clarity improvements. Fixes ambiguity and adds minimal context.
DETAILEDRich expansion with context, constraints, format guidance, and quality expectations.
STRUCTUREDExpansion with clear sections: Task, Format, Requirements, Style, Constraints.
CREATIVEExpansion with vivid, inspiring language and creative direction.
Basic Usage
from praisonaiagents import PromptExpanderAgent, ExpandStrategy
# Default (AUTO strategy)
agent = PromptExpanderAgent()
result = agent.expand("write a poem")
print(result.expanded_prompt)Using Specific Strategies
from praisonaiagents import PromptExpanderAgent, ExpandStrategy
agent = PromptExpanderAgent()
# Basic - minimal expansion
result = agent.expand("AI blog", strategy=ExpandStrategy.BASIC)
# Detailed - rich context and requirements
result = agent.expand("AI blog", strategy=ExpandStrategy.DETAILED)
# Structured - clear sections
result = agent.expand("AI blog", strategy=ExpandStrategy.STRUCTURED)
# Creative - vivid language
result = agent.expand("AI blog", strategy=ExpandStrategy.CREATIVE)Using Tools for Context
from praisonaiagents import PromptExpanderAgent
def search_tool(query: str) -> str:
"""Search for context."""
# Your search implementation
return "Latest AI trends: LLMs, multimodal, agents"
agent = PromptExpanderAgent(tools=[search_tool])
result = agent.expand("write about AI trends")
print(result.expanded_prompt)Configuration Options
agent = PromptExpanderAgent(
name="PromptExpander",
model="gpt-4o-mini",
temperature=0.7, # Higher for creativity
max_tokens=1000,
tools=[...] # Optional tools for context
)ExpandResult Properties
result = agent.expand("write a poem")
# Access properties
print(result.original_prompt) # Original input
print(result.expanded_prompt) # Expanded output
print(result.strategy_used) # Strategy that was used
print(result.metadata) # Additional metadataConvenience Methods
agent = PromptExpanderAgent()
# Direct strategy methods
result = agent.expand_basic("short prompt")
result = agent.expand_detailed("short prompt")
result = agent.expand_structured("short prompt")
result = agent.expand_creative("short prompt")Key Difference from Query Rewriter
| Feature | Query Rewriter | Prompt Expander |
|---|---|---|
| Purpose | Optimize for search/retrieval | Expand for task execution |
| Use Case | RAG applications | Task prompts |
| Output | Search-optimized queries | Detailed action prompts |
| CLI Flag | --query-rewrite | --expand-prompt |
Example: Movie Script
Input:
write a movie script in 3 linesExpanded (Creative Strategy):
Craft a captivating movie script distilled into just three powerful lines,
each word infused with vivid imagery and emotional weight. Your lines should
ignite the spark of adventure and intrigue, capturing a moment that hints at
a grand journey ahead—one that resonates deeply with the audience's hearts
and imaginations. Use poignant dialogue, evocative descriptions, and a
tantalizing glimpse of conflict that will leave viewers breathless.Monitor / Verify
praisonai "test prompt" --expand-prompt --verboseFeatures Demonstrated
| Feature | Implementation |
|---|---|
| Workflow | Single-step prompt expansion |
| Observability | --verbose flag |
| Tools | Optional context-gathering tools |
| Structured Output | ExpandResult with metadata |
Best Practices
Match the strategy to the goal
Use BASIC to fix ambiguity, STRUCTURED for task specs, and CREATIVE for writing prompts. The wrong strategy over- or under-expands the request.
Raise temperature for creative expansion
Creative strategies benefit from a higher temperature. Keep it low for structured, deterministic expansions where you want repeatable output.
Attach tools to ground the expansion
Pass tools=[search_tool] so the agent pulls real context before expanding — useful when the prompt references current events or your own data.
Use Query Rewriter for search, not expansion
This agent enriches prompts for task execution. To optimise text for retrieval and RAG, use the Query Rewriter Agent instead.