Questo contenuto non è ancora disponibile in una versione localizzata per Italy. Stai visualizzando la versione globale.

Visualizza pagina globale

Build AI Agents in 30 Minutes: The 90/10 Playbook for Python

Vibe Marketing••By 3L3C

Build AI agents fast with the 90/10 rule. Get a ≈50‑line Python example, a 5-part System Prompt, and a one-week launch checklist to ship before year-end.

AI agentsPydantic AIOpenRouterRAGSystem PromptLangfuseGuardrails AI
Share:

Featured image for Build AI Agents in 30 Minutes: The 90/10 Playbook for Python

November is crunch time. Budgets are closing, Black Friday is here, and teams are racing to ship meaningful wins before year-end. If you've been circling the idea of AI agents but stuck in analysis paralysis, this guide will help you ship something real—fast. We'll show you how to build AI agents with a simple 90/10 approach that delivers outsized impact in minutes, not months.

Here's the promise: focus on the 90% that matters—clear instructions, the right model, a couple of well-defined tools, and practical memory—and ignore the exotic 10% you don't need yet. You'll get a production-ready blueprint, a ≈50‑line Python example using Pydantic AI and OpenRouter, a five-part System Prompt template, and a lightweight stack for RAG, security, observability, and long-term memory.

Why the 90/10 Rule Wins for AI Agents

Most teams overcomplicate AI agents. They start with multi-agent swarms, advanced routing, or exotic vector databases before they've proven value. The 90/10 rule flips this: ship a single, capable agent that handles one job exceptionally well.

  • The simple 90% to focus on:

    • A single agent with a tight System Prompt
    • One small-but-mighty model via OpenRouter (e.g., a fast, cost-effective option)
    • 1–3 deterministic tools (search, summarize, calculate)
    • Basic Retrieval-Augmented Generation (RAG) from your docs
    • Guardrails that block unsafe requests
    • Observability to track quality, latency, and cost
  • The complex 10% to ignore (for now):

    • Multi-agent planning and hierarchical orchestration
    • Dynamic tool-learning and genetic tool selection
    • Custom embeddings research and model fine-tuning
    • Streaming pipelines with intricate retries and caching layers

When you lead with the 90%, you get ROI in days and real telemetry to inform v2. It's exactly the kind of quick win that helps teams lock in 2026 budgets this quarter.

The Four Core Components of an AI Agent

Every effective agent is four parts working in concert: Tools (hands), LLM (brain), System Prompt (instructions), and Memory (context).

1) Tools: The agent's hands

Tools are just safe, typed functions that do things models can't reliably do alone—query a database, call an API, run a calculation.

  • Start with deterministic utilities: search_docs, summarize, fetch_record, compute_price.
  • Keep inputs/outputs typed to reduce hallucinations and make logs useful.
  • Add only the tools you need to complete your primary workflow end-to-end.

2) LLM: The agent's brain

Pick a fast, reliable model accessible through OpenRouter so you can swap models without code upheaval. For most business workflows, a small or mid-tier model balances speed and cost. Upgrade only if telemetry shows a quality gap.

3) System Prompt: The instruction manual

Your System Prompt defines scope, tone, constraints, and when to use tools. This is where most wins are hiding. A tight prompt can outperform a larger model with a sloppy prompt.

4) Memory: The agent's context

Memory comes in two layers:

  • Short-term: the conversation and working notes
  • Long-term: RAG over your docs plus selective memory for recurring facts (customer preferences, past resolutions)

Start with RAG for domain grounding; add long-term memory only when the agent needs continuity beyond a single session.

A 50-Line Python Agent with Pydantic AI

Below is a compact example that shows the essentials: a typed tool, a clear System Prompt, and a single model via OpenRouter. Treat it as a skeleton you can adapt.

# ≈50 lines, illustrative
import os
from pydantic import BaseModel
from pydantic_ai import Agent, tool

# 1) Configure model via OpenRouter (swap models freely)
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
MODEL = "openrouter/anthropic/claude-3-haiku"

# 2) Typed tool: deterministic summarizer (placeholder logic)
class SummarizeInput(BaseModel):
    text: str
    words: int = 80

@tool
def summarize(inp: SummarizeInput) -> str:
    clean = " ".join(inp.text.split())
    # naive cutoff; replace with your summarization logic or API
    return clean[: inp.words * 6]

# 3) System Prompt: tight scope + rules + tool use
SYSTEM_PROMPT = """
Role: Focused research assistant for SMB owners.
Goals:
- Answer questions with evidence from provided context.
- Use tools when they improve accuracy or brevity.
Constraints:
- If unsure, ask a clarifying question before answering.
- Never fabricate data; prefer step-by-step reasoning.
Tools:
- summarize(text, words): compresses long passages.
Style:
- Clear, structured, bullet-first when helpful.
Output:
- Provide final answer + any assumptions.
"""

# 4) Initialize agent
agent = Agent(model=MODEL, system=SYSTEM_PROMPT, api_key=OPENROUTER_API_KEY)

# 5) Minimal runner with ephemeral memory (add RAG later)
def run(query: str, context: str = ""):
    memory = {"context": context}
    return agent.run(query, tools=[summarize], memory=memory)

if __name__ == "__main__":
    print(run("Summarize the key tax tips for Q4 sales.", context="...your docs..."))

What to customize next:

  • Replace the summarizer with real logic or a specialized endpoint.
  • Add a search_docs(query) tool that queries your vector store.
  • Swap models by changing the MODEL string—no other code required.

Write the Perfect System Prompt (5-Part Template)

Use this template to create a durable instruction manual for your agent. Drop it straight into your code and fill in the blanks.

  1. Role
  • Who is the agent for and what is its job?
  • Example: "You are a customer support triage agent for a SaaS billing team."
  1. Goals
  • What outcomes matter? What's in/out of scope?
  • Example bullets: resolve top-20 billing issues; escalate edge cases with a structured ticket.
  1. Constraints
  • Guardrails and decision rules that reduce risk and drift.
  • Example bullets: never change account data; if identity is unclear, ask for verification.
  1. Tools & When to Use Them
  • Enumerate tools and trigger conditions.
  • Example: use search_docs for policy questions; use summarize for long replies.
  1. Style & Output Contract
  • Tone, structure, and the schema of responses.
  • Example: respond with a short summary, numbered steps, and a JSON snippet of key fields.

Pro tip: Keep each section to 3–5 crisp bullets. If you need more, you likely need multiple, simpler agents instead of one mega-agent.

RAG, Security, Observability, Memory: The Essentials

You don't need a sprawling platform to be safe and reliable. Add these four building blocks early, but keep them simple.

Retrieval-Augmented Generation (RAG)

  • Start with one vector store collection per domain (Policies, Product, Pricing).
  • Chunk your docs sensibly (300–800 tokens) and embed with one consistent model.
  • At query time, retrieve top 5–8 passages; include titles and URLs in the context string (as plain text, no live links needed).
  • Log retrieval hits so you can see when answers lack evidence.

Security with Guardrails AI

  • Define allow/deny policies: PII handling, dangerous operations, off-topic filtering.
  • Add schema validation for tool inputs to block malformed or risky requests.
  • Include "refuse and explain" patterns in the System Prompt for disallowed actions.

Observability with Langfuse

  • Track: success rate (helpfulness), latency, token cost, and tool call count.
  • Add tags per request: customer_tier, use_case, model_version.
  • Review 10 transcripts/day; create a feedback loop to update prompts and tools weekly.

Long-Term Memory with Mem0

  • Store durable facts only: user preferences, account IDs, recurring constraints.
  • Use time-decay or confidence scores so stale memories expire.
  • Add a "memory disclosure" line in responses when a memory shaped the answer.

Fast-Track Launch Checklist (One-Week Plan)

Day 1: Define the job to be done

  • Pick one workflow with clear success criteria (e.g., "answer policy questions under 10 seconds with source citations").
  • Draft the 5-part System Prompt and create a success rubric.

Day 2: Build the minimal agent

  • Implement 1–2 tools.
  • Wire a small model via OpenRouter; confirm latency and cost.

Day 3: Add RAG

  • Embed 20–50 high-value docs and connect a search_docs tool.
  • Test on real questions; iterate your prompt.

Day 4: Guardrails

  • Enforce input schemas and allow/deny policies.
  • Add refusal patterns to the prompt.

Day 5: Observability

  • Instrument Langfuse events for every step.
  • Start a daily transcript review ritual.

Day 6: Memory

  • Add Mem0 for 1–2 durable facts; keep the schema minimal.

Day 7: UAT and handoff

  • Run 30–50 scripted tests and 10 live sessions.
  • Document playbooks and create a rollback plan.

Putting It All Together

The fastest path to value with AI agents is surprisingly simple: a sharp System Prompt, a reliable model, a couple of typed tools, pragmatic RAG, and lightweight safety and telemetry. With the 90/10 playbook, you can ship a credible pilot before year-end and gather real evidence to guide 2026 investments.

If you want a pressure-tested blueprint tailored to your stack, book a short working session with the Vibe Marketing team—we'll help you scope, build, and measure your first agent in days. What's the one workflow you could automate this week if an agent did it reliably end-to-end?