AIH Automaton
Examples

Automaton Examples: Market Content Generator

This example demonstrates how to implement the Market Content Generator – a production-grade multi-agent pipeline used by AI-Horizon to research stock market indices, extract SEO search keywords, compose detailed marketing blog posts, and compile professional PDF reports automatically.


Complete Python Workflow Implementation

Below is the python script coordinating the multi-agent task execution:

import os
from aih import Agent, Task, Pipeline
 
# Configure API Keys
os.environ["OPENAI_API_KEY"] = "sk-..."
 
# Step 1: Define the Research Agent
researcher = Agent(
    role="SEO Keyword Generator Agent",
    prompt_persona="""You are an expert SEO marketing consultant.
    Analyze the text query and generate the top 5 highly relevant SEO keywords
    to drive web traffic. Format output as a JSON list.""",
    temperature=0.0
)
 
# Step 2: Define the Writing Agent
writer = Agent(
    role="Market Content Generator Writer",
    prompt_persona="""You are a professional financial blogger.
    Write a 500-word blog post based on the research results and include
    the generated SEO keywords naturally. Use clean Markdown structure.""",
    temperature=0.3
)
 
# Step 3: Define Tasks
seo_task = Task(
    name="Keyword Generation",
    description="Analyze current trends for 'SenSex Stock Index 2025' and generate keywords.",
    agent=researcher,
    output_path="./temp_keywords.json"
)
 
blog_task = Task(
    name="Blog Drafting",
    description="Draft the final market trends report using keywords from Keyword Generation task.",
    agent=writer,
    input_files=["./temp_keywords.json"],
    output_path="./output/blog_post.md"
)
 
# Step 4: Run the Pipeline
market_content_pipeline = Pipeline(
    name="Market Blog Pipeline",
    tasks=[seo_task, blog_task]
)
 
results = market_content_pipeline.run()
 
print("Execution Finished! Final Blog Post Location:", results.output_file)

Orchestrating Output Compilers

Once the agents complete their content composition, you can feed the resulting Markdown directly into a document compiler module (like AI-Horizon's text-to-pdf engine) to output publication-ready PDFs:

from aih.compilers import PDFCompiler
 
compiler = PDFCompiler()
compiler.compile(
    input_markdown_path="./output/blog_post.md",
    output_pdf_path="./output/Market_content_report.pdf",
    branding_title="AI Market Content Generator"
)
print("PDF Compiled successfully!")