ChatBot.prompt_builder
Create an attention-optimized prompt builder for declarative prompt composition.
USAGE
='general') ChatBot.prompt_builder(builder_type
This method returns a specialized prompt builder that implements attention-based structuring principles from modern prompt engineering research. The builder helps engineers create prompts with optimal attention patterns through a fluent, declarative API.
Based on research showing that structure matters more than specific word choices, this builder enables you to:
- front-load critical information (primacy bias)
- create structured sections for clear attention clustering
- avoid attention drift through specific constraints
- build modular, maintainable prompt components
Parameters
builder_type : Union[str, BuilderTypes] = 'general'
-
Type of prompt builder to create. You can use either a string or a constant from
BuilderTypes
for better autocomplete and type safety.
Returns
PromptBuilder
-
A prompt builder with methods for declarative prompt composition.
Available builder types
The following builder types are available:
BuilderTypes.GENERAL
or"general"
: basic attention-optimized builderBuilderTypes.ARCHITECTURAL
or"architectural"
: pre-configured for code architecture analysisBuilderTypes.CODE_REVIEW
or"code_review"
: pre-configured for code review tasksBuilderTypes.DEBUGGING
or"debugging"
: pre-configured for debugging assistance
Examples
Basic attention-optimized prompt building
import talk_box as tb
= tb.ChatBot().model("gpt-4-turbo")
bot
# Build an attention-optimized prompt
= (bot.prompt_builder()
prompt "senior software architect", "comprehensive codebase analysis")
.persona("Create architectural documentation")
.task_context("Focus on identifying architectural debt")
.critical_constraint(
.core_analysis(["Tools, frameworks, and design patterns",
"Data models and API design patterns",
"Architectural inconsistencies"
])
.output_format(["Use clear headings and bullet points",
"Include specific examples from codebase"
])"Prioritize findings by impact and consistency")
.final_emphasis(
.build())
# Use the structured prompt
= bot.chat(prompt) response
Pre-configured builders for common tasks
# Architectural analysis with pre-configured structure
= (bot.prompt_builder(tb.BuilderTypes.ARCHITECTURAL)
arch_prompt "identifying technical debt")
.focus_on(
.build())
# Code review with attention-optimized structure
= (bot.prompt_builder(tb.BuilderTypes.CODE_REVIEW)
review_prompt "personal criticism"])
.avoid_topics(["actionable improvement suggestions")
.focus_on( .build())
Preview prompt structure before building
= (bot.prompt_builder()
builder "technical advisor")
.persona("Security", "Performance", "Maintainability"])
.core_analysis(["Structured sections", "Specific examples"]))
.output_format([
# Preview the attention structure
= builder.preview_structure()
structure print(f"Estimated tokens: {structure['estimated_tokens']}")
print(f"Priority sections: {len(structure['structured_sections'])}")
# Build when satisfied with structure
= builder._build() prompt
Notes
The returned builder implements attention-based principles:
- Primacy bias: critical information is front-loaded
- Structured sections: clear attention clustering prevents drift
- Personas: behavioral anchoring for consistent responses
- Specific constraints: avoid vague instructions that cause attention drift
- Recency bias: final emphasis leverages end-of-prompt attention
See Also
PromptBuilder : The full prompt builder API preset : Use presets for quick specialized configurations persona : Set behavioral context for responses