Project: Messaging Assistant

Capstone four: an agent living in Telegram or Slack — personalized through memory, guarded at the boundary, monitored like production. The front door of everything you've built.

▶ Watch this reel

What you'll learn

  1. The bot surface
  2. Tools & memory
  3. Safety in a chat
  4. Deploy & monitor

Remember this

Surface

Tools & memory

Safety

Deploy & monitor

Code: The chat worker: loop + memory + gates, compact

async def handle_chat(job: ChatJob):
    user = users.for_platform(job.user_id)
    trust = user.trust_level(job.chat_type)      # known/unknown/group

    ctx = context.build(
        system=CHAT_SYSTEM,                      # untrusted-content rules
        memory=memory.recall(job.text, user.id,  # threshold-gated
                             k=4),
        recent=recent_turns(job.chat_id, cap=8_000),
    )
    async with budget(user.daily_budget.remaining()):
        result = await agent_loop(ctx, tools=tools_for(trust))

    if result.needs_confirmation:                # inline buttons
        await send_buttons(job.chat_id, result.preview,
                           [Send, Edit, Cancel])
        return

    await telegram.edit(job.placeholder, result.reply)
    await react_buttons(job.chat_id)             # 👍👎 feedback
    memory.consider_write(user.id, job.thread)   # end-of-thread gate