hashnode, perplexity (for research), and falai (for image generation) MCP applications. This is based on examples/blog.py.
Objective
Create an agent that, given a topic and Hashnode publication ID:- Researches the topic using a research tool (Perplexity).
- Generates blog post content (title, subtitle, main content, tags) in Markdown format, adhering to specific writing guidelines.
- Generates a suitable cover image for the blog post.
- Publishes the generated blog post with the cover image to the specified Hashnode publication.
Steps
-
Set up Applications:
Load
hashnode,perplexity, andfalaiapplications. -
Initialize LLM and ToolManager:
-
Register Tools:
Register all tools from the
blog_app(Hashnode) andresearch_app(Perplexity). For theimage_app, explicitly add itsgenerate_imagetool with a clear name. -
Get Tools in Langchain Format:
-
Create the Langchain Agent:
-
Define the Detailed Agent Task Prompt:
This prompt is crucial as it guides the LLM through the entire content creation and publishing workflow.
-
Invoke the Agent:
How It Works
The agent will execute a complex sequence:- Use a Perplexity tool (e.g.,
perplexity_search) to research the given topic. - The LLM synthesizes this research and its instructions to draft the blog post content (title, slug, content, tags).
- It then calls the
generate_cover_imagetool (from thefalaiapp) with a prompt derived from the blog topic/title to get an image URL. - Finally, it uses a Hashnode tool (e.g.,
hashnode_publish_post), providing the generated Markdown content, title, slug, tags, and the cover image URL to publish the post.