DEV Community

Cover image for Building a Multi-Agent AI for Company LinkedIn Pages - Part 10: Wiring All the Agents Together
Manav
Manav

Posted on

Building a Multi-Agent AI for Company LinkedIn Pages - Part 10: Wiring All the Agents Together

In the previous articles, we built every agent individually.

Each one had a single responsibility. The Orchestrator classified the topic. The Research Agent gathered information. The Examples Agent found supporting examples. The Critic Agent questioned the research. The Brief Agent structured everything. The Hook Agent generated opening lines. The Draft Agent wrote complete posts. Finally, the Writing Critic Agent evaluated those drafts.

Now it's time to connect everything together.

That's why we write the main.py file.

Unlike the previous articles, we aren't introducing a new agent here. Instead, we're wiring every existing agent into a single pipeline where the output of one agent becomes the input of the next.

User Topic 
    │ 
    ▼
Orchestrator 
    │ 
    ▼ 
 Research 
    │ 
    ▼ 
 Examples 
    │ 
    ▼ 
  Critic 
    │ 
    ▼ 
  Brief 
    │ 
    ▼ 
  Hook 
    │ 
    ▼ 
  Draft 
    │ 
    ▼ 
Writing Critic 
    │ 
    ▼ 
Final Result
Enter fullscreen mode Exit fullscreen mode

Before writing the main() function, we import every agent we've built so far.

from agents.writing_critic import rate_drafts 
from agents.draft import generate_drafts 
from agents.hook import generate_hooks 
from agents.brief import create_brief 
from agents.critic import be_critique 
from agents.examples import get_examples 
from agents.research import research_agent 
from agents.orchestrator import classify_topic
Enter fullscreen mode Exit fullscreen mode

The order of these imports almost mirrors the order of execution. Every stage depends on the output produced by the previous one.

Now let's break down the main() function before looking at the complete code.

It starts by taking a topic from the user and passing it to the Orchestrator Agent. If classification fails, the pipeline stops immediately.

Every step after that follows the same pattern:

  • Run the agent.
  • Validate its output.
  • Stop if it fails.
  • Otherwise pass the result to the next agent.

This makes the pipeline predictable and prevents downstream agents from working with incomplete data.

if classified_topic is None: return
Enter fullscreen mode Exit fullscreen mode

The same idea is repeated throughout the pipeline.

Research must return chunks.

Examples must return examples.

The Brief Agent must return a valid ContentBrief.

The Draft Agent must return two drafts.

If any step fails, we stop immediately instead of allowing later agents to produce unreliable output.

if len(research) == 0: return
Enter fullscreen mode Exit fullscreen mode

Once every agent succeeds, the final stage is the Writing Critic Agent.

Instead of generating more content, it evaluates both drafts, scores them across multiple dimensions, and recommends the stronger draft.

print("Scoring the drafts...")
scoring = rate_drafts(hooks, drafts)
Enter fullscreen mode Exit fullscreen mode

Putting everything together gives us the complete orchestration function.

def main(topic): 
   print("Classifying topic...") 
   classified_topic = classify_topic(topic) 
   if classified_topic is None: 
      print("Failed to classify topic") 
      return 
   print("Researching...") 
   research = research_agent(classified_topic) 
   if len(research) == 0: 
      print("Failed to research") 
      return 
   print("Fetching suitable examples...") 
   examples = get_examples(classified_topic, research) 
   if len(examples) == 0: 
      print("Failed to fetch examples") 
      return 
   print("Flagging mistakes...") 
   critic = be_critique(classified_topic, research, examples) 
   if len(critic) == 0: 
      print("Failed to flag mistakes") 
      return 
   print("Creating a brief...") 
   brief = create_brief(classified_topic, research, examples, critic)
   if brief is None: 
      print("Failed to create brief") 
      return 
   print("Generating 5 Hooks...") 
   hooks = generate_hooks(brief) 
   if len(hooks) < 3: 
      print("Failed to generate enough hooks") 
      return 
   print("Generating 2 drafts...") 
   drafts = generate_drafts(hooks, brief) 
   if len(drafts) == 0: 
      print("Failed to generate drafts") 
      return 
   print("Scoring the drafts...") 
   scoring = rate_drafts(hooks, drafts) 
   if scoring is None: 
      print("Failed to generate score") 
      return print(scoring) 
   print("Feel free to suggest any changes!")

   if __name__ == "__main__":
      topic = input("Enter your topic") main(topic)
Enter fullscreen mode Exit fullscreen mode

At this point, we've successfully wired every agent into a single end-to-end pipeline. From a single topic, the system can classify the request, gather research, find supporting examples, critique the evidence, build a structured brief, generate multiple hooks, write complete drafts, and score them automatically.

Right now, everything still runs from the terminal. In the next article, we'll expose this entire pipeline through a FastAPI backend, allowing any frontend application to generate LinkedIn posts with a single API request.

GitHub Repo: https://github.com/Manav-N4/linkedin-agent#linkedin-agent

Top comments (0)