OSSS.ai.workflows.prompt_composer¶
OSSS.ai.workflows.prompt_composer
¶
Prompt Composer System for Dynamic Agent Behavior Configuration
This module provides dynamic prompt composition capabilities, allowing agents to modify their behavior based on YAML configuration without code changes. The composer integrates with the existing prompt system while enabling runtime customization.
Architecture: - Template-based prompt composition with variable substitution - Integration with existing prompt_loader.py system - Configuration-driven behavioral modifications - Fallback to default prompts for backward compatibility
TemplateVariables
¶
Bases: TypedDict
Strictly typed template variables for prompt composition.
Uses TypedDict with total=False to allow partial dictionaries while maintaining strict typing for each key that is present. This ensures type safety while allowing different agents to use different subsets of variables.
ComposedPrompt
¶
Bases: BaseModel
Container for a composed prompt with metadata.
Provides structured prompt composition with template management, variable substitution, and comprehensive metadata tracking for agent behavior configuration.
validate_system_prompt_not_empty(v)
classmethod
¶
Ensure system prompt is not empty.
validate_template_names(v)
classmethod
¶
Ensure template names are valid identifiers.
get_template(template_name)
¶
Get a specific template by name.
substitute_variables(template)
¶
Substitute variables in a template string.
PromptComposer
¶
Dynamic prompt composition system for configurable agent behavior.
The PromptComposer enables runtime modification of agent prompts based on configuration while maintaining backward compatibility with existing systems.
__init__()
¶
Initialize the prompt composer.
compose_refiner_prompt(config)
¶
Compose refiner agent prompt based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RefinerConfig
|
RefinerConfig with behavioral and prompt settings |
required |
Returns:
| Type | Description |
|---|---|
ComposedPrompt
|
ComposedPrompt with customized system prompt and templates |
compose_critic_prompt(config)
¶
Compose critic agent prompt based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CriticConfig
|
CriticConfig with analysis and evaluation settings |
required |
Returns:
| Type | Description |
|---|---|
ComposedPrompt
|
ComposedPrompt with customized critical analysis prompt |
compose_historian_prompt(config)
¶
Compose historian agent prompt based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
HistorianConfig
|
HistorianConfig with search and context settings |
required |
Returns:
| Type | Description |
|---|---|
ComposedPrompt
|
ComposedPrompt with customized context retrieval prompt |
compose_synthesis_prompt(config)
¶
Compose synthesis agent prompt based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SynthesisConfig
|
SynthesisConfig with integration and analysis settings |
required |
Returns:
| Type | Description |
|---|---|
ComposedPrompt
|
ComposedPrompt with customized synthesis prompt |
compose_final_prompt(config)
¶
Compose FINAL agent prompt based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FinalConfig
|
FinalConfig with behavioral and prompt settings |
required |
Returns:
| Type | Description |
|---|---|
ComposedPrompt
|
ComposedPrompt with customized system prompt and templates |
compose_prompt(agent_type, config)
¶
Universal prompt composition method for any agent type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_type
|
str
|
Type of agent ("refiner", "critic", "historian", "synthesis") |
required |
config
|
AgentConfigType
|
Agent-specific configuration object |
required |
Returns:
| Type | Description |
|---|---|
ComposedPrompt
|
ComposedPrompt with customized prompt for the agent |
Raises:
| Type | Description |
|---|---|
ValueError
|
If agent_type is not supported |
get_default_prompt(agent_type)
¶
Get the default prompt for an agent type (fallback behavior).
validate_composition(composed_prompt)
¶
Validate that a composed prompt is well-formed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
composed_prompt
|
ComposedPrompt
|
ComposedPrompt to validate |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if prompt is valid, False otherwise |