Build a Powerful AI Motivational Quote Generator in Python

Learn how to build a motivational quote generator using Python and AI agents. Step-by-step tutorial with streaming output, tool use, and real-time logic.

Feeling uninspired? What if you had your own personal quote generator—powered by AI—that could fire off motivational quotes whenever you need a boost? In this guide, you’ll build a powerful AI-based quote generator using Python, streaming real-time inspiration straight to your terminal.

In this guide, I’ll walk you through creating a Motivational Quote Generator using AI agents in Python. This quote generator works by combining agent-based decision logic with real-time output streaming. Whether you’re a developer looking to flex your async muscles or someone curious about how agent-based automation works, this one’s for you.


💡 What This AI Quote Generator Does

An AI-powered agent that:

  • Randomly decides how many motivational quotes you need
  • Pulls them from a (mocked or real) database
  • Streams the response one quote at a time
  • Is modular, extendable, and fun to use!

🛠️ Tools & Libraries Used

  • Python 3.8+
  • asyncio: For asynchronous event handling
  • random: To randomly select number of quotes
  • A simple Agent framework (like LangGraph, crewAI, or a custom one)
  • Custom modules: Agent, ItemHelpers, Runner, and function_tool

🚀 Step-by-Step Implementation

1. Setup the Tool Function

Start by creating a function that determines how many motivational quotes to serve. We use a decorator to register it as a tool:

@function_tool
def how_many_quotes() -> int:
return random.randint(1, 5)

This function mimics a real-world scenario where an agent can dynamically decide things based on logic or user input.


2. Create the Agent

Now define an Agent with specific instructions and tools.

agent = Agent(
name="Motivator",
instructions="First call the `how_many_quotes` tool, then provide that many motivational quotes.",
tools=[how_many_quotes],
)

This setup tells the agent:

“Hey Motivator, first figure out how many quotes to give, then serve up that many.”

The agent follows this logic autonomously.


3. How the Quote Generator Streams AI Output

Use an async function to run the agent and handle streamed events. This allows real-time updates as the agent works.

result = Runner.run_streamed(agent, input="I need motivation")

Then, we loop through each event to log outputs:

async for event in result.stream_events():
if event.type == "raw_response_event":
continue
elif event.type == "agent_updated_stream_event":
print(f"Agent updated: {event.new_agent.name}")
elif event.item.type == "tool_call_item":
print("-- Tool was called")
elif event.item.type == "tool_call_output_item":
quote_count = int(event.item.output)
print(f"-- Tool output: {quote_count}")
elif event.item.type == "message_output_item":
print(f"-- Message output:\n {ItemHelpers.text_message_output(event.item)}")

This stream-based design is scalable and great for real-time systems (think chatbots, APIs, or even motivational apps!).


4. Run Everything

Wrap the logic in a main async entry point and trigger it:

if __name__ == "__main__":
asyncio.run(main())

Done. Now every time you run the script, it will:

  1. Ask the tool how many quotes to deliver.
  2. Print that many motivational quotes (currently mocked or scripted).
  3. Stream results in real time.

📦 Sample Output

Here’s what running it might look like:

=== Run starting ===
-- Tool was called
-- Tool output: 3
-- Message output:
"Believe you can and you're halfway there."
-- Message output:
"Don’t watch the clock; do what it does. Keep going."
-- Message output:
"Everything you can imagine is real."
=== Run complete ===

🔄 Upgrade Your Quote Generator with More AI Power

Want to make it smarter? Here’s how:

  • Replace random.randint with a GPT tool call to personalize quote count
  • Add a real quote API (like ZenQuotes or Type.fit)
  • Add emotional context detection from user input
  • Deploy via FastAPI or integrate with Slack/Telegram bots

📊 Feature Table

FeatureStatusDescription
Randomized quote countUses a tool to decide 1–5 quotes
Agent logic executionAI agent follows multi-step instructions
Streaming outputQuotes delivered one by one in real-time
ExtendabilityModular for APIs, UI, or advanced logic

🧠 Why It Matters

Using agent-based automation lets you simulate real decision-making, adding nuance and personalization. This isn’t just about quotes—this is about how AI can automate soft skills like motivation and empathy.

And if an AI can uplift your day… imagine what else it can do.


🙌 Final Thoughts

Building this quote generator is a small but powerful peek into how intelligent agents can be used for more than just number crunching—they can inspire, entertain, and emotionally connect.

So go ahead—build your own motivator bot. Your future self will thank you for the boost.


📣 Call-to-Action

If you enjoyed this guide or want to explore building agentic AI solutions for your business, contact Ossels AI — we specialize in bringing AI to life through smart automation.

Or, explore more on the Ossels AI Blog for tutorials, tools, and trends!

Posted by Ananya Rajeev

Ananya Rajeev is a Kerala-born data scientist and AI enthusiast who simplifies generative and agentic AI for curious minds. B.Tech grad, code lover, and storyteller at heart.