Skip to main content

Output Styles

Configure how agents format their responses. Control verbosity, format, tone, and length to match your application’s needs.

Quick Start

from praisonaiagents.output import OutputStyle, OutputFormatter

# Use a preset style
style = OutputStyle.concise()
formatter = OutputFormatter(style)

# Format output
text = "# Hello\n\nThis is **bold** text."
plain = formatter.format(text)
print(plain)  # "Hello\n\nThis is bold text."

Style Presets

Pre-configured styles for common use cases:
from praisonaiagents.output import OutputStyle

# Available presets
concise = OutputStyle.concise()        # Minimal, direct
detailed = OutputStyle.detailed()      # Verbose, thorough
technical = OutputStyle.technical()    # Developer-focused
conversational = OutputStyle.conversational()  # Friendly tone
structured = OutputStyle.structured()  # Organized with headers
minimal = OutputStyle.minimal()        # Bare minimum

Custom Styles

style = OutputStyle(
    name="custom",
    verbosity="normal",      # minimal, normal, verbose
    format="markdown",       # markdown, plain, json
    tone="professional",     # professional, friendly, technical
    max_length=1000,         # Character limit
    include_examples=True,
    include_code_blocks=True
)

Output Formatting

Format Conversion

from praisonaiagents.output import OutputFormatter

# Markdown to plain text
plain_style = OutputStyle(format="plain")
formatter = OutputFormatter(plain_style)

markdown = "# Title\n\n**Bold** and *italic*"
plain = formatter.format(markdown)
# "Title\n\nBold and italic"

Length Control

style = OutputStyle(max_length=100)
formatter = OutputFormatter(style)

long_text = "This is a sample sentence. " * 20
truncated = formatter.format(long_text)
# Truncated to ~100 characters with "..."

JSON Output

json_style = OutputStyle(format="json")
formatter = OutputFormatter(json_style)

result = formatter.format("Hello, World!")
# {"response": "Hello, World!", "format": "text"}

Utility Functions

formatter = OutputFormatter()

text = "This is a test sentence with several words."

# Count words
words = formatter.get_word_count(text)  # 8

# Count characters
chars = formatter.get_char_count(text)  # 43

# Estimate tokens
tokens = formatter.estimate_tokens(text)  # ~10

System Prompt Integration

Styles can generate system prompt additions:
style = OutputStyle.concise()
prompt_addition = style.get_system_prompt_addition()
# "Be concise and direct. Avoid unnecessary elaboration..."

# Add to agent instructions
full_instructions = f"{base_instructions}\n\n{prompt_addition}"

Serialization

# Save style
style = OutputStyle(name="custom", format="markdown")
data = style.to_dict()

# Restore style
restored = OutputStyle.from_dict(data)

Agent Integration

from praisonaiagents import Agent
from praisonaiagents.output import OutputStyle

agent = Agent(
    instructions="Research assistant",
    output_style=OutputStyle.structured()
)

Zero Performance Impact

Output styles use lazy loading:
# Only loads when accessed
from praisonaiagents.output import OutputStyle