PTENES
MODULE 4.3

βš™ Automation and Webhooks

Cron, Heartbeat, webhooks with n8n, sub-agents, and TinyClaw multi-agent.

6
Topics
60
Minutes
Interm.
Level
Advanced
Type
1

πŸ• Cron Scheduling

cron.py turns Jarvis from reactive to proactive. Scheduled tasks in standard cron format with automatic error recovery.

πŸ“Œ Scheduled Task Examples

  • β€’0 9 * * 1-5 β†’ daily pending items report at 9 a.m. (weekdays)
  • β€’*/30 * * * * β†’ check for important emails every 30min
  • β€’0 18 * * 5 β†’ weekly summary every Friday at 6 p.m.
  • β€’0 0 * * 0 β†’ back up memory.db every Sunday at midnight
  • β€’*/5 * * * * β†’ heartbeat for critical services every 5min

πŸ’‘ Practical Tip

Avoid schedules that run too frequently with expensive models. A heartbeat every 5min with GPT-4o costs ~R$50/day. Use inexpensive models for periodic checks.

2

πŸ’“ Heartbeat β€” Active Monitoring

Heartbeat is Jarvis’s nervous system. Configurable periodic checks that proactively alert you when something is out of the ordinary.

πŸ“Œ What the Heartbeat Monitors

  • β€’Critical service APIs: status code != 200 β†’ alert
  • β€’Memory usage: memory.db > 100MB β†’ compact
  • β€’Daily API cost: > threshold β†’ alert and throttle
  • β€’Important files: did the hash change? β†’ possible compromise
  • β€’Jarvis's own uptime: response timeout β†’ auto-restart

πŸ’‘ Practical Tip

Set up heartbeats at multiple intervals: fast (5min) for critical services, slow (1h) for non-urgent checks. Balance cost vs. responsiveness.

3

πŸ”— Webhooks with n8n and Zapier

Webhooks connect Jarvis to the existing automation ecosystem. n8n, Zapier, Make.com can trigger Jarvis actions via HTTP.

πŸ“Œ Webhook Integration Flow

  • β€’n8n detects a new lead in the CRM β†’ POST to /webhook/new-lead
  • β€’Jarvis receives an event, analyzes it with an LLM, and generates a personalized email
  • β€’Jarvis calls GmailTool to send an email to the lead
  • β€’Jarvis updates the CRM via API with the action result
  • β€’Audit log records the entire chain

πŸ’‘ Practical Tip

Always validate the webhook’s HMAC signature before processing. Unauthenticated webhooks are vulnerable to replay attacks and spam.

4

πŸ€– Background Sub-Agents

Sub-agents enable true parallelism. The main Jarvis creates sub-agents for long-running tasks without blocking the main conversation.

πŸ“Œ Sub-Agent Use Cases

  • β€’Large repository analysis: a sub-agent scans and indexes while the main agent talks
  • β€’Extensive web research: 3 sub-agents research in parallel, the main agent aggregates
  • β€’Report compilation: sub-agent collects data, primary agent formats and sends it
  • β€’Continuous monitoring: sub-agent monitors in a loop, main agent receives alerts
  • β€’Deploy pipeline: a sub-agent executes steps, the main agent reports progress

πŸ’‘ Practical Tip

Limit the number of simultaneous sub-agents (recommended: max 5). Each sub-agent consumes tokens and incurs costs. Use an agent pool for reuse.

5

🀝 TinyClaw Multi-Agents

TinyClaw is the standard for INTELECTO agent teams. Specialized agents collaborate passing work among themselves with defined roles.

πŸ“Œ Common Roles in TinyClaw

  • β€’@coder: generates code and tests based on the spec
  • β€’@reviewer: analyzes generated code for bugs and style
  • β€’@writer: documents the code and generates a changelog
  • β€’@deployer: runs deploy scripts with approval
  • β€’@orchestrator: coordinates work among the other agents

πŸ’‘ Practical Tip

Each TinyClaw agent has a specialized SOUL.md. @reviewer is deliberately critical; @coder focuses on functionality; @writer prioritizes clarity.

6

πŸ“Š System Observability

Without observability, optimization is guesswork. metrics.py collects latency, cost, errors, and real-time tool usage.

πŸ“Œ Collected Metrics

  • β€’Latency per request: p50, p95, p99 in ms
  • β€’Tokens per request: input + output + cost in USD
  • β€’Tool calls: frequency and success rate per tool
  • β€’Error rate: by error type and provider
  • β€’Agent loop depth: distribution of rounds used per conversation

πŸ’‘ Practical Tip

Export metrics to a dashboard via the /metrics endpoint. Grafana + Prometheus, or just a simple endpoint that Jarvis reads when asked.

βœ… Module 4.3 Summary

βœ“
Cron Scheduling β€” Standard cron format, asyncio scheduler, automatic error recovery
βœ“
Heartbeat β€” Active Monitoring β€” Configurable checks with proactive alerts β€” monitoring without an external SIEM
βœ“
Webhooks with n8n and Zapier β€” HTTP endpoints with HMAC auth β€” integration with any automation platform
βœ“
Background Sub-Agents β€” True parallelism with asyncio tasks β€” long-running tasks without blocking conversations
βœ“
TinyClaw Multi-Agents β€” Specialized agents with their own SOUL.md β€” complex pipelines without orchestration code
βœ“
System Observability β€” Latency, cost, errors, and tool usage β€” data for guided optimization

Next:

Track 5: Architectures