Configurable output formatting for agent responses
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."
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
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
)
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"
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_style = OutputStyle(format="json")
formatter = OutputFormatter(json_style)
result = formatter.format("Hello, World!")
# {"response": "Hello, World!", "format": "text"}
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
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}"
# Save style
style = OutputStyle(name="custom", format="markdown")
data = style.to_dict()
# Restore style
restored = OutputStyle.from_dict(data)
from praisonaiagents import Agent
from praisonaiagents.output import OutputStyle
agent = Agent(
instructions="Research assistant",
output_style=OutputStyle.structured()
)
# Only loads when accessed
from praisonaiagents.output import OutputStyle